mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-08-10 05:00:13 +02:00
prevent sending signals in the entities script engine
This commit is contained in:
parent
9ab603e9a5
commit
b9d5412aad
3 changed files with 56 additions and 22 deletions
|
@ -113,10 +113,10 @@ void EntityTreeRenderer::init() {
|
||||||
|
|
||||||
if (_wantScripts) {
|
if (_wantScripts) {
|
||||||
_entitiesScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities",
|
_entitiesScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities",
|
||||||
_scriptingServices->getControllerScriptingInterface());
|
_scriptingServices->getControllerScriptingInterface(), false);
|
||||||
_scriptingServices->registerScriptEngineWithApplicationServices(_entitiesScriptEngine);
|
_scriptingServices->registerScriptEngineWithApplicationServices(_entitiesScriptEngine);
|
||||||
|
|
||||||
_sandboxScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities Sandbox", NULL);
|
_sandboxScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities Sandbox", NULL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure our "last avatar position" is something other than our current position, so that on our
|
// make sure our "last avatar position" is something other than our current position, so that on our
|
||||||
|
|
|
@ -81,7 +81,7 @@ void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputCon
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString,
|
ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString,
|
||||||
AbstractControllerScriptingInterface* controllerScriptingInterface) :
|
AbstractControllerScriptingInterface* controllerScriptingInterface, bool wantSignals) :
|
||||||
|
|
||||||
_scriptContents(scriptContents),
|
_scriptContents(scriptContents),
|
||||||
_isFinished(false),
|
_isFinished(false),
|
||||||
|
@ -95,6 +95,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam
|
||||||
_avatarSound(NULL),
|
_avatarSound(NULL),
|
||||||
_numAvatarSoundSentBytes(0),
|
_numAvatarSoundSentBytes(0),
|
||||||
_controllerScriptingInterface(controllerScriptingInterface),
|
_controllerScriptingInterface(controllerScriptingInterface),
|
||||||
|
_wantSignals(wantSignals),
|
||||||
_avatarData(NULL),
|
_avatarData(NULL),
|
||||||
_scriptName(),
|
_scriptName(),
|
||||||
_fileNameString(fileNameString),
|
_fileNameString(fileNameString),
|
||||||
|
@ -299,10 +300,14 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
||||||
qCDebug(scriptengine) << "ScriptEngine loading file:" << _fileNameString;
|
qCDebug(scriptengine) << "ScriptEngine loading file:" << _fileNameString;
|
||||||
QTextStream in(&scriptFile);
|
QTextStream in(&scriptFile);
|
||||||
_scriptContents = in.readAll();
|
_scriptContents = in.readAll();
|
||||||
emit scriptLoaded(_fileNameString);
|
if (_wantSignals) {
|
||||||
|
emit scriptLoaded(_fileNameString);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qCDebug(scriptengine) << "ERROR Loading file:" << _fileNameString << "line:" << __LINE__;
|
qCDebug(scriptengine) << "ERROR Loading file:" << _fileNameString << "line:" << __LINE__;
|
||||||
emit errorLoadingScript(_fileNameString);
|
if (_wantSignals) {
|
||||||
|
emit errorLoadingScript(_fileNameString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool isPending;
|
bool isPending;
|
||||||
|
@ -314,12 +319,16 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
||||||
|
|
||||||
void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) {
|
void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) {
|
||||||
_scriptContents = scriptContents;
|
_scriptContents = scriptContents;
|
||||||
emit scriptLoaded(_fileNameString);
|
if (_wantSignals) {
|
||||||
|
emit scriptLoaded(_fileNameString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::errorInLoadingScript(const QUrl& url) {
|
void ScriptEngine::errorInLoadingScript(const QUrl& url) {
|
||||||
qCDebug(scriptengine) << "ERROR Loading file:" << url.toString() << "line:" << __LINE__;
|
qCDebug(scriptengine) << "ERROR Loading file:" << url.toString() << "line:" << __LINE__;
|
||||||
emit errorLoadingScript(_fileNameString); // ??
|
if (_wantSignals) {
|
||||||
|
emit errorLoadingScript(_fileNameString); // ??
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::init() {
|
void ScriptEngine::init() {
|
||||||
|
@ -524,7 +533,9 @@ void ScriptEngine::evaluate() {
|
||||||
if (hasUncaughtException()) {
|
if (hasUncaughtException()) {
|
||||||
int line = uncaughtExceptionLineNumber();
|
int line = uncaughtExceptionLineNumber();
|
||||||
qCDebug(scriptengine) << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
|
qCDebug(scriptengine) << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
|
||||||
emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
|
if (_wantSignals) {
|
||||||
|
emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
|
||||||
|
}
|
||||||
clearExceptions();
|
clearExceptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -541,7 +552,9 @@ QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileN
|
||||||
qCDebug(scriptengine) << "Uncaught exception at (" << _fileNameString << " : " << fileName << ") line" << line << ": " << result.toString();
|
qCDebug(scriptengine) << "Uncaught exception at (" << _fileNameString << " : " << fileName << ") line" << line << ": " << result.toString();
|
||||||
}
|
}
|
||||||
_evaluatesPending--;
|
_evaluatesPending--;
|
||||||
emit evaluationFinished(result, hasUncaughtException());
|
if (_wantSignals) {
|
||||||
|
emit evaluationFinished(result, hasUncaughtException());
|
||||||
|
}
|
||||||
clearExceptions();
|
clearExceptions();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -567,7 +580,9 @@ void ScriptEngine::run() {
|
||||||
}
|
}
|
||||||
_isRunning = true;
|
_isRunning = true;
|
||||||
_isFinished = false;
|
_isFinished = false;
|
||||||
emit runningStateChanged();
|
if (_wantSignals) {
|
||||||
|
emit runningStateChanged();
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue result = evaluate(_scriptContents);
|
QScriptValue result = evaluate(_scriptContents);
|
||||||
|
|
||||||
|
@ -714,19 +729,25 @@ void ScriptEngine::run() {
|
||||||
if (hasUncaughtException()) {
|
if (hasUncaughtException()) {
|
||||||
int line = uncaughtExceptionLineNumber();
|
int line = uncaughtExceptionLineNumber();
|
||||||
qCDebug(scriptengine) << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << uncaughtException().toString();
|
qCDebug(scriptengine) << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << uncaughtException().toString();
|
||||||
emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + uncaughtException().toString());
|
if (_wantSignals) {
|
||||||
|
emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + uncaughtException().toString());
|
||||||
|
}
|
||||||
clearExceptions();
|
clearExceptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_isFinished) {
|
if (!_isFinished) {
|
||||||
emit update(deltaTime);
|
if (_wantSignals) {
|
||||||
|
emit update(deltaTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lastUpdate = now;
|
lastUpdate = now;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stopAllTimers(); // make sure all our timers are stopped if the script is ending
|
stopAllTimers(); // make sure all our timers are stopped if the script is ending
|
||||||
emit scriptEnding();
|
if (_wantSignals) {
|
||||||
|
emit scriptEnding();
|
||||||
|
}
|
||||||
|
|
||||||
// kill the avatar identity timer
|
// kill the avatar identity timer
|
||||||
delete _avatarIdentityTimer;
|
delete _avatarIdentityTimer;
|
||||||
|
@ -747,12 +768,15 @@ void ScriptEngine::run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit finished(_fileNameString);
|
if (_wantSignals) {
|
||||||
|
emit finished(_fileNameString);
|
||||||
|
}
|
||||||
|
|
||||||
_isRunning = false;
|
_isRunning = false;
|
||||||
emit runningStateChanged();
|
if (_wantSignals) {
|
||||||
|
emit runningStateChanged();
|
||||||
emit doneRunning();
|
emit doneRunning();
|
||||||
|
}
|
||||||
|
|
||||||
_doneRunningThisScript = true;
|
_doneRunningThisScript = true;
|
||||||
}
|
}
|
||||||
|
@ -771,7 +795,9 @@ void ScriptEngine::stopAllTimers() {
|
||||||
void ScriptEngine::stop() {
|
void ScriptEngine::stop() {
|
||||||
if (!_isFinished) {
|
if (!_isFinished) {
|
||||||
_isFinished = true;
|
_isFinished = true;
|
||||||
emit runningStateChanged();
|
if (_wantSignals) {
|
||||||
|
emit runningStateChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -859,7 +885,9 @@ QUrl ScriptEngine::resolvePath(const QString& include) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::print(const QString& message) {
|
void ScriptEngine::print(const QString& message) {
|
||||||
emit printedMessage(message);
|
if (_wantSignals) {
|
||||||
|
emit printedMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a callback is specified, the included files will be loaded asynchronously and the callback will be called
|
// If a callback is specified, the included files will be loaded asynchronously and the callback will be called
|
||||||
|
@ -943,9 +971,13 @@ void ScriptEngine::load(const QString& loadFile) {
|
||||||
if (_isReloading) {
|
if (_isReloading) {
|
||||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||||
scriptCache->deleteScript(url.toString());
|
scriptCache->deleteScript(url.toString());
|
||||||
emit reloadScript(url.toString(), false);
|
if (_wantSignals) {
|
||||||
|
emit reloadScript(url.toString(), false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
emit loadScript(url.toString(), false);
|
if (_wantSignals) {
|
||||||
|
emit loadScript(url.toString(), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,8 @@ class ScriptEngine : public QScriptEngine, public ScriptUser {
|
||||||
public:
|
public:
|
||||||
ScriptEngine(const QString& scriptContents = NO_SCRIPT,
|
ScriptEngine(const QString& scriptContents = NO_SCRIPT,
|
||||||
const QString& fileNameString = QString(""),
|
const QString& fileNameString = QString(""),
|
||||||
AbstractControllerScriptingInterface* controllerScriptingInterface = NULL);
|
AbstractControllerScriptingInterface* controllerScriptingInterface = NULL,
|
||||||
|
bool wantSignals = true);
|
||||||
|
|
||||||
~ScriptEngine();
|
~ScriptEngine();
|
||||||
|
|
||||||
|
@ -156,6 +157,7 @@ protected:
|
||||||
int _numAvatarSoundSentBytes;
|
int _numAvatarSoundSentBytes;
|
||||||
bool _isAgent = false;
|
bool _isAgent = false;
|
||||||
QSet<QUrl> _includedURLs;
|
QSet<QUrl> _includedURLs;
|
||||||
|
bool _wantSignals = true;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void stopAllTimers();
|
void stopAllTimers();
|
||||||
|
|
Loading…
Reference in a new issue