Script: Boost gamescript op limit when game is paused due to game script
This commit is contained in:
@@ -258,7 +258,7 @@ void ScriptInstance::GameLoop()
|
|||||||
}
|
}
|
||||||
ScriptObject::SetAllowDoCommand(true);
|
ScriptObject::SetAllowDoCommand(true);
|
||||||
/* Start the script by calling Start() */
|
/* Start the script by calling Start() */
|
||||||
if (!this->engine->CallMethod(*this->instance, "Start", _settings_game.script.script_max_opcode_till_suspend) || !this->engine->IsSuspended()) this->Died();
|
if (!this->engine->CallMethod(*this->instance, "Start", this->GetMaxOpsTillSuspend()) || !this->engine->IsSuspended()) this->Died();
|
||||||
} catch (Script_Suspend &e) {
|
} catch (Script_Suspend &e) {
|
||||||
this->suspend = e.GetSuspendTime();
|
this->suspend = e.GetSuspendTime();
|
||||||
this->callback = e.GetSuspendCallback();
|
this->callback = e.GetSuspendCallback();
|
||||||
@@ -279,7 +279,7 @@ void ScriptInstance::GameLoop()
|
|||||||
|
|
||||||
/* Continue the VM */
|
/* Continue the VM */
|
||||||
try {
|
try {
|
||||||
if (!this->engine->Resume(_settings_game.script.script_max_opcode_till_suspend)) this->Died();
|
if (!this->engine->Resume(this->GetMaxOpsTillSuspend())) this->Died();
|
||||||
} catch (Script_Suspend &e) {
|
} catch (Script_Suspend &e) {
|
||||||
this->suspend = e.GetSuspendTime();
|
this->suspend = e.GetSuspendTime();
|
||||||
this->callback = e.GetSuspendCallback();
|
this->callback = e.GetSuspendCallback();
|
||||||
@@ -581,7 +581,7 @@ void ScriptInstance::Pause()
|
|||||||
{
|
{
|
||||||
/* Suspend script. */
|
/* Suspend script. */
|
||||||
HSQUIRRELVM vm = this->engine->GetVM();
|
HSQUIRRELVM vm = this->engine->GetVM();
|
||||||
Squirrel::DecreaseOps(vm, _settings_game.script.script_max_opcode_till_suspend);
|
Squirrel::DecreaseOps(vm, this->GetOpsTillSuspend());
|
||||||
|
|
||||||
this->is_paused = true;
|
this->is_paused = true;
|
||||||
}
|
}
|
||||||
@@ -789,6 +789,15 @@ void ScriptInstance::LimitOpsTillSuspend(SQInteger suspend)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 ScriptInstance::GetMaxOpsTillSuspend() const
|
||||||
|
{
|
||||||
|
if (this->script_type == ST_GS && (_pause_mode & PM_PAUSED_GAME_SCRIPT) != PM_UNPAUSED) {
|
||||||
|
/* Boost opcodes till suspend when paused due to game script */
|
||||||
|
return std::min<uint32>(250000, _settings_game.script.script_max_opcode_till_suspend * 10);
|
||||||
|
}
|
||||||
|
return _settings_game.script.script_max_opcode_till_suspend;
|
||||||
|
}
|
||||||
|
|
||||||
bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd)
|
bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd)
|
||||||
{
|
{
|
||||||
ScriptObject::ActiveInstance active(this);
|
ScriptObject::ActiveInstance active(this);
|
||||||
|
@@ -211,6 +211,8 @@ public:
|
|||||||
|
|
||||||
void LimitOpsTillSuspend(SQInteger suspend);
|
void LimitOpsTillSuspend(SQInteger suspend);
|
||||||
|
|
||||||
|
uint32 GetMaxOpsTillSuspend() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DoCommand callback function for all commands executed by scripts.
|
* DoCommand callback function for all commands executed by scripts.
|
||||||
* @param result The result of the command.
|
* @param result The result of the command.
|
||||||
|
Reference in New Issue
Block a user