mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
EntityScriptServer tracks server scripts
This commit is contained in:
parent
97e9bfff36
commit
20b7bb0c54
6 changed files with 19 additions and 4 deletions
|
@ -97,7 +97,7 @@ void EntityScriptServer::run() {
|
|||
auto tree = _entityViewer.getTree().get();
|
||||
connect(tree, &EntityTree::deletingEntity, this, &EntityScriptServer::deletingEntity, Qt::QueuedConnection);
|
||||
connect(tree, &EntityTree::addingEntity, this, &EntityScriptServer::addingEntity, Qt::QueuedConnection);
|
||||
connect(tree, &EntityTree::entityScriptChanging, this, &EntityScriptServer::entityScriptChanging, Qt::QueuedConnection);
|
||||
connect(tree, &EntityTree::entityServerScriptChanging, this, &EntityScriptServer::entityServerScriptChanging, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void EntityScriptServer::nodeActivated(SharedNodePointer activatedNode) {
|
||||
|
@ -220,7 +220,7 @@ void EntityScriptServer::deletingEntity(const EntityItemID& entityID) {
|
|||
}
|
||||
}
|
||||
|
||||
void EntityScriptServer::entityScriptChanging(const EntityItemID& entityID, const bool reload) {
|
||||
void EntityScriptServer::entityServerScriptChanging(const EntityItemID& entityID, const bool reload) {
|
||||
if (_entityViewer.getTree() && !_shuttingDown) {
|
||||
_entitiesScriptEngine->unloadEntityScript(entityID);
|
||||
checkAndCallPreload(entityID, reload);
|
||||
|
@ -231,7 +231,7 @@ void EntityScriptServer::checkAndCallPreload(const EntityItemID& entityID, const
|
|||
if (_entityViewer.getTree() && !_shuttingDown) {
|
||||
EntityItemPointer entity = _entityViewer.getTree()->findEntityByEntityItemID(entityID);
|
||||
if (entity && entity->shouldPreloadScript() && _entitiesScriptEngine) {
|
||||
QString scriptUrl = entity->getScript();
|
||||
QString scriptUrl = entity->getServerScripts();
|
||||
scriptUrl = ResourceManager::normalizeURL(scriptUrl);
|
||||
ScriptEngine::loadEntityScript(_entitiesScriptEngine, entityID, scriptUrl, reload);
|
||||
entity->scriptHasPreloaded();
|
||||
|
|
|
@ -48,7 +48,7 @@ private:
|
|||
void shutdown();
|
||||
void addingEntity(const EntityItemID& entityID);
|
||||
void deletingEntity(const EntityItemID& entityID);
|
||||
void entityScriptChanging(const EntityItemID& entityID, const bool reload);
|
||||
void entityServerScriptChanging(const EntityItemID& entityID, const bool reload);
|
||||
void checkAndCallPreload(const EntityItemID& entityID, const bool reload = false);
|
||||
|
||||
bool _shuttingDown { false };
|
||||
|
|
|
@ -444,6 +444,10 @@ public:
|
|||
((_loadedScript != _script) || (_loadedScriptTimestamp != _scriptTimestamp)); }
|
||||
void scriptHasPreloaded() { _loadedScript = _script; _loadedScriptTimestamp = _scriptTimestamp; }
|
||||
|
||||
bool shouldPreloadServerScript() const { return !_script.isEmpty() &&
|
||||
((_loadedScript != _script) || (_loadedScriptTimestamp != _scriptTimestamp)); }
|
||||
void serverScriptHasPreloaded() { _loadedScript = _script; _loadedScriptTimestamp = _scriptTimestamp; }
|
||||
|
||||
bool getClientOnly() const { return _clientOnly; }
|
||||
void setClientOnly(bool clientOnly) { _clientOnly = clientOnly; }
|
||||
// if this entity is client-only, which avatar is it associated with?
|
||||
|
|
|
@ -394,6 +394,10 @@ void EntityTree::emitEntityScriptChanging(const EntityItemID& entityItemID, cons
|
|||
emit entityScriptChanging(entityItemID, reload);
|
||||
}
|
||||
|
||||
void EntityTree::emitEntityServerScriptChanging(const EntityItemID& entityItemID, const bool reload) {
|
||||
emit entityServerScriptChanging(entityItemID, reload);
|
||||
}
|
||||
|
||||
void EntityTree::notifyNewCollisionSoundURL(const QString& newURL, const EntityItemID& entityID) {
|
||||
emit newCollisionSoundURL(QUrl(newURL), entityID);
|
||||
}
|
||||
|
|
|
@ -202,6 +202,7 @@ public:
|
|||
void entityChanged(EntityItemPointer entity);
|
||||
|
||||
void emitEntityScriptChanging(const EntityItemID& entityItemID, const bool reload);
|
||||
void emitEntityServerScriptChanging(const EntityItemID& entityItemID, const bool reload);
|
||||
|
||||
void setSimulation(EntitySimulationPointer simulation);
|
||||
EntitySimulationPointer getSimulation() const { return _simulation; }
|
||||
|
@ -270,6 +271,7 @@ signals:
|
|||
void deletingEntity(const EntityItemID& entityID);
|
||||
void addingEntity(const EntityItemID& entityID);
|
||||
void entityScriptChanging(const EntityItemID& entityItemID, const bool reload);
|
||||
void entityServerScriptChanging(const EntityItemID& entityItemID, const bool reload);
|
||||
void newCollisionSoundURL(const QUrl& url, const EntityItemID& entityID);
|
||||
void clearingEntities();
|
||||
|
||||
|
|
|
@ -925,6 +925,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
|||
// 3) remember the old cube for the entity so we can mark it as dirty
|
||||
if (entityItem) {
|
||||
QString entityScriptBefore = entityItem->getScript();
|
||||
QString entityServerScriptsBefore = entityItem->getServerScripts();
|
||||
quint64 entityScriptTimestampBefore = entityItem->getScriptTimestamp();
|
||||
bool bestFitBefore = bestFitEntityBounds(entityItem);
|
||||
EntityTreeElementPointer currentContainingElement = _myTree->getContainingElement(entityItemID);
|
||||
|
@ -948,6 +949,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
|||
}
|
||||
|
||||
QString entityScriptAfter = entityItem->getScript();
|
||||
QString entityServerScriptsAfter = entityItem->getServerScripts();
|
||||
quint64 entityScriptTimestampAfter = entityItem->getScriptTimestamp();
|
||||
bool reload = entityScriptTimestampBefore != entityScriptTimestampAfter;
|
||||
|
||||
|
@ -956,6 +958,9 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
|
|||
if (entityScriptBefore != entityScriptAfter || reload) {
|
||||
_myTree->emitEntityScriptChanging(entityItemID, reload); // the entity script has changed
|
||||
}
|
||||
if (entityServerScriptsBefore != entityServerScriptsAfter || reload) {
|
||||
_myTree->emitEntityServerScriptChanging(entityItemID, reload); // the entity server script has changed
|
||||
}
|
||||
|
||||
} else {
|
||||
entityItem = EntityTypes::constructEntityItem(dataAt, bytesLeftToRead, args);
|
||||
|
|
Loading…
Reference in a new issue