Script: Allow changing ops limit and memory limit settings in game
This commit is contained in:
@@ -710,6 +710,16 @@ SQInteger ScriptInstance::GetOpsTillSuspend()
|
||||
return this->engine->GetOpsTillSuspend();
|
||||
}
|
||||
|
||||
void ScriptInstance::LimitOpsTillSuspend(SQInteger suspend)
|
||||
{
|
||||
SQInteger current = this->GetOpsTillSuspend();
|
||||
if (suspend < current) {
|
||||
/* Reduce script ops. */
|
||||
HSQUIRRELVM vm = this->engine->GetVM();
|
||||
Squirrel::DecreaseOps(vm, current - suspend);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptInstance::DoCommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
|
||||
{
|
||||
ScriptObject::ActiveInstance active(this);
|
||||
@@ -746,6 +756,11 @@ size_t ScriptInstance::GetAllocatedMemory() const
|
||||
return this->engine->GetAllocatedMemory();
|
||||
}
|
||||
|
||||
void ScriptInstance::SetMemoryAllocationLimit(size_t limit) const
|
||||
{
|
||||
if (this->engine != nullptr) this->engine->SetMemoryAllocationLimit(limit);
|
||||
}
|
||||
|
||||
void ScriptInstance::ReleaseSQObject(HSQOBJECT *obj)
|
||||
{
|
||||
if (!this->in_shutdown) this->engine->ReleaseObject(obj);
|
||||
|
@@ -174,6 +174,8 @@ public:
|
||||
*/
|
||||
SQInteger GetOpsTillSuspend();
|
||||
|
||||
void LimitOpsTillSuspend(SQInteger suspend);
|
||||
|
||||
/**
|
||||
* DoCommand callback function for all commands executed by scripts.
|
||||
* @param result The result of the command.
|
||||
@@ -200,6 +202,8 @@ public:
|
||||
|
||||
size_t GetAllocatedMemory() const;
|
||||
|
||||
void SetMemoryAllocationLimit(size_t limit) const;
|
||||
|
||||
/**
|
||||
* Indicate whether this instance is currently being destroyed.
|
||||
*/
|
||||
|
@@ -129,6 +129,13 @@ size_t Squirrel::GetAllocatedMemory() const noexcept
|
||||
return this->allocator->allocated_size;
|
||||
}
|
||||
|
||||
void Squirrel::SetMemoryAllocationLimit(size_t limit) noexcept
|
||||
{
|
||||
if (this->allocator != nullptr) {
|
||||
this->allocator->allocation_limit = limit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Squirrel::CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
|
||||
{
|
||||
|
@@ -280,6 +280,8 @@ public:
|
||||
* Get number of bytes allocated by this VM.
|
||||
*/
|
||||
size_t GetAllocatedMemory() const noexcept;
|
||||
|
||||
void SetMemoryAllocationLimit(size_t limit) noexcept;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user