mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 20:25:00 +02:00
add support for unload method
This commit is contained in:
parent
0a6ffe3dbd
commit
b2c342c5c7
3 changed files with 40 additions and 3 deletions
|
@ -2317,7 +2317,7 @@ void Application::update(float deltaTime) {
|
||||||
updateDialogs(deltaTime); // update various stats dialogs if present
|
updateDialogs(deltaTime); // update various stats dialogs if present
|
||||||
updateCursor(deltaTime); // Handle cursor updates
|
updateCursor(deltaTime); // Handle cursor updates
|
||||||
|
|
||||||
{
|
if (!_aboutToQuit) {
|
||||||
PerformanceTimer perfTimer("entities");
|
PerformanceTimer perfTimer("entities");
|
||||||
_entities.update(); // update the models...
|
_entities.update(); // update the models...
|
||||||
{
|
{
|
||||||
|
|
|
@ -86,7 +86,7 @@ void EntityTreeRenderer::init() {
|
||||||
|
|
||||||
connect(entityTree, &EntityTree::deletingEntity, this, &EntityTreeRenderer::deletingEntity);
|
connect(entityTree, &EntityTree::deletingEntity, this, &EntityTreeRenderer::deletingEntity);
|
||||||
connect(entityTree, &EntityTree::addingEntity, this, &EntityTreeRenderer::checkAndCallPreload);
|
connect(entityTree, &EntityTree::addingEntity, this, &EntityTreeRenderer::checkAndCallPreload);
|
||||||
connect(entityTree, &EntityTree::entityScriptChanging, this, &EntityTreeRenderer::checkAndCallPreload);
|
connect(entityTree, &EntityTree::entityScriptChanging, this, &EntityTreeRenderer::entitySciptChanging);
|
||||||
connect(entityTree, &EntityTree::changingEntityID, this, &EntityTreeRenderer::changingEntityID);
|
connect(entityTree, &EntityTree::changingEntityID, this, &EntityTreeRenderer::changingEntityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,6 +192,22 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
||||||
return entityScriptObject; // newly constructed
|
return entityScriptObject; // newly constructed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QScriptValue EntityTreeRenderer::getPreviouslyLoadedEntityScript(const EntityItemID& entityItemID) {
|
||||||
|
EntityItem* entity = static_cast<EntityTree*>(_tree)->findEntityByEntityItemID(entityItemID);
|
||||||
|
return getPreviouslyLoadedEntityScript(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QScriptValue EntityTreeRenderer::getPreviouslyLoadedEntityScript(EntityItem* entity) {
|
||||||
|
if (entity) {
|
||||||
|
EntityItemID entityID = entity->getEntityItemID();
|
||||||
|
if (_entityScripts.contains(entityID)) {
|
||||||
|
EntityScriptDetails details = _entityScripts[entityID];
|
||||||
|
return details.scriptObject; // previously loaded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QScriptValue(); // no script
|
||||||
|
}
|
||||||
void EntityTreeRenderer::setTree(Octree* newTree) {
|
void EntityTreeRenderer::setTree(Octree* newTree) {
|
||||||
OctreeRenderer::setTree(newTree);
|
OctreeRenderer::setTree(newTree);
|
||||||
static_cast<EntityTree*>(_tree)->setFBXService(this);
|
static_cast<EntityTree*>(_tree)->setFBXService(this);
|
||||||
|
@ -842,9 +858,16 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) {
|
void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) {
|
||||||
|
|
||||||
|
checkAndCallUnload(entityID);
|
||||||
_entityScripts.remove(entityID);
|
_entityScripts.remove(entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityTreeRenderer::entitySciptChanging(const EntityItemID& entityID) {
|
||||||
|
checkAndCallUnload(entityID);
|
||||||
|
checkAndCallPreload(entityID);
|
||||||
|
}
|
||||||
|
|
||||||
void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID) {
|
void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID) {
|
||||||
// load the entity script if needed...
|
// load the entity script if needed...
|
||||||
QScriptValue entityScript = loadEntityScript(entityID);
|
QScriptValue entityScript = loadEntityScript(entityID);
|
||||||
|
@ -854,6 +877,15 @@ void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityTreeRenderer::checkAndCallUnload(const EntityItemID& entityID) {
|
||||||
|
QScriptValue entityScript = getPreviouslyLoadedEntityScript(entityID);
|
||||||
|
if (entityScript.property("unload").isValid()) {
|
||||||
|
QScriptValueList entityArgs = createEntityArgs(entityID);
|
||||||
|
entityScript.property("unload").call(entityScript, entityArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void EntityTreeRenderer::changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID) {
|
void EntityTreeRenderer::changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID) {
|
||||||
if (_entityScripts.contains(oldEntityID)) {
|
if (_entityScripts.contains(oldEntityID)) {
|
||||||
EntityScriptDetails details = _entityScripts[oldEntityID];
|
EntityScriptDetails details = _entityScripts[oldEntityID];
|
||||||
|
|
|
@ -106,9 +106,12 @@ signals:
|
||||||
public slots:
|
public slots:
|
||||||
void deletingEntity(const EntityItemID& entityID);
|
void deletingEntity(const EntityItemID& entityID);
|
||||||
void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID);
|
void changingEntityID(const EntityItemID& oldEntityID, const EntityItemID& newEntityID);
|
||||||
void checkAndCallPreload(const EntityItemID& entityID);
|
void entitySciptChanging(const EntityItemID& entityID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void checkAndCallPreload(const EntityItemID& entityID);
|
||||||
|
void checkAndCallUnload(const EntityItemID& entityID);
|
||||||
|
|
||||||
QList<Model*> _releasedModels;
|
QList<Model*> _releasedModels;
|
||||||
void renderProxies(const EntityItem* entity, RenderArgs* args);
|
void renderProxies(const EntityItem* entity, RenderArgs* args);
|
||||||
PickRay computePickRay(float x, float y);
|
PickRay computePickRay(float x, float y);
|
||||||
|
@ -127,6 +130,8 @@ private:
|
||||||
|
|
||||||
QScriptValue loadEntityScript(EntityItem* entity);
|
QScriptValue loadEntityScript(EntityItem* entity);
|
||||||
QScriptValue loadEntityScript(const EntityItemID& entityItemID);
|
QScriptValue loadEntityScript(const EntityItemID& entityItemID);
|
||||||
|
QScriptValue getPreviouslyLoadedEntityScript(const EntityItemID& entityItemID);
|
||||||
|
QScriptValue getPreviouslyLoadedEntityScript(EntityItem* entity);
|
||||||
QString loadScriptContents(const QString& scriptMaybeURLorText);
|
QString loadScriptContents(const QString& scriptMaybeURLorText);
|
||||||
QScriptValueList createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID);
|
QScriptValueList createMouseEventArgs(const EntityItemID& entityID, QMouseEvent* event, unsigned int deviceID);
|
||||||
QScriptValueList createMouseEventArgs(const EntityItemID& entityID, const MouseEvent& mouseEvent);
|
QScriptValueList createMouseEventArgs(const EntityItemID& entityID, const MouseEvent& mouseEvent);
|
||||||
|
|
Loading…
Reference in a new issue