diff options
Diffstat (limited to 'src/systems/realizing.cpp')
| -rw-r--r-- | src/systems/realizing.cpp | 66 |
1 files changed, 42 insertions, 24 deletions
| diff --git a/src/systems/realizing.cpp b/src/systems/realizing.cpp index 28e2279..2ee5897 100644 --- a/src/systems/realizing.cpp +++ b/src/systems/realizing.cpp | |||
| @@ -12,11 +12,11 @@ | |||
| 12 | #include "components/playable.h" | 12 | #include "components/playable.h" |
| 13 | #include "components/ponderable.h" | 13 | #include "components/ponderable.h" |
| 14 | #include "components/transformable.h" | 14 | #include "components/transformable.h" |
| 15 | #include "components/automatable.h" | 15 | #include "components/prototypable.h" |
| 16 | #include "systems/mapping.h" | 16 | #include "systems/mapping.h" |
| 17 | #include "systems/animating.h" | 17 | #include "systems/animating.h" |
| 18 | #include "systems/pondering.h" | 18 | #include "systems/pondering.h" |
| 19 | #include "systems/automating.h" | 19 | #include "systems/scripting.h" |
| 20 | 20 | ||
| 21 | inline xmlChar* getProp(xmlNodePtr node, const char* attr) | 21 | inline xmlChar* getProp(xmlNodePtr node, const char* attr) |
| 22 | { | 22 | { |
| @@ -40,9 +40,6 @@ EntityManager::id_type RealizingSystem::initSingleton( | |||
| 40 | auto& realizable = game_.getEntityManager(). | 40 | auto& realizable = game_.getEntityManager(). |
| 41 | emplaceComponent<RealizableComponent>(world); | 41 | emplaceComponent<RealizableComponent>(world); |
| 42 | 42 | ||
| 43 | game_.getSystemManager().getSystem<AutomatingSystem>(). | ||
| 44 | initScriptEngine(realizable.scriptEngine); | ||
| 45 | |||
| 46 | realizable.worldFile = worldFile; | 43 | realizable.worldFile = worldFile; |
| 47 | realizable.prototypeFile = prototypeFile; | 44 | realizable.prototypeFile = prototypeFile; |
| 48 | 45 | ||
| @@ -216,14 +213,28 @@ EntityManager::id_type RealizingSystem::initSingleton( | |||
| 216 | game_.getSystemManager().getSystem<PonderingSystem>(). | 213 | game_.getSystemManager().getSystem<PonderingSystem>(). |
| 217 | initializeBody(mapObject, PonderableComponent::Type::vacuumed); | 214 | initializeBody(mapObject, PonderableComponent::Type::vacuumed); |
| 218 | 215 | ||
| 216 | |||
| 217 | |||
| 218 | |||
| 219 | |||
| 220 | auto& prototypable = game_.getEntityManager(). | ||
| 221 | emplaceComponent<PrototypableComponent>(mapObject); | ||
| 222 | |||
| 223 | prototypable.prototypeId = prototypeId; | ||
| 224 | |||
| 225 | key = getProp(mapNode, "index"); | ||
| 226 | prototypable.mapObjectIndex = atoi(reinterpret_cast<char*>(key)); | ||
| 227 | xmlFree(key); | ||
| 228 | |||
| 219 | if (prototypeId == "movplat") | 229 | if (prototypeId == "movplat") |
| 220 | { | 230 | { |
| 221 | auto& automatable = game_.getEntityManager(). | 231 | prototypable.hasBehavior = true; |
| 222 | emplaceComponent<AutomatableComponent>(mapObject); | 232 | } else if (prototypeId == "checkpoint") |
| 223 | 233 | { | |
| 234 | auto& ponderable = game_.getEntityManager(). | ||
| 235 | getComponent<PonderableComponent>(mapObject); | ||
| 224 | 236 | ||
| 225 | realizable.scriptEngine.script_file( | 237 | ponderable.colliderType = PonderableComponent::Collision::event; |
| 226 | "res/platform.lua");//, | ||
| 227 | } | 238 | } |
| 228 | 239 | ||
| 229 | mappable.objects.push_back(mapObject); | 240 | mappable.objects.push_back(mapObject); |
| @@ -319,7 +330,6 @@ void RealizingSystem::loadMap(id_type mapEntity) | |||
| 319 | 330 | ||
| 320 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); | 331 | auto& animating = game_.getSystemManager().getSystem<AnimatingSystem>(); |
| 321 | auto& pondering = game_.getSystemManager().getSystem<PonderingSystem>(); | 332 | auto& pondering = game_.getSystemManager().getSystem<PonderingSystem>(); |
| 322 | auto& automating = game_.getSystemManager().getSystem<AutomatingSystem>(); | ||
| 323 | 333 | ||
| 324 | std::set<id_type> players = | 334 | std::set<id_type> players = |
| 325 | game_.getEntityManager().getEntitiesWithComponents< | 335 | game_.getEntityManager().getEntitiesWithComponents< |
| @@ -380,11 +390,6 @@ void RealizingSystem::loadMap(id_type mapEntity) | |||
| 380 | pondering.initPrototype(prototype); | 390 | pondering.initPrototype(prototype); |
| 381 | } | 391 | } |
| 382 | 392 | ||
| 383 | if (game_.getEntityManager().hasComponent<AutomatableComponent>(prototype)) | ||
| 384 | { | ||
| 385 | automating.initPrototype(prototype); | ||
| 386 | } | ||
| 387 | |||
| 388 | enterActiveMap(prototype); | 393 | enterActiveMap(prototype); |
| 389 | } | 394 | } |
| 390 | 395 | ||
| @@ -419,12 +424,19 @@ void RealizingSystem::enterActiveMap(id_type entity) | |||
| 419 | ponderable.active = true; | 424 | ponderable.active = true; |
| 420 | } | 425 | } |
| 421 | 426 | ||
| 422 | if (game_.getEntityManager().hasComponent<AutomatableComponent>(entity)) | 427 | if (game_.getEntityManager().hasComponent<PrototypableComponent>(entity)) |
| 423 | { | 428 | { |
| 424 | auto& automatable = game_.getEntityManager(). | 429 | auto& prototypable = game_.getEntityManager(). |
| 425 | getComponent<AutomatableComponent>(entity); | 430 | getComponent<PrototypableComponent>(entity); |
| 431 | |||
| 432 | if (prototypable.hasBehavior) | ||
| 433 | { | ||
| 434 | auto& scripting = game_.getSystemManager().getSystem<ScriptingSystem>(); | ||
| 426 | 435 | ||
| 427 | automatable.active = true; | 436 | prototypable.hasBehavior = true; |
| 437 | prototypable.runningBehavior = true; | ||
| 438 | prototypable.behaviorScript = scripting.runBehaviorScript(entity); | ||
| 439 | } | ||
| 428 | } | 440 | } |
| 429 | } | 441 | } |
| 430 | 442 | ||
| @@ -446,11 +458,17 @@ void RealizingSystem::leaveActiveMap(id_type entity) | |||
| 446 | ponderable.active = false; | 458 | ponderable.active = false; |
| 447 | } | 459 | } |
| 448 | 460 | ||
| 449 | if (game_.getEntityManager().hasComponent<AutomatableComponent>(entity)) | 461 | if (game_.getEntityManager().hasComponent<PrototypableComponent>(entity)) |
| 450 | { | 462 | { |
| 451 | auto& automatable = game_.getEntityManager(). | 463 | auto& prototypable = game_.getEntityManager(). |
| 452 | getComponent<AutomatableComponent>(entity); | 464 | getComponent<PrototypableComponent>(entity); |
| 453 | 465 | ||
| 454 | automatable.active = false; | 466 | if (prototypable.runningBehavior) |
| 467 | { | ||
| 468 | auto& scripting = game_.getSystemManager().getSystem<ScriptingSystem>(); | ||
| 469 | scripting.killScript(prototypable.behaviorScript); | ||
| 470 | |||
| 471 | prototypable.runningBehavior = false; | ||
| 472 | } | ||
| 455 | } | 473 | } |
| 456 | } | 474 | } |
