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/components/runnable.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/components/runnable.h') diff --git a/src/components/runnable.h b/src/components/runnable.h index 1b994fb..956bfdc 100644 --- a/src/components/runnable.h +++ b/src/components/runnable.h @@ -4,12 +4,48 @@ #include "component.h" #include #include +#include "entity_manager.h" class RunnableComponent : public Component { public: + using id_type = EntityManager::id_type; + + /** + * A Lua stack where the entity's script is running. + * + * NOTE: This object is called a thread, but there is no multi-threading going + * on. + * + * @managed_by ScriptingSystem + */ std::unique_ptr runner; + + /** + * An entry point to the script running in the runner thread. + * + * @managed_by ScriptingSystem + */ std::unique_ptr callable; + + /** + * Whether or not this entity represents a behavior script. A behavior script + * usually does not terminate on its own, and can be terminated at will by + * another system, usually when the automatable entity leaves the active map. + * + * @managed_by ScriptingSystem + */ + bool behavior = false; + + /** + * If this is a behavior script, this is the ID of the automatable entity that + * the behavior belongs to. This is required so that the ScriptingSystem can + * notify the automatable entity if the behavior script terminates by itself, + * and that it shouldn't attempt to terminate it. + * + * @managed_by ScriptingSystem + */ + id_type actor; }; #endif /* end of include guard: AUTOMATABLE_H_3D519131 */ -- cgit 1.4.1