summary refs log tree commit diff stats
path: root/src/systems/realizing.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-14 18:40:54 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-17 15:39:39 -0400
commit5e48cf6333aca7af6854d79194f138d57ce0b5e1 (patch)
treeb1703c6268b762a04a101f35188163fe2d9feb45 /src/systems/realizing.cpp
parent046ee24a341468e9b3ea2983a731dbce18b52ac6 (diff)
downloadtherapy-5e48cf6333aca7af6854d79194f138d57ce0b5e1.tar.gz
therapy-5e48cf6333aca7af6854d79194f138d57ce0b5e1.tar.bz2
therapy-5e48cf6333aca7af6854d79194f138d57ce0b5e1.zip
Specialized treatment of behavior scripts
The AutomatableComponent now links to the Runnable entity representing the behavior script.

Also reordered the SystemManager and EntityManager members of the Game class such that the EntityManager is destroyed before the SystemManager is. This fixes a bug where the destruction of a component has some affect on the state of a system. Specifically, if the ScriptingSystem (and thus the Lua state) is destroyed before the EntityManager is and there are any Runnable entities, the game will crash when trying to destroy them.
Diffstat (limited to 'src/systems/realizing.cpp')
-rw-r--r--src/systems/realizing.cpp33
1 files changed, 9 insertions, 24 deletions
diff --git a/src/systems/realizing.cpp b/src/systems/realizing.cpp index 7f5aefb..baacf5a 100644 --- a/src/systems/realizing.cpp +++ b/src/systems/realizing.cpp
@@ -12,6 +12,7 @@
12#include "components/ponderable.h" 12#include "components/ponderable.h"
13#include "components/transformable.h" 13#include "components/transformable.h"
14#include "components/prototypable.h" 14#include "components/prototypable.h"
15#include "components/automatable.h"
15#include "systems/mapping.h" 16#include "systems/mapping.h"
16#include "systems/animating.h" 17#include "systems/animating.h"
17#include "systems/pondering.h" 18#include "systems/pondering.h"
@@ -223,7 +224,10 @@ RealizingSystem::RealizingSystem(
223 224
224 if (prototypeId == "movplat") 225 if (prototypeId == "movplat")
225 { 226 {
226 prototypable.hasBehavior = true; 227 auto& automatable = game_.getEntityManager().
228 emplaceComponent<AutomatableComponent>(mapObject);
229
230 automatable.table = prototypeId;
227 } else if (prototypeId == "checkpoint") 231 } else if (prototypeId == "checkpoint")
228 { 232 {
229 auto& ponderable = game_.getEntityManager(). 233 auto& ponderable = game_.getEntityManager().
@@ -403,19 +407,9 @@ void RealizingSystem::enterActiveMap(id_type entity)
403 ponderable.active = true; 407 ponderable.active = true;
404 } 408 }
405 409
406 if (game_.getEntityManager().hasComponent<PrototypableComponent>(entity)) 410 if (game_.getEntityManager().hasComponent<AutomatableComponent>(entity))
407 { 411 {
408 auto& prototypable = game_.getEntityManager(). 412 game_.getSystemManager().getSystem<ScriptingSystem>().startBehavior(entity);
409 getComponent<PrototypableComponent>(entity);
410
411 if (prototypable.hasBehavior)
412 {
413 auto& scripting = game_.getSystemManager().getSystem<ScriptingSystem>();
414
415 prototypable.hasBehavior = true;
416 prototypable.runningBehavior = true;
417 prototypable.behaviorScript = scripting.runBehaviorScript(entity);
418 }
419 } 413 }
420} 414}
421 415
@@ -437,17 +431,8 @@ void RealizingSystem::leaveActiveMap(id_type entity)
437 ponderable.active = false; 431 ponderable.active = false;
438 } 432 }
439 433
440 if (game_.getEntityManager().hasComponent<PrototypableComponent>(entity)) 434 if (game_.getEntityManager().hasComponent<AutomatableComponent>(entity))
441 { 435 {
442 auto& prototypable = game_.getEntityManager(). 436 game_.getSystemManager().getSystem<ScriptingSystem>().stopBehavior(entity);
443 getComponent<PrototypableComponent>(entity);
444
445 if (prototypable.runningBehavior)
446 {
447 auto& scripting = game_.getSystemManager().getSystem<ScriptingSystem>();
448 scripting.killScript(prototypable.behaviorScript);
449
450 prototypable.runningBehavior = false;
451 }
452 } 437 }
453} 438}