summary refs log tree commit diff stats
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/automatable.h34
-rw-r--r--src/components/prototypable.h11
-rw-r--r--src/components/runnable.h36
3 files changed, 76 insertions, 5 deletions
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 @@
1#ifndef AUTOMATABLE_H_FACB42A5
2#define AUTOMATABLE_H_FACB42A5
3
4#include "component.h"
5#include "entity_manager.h"
6
7class AutomatableComponent : public Component {
8public:
9
10 using id_type = EntityManager::id_type;
11
12 /**
13 * Controls what script will be run as this entity's behavior. It should refer
14 * to a table in the global namespace of the script engine state, and that
15 * table should contain a function called "Behavior".
16 */
17 std::string table;
18
19 /**
20 * Whether or not the behavior script is running.
21 *
22 * @managed_by ScriptingSystem
23 */
24 bool running = false;
25
26 /**
27 * The entity ID of the running script, if there is one.
28 *
29 * @managed_by ScriptingSystem
30 */
31 id_type script;
32};
33
34#endif /* end of include guard: AUTOMATABLE_H_FACB42A5 */
diff --git a/src/components/prototypable.h b/src/components/prototypable.h index 4659e7c..c0dd972 100644 --- a/src/components/prototypable.h +++ b/src/components/prototypable.h
@@ -9,14 +9,15 @@ public:
9 9
10 using id_type = EntityManager::id_type; 10 using id_type = EntityManager::id_type;
11 11
12 /**
13 * The index of the object in the map definition.
14 */
12 size_t mapObjectIndex; 15 size_t mapObjectIndex;
13 16
17 /**
18 * The name of the prototype that the object was spawned from.
19 */
14 std::string prototypeId; 20 std::string prototypeId;
15
16 bool hasBehavior = false;
17 bool runningBehavior = false;
18
19 id_type behaviorScript;
20}; 21};
21 22
22#endif /* end of include guard: PROTOTYPABLE_H_817F2205 */ 23#endif /* end of include guard: PROTOTYPABLE_H_817F2205 */
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 */