1
0
forked from mirrors/0ad

Get a promise when starting a GUIpage

When calling `Engine.PushGuiPage` a promise is returned. The promise is
settled when the "child" page is closed. That allows to `await` it
inside `async` functions.
Previously the callback was run right inside the call to
`Engine.PopGuiPage`. Now the continuation of the promise is called at
the end of the "tick".

This won't help performance. It will more likely make things worse.
Since gui pages aren't opened or closed that frequently, it doesn't
matter that much.

Refs: 86c151ebaa

For the engine side:
The promise is stored in the `CGUIManager::SGUIPage` (like previously
the callback). When the promise is fulfilled it enqueues a callback in
the `JobQueue` of the `JSContext`.

Original patch by: @wraitii
Comments by: @wraitii, @Stan, @Polakrity, @lyv, @elexis, @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D3807
This was SVN commit r28145.
This commit is contained in:
phosit
2024-07-08 19:07:04 +00:00
parent ae67a77bd9
commit f9114a87f2
22 changed files with 212 additions and 210 deletions
+12 -5
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2023 Wildfire Games.
/* Copyright (C) 2024 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -22,6 +22,7 @@
#include "lib/alignment.h"
#include "ps/GameSetup/Config.h"
#include "ps/Profile.h"
#include "scriptinterface/Promises.h"
#include "scriptinterface/ScriptExtraHeaders.h"
#include "scriptinterface/ScriptEngine.h"
#include "scriptinterface/ScriptInterface.h"
@@ -83,10 +84,9 @@ std::shared_ptr<ScriptContext> ScriptContext::CreateContext(int contextSize, int
}
ScriptContext::ScriptContext(int contextSize, int heapGrowthBytesGCTrigger):
m_LastGCBytes(0),
m_LastGCCheck(0.0f),
m_HeapGrowthBytesGCTrigger(heapGrowthBytesGCTrigger),
m_ContextSize(contextSize)
m_JobQueue{std::make_unique<Script::JobQueue>()},
m_ContextSize{contextSize},
m_HeapGrowthBytesGCTrigger{heapGrowthBytesGCTrigger}
{
ENSURE(ScriptEngine::IsInitialised() && "The ScriptEngine must be initialized before constructing any ScriptContexts!");
@@ -130,6 +130,8 @@ ScriptContext::ScriptContext(int contextSize, int heapGrowthBytesGCTrigger):
JS::ContextOptionsRef(m_cx).setStrictMode(true);
ScriptEngine::GetSingleton().RegisterContext(m_cx);
JS::SetJobQueue(m_cx, m_JobQueue.get());
}
ScriptContext::~ScriptContext()
@@ -268,6 +270,11 @@ void ScriptContext::ShrinkingGC()
JS_SetGCParameter(m_cx, JSGC_PER_ZONE_GC_ENABLED, false);
}
void ScriptContext::RunJobs()
{
m_JobQueue->runJobs(m_cx);
}
void ScriptContext::PrepareZonesForIncrementalGC() const
{
for (JS::Realm* const& realm : m_Realms)