mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 09:48:27 +02:00
added leaveAllEntities support
This commit is contained in:
parent
97d617bd17
commit
32ea38b938
3 changed files with 26 additions and 2 deletions
|
@ -27,10 +27,12 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
this.enterEntity = function(entityID) {
|
this.enterEntity = function(entityID) {
|
||||||
|
print("enterEntity("+entityID.id+")");
|
||||||
playSound();
|
playSound();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.leaveEntity = function(entityID) {
|
this.leaveEntity = function(entityID) {
|
||||||
|
print("leaveEntity("+entityID.id+")");
|
||||||
playSound();
|
playSound();
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
@ -62,6 +62,7 @@ EntityTreeRenderer::~EntityTreeRenderer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTreeRenderer::clear() {
|
void EntityTreeRenderer::clear() {
|
||||||
|
leaveAllEntities();
|
||||||
foreach (const EntityItemID& entityID, _entityScripts.keys()) {
|
foreach (const EntityItemID& entityID, _entityScripts.keys()) {
|
||||||
checkAndCallUnload(entityID);
|
checkAndCallUnload(entityID);
|
||||||
}
|
}
|
||||||
|
@ -82,8 +83,7 @@ void EntityTreeRenderer::init() {
|
||||||
|
|
||||||
// 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
|
||||||
// first chance, we'll check for enter/leave entity events.
|
// first chance, we'll check for enter/leave entity events.
|
||||||
glm::vec3 avatarPosition = _viewState->getAvatarPosition();
|
_lastAvatarPosition = _viewState->getAvatarPosition() + glm::vec3(1.0f, 1.0f, 1.0f);
|
||||||
_lastAvatarPosition = avatarPosition + glm::vec3(1.0f, 1.0f, 1.0f);
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -297,6 +297,27 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityTreeRenderer::leaveAllEntities() {
|
||||||
|
if (_tree) {
|
||||||
|
_tree->lockForWrite(); // so that our scripts can do edits if they want
|
||||||
|
|
||||||
|
// for all of our previous containing entities, if they are no longer containing then send them a leave event
|
||||||
|
foreach(const EntityItemID& entityID, _currentEntitiesInside) {
|
||||||
|
emit leaveEntity(entityID);
|
||||||
|
QScriptValueList entityArgs = createEntityArgs(entityID);
|
||||||
|
QScriptValue entityScript = loadEntityScript(entityID);
|
||||||
|
if (entityScript.property("leaveEntity").isValid()) {
|
||||||
|
entityScript.property("leaveEntity").call(entityScript, entityArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_currentEntitiesInside.clear();
|
||||||
|
|
||||||
|
// make sure our "last avatar position" is something other than our current position, so that on our
|
||||||
|
// first chance, we'll check for enter/leave entity events.
|
||||||
|
_lastAvatarPosition = _viewState->getAvatarPosition() + glm::vec3(1.0f, 1.0f, 1.0f);
|
||||||
|
_tree->unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::RenderSide renderSide) {
|
void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::RenderSide renderSide) {
|
||||||
if (_tree) {
|
if (_tree) {
|
||||||
Model::startScene(renderSide);
|
Model::startScene(renderSide);
|
||||||
|
|
|
@ -129,6 +129,7 @@ private:
|
||||||
|
|
||||||
QScriptValueList createEntityArgs(const EntityItemID& entityID);
|
QScriptValueList createEntityArgs(const EntityItemID& entityID);
|
||||||
void checkEnterLeaveEntities();
|
void checkEnterLeaveEntities();
|
||||||
|
void leaveAllEntities();
|
||||||
glm::vec3 _lastAvatarPosition;
|
glm::vec3 _lastAvatarPosition;
|
||||||
QVector<EntityItemID> _currentEntitiesInside;
|
QVector<EntityItemID> _currentEntitiesInside;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue