summary refs log tree commit diff stats
path: root/src/components
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-10 19:27:59 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-17 15:39:39 -0400
commit4bbfeae42a1245b1b84e8847787d7643e6a6f2cf (patch)
tree8dd65d9ab0cfffd0e79f670c94b035c5eebfa934 /src/components
parent67b24a8ddd89371cfb944c5b441c852f0edc23b1 (diff)
downloadtherapy-4bbfeae42a1245b1b84e8847787d7643e6a6f2cf.tar.gz
therapy-4bbfeae42a1245b1b84e8847787d7643e6a6f2cf.tar.bz2
therapy-4bbfeae42a1245b1b84e8847787d7643e6a6f2cf.zip
Started integrating Lua as a scripting engine
Currently moving platforms are able to have their movement controlled by a script rather than by XML, which is probably a better implementation and scales better to other things. The scripts, instead of using the components as state, use the stack as state. In this way, they pretend to be multithreaded. For instance, the moving platform calls moveRight and then moveLeft. Both of those functions internally make calls that say to wait until the next tick. When the AutomatingSystem ticks, it continues execution of all scripts (sequentially, of course) until they ask for the next tick again. This is implemented using coroutines.
Diffstat (limited to 'src/components')
-rw-r--r--src/components/automatable.h81
-rw-r--r--src/components/realizable.h3
2 files changed, 8 insertions, 76 deletions
diff --git a/src/components/automatable.h b/src/components/automatable.h index c1fd1a3..d30340a 100644 --- a/src/components/automatable.h +++ b/src/components/automatable.h
@@ -2,87 +2,16 @@
2#define AUTOMATABLE_H_3D519131 2#define AUTOMATABLE_H_3D519131
3 3
4#include "component.h" 4#include "component.h"
5#include <vector> 5#include <sol.hpp>
6#include <random> 6#include <memory>
7#include "vector.h"
8 7
9class AutomatableComponent : public Component { 8class AutomatableComponent : public Component {
10public: 9public:
11 10
12 /** 11 std::unique_ptr<sol::thread> runner;
13 * Helper class that defines an automatable action. 12 std::unique_ptr<sol::coroutine> behavior;
14 */
15 class Action {
16 public:
17
18 /**
19 * The horizontal and vertical speed, in pixels/sec, that the entity should
20 * move at.
21 */
22 vec2d speed;
23
24 /**
25 * The duration of the action in seconds.
26 */
27 double dur;
28 };
29
30 /**
31 * Helper type that defines a behavior that an entity can exhibit, which is a
32 * list of actions that are stepped through in sequence.
33 */
34 using Behavior = std::vector<Action>;
35
36 /**
37 * A group of behaviors that the entity can exhibit, which are picked at
38 * random at the start of automation and whenever a behavior completes.
39 *
40 * @managed_by RealizingSystem
41 */
42 std::vector<Behavior> behaviors;
43
44 /**
45 * A random distribution over the above behaviors.
46 *
47 * @managed_by RealizingSystem
48 */
49 std::discrete_distribution<size_t> behaviorDist;
50
51 /**
52 * A flag indicating whether a behavior is currently executing.
53 *
54 * @managed_by AutomatingSystem
55 */
56 bool behaviorRunning = false;
57
58 /**
59 * A flag indicating whether an action is currently executing.
60 *
61 * @managed_by AutomatingSystem
62 */
63 bool actionRunning = false;
64
65 /**
66 * The index of the currently executing behavior, if there is one.
67 *
68 * @managed_by AutomatingSystem
69 */
70 size_t currentBehavior;
71 13
72 /** 14 sol::environment origBehavior;
73 * The index of the currently executing action, if there is one.
74 *
75 * @managed_by AutomatingSystem
76 */
77 size_t currentAction;
78
79 /**
80 * The amount of time remaining, in seconds, of the currently executing
81 * action.
82 *
83 * @managed_by AutomatingSystem
84 */
85 double remaining;
86 15
87 /** 16 /**
88 * If this flag is disabled, the entity will be ignored by the automating 17 * If this flag is disabled, the entity will be ignored by the automating
diff --git a/src/components/realizable.h b/src/components/realizable.h index b749aeb..bc834a2 100644 --- a/src/components/realizable.h +++ b/src/components/realizable.h
@@ -4,6 +4,7 @@
4#include "component.h" 4#include "component.h"
5#include <set> 5#include <set>
6#include <map> 6#include <map>
7#include <sol.hpp>
7#include "entity_manager.h" 8#include "entity_manager.h"
8#include "vector.h" 9#include "vector.h"
9 10
@@ -69,6 +70,8 @@ public:
69 * The entity ID of the currently active player. 70 * The entity ID of the currently active player.
70 */ 71 */
71 id_type activePlayer; 72 id_type activePlayer;
73
74 sol::state scriptEngine;
72}; 75};
73 76
74#endif /* end of include guard: REALIZABLE_H_36D8D71E */ 77#endif /* end of include guard: REALIZABLE_H_36D8D71E */