mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 16:38:27 +02:00
* integrate with latest master
* consolidate emit entityScriptDetailsUpdated calls * limit maxRetries to 1 when isEntityServerScript()
This commit is contained in:
parent
831bf93500
commit
0f7652e173
2 changed files with 37 additions and 21 deletions
|
@ -183,6 +183,7 @@ QString ScriptEngine::reportUncaughtException(const QString& overrideFileName) {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ScriptEngine::processLevelMaxRetries { ScriptRequest::MAX_RETRIES };
|
||||||
ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const QString& fileNameString) :
|
ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const QString& fileNameString) :
|
||||||
_context(context),
|
_context(context),
|
||||||
_scriptContents(scriptContents),
|
_scriptContents(scriptContents),
|
||||||
|
@ -198,6 +199,11 @@ ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const
|
||||||
});
|
});
|
||||||
|
|
||||||
setProcessEventsInterval(MSECS_PER_SECOND);
|
setProcessEventsInterval(MSECS_PER_SECOND);
|
||||||
|
if (isEntityServerScript()) {
|
||||||
|
qCDebug(scriptengine) << "isEntityServerScript() -- limiting maxRetries to 1";
|
||||||
|
processLevelMaxRetries = 1;
|
||||||
|
}
|
||||||
|
qCDebug(scriptengine) << getContext() << "processLevelMaxRetries =" << processLevelMaxRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ScriptEngine::getContext() const {
|
QString ScriptEngine::getContext() const {
|
||||||
|
@ -1372,7 +1378,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
||||||
// If we are destroyed before the loader completes, make sure to clean it up
|
// If we are destroyed before the loader completes, make sure to clean it up
|
||||||
connect(this, &QObject::destroyed, loader, &QObject::deleteLater);
|
connect(this, &QObject::destroyed, loader, &QObject::deleteLater);
|
||||||
|
|
||||||
loader->start();
|
loader->start(processLevelMaxRetries);
|
||||||
|
|
||||||
if (!callback.isFunction() && !loader->isFinished()) {
|
if (!callback.isFunction() && !loader->isFinished()) {
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
|
@ -1452,6 +1458,7 @@ int ScriptEngine::getNumRunningEntityScripts() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
QString ScriptEngine::getEntityScriptStatus(const EntityItemID& entityID) {
|
QString ScriptEngine::getEntityScriptStatus(const EntityItemID& entityID) {
|
||||||
if (_entityScripts.contains(entityID))
|
if (_entityScripts.contains(entityID))
|
||||||
|
@ -1468,17 +1475,30 @@ bool ScriptEngine::getEntityScriptDetails(const EntityItemID& entityID, EntitySc
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptEngine::setEntityScriptDetails(const EntityItemID& entityID, const EntityScriptDetails& details) {
|
||||||
|
_entityScripts[entityID] = details;
|
||||||
|
emit entityScriptDetailsUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptEngine::updateEntityScriptStatus(const EntityItemID& entityID, const EntityScriptStatus &status, const QString& errorInfo) {
|
||||||
|
EntityScriptDetails &details = _entityScripts[entityID];
|
||||||
|
details.status = status;
|
||||||
|
details.errorInfo = errorInfo;
|
||||||
|
emit entityScriptDetailsUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
// since all of these operations can be asynch we will always do the actual work in the response handler
|
// since all of these operations can be asynch we will always do the actual work in the response handler
|
||||||
// for the download
|
// for the download
|
||||||
void ScriptEngine::loadEntityScript(QWeakPointer<ScriptEngine> theEngine, const EntityItemID& entityID, const QString& entityScript, bool forceRedownload) {
|
void ScriptEngine::loadEntityScript(QWeakPointer<ScriptEngine> theEngine, const EntityItemID& entityID, const QString& entityScript, bool forceRedownload) {
|
||||||
|
|
||||||
{
|
{
|
||||||
// set EntityScriptDetails.status to LOADING (over on theEngine's thread)
|
// set EntityScriptDetails.status to LOADING (over on theEngine's thread)
|
||||||
QObject threadPunter;
|
QObject threadPunter;
|
||||||
connect(&threadPunter, &QObject::destroyed, theEngine.data(), [=]() {
|
auto engine = theEngine.data();
|
||||||
EntityScriptDetails &details = theEngine.data()->_entityScripts[entityID];
|
connect(&threadPunter, &QObject::destroyed, engine, [=]() {
|
||||||
|
EntityScriptDetails details = engine->_entityScripts[entityID];
|
||||||
if (details.status == EntityScriptStatus::PENDING || details.status == EntityScriptStatus::UNLOADED) {
|
if (details.status == EntityScriptStatus::PENDING || details.status == EntityScriptStatus::UNLOADED) {
|
||||||
details.status = EntityScriptStatus::LOADING;
|
engine->updateEntityScriptStatus(entityID, EntityScriptStatus::LOADING, QThread::currentThread()->objectName());
|
||||||
emit entityScriptDetailsUpdated();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1496,7 +1516,7 @@ void ScriptEngine::loadEntityScript(QWeakPointer<ScriptEngine> theEngine, const
|
||||||
#endif
|
#endif
|
||||||
strongEngine->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success, status);
|
strongEngine->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success, status);
|
||||||
}
|
}
|
||||||
}, forceRedownload);
|
}, forceRedownload, processLevelMaxRetries);
|
||||||
}
|
}
|
||||||
|
|
||||||
// since all of these operations can be asynch we will always do the actual work in the response handler
|
// since all of these operations can be asynch we will always do the actual work in the response handler
|
||||||
|
@ -1534,8 +1554,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
|
||||||
if (!success) {
|
if (!success) {
|
||||||
newDetails.status = EntityScriptStatus::ERROR_LOADING_SCRIPT;
|
newDetails.status = EntityScriptStatus::ERROR_LOADING_SCRIPT;
|
||||||
newDetails.errorInfo = "Failed to load script (" + status + ")";
|
newDetails.errorInfo = "Failed to load script (" + status + ")";
|
||||||
_entityScripts[entityID] = newDetails;
|
setEntityScriptDetails(entityID, newDetails);
|
||||||
emit entityScriptDetailsUpdated();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1544,8 +1563,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
|
||||||
if (!syntaxError.isNull() || program.isNull()) {
|
if (!syntaxError.isNull() || program.isNull()) {
|
||||||
newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT;
|
newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT;
|
||||||
newDetails.errorInfo = QString("Bad syntax (%1)").arg(syntaxError);
|
newDetails.errorInfo = QString("Bad syntax (%1)").arg(syntaxError);
|
||||||
_entityScripts[entityID] = newDetails;
|
setEntityScriptDetails(entityID, newDetails);
|
||||||
emit entityScriptDetailsUpdated();
|
|
||||||
qCDebug(scriptengine) << newDetails.errorInfo << scriptOrURL;
|
qCDebug(scriptengine) << newDetails.errorInfo << scriptOrURL;
|
||||||
return; // done processing script
|
return; // done processing script
|
||||||
}
|
}
|
||||||
|
@ -1578,8 +1596,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
|
||||||
if (!exceptionMessage.isNull()) {
|
if (!exceptionMessage.isNull()) {
|
||||||
newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT;
|
newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT;
|
||||||
newDetails.errorInfo = exceptionMessage;
|
newDetails.errorInfo = exceptionMessage;
|
||||||
_entityScripts[entityID] = newDetails;
|
setEntityScriptDetails(entityID, newDetails);
|
||||||
emit entityScriptDetailsUpdated();
|
|
||||||
qCDebug(scriptengine) << "----- ScriptEngine::entityScriptContentAvailable -- hadUncaughtExceptions (" << scriptOrURL << ")";
|
qCDebug(scriptengine) << "----- ScriptEngine::entityScriptContentAvailable -- hadUncaughtExceptions (" << scriptOrURL << ")";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1601,8 +1618,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
|
||||||
|
|
||||||
newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT;
|
newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT;
|
||||||
newDetails.errorInfo = "Could not find constructor";
|
newDetails.errorInfo = "Could not find constructor";
|
||||||
_entityScripts[entityID] = newDetails;
|
setEntityScriptDetails(entityID, newDetails);
|
||||||
emit entityScriptDetailsUpdated();
|
|
||||||
|
|
||||||
qCDebug(scriptengine) << "----- ScriptEngine::entityScriptContentAvailable -- failed to run (" << scriptOrURL << ")";
|
qCDebug(scriptengine) << "----- ScriptEngine::entityScriptContentAvailable -- failed to run (" << scriptOrURL << ")";
|
||||||
return; // done processing script
|
return; // done processing script
|
||||||
|
@ -1625,8 +1641,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
|
||||||
newDetails.scriptObject = entityScriptObject;
|
newDetails.scriptObject = entityScriptObject;
|
||||||
newDetails.lastModified = lastModified;
|
newDetails.lastModified = lastModified;
|
||||||
newDetails.definingSandboxURL = sandboxURL;
|
newDetails.definingSandboxURL = sandboxURL;
|
||||||
_entityScripts[entityID] = newDetails;
|
setEntityScriptDetails(entityID, newDetails);
|
||||||
emit entityScriptDetailsUpdated();
|
|
||||||
|
|
||||||
if (isURL) {
|
if (isURL) {
|
||||||
setParentURL("");
|
setParentURL("");
|
||||||
|
@ -1656,11 +1671,10 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) {
|
||||||
if (isEntityScriptRunning(entityID)) {
|
if (isEntityScriptRunning(entityID)) {
|
||||||
callEntityScriptMethod(entityID, "unload");
|
callEntityScriptMethod(entityID, "unload");
|
||||||
}
|
}
|
||||||
EntityScriptDetails details;
|
EntityScriptDetails newDetails;
|
||||||
details.status = EntityScriptStatus::UNLOADED;
|
newDetails.status = EntityScriptStatus::UNLOADED;
|
||||||
_entityScripts[entityID] = details;
|
setEntityScriptDetails(entityID, newDetails);
|
||||||
stopAllTimersForEntityScript(entityID);
|
stopAllTimersForEntityScript(entityID);
|
||||||
emit entityScriptDetailsUpdated();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,7 @@ public:
|
||||||
AGENT_SCRIPT
|
AGENT_SCRIPT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int processLevelMaxRetries;
|
||||||
ScriptEngine(Context context, const QString& scriptContents = NO_SCRIPT, const QString& fileNameString = QString(""));
|
ScriptEngine(Context context, const QString& scriptContents = NO_SCRIPT, const QString& fileNameString = QString(""));
|
||||||
~ScriptEngine();
|
~ScriptEngine();
|
||||||
|
|
||||||
|
@ -243,7 +244,8 @@ protected:
|
||||||
void stopAllTimers();
|
void stopAllTimers();
|
||||||
void stopAllTimersForEntityScript(const EntityItemID& entityID);
|
void stopAllTimersForEntityScript(const EntityItemID& entityID);
|
||||||
void refreshFileScript(const EntityItemID& entityID);
|
void refreshFileScript(const EntityItemID& entityID);
|
||||||
|
void updateEntityScriptStatus(const EntityItemID& entityID, const EntityScriptStatus& status, const QString& errorInfo = QString());
|
||||||
|
void setEntityScriptDetails(const EntityItemID& entityID, const EntityScriptDetails& details);
|
||||||
void setParentURL(const QString& parentURL) { _parentURL = parentURL; }
|
void setParentURL(const QString& parentURL) { _parentURL = parentURL; }
|
||||||
|
|
||||||
QObject* setupTimerWithInterval(const QScriptValue& function, int intervalMS, bool isSingleShot);
|
QObject* setupTimerWithInterval(const QScriptValue& function, int intervalMS, bool isSingleShot);
|
||||||
|
|
Loading…
Reference in a new issue