mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
Fix scripts not reloading in certain edge cases
This commit is contained in:
parent
bb5c6e4373
commit
20a82df9a0
4 changed files with 12 additions and 13 deletions
|
@ -216,12 +216,6 @@ void EntityScriptServer::resetEntitiesScriptEngine() {
|
|||
auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor);
|
||||
newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
|
||||
|
||||
|
||||
// newEngine->setEmitScriptUpdatesFunction([this]() {
|
||||
// SharedNodePointer entityServerNode = DependencyManager::get<NodeList>()->soloNodeOfType(NodeType::EntityServer);
|
||||
// return !entityServerNode || isPhysicsEnabled();
|
||||
// });
|
||||
|
||||
newEngine->registerGlobalObject("AvatarList", DependencyManager::get<AvatarHashMap>().data());
|
||||
newEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
|
||||
|
||||
|
@ -287,14 +281,15 @@ void EntityScriptServer::entityServerScriptChanging(const EntityItemID& entityID
|
|||
}
|
||||
|
||||
void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, const bool reload) {
|
||||
if (_entityViewer.getTree() && !_shuttingDown) {
|
||||
if (_entityViewer.getTree() && !_shuttingDown && _entitiesScriptEngine) {
|
||||
auto details = _entitiesScriptEngine->getEntityScriptDetails(entityID);
|
||||
|
||||
EntityItemPointer entity = _entityViewer.getTree()->findEntityByEntityItemID(entityID);
|
||||
if (entity && entity->shouldPreloadServerScript() && _entitiesScriptEngine) {
|
||||
if (entity && (details.scriptText != entity->getServerScripts() || reload)) {
|
||||
QString scriptUrl = entity->getServerScripts();
|
||||
scriptUrl = ResourceManager::normalizeURL(scriptUrl);
|
||||
qDebug() << "Loading entity server script" << scriptUrl << "for" << entityID;
|
||||
ScriptEngine::loadEntityScript(_entitiesScriptEngine, entityID, scriptUrl, reload);
|
||||
entity->serverScriptHasPreloaded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -444,9 +444,6 @@ public:
|
|||
((_loadedScript != _script) || (_loadedScriptTimestamp != _scriptTimestamp)); }
|
||||
void scriptHasPreloaded() { _loadedScript = _script; _loadedScriptTimestamp = _scriptTimestamp; }
|
||||
|
||||
bool shouldPreloadServerScript() const { return !_serverScripts.isEmpty() && ((_loadedServerScripts != _serverScripts)); }
|
||||
void serverScriptHasPreloaded() { _loadedServerScripts = _serverScripts; }
|
||||
|
||||
bool getClientOnly() const { return _clientOnly; }
|
||||
void setClientOnly(bool clientOnly) { _clientOnly = clientOnly; }
|
||||
// if this entity is client-only, which avatar is it associated with?
|
||||
|
@ -519,7 +516,6 @@ protected:
|
|||
QString _loadedScript; /// the value of _script when the last preload signal was sent
|
||||
quint64 _scriptTimestamp{ ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP }; /// the script loaded property used for forced reload
|
||||
QString _serverScripts;
|
||||
QString _loadedServerScripts;
|
||||
|
||||
/// the value of _scriptTimestamp when the last preload signal was sent
|
||||
// NOTE: on construction we want this to be different from _scriptTimestamp so we intentionally bump it
|
||||
|
|
|
@ -1587,6 +1587,13 @@ void ScriptEngine::unloadAllEntityScripts() {
|
|||
#endif // DEBUG_ENGINE_STATE
|
||||
}
|
||||
|
||||
EntityScriptDetails ScriptEngine::getEntityScriptDetails(const EntityItemID& entityID) const {
|
||||
if (_entityScripts.contains(entityID)) {
|
||||
return _entityScripts[entityID];
|
||||
}
|
||||
return EntityScriptDetails();
|
||||
}
|
||||
|
||||
void ScriptEngine::refreshFileScript(const EntityItemID& entityID) {
|
||||
if (!_entityScripts.contains(entityID)) {
|
||||
return;
|
||||
|
|
|
@ -149,6 +149,7 @@ public:
|
|||
const QStringList& params = QStringList()) override;
|
||||
Q_INVOKABLE void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const PointerEvent& event);
|
||||
Q_INVOKABLE void callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const EntityItemID& otherID, const Collision& collision);
|
||||
Q_INVOKABLE EntityScriptDetails getEntityScriptDetails(const EntityItemID& entityID) const;
|
||||
|
||||
Q_INVOKABLE void requestGarbageCollection() { collectGarbage(); }
|
||||
|
||||
|
|
Loading…
Reference in a new issue