From 5e48cf6333aca7af6854d79194f138d57ce0b5e1 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 14 May 2018 18:40:54 -0400 Subject: 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. --- src/systems/realizing.cpp | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) (limited to 'src/systems/realizing.cpp') 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 @@ #include "components/ponderable.h" #include "components/transformable.h" #include "components/prototypable.h" +#include "components/automatable.h" #include "systems/mapping.h" #include "systems/animating.h" #include "systems/pondering.h" @@ -223,7 +224,10 @@ RealizingSystem::RealizingSystem( if (prototypeId == "movplat") { - prototypable.hasBehavior = true; + auto& automatable = game_.getEntityManager(). + emplaceComponent(mapObject); + + automatable.table = prototypeId; } else if (prototypeId == "checkpoint") { auto& ponderable = game_.getEntityManager(). @@ -403,19 +407,9 @@ void RealizingSystem::enterActiveMap(id_type entity) ponderable.active = true; } - if (game_.getEntityManager().hasComponent(entity)) + if (game_.getEntityManager().hasComponent(entity)) { - auto& prototypable = game_.getEntityManager(). - getComponent(entity); - - if (prototypable.hasBehavior) - { - auto& scripting = game_.getSystemManager().getSystem(); - - prototypable.hasBehavior = true; - prototypable.runningBehavior = true; - prototypable.behaviorScript = scripting.runBehaviorScript(entity); - } + game_.getSystemManager().getSystem().startBehavior(entity); } } @@ -437,17 +431,8 @@ void RealizingSystem::leaveActiveMap(id_type entity) ponderable.active = false; } - if (game_.getEntityManager().hasComponent(entity)) + if (game_.getEntityManager().hasComponent(entity)) { - auto& prototypable = game_.getEntityManager(). - getComponent(entity); - - if (prototypable.runningBehavior) - { - auto& scripting = game_.getSystemManager().getSystem(); - scripting.killScript(prototypable.behaviorScript); - - prototypable.runningBehavior = false; - } + game_.getSystemManager().getSystem().stopBehavior(entity); } } -- cgit 1.4.1