summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/script_instance.cpp17
-rw-r--r--src/script/script_instance.hpp26
2 files changed, 36 insertions, 7 deletions
diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp
index 95fcf6f0d..dc56c6c1f 100644
--- a/src/script/script_instance.cpp
+++ b/src/script/script_instance.cpp
@@ -54,6 +54,7 @@ ScriptInstance::ScriptInstance(const char *APIName) :
instance(NULL),
is_started(false),
is_dead(false),
+ is_paused(false),
is_save_data_on_stack(false),
suspend(0),
callback(NULL)
@@ -165,6 +166,7 @@ void ScriptInstance::GameLoop()
this->Died();
return;
}
+ if (this->is_paused) return;
this->controller->ticks++;
if (this->suspend < -1) this->suspend++; // Multiplayer suspend, increase up to -1.
@@ -520,10 +522,23 @@ void ScriptInstance::Save()
}
}
-void ScriptInstance::Suspend()
+void ScriptInstance::Pause()
{
+ /* Suspend script. */
HSQUIRRELVM vm = this->engine->GetVM();
Squirrel::DecreaseOps(vm, _settings_game.script.script_max_opcode_till_suspend);
+
+ this->is_paused = true;
+}
+
+void ScriptInstance::Unpause()
+{
+ this->is_paused = false;
+}
+
+bool ScriptInstance::IsPaused()
+{
+ return this->is_paused;
}
/* static */ bool ScriptInstance::LoadObjects(HSQUIRRELVM vm)
diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp
index 0cda170f4..2e7eb55cc 100644
--- a/src/script/script_instance.hpp
+++ b/src/script/script_instance.hpp
@@ -140,12 +140,24 @@ public:
static void LoadEmpty();
/**
- * Reduces the number of opcodes the script have left to zero. Unless
- * the script is in a state where it cannot suspend it will be suspended
- * for the reminder of the current tick. This function is safe to
- * call from within a function called by the script.
+ * Suspends the script for the current tick and then pause the execution
+ * of script. The script will not be resumed from its suspended state
+ * until the script has been unpaused.
*/
- void Suspend();
+ void Pause();
+
+ /**
+ * Checks if the script is paused.
+ * @return true if the script is paused, otherwise false
+ */
+ bool IsPaused();
+
+ /**
+ * Resume execution of the script. This function will not actually execute
+ * the script, but set a flag so that the script is executed my the usual
+ * mechanism that executes the script.
+ */
+ void Unpause();
/**
* Get the number of operations the script can execute before being suspended.
@@ -171,7 +183,8 @@ public:
/**
* Check if the instance is sleeping, which either happened because the
- * script executed a DoCommand, or executed this.Sleep().
+ * script executed a DoCommand, executed this.Sleep() or it has been
+ * paused.
*/
bool IsSleeping() { return this->suspend != 0; }
@@ -216,6 +229,7 @@ private:
bool is_dead; ///< True if the script has been stopped.
bool is_save_data_on_stack; ///< Is the save data still on the squirrel stack?
int suspend; ///< The amount of ticks to suspend this script before it's allowed to continue.
+ bool is_paused; ///< Is the script paused? (a paused script will not be executed until unpaused)
Script_SuspendCallbackProc *callback; ///< Callback that should be called in the next tick the script runs.
/**