mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 22:40:12 +02:00
Hide script stop behind accessor and fix friendship
This commit is contained in:
parent
59e4b9c356
commit
36565598a7
4 changed files with 19 additions and 13 deletions
|
@ -754,7 +754,7 @@ void ScriptEngine::addEventHandler(const EntityItemID& entityID, const QString&
|
||||||
|
|
||||||
|
|
||||||
QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fileName, int lineNumber) {
|
QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fileName, int lineNumber) {
|
||||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
if (DependencyManager::get<ScriptEngines>()->isStopped()) {
|
||||||
return QScriptValue(); // bail early
|
return QScriptValue(); // bail early
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -790,7 +790,7 @@ QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fi
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::run() {
|
void ScriptEngine::run() {
|
||||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
if (DependencyManager::get<ScriptEngines>()->isStopped()) {
|
||||||
return; // bail early - avoid setting state in init(), as evaluate() will bail too
|
return; // bail early - avoid setting state in init(), as evaluate() will bail too
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,7 +1023,7 @@ QObject* ScriptEngine::setupTimerWithInterval(const QScriptValue& function, int
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject* ScriptEngine::setInterval(const QScriptValue& function, int intervalMS) {
|
QObject* ScriptEngine::setInterval(const QScriptValue& function, int intervalMS) {
|
||||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
if (DependencyManager::get<ScriptEngines>()->isStopped()) {
|
||||||
qCDebug(scriptengine) << "Script.setInterval() while shutting down is ignored... parent script:" << getFilename();
|
qCDebug(scriptengine) << "Script.setInterval() while shutting down is ignored... parent script:" << getFilename();
|
||||||
return NULL; // bail early
|
return NULL; // bail early
|
||||||
}
|
}
|
||||||
|
@ -1032,7 +1032,7 @@ QObject* ScriptEngine::setInterval(const QScriptValue& function, int intervalMS)
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject* ScriptEngine::setTimeout(const QScriptValue& function, int timeoutMS) {
|
QObject* ScriptEngine::setTimeout(const QScriptValue& function, int timeoutMS) {
|
||||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
if (DependencyManager::get<ScriptEngines>()->isStopped()) {
|
||||||
qCDebug(scriptengine) << "Script.setTimeout() while shutting down is ignored... parent script:" << getFilename();
|
qCDebug(scriptengine) << "Script.setTimeout() while shutting down is ignored... parent script:" << getFilename();
|
||||||
return NULL; // bail early
|
return NULL; // bail early
|
||||||
}
|
}
|
||||||
|
@ -1084,7 +1084,7 @@ void ScriptEngine::print(const QString& message) {
|
||||||
// If no callback is specified, the included files will be loaded synchronously and will block execution until
|
// If no callback is specified, the included files will be loaded synchronously and will block execution until
|
||||||
// all of the files have finished loading.
|
// all of the files have finished loading.
|
||||||
void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callback) {
|
void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callback) {
|
||||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
if (DependencyManager::get<ScriptEngines>()->isStopped()) {
|
||||||
qCDebug(scriptengine) << "Script.include() while shutting down is ignored..."
|
qCDebug(scriptengine) << "Script.include() while shutting down is ignored..."
|
||||||
<< "includeFiles:" << includeFiles << "parent script:" << getFilename();
|
<< "includeFiles:" << includeFiles << "parent script:" << getFilename();
|
||||||
return; // bail early
|
return; // bail early
|
||||||
|
@ -1182,7 +1182,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {
|
void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {
|
||||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
if (DependencyManager::get<ScriptEngines>()->isStopped()) {
|
||||||
qCDebug(scriptengine) << "Script.include() while shutting down is ignored... "
|
qCDebug(scriptengine) << "Script.include() while shutting down is ignored... "
|
||||||
<< "includeFile:" << includeFile << "parent script:" << getFilename();
|
<< "includeFile:" << includeFile << "parent script:" << getFilename();
|
||||||
return; // bail early
|
return; // bail early
|
||||||
|
@ -1197,7 +1197,7 @@ void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {
|
||||||
// as a stand-alone script. To accomplish this, the ScriptEngine class just emits a signal which
|
// as a stand-alone script. To accomplish this, the ScriptEngine class just emits a signal which
|
||||||
// the Application or other context will connect to in order to know to actually load the script
|
// the Application or other context will connect to in order to know to actually load the script
|
||||||
void ScriptEngine::load(const QString& loadFile) {
|
void ScriptEngine::load(const QString& loadFile) {
|
||||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
if (DependencyManager::get<ScriptEngines>()->isStopped()) {
|
||||||
qCDebug(scriptengine) << "Script.load() while shutting down is ignored... "
|
qCDebug(scriptengine) << "Script.load() while shutting down is ignored... "
|
||||||
<< "loadFile:" << loadFile << "parent script:" << getFilename();
|
<< "loadFile:" << loadFile << "parent script:" << getFilename();
|
||||||
return; // bail early
|
return; // bail early
|
||||||
|
|
|
@ -83,6 +83,10 @@ public:
|
||||||
/// run the script in the callers thread, exit when stop() is called.
|
/// run the script in the callers thread, exit when stop() is called.
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
void waitTillDoneRunning();
|
||||||
|
|
||||||
|
QString getFilename() const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// NOTE - these are NOT intended to be public interfaces available to scripts, the are only Q_INVOKABLE so we can
|
// NOTE - these are NOT intended to be public interfaces available to scripts, the are only Q_INVOKABLE so we can
|
||||||
// properly ensure they are only called on the correct thread
|
// properly ensure they are only called on the correct thread
|
||||||
|
@ -199,8 +203,6 @@ protected:
|
||||||
qint64 _lastUpdate;
|
qint64 _lastUpdate;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
QString getFilename() const;
|
|
||||||
void waitTillDoneRunning();
|
|
||||||
bool evaluatePending() const { return _evaluatesPending > 0; }
|
bool evaluatePending() const { return _evaluatesPending > 0; }
|
||||||
void timerFired();
|
void timerFired();
|
||||||
void stopAllTimers();
|
void stopAllTimers();
|
||||||
|
|
|
@ -119,7 +119,7 @@ void ScriptEngines::registerScriptInitializer(ScriptInitializer initializer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngines::addScriptEngine(ScriptEngine* engine) {
|
void ScriptEngines::addScriptEngine(ScriptEngine* engine) {
|
||||||
if (_stopped) {
|
if (_isStopped) {
|
||||||
engine->deleteLater();
|
engine->deleteLater();
|
||||||
} else {
|
} else {
|
||||||
QMutexLocker locker(&_allScriptsMutex);
|
QMutexLocker locker(&_allScriptsMutex);
|
||||||
|
@ -131,14 +131,14 @@ void ScriptEngines::removeScriptEngine(ScriptEngine* engine) {
|
||||||
// If we're not already in the middle of stopping all scripts, then we should remove ourselves
|
// If we're not already in the middle of stopping all scripts, then we should remove ourselves
|
||||||
// from the list of running scripts. We don't do this if we're in the process of stopping all scripts
|
// from the list of running scripts. We don't do this if we're in the process of stopping all scripts
|
||||||
// because that method removes scripts from its list as it iterates them
|
// because that method removes scripts from its list as it iterates them
|
||||||
if (!_stopped) {
|
if (!_isStopped) {
|
||||||
QMutexLocker locker(&_allScriptsMutex);
|
QMutexLocker locker(&_allScriptsMutex);
|
||||||
_allKnownScriptEngines.remove(engine);
|
_allKnownScriptEngines.remove(engine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngines::shutdownScripting() {
|
void ScriptEngines::shutdownScripting() {
|
||||||
_stopped = true;
|
_isStopped = true;
|
||||||
QMutexLocker locker(&_allScriptsMutex);
|
QMutexLocker locker(&_allScriptsMutex);
|
||||||
qCDebug(scriptengine) << "Stopping all scripts.... currently known scripts:" << _allKnownScriptEngines.size();
|
qCDebug(scriptengine) << "Stopping all scripts.... currently known scripts:" << _allKnownScriptEngines.size();
|
||||||
|
|
||||||
|
@ -498,6 +498,9 @@ void ScriptEngines::launchScriptEngine(ScriptEngine* scriptEngine) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptEngines::isStopped() const {
|
||||||
|
return _isStopped;
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptEngines::onScriptFinished(const QString& rawScriptURL, ScriptEngine* engine) {
|
void ScriptEngines::onScriptFinished(const QString& rawScriptURL, ScriptEngine* engine) {
|
||||||
bool removed = false;
|
bool removed = false;
|
||||||
|
|
|
@ -86,6 +86,7 @@ protected:
|
||||||
void onScriptEngineLoaded(const QString& scriptFilename);
|
void onScriptEngineLoaded(const QString& scriptFilename);
|
||||||
void onScriptEngineError(const QString& scriptFilename);
|
void onScriptEngineError(const QString& scriptFilename);
|
||||||
void launchScriptEngine(ScriptEngine* engine);
|
void launchScriptEngine(ScriptEngine* engine);
|
||||||
|
bool isStopped() const;
|
||||||
|
|
||||||
QReadWriteLock _scriptEnginesHashLock;
|
QReadWriteLock _scriptEnginesHashLock;
|
||||||
QHash<QUrl, ScriptEngine*> _scriptEnginesHash;
|
QHash<QUrl, ScriptEngine*> _scriptEnginesHash;
|
||||||
|
@ -95,7 +96,7 @@ protected:
|
||||||
mutable Setting::Handle<QString> _scriptsLocationHandle;
|
mutable Setting::Handle<QString> _scriptsLocationHandle;
|
||||||
ScriptsModel _scriptsModel;
|
ScriptsModel _scriptsModel;
|
||||||
ScriptsModelFilter _scriptsModelFilter;
|
ScriptsModelFilter _scriptsModelFilter;
|
||||||
std::atomic<bool> _stopped { false };
|
std::atomic<bool> _isStopped { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
QUrl normalizeScriptURL(const QUrl& rawScriptURL);
|
QUrl normalizeScriptURL(const QUrl& rawScriptURL);
|
||||||
|
|
Loading…
Reference in a new issue