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/automatable.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/components/automatable.h (limited to 'src/components/automatable.h') diff --git a/src/components/automatable.h b/src/components/automatable.h new file mode 100644 index 0000000..22d9859 --- /dev/null +++ b/src/components/automatable.h @@ -0,0 +1,34 @@ +#ifndef AUTOMATABLE_H_FACB42A5 +#define AUTOMATABLE_H_FACB42A5 + +#include "component.h" +#include "entity_manager.h" + +class AutomatableComponent : public Component { +public: + + using id_type = EntityManager::id_type; + + /** + * Controls what script will be run as this entity's behavior. It should refer + * to a table in the global namespace of the script engine state, and that + * table should contain a function called "Behavior". + */ + std::string table; + + /** + * Whether or not the behavior script is running. + * + * @managed_by ScriptingSystem + */ + bool running = false; + + /** + * The entity ID of the running script, if there is one. + * + * @managed_by ScriptingSystem + */ + id_type script; +}; + +#endif /* end of include guard: AUTOMATABLE_H_FACB42A5 */ -- cgit 1.4.1