summary refs log tree commit diff stats
path: root/src/components/runnable.h
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/components/runnable.h
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/components/runnable.h')
-rw-r--r--src/components/runnable.h36
1 files changed, 36 insertions, 0 deletions
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 @@
4#include "component.h" 4#include "component.h"
5#include <sol.hpp> 5#include <sol.hpp>
6#include <memory> 6#include <memory>
7#include "entity_manager.h"
7 8
8class RunnableComponent : public Component { 9class RunnableComponent : public Component {
9public: 10public:
10 11
12 using id_type = EntityManager::id_type;
13
14 /**
15 * A Lua stack where the entity's script is running.
16 *
17 * NOTE: This object is called a thread, but there is no multi-threading going
18 * on.
19 *
20 * @managed_by ScriptingSystem
21 */
11 std::unique_ptr<sol::thread> runner; 22 std::unique_ptr<sol::thread> runner;
23
24 /**
25 * An entry point to the script running in the runner thread.
26 *
27 * @managed_by ScriptingSystem
28 */
12 std::unique_ptr<sol::coroutine> callable; 29 std::unique_ptr<sol::coroutine> callable;
30
31 /**
32 * Whether or not this entity represents a behavior script. A behavior script
33 * usually does not terminate on its own, and can be terminated at will by
34 * another system, usually when the automatable entity leaves the active map.
35 *
36 * @managed_by ScriptingSystem
37 */
38 bool behavior = false;
39
40 /**
41 * If this is a behavior script, this is the ID of the automatable entity that
42 * the behavior belongs to. This is required so that the ScriptingSystem can
43 * notify the automatable entity if the behavior script terminates by itself,
44 * and that it shouldn't attempt to terminate it.
45 *
46 * @managed_by ScriptingSystem
47 */
48 id_type actor;
13}; 49};
14 50
15#endif /* end of include guard: AUTOMATABLE_H_3D519131 */ 51#endif /* end of include guard: AUTOMATABLE_H_3D519131 */