From 324346a87c114f0991a092ac8653afecada364b5 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 5 Jul 2021 11:58:29 -0400 Subject: Added background scripts Background scripts are scripts that are launched when a map is loaded. They differ in use from a map's init script in that they are expected to contain an infinite loop. These scripts are linked to a sprite and will be killed when that sprite is destroyed (usually when the map is unloaded, but if the sprite is made persistent then it may last longer). The thread running the script is given no warning that it is being killed; the coroutine is simply never called again, and the thread is disposed of. Because of this, background scripts MUST ensure the game is in a consistent state before coroutine yielding, because it is not guaranteed that the coroutine will ever be called again. --- src/script_system.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/script_system.h') diff --git a/src/script_system.h b/src/script_system.h index 6a28430..0718e90 100644 --- a/src/script_system.h +++ b/src/script_system.h @@ -19,9 +19,11 @@ public: void tick(double dt) override; + void destroySprite(int spriteId) override; + bool mapHasScript(std::string mapName, std::string scriptName); - void runScript(std::string mapName, std::string scriptName); + void runScript(std::string mapName, std::string scriptName, int linkedSprite = -1); void runDebugScript(std::string script); @@ -33,6 +35,7 @@ private: std::unique_ptr runner; std::unique_ptr callable; std::string debugInfo; + int linkedSprite = -1; }; Game& game_; -- cgit 1.4.1