From 4bbfeae42a1245b1b84e8847787d7643e6a6f2cf Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 10 May 2018 19:27:59 -0400 Subject: 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. --- src/components/automatable.h | 81 +++----------------------------------------- src/components/realizable.h | 3 ++ 2 files changed, 8 insertions(+), 76 deletions(-) (limited to 'src/components') 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 @@ #define AUTOMATABLE_H_3D519131 #include "component.h" -#include -#include -#include "vector.h" +#include +#include class AutomatableComponent : public Component { public: - /** - * Helper class that defines an automatable action. - */ - class Action { - public: - - /** - * The horizontal and vertical speed, in pixels/sec, that the entity should - * move at. - */ - vec2d speed; - - /** - * The duration of the action in seconds. - */ - double dur; - }; - - /** - * Helper type that defines a behavior that an entity can exhibit, which is a - * list of actions that are stepped through in sequence. - */ - using Behavior = std::vector; - - /** - * A group of behaviors that the entity can exhibit, which are picked at - * random at the start of automation and whenever a behavior completes. - * - * @managed_by RealizingSystem - */ - std::vector behaviors; - - /** - * A random distribution over the above behaviors. - * - * @managed_by RealizingSystem - */ - std::discrete_distribution behaviorDist; - - /** - * A flag indicating whether a behavior is currently executing. - * - * @managed_by AutomatingSystem - */ - bool behaviorRunning = false; - - /** - * A flag indicating whether an action is currently executing. - * - * @managed_by AutomatingSystem - */ - bool actionRunning = false; - - /** - * The index of the currently executing behavior, if there is one. - * - * @managed_by AutomatingSystem - */ - size_t currentBehavior; + std::unique_ptr runner; + std::unique_ptr behavior; - /** - * The index of the currently executing action, if there is one. - * - * @managed_by AutomatingSystem - */ - size_t currentAction; - - /** - * The amount of time remaining, in seconds, of the currently executing - * action. - * - * @managed_by AutomatingSystem - */ - double remaining; + sol::environment origBehavior; /** * 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 @@ #include "component.h" #include #include +#include #include "entity_manager.h" #include "vector.h" @@ -69,6 +70,8 @@ public: * The entity ID of the currently active player. */ id_type activePlayer; + + sol::state scriptEngine; }; #endif /* end of include guard: REALIZABLE_H_36D8D71E */ -- cgit 1.4.1