mirror of
https://github.com/overte-org/overte.git
synced 2025-04-16 09:07:19 +02:00
Merge pull request #9922 from birarda/bug/stuck-ess
fix a couple of ESS issues during ES/ESS restart
This commit is contained in:
commit
4c789c44aa
8 changed files with 64 additions and 49 deletions
|
@ -58,6 +58,8 @@ EntityScriptServer::EntityScriptServer(ReceivedMessage& message) : ThreadedAssig
|
|||
|
||||
DependencyManager::registerInheritance<SpatialParentFinder, AssignmentParentFinder>();
|
||||
|
||||
DependencyManager::set<AudioScriptingInterface>();
|
||||
|
||||
DependencyManager::set<ResourceCacheSharedItems>();
|
||||
DependencyManager::set<SoundCache>();
|
||||
DependencyManager::set<AudioInjectorManager>();
|
||||
|
@ -324,7 +326,26 @@ void EntityScriptServer::nodeActivated(SharedNodePointer activatedNode) {
|
|||
void EntityScriptServer::nodeKilled(SharedNodePointer killedNode) {
|
||||
switch (killedNode->getType()) {
|
||||
case NodeType::EntityServer: {
|
||||
clear();
|
||||
// Before we clear, make sure this was our only entity server.
|
||||
// Otherwise we're assuming that we have "trading" entity servers
|
||||
// (an old one going away and a new one coming onboard)
|
||||
// and that we shouldn't clear here because we're still doing work.
|
||||
bool hasAnotherEntityServer = false;
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
nodeList->eachNodeBreakable([&hasAnotherEntityServer, &killedNode](const SharedNodePointer& node){
|
||||
if (node->getType() == NodeType::EntityServer && node->getUUID() != killedNode->getUUID()) {
|
||||
// we're talking to > 1 entity servers, we know we won't clear
|
||||
hasAnotherEntityServer = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!hasAnotherEntityServer) {
|
||||
clear();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -395,7 +416,8 @@ void EntityScriptServer::selectAudioFormat(const QString& selectedCodecName) {
|
|||
|
||||
void EntityScriptServer::resetEntitiesScriptEngine() {
|
||||
auto engineName = QString("about:Entities %1").arg(++_entitiesScriptEngineCount);
|
||||
auto newEngine = QSharedPointer<ScriptEngine>(new ScriptEngine(ScriptEngine::ENTITY_SERVER_SCRIPT, NO_SCRIPT, engineName));
|
||||
auto newEngine = QSharedPointer<ScriptEngine>(new ScriptEngine(ScriptEngine::ENTITY_SERVER_SCRIPT, NO_SCRIPT, engineName),
|
||||
&ScriptEngine::deleteLater);
|
||||
|
||||
auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor);
|
||||
newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
|
||||
|
|
|
@ -740,23 +740,24 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
|||
}
|
||||
});
|
||||
|
||||
auto& audioScriptingInterface = AudioScriptingInterface::getInstance();
|
||||
auto audioScriptingInterface = DependencyManager::set<AudioScriptingInterface>();
|
||||
connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start);
|
||||
connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
|
||||
connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
|
||||
connect(audioIO.data(), &AudioClient::muteToggled, this, &Application::audioMuteToggled);
|
||||
connect(audioIO.data(), &AudioClient::mutedByMixer, &audioScriptingInterface, &AudioScriptingInterface::mutedByMixer);
|
||||
connect(audioIO.data(), &AudioClient::receivedFirstPacket, &audioScriptingInterface, &AudioScriptingInterface::receivedFirstPacket);
|
||||
connect(audioIO.data(), &AudioClient::disconnected, &audioScriptingInterface, &AudioScriptingInterface::disconnected);
|
||||
connect(audioIO.data(), &AudioClient::mutedByMixer, audioScriptingInterface.data(), &AudioScriptingInterface::mutedByMixer);
|
||||
connect(audioIO.data(), &AudioClient::receivedFirstPacket, audioScriptingInterface.data(), &AudioScriptingInterface::receivedFirstPacket);
|
||||
connect(audioIO.data(), &AudioClient::disconnected, audioScriptingInterface.data(), &AudioScriptingInterface::disconnected);
|
||||
connect(audioIO.data(), &AudioClient::muteEnvironmentRequested, [](glm::vec3 position, float radius) {
|
||||
auto audioClient = DependencyManager::get<AudioClient>();
|
||||
auto audioScriptingInterface = DependencyManager::get<AudioScriptingInterface>();
|
||||
auto myAvatarPosition = DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition();
|
||||
float distance = glm::distance(myAvatarPosition, position);
|
||||
bool shouldMute = !audioClient->isMuted() && (distance < radius);
|
||||
|
||||
if (shouldMute) {
|
||||
audioClient->toggleMute();
|
||||
AudioScriptingInterface::getInstance().environmentMuted();
|
||||
audioScriptingInterface->environmentMuted();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1181,10 +1182,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
|||
|
||||
// set the local loopback interface for local sounds
|
||||
AudioInjector::setLocalAudioInterface(audioIO.data());
|
||||
AudioScriptingInterface::getInstance().setLocalAudioInterface(audioIO.data());
|
||||
connect(audioIO.data(), &AudioClient::noiseGateOpened, &AudioScriptingInterface::getInstance(), &AudioScriptingInterface::noiseGateOpened);
|
||||
connect(audioIO.data(), &AudioClient::noiseGateClosed, &AudioScriptingInterface::getInstance(), &AudioScriptingInterface::noiseGateClosed);
|
||||
connect(audioIO.data(), &AudioClient::inputReceived, &AudioScriptingInterface::getInstance(), &AudioScriptingInterface::inputReceived);
|
||||
audioScriptingInterface->setLocalAudioInterface(audioIO.data());
|
||||
connect(audioIO.data(), &AudioClient::noiseGateOpened, audioScriptingInterface.data(), &AudioScriptingInterface::noiseGateOpened);
|
||||
connect(audioIO.data(), &AudioClient::noiseGateClosed, audioScriptingInterface.data(), &AudioScriptingInterface::noiseGateClosed);
|
||||
connect(audioIO.data(), &AudioClient::inputReceived, audioScriptingInterface.data(), &AudioScriptingInterface::inputReceived);
|
||||
|
||||
|
||||
this->installEventFilter(this);
|
||||
|
@ -1949,7 +1950,7 @@ void Application::initializeUi() {
|
|||
// For some reason there is already an "Application" object in the QML context,
|
||||
// though I can't find it. Hence, "ApplicationInterface"
|
||||
rootContext->setContextProperty("ApplicationInterface", this);
|
||||
rootContext->setContextProperty("Audio", &AudioScriptingInterface::getInstance());
|
||||
rootContext->setContextProperty("Audio", DependencyManager::get<AudioScriptingInterface>().data());
|
||||
rootContext->setContextProperty("AudioStats", DependencyManager::get<AudioClient>()->getStats().data());
|
||||
rootContext->setContextProperty("AudioScope", DependencyManager::get<AudioScope>().data());
|
||||
|
||||
|
|
|
@ -19,11 +19,6 @@ void registerAudioMetaTypes(QScriptEngine* engine) {
|
|||
qScriptRegisterMetaType(engine, soundSharedPointerToScriptValue, soundSharedPointerFromScriptValue);
|
||||
}
|
||||
|
||||
AudioScriptingInterface& AudioScriptingInterface::getInstance() {
|
||||
static AudioScriptingInterface staticInstance;
|
||||
return staticInstance;
|
||||
}
|
||||
|
||||
AudioScriptingInterface::AudioScriptingInterface() :
|
||||
_localAudioInterface(NULL)
|
||||
{
|
||||
|
|
|
@ -14,18 +14,20 @@
|
|||
|
||||
#include <AbstractAudioInterface.h>
|
||||
#include <AudioInjector.h>
|
||||
#include <DependencyManager.h>
|
||||
#include <Sound.h>
|
||||
|
||||
class ScriptAudioInjector;
|
||||
|
||||
class AudioScriptingInterface : public QObject {
|
||||
class AudioScriptingInterface : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static AudioScriptingInterface& getInstance();
|
||||
SINGLETON_DEPENDENCY
|
||||
|
||||
public:
|
||||
void setLocalAudioInterface(AbstractAudioInterface* audioInterface) { _localAudioInterface = audioInterface; }
|
||||
|
||||
protected:
|
||||
|
||||
// this method is protected to stop C++ callers from calling, but invokable from script
|
||||
Q_INVOKABLE ScriptAudioInjector* playSound(SharedSoundPointer sound, const AudioInjectorOptions& injectorOptions = AudioInjectorOptions());
|
||||
|
||||
|
@ -42,6 +44,7 @@ signals:
|
|||
|
||||
private:
|
||||
AudioScriptingInterface();
|
||||
|
||||
AbstractAudioInterface* _localAudioInterface;
|
||||
};
|
||||
|
||||
|
|
|
@ -464,17 +464,17 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
|||
|
||||
void ScriptEngine::scriptErrorMessage(const QString& message) {
|
||||
qCCritical(scriptengine) << qPrintable(message);
|
||||
emit errorMessage(message);
|
||||
emit errorMessage(message, getFilename());
|
||||
}
|
||||
|
||||
void ScriptEngine::scriptWarningMessage(const QString& message) {
|
||||
qCWarning(scriptengine) << message;
|
||||
emit warningMessage(message);
|
||||
emit warningMessage(message, getFilename());
|
||||
}
|
||||
|
||||
void ScriptEngine::scriptInfoMessage(const QString& message) {
|
||||
qCInfo(scriptengine) << message;
|
||||
emit infoMessage(message);
|
||||
emit infoMessage(message, getFilename());
|
||||
}
|
||||
|
||||
// Even though we never pass AnimVariantMap directly to and from javascript, the queued invokeMethod of
|
||||
|
@ -627,6 +627,9 @@ void ScriptEngine::init() {
|
|||
qScriptRegisterMetaType(this, qWSCloseCodeToScriptValue, qWSCloseCodeFromScriptValue);
|
||||
qScriptRegisterMetaType(this, wscReadyStateToScriptValue, wscReadyStateFromScriptValue);
|
||||
|
||||
// NOTE: You do not want to end up creating new instances of singletons here. They will be on the ScriptEngine thread
|
||||
// and are likely to be unusable if we "reset" the ScriptEngine by creating a new one (on a whole new thread).
|
||||
|
||||
registerGlobalObject("Script", this);
|
||||
|
||||
{
|
||||
|
@ -638,7 +641,8 @@ void ScriptEngine::init() {
|
|||
resetModuleCache();
|
||||
}
|
||||
|
||||
registerGlobalObject("Audio", &AudioScriptingInterface::getInstance());
|
||||
registerGlobalObject("Audio", DependencyManager::get<AudioScriptingInterface>().data());
|
||||
|
||||
registerGlobalObject("Entities", entityScriptingInterface.data());
|
||||
registerGlobalObject("Quat", &_quatLibrary);
|
||||
registerGlobalObject("Vec3", &_vec3Library);
|
||||
|
@ -1347,7 +1351,7 @@ QUrl ScriptEngine::resourcesPath() const {
|
|||
}
|
||||
|
||||
void ScriptEngine::print(const QString& message) {
|
||||
emit printedMessage(message);
|
||||
emit printedMessage(message, getFilename());
|
||||
}
|
||||
|
||||
// Script.require.resolve -- like resolvePath, but performs more validation and throws exceptions on invalid module identifiers (for consistency with Node.js)
|
||||
|
|
|
@ -236,10 +236,10 @@ signals:
|
|||
void scriptEnding();
|
||||
void finished(const QString& fileNameString, ScriptEngine* engine);
|
||||
void cleanupMenuItem(const QString& menuItemString);
|
||||
void printedMessage(const QString& message);
|
||||
void errorMessage(const QString& message);
|
||||
void warningMessage(const QString& message);
|
||||
void infoMessage(const QString& message);
|
||||
void printedMessage(const QString& message, const QString& scriptName);
|
||||
void errorMessage(const QString& message, const QString& scriptName);
|
||||
void warningMessage(const QString& message, const QString& scriptName);
|
||||
void infoMessage(const QString& message, const QString& scriptName);
|
||||
void runningStateChanged();
|
||||
void loadScript(const QString& scriptName, bool isUserLoaded);
|
||||
void reloadScript(const QString& scriptName, bool isUserLoaded);
|
||||
|
|
|
@ -34,34 +34,24 @@ ScriptsModel& getScriptsModel() {
|
|||
return scriptsModel;
|
||||
}
|
||||
|
||||
void ScriptEngines::onPrintedMessage(const QString& message) {
|
||||
auto scriptEngine = qobject_cast<ScriptEngine*>(sender());
|
||||
auto scriptName = scriptEngine ? scriptEngine->getFilename() : "";
|
||||
void ScriptEngines::onPrintedMessage(const QString& message, const QString& scriptName) {
|
||||
emit printedMessage(message, scriptName);
|
||||
}
|
||||
|
||||
void ScriptEngines::onErrorMessage(const QString& message) {
|
||||
auto scriptEngine = qobject_cast<ScriptEngine*>(sender());
|
||||
auto scriptName = scriptEngine ? scriptEngine->getFilename() : "";
|
||||
void ScriptEngines::onErrorMessage(const QString& message, const QString& scriptName) {
|
||||
emit errorMessage(message, scriptName);
|
||||
}
|
||||
|
||||
void ScriptEngines::onWarningMessage(const QString& message) {
|
||||
auto scriptEngine = qobject_cast<ScriptEngine*>(sender());
|
||||
auto scriptName = scriptEngine ? scriptEngine->getFilename() : "";
|
||||
void ScriptEngines::onWarningMessage(const QString& message, const QString& scriptName) {
|
||||
emit warningMessage(message, scriptName);
|
||||
}
|
||||
|
||||
void ScriptEngines::onInfoMessage(const QString& message) {
|
||||
auto scriptEngine = qobject_cast<ScriptEngine*>(sender());
|
||||
auto scriptName = scriptEngine ? scriptEngine->getFilename() : "";
|
||||
void ScriptEngines::onInfoMessage(const QString& message, const QString& scriptName) {
|
||||
emit infoMessage(message, scriptName);
|
||||
}
|
||||
|
||||
void ScriptEngines::onErrorLoadingScript(const QString& url) {
|
||||
auto scriptEngine = qobject_cast<ScriptEngine*>(sender());
|
||||
auto scriptName = scriptEngine ? scriptEngine->getFilename() : "";
|
||||
emit errorLoadingScript(url, scriptName);
|
||||
emit errorLoadingScript(url);
|
||||
}
|
||||
|
||||
ScriptEngines::ScriptEngines(ScriptEngine::Context context)
|
||||
|
|
|
@ -79,13 +79,13 @@ signals:
|
|||
void errorMessage(const QString& message, const QString& engineName);
|
||||
void warningMessage(const QString& message, const QString& engineName);
|
||||
void infoMessage(const QString& message, const QString& engineName);
|
||||
void errorLoadingScript(const QString& url, const QString& engineName);
|
||||
void errorLoadingScript(const QString& url);
|
||||
|
||||
public slots:
|
||||
void onPrintedMessage(const QString& message);
|
||||
void onErrorMessage(const QString& message);
|
||||
void onWarningMessage(const QString& message);
|
||||
void onInfoMessage(const QString& message);
|
||||
void onPrintedMessage(const QString& message, const QString& scriptName);
|
||||
void onErrorMessage(const QString& message, const QString& scriptName);
|
||||
void onWarningMessage(const QString& message, const QString& scriptName);
|
||||
void onInfoMessage(const QString& message, const QString& scriptName);
|
||||
void onErrorLoadingScript(const QString& url);
|
||||
|
||||
protected slots:
|
||||
|
|
Loading…
Reference in a new issue