mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:08:47 +02:00
Mv entities script engine deleter to fn
This commit is contained in:
parent
2140dc77b3
commit
61fbb7022c
1 changed files with 14 additions and 11 deletions
|
@ -78,13 +78,8 @@ EntityTreeRenderer::~EntityTreeRenderer() {
|
||||||
|
|
||||||
int EntityTreeRenderer::_entitiesScriptEngineCount = 0;
|
int EntityTreeRenderer::_entitiesScriptEngineCount = 0;
|
||||||
|
|
||||||
void EntityTreeRenderer::resetEntitiesScriptEngine() {
|
void entitiesScriptEngineDeleter(ScriptEngine* engine) {
|
||||||
// Keep a ref to oldEngine until newEngine is ready so EntityScriptingInterface has something to use
|
class WaitRunnable : public QRunnable {
|
||||||
auto oldEngine = _entitiesScriptEngine;
|
|
||||||
|
|
||||||
auto newEngine = new ScriptEngine(NO_SCRIPT, QString("Entities %1").arg(++_entitiesScriptEngineCount));
|
|
||||||
_entitiesScriptEngine = QSharedPointer<ScriptEngine>(newEngine, [](ScriptEngine* engine){
|
|
||||||
class WaitRunnable : public QRunnable {
|
|
||||||
public:
|
public:
|
||||||
WaitRunnable(ScriptEngine* engine) : _engine(engine) {}
|
WaitRunnable(ScriptEngine* engine) : _engine(engine) {}
|
||||||
virtual void run() override {
|
virtual void run() override {
|
||||||
|
@ -94,10 +89,18 @@ void EntityTreeRenderer::resetEntitiesScriptEngine() {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScriptEngine* _engine;
|
ScriptEngine* _engine;
|
||||||
};
|
};
|
||||||
// Wait for the scripting thread from the thread pool to avoid hanging the main thread
|
|
||||||
QThreadPool::globalInstance()->start(new WaitRunnable(engine));
|
// Wait for the scripting thread from the thread pool to avoid hanging the main thread
|
||||||
});
|
QThreadPool::globalInstance()->start(new WaitRunnable(engine));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityTreeRenderer::resetEntitiesScriptEngine() {
|
||||||
|
// Keep a ref to oldEngine until newEngine is ready so EntityScriptingInterface has something to use
|
||||||
|
auto oldEngine = _entitiesScriptEngine;
|
||||||
|
|
||||||
|
auto newEngine = new ScriptEngine(NO_SCRIPT, QString("Entities %1").arg(++_entitiesScriptEngineCount));
|
||||||
|
_entitiesScriptEngine = QSharedPointer<ScriptEngine>(newEngine, entitiesScriptEngineDeleter);
|
||||||
|
|
||||||
_scriptingServices->registerScriptEngineWithApplicationServices(_entitiesScriptEngine.data());
|
_scriptingServices->registerScriptEngineWithApplicationServices(_entitiesScriptEngine.data());
|
||||||
_entitiesScriptEngine->runInThread();
|
_entitiesScriptEngine->runInThread();
|
||||||
|
|
Loading…
Reference in a new issue