mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
fix locking issue in enter/leave entity scripts
This commit is contained in:
parent
f3c9e8cd26
commit
8e7ead2ead
2 changed files with 14 additions and 7 deletions
|
@ -9,15 +9,20 @@
|
|||
|
||||
this.preload = function(entityID) {
|
||||
teleport = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/birarda/teleport.raw");
|
||||
|
||||
|
||||
var properties = Entities.getEntityProperties(entityID);
|
||||
portalDestination = properties.userData;
|
||||
animationURL = properties.modelURL;
|
||||
|
||||
print("The portal destination is " + portalDestination);
|
||||
}
|
||||
|
||||
this.enterEntity = function(entityID) {
|
||||
|
||||
var properties = Entities.getEntityProperties(entityID); // in case the userData/portalURL has changed
|
||||
portalDestination = properties.userData;
|
||||
|
||||
print("enterEntity() .... The portal destination is " + portalDestination);
|
||||
|
||||
if (portalDestination.length > 0) {
|
||||
print("Teleporting to hifi://" + portalDestination);
|
||||
Window.location = "hifi://" + portalDestination;
|
||||
|
|
|
@ -277,7 +277,6 @@ void EntityTreeRenderer::update() {
|
|||
|
||||
void EntityTreeRenderer::checkEnterLeaveEntities() {
|
||||
if (_tree && !_shuttingDown) {
|
||||
_tree->lockForWrite(); // so that our scripts can do edits if they want
|
||||
glm::vec3 avatarPosition = _viewState->getAvatarPosition();
|
||||
|
||||
if (avatarPosition != _lastAvatarPosition) {
|
||||
|
@ -286,6 +285,7 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
|
|||
QVector<EntityItemID> entitiesContainingAvatar;
|
||||
|
||||
// find the entities near us
|
||||
_tree->lockForRead(); // don't let someone else change our tree while we search
|
||||
static_cast<EntityTree*>(_tree)->findEntities(avatarPosition, radius, foundEntities);
|
||||
|
||||
// create a list of entities that actually contain the avatar's position
|
||||
|
@ -294,6 +294,11 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
|
|||
entitiesContainingAvatar << entity->getEntityItemID();
|
||||
}
|
||||
}
|
||||
_tree->unlock();
|
||||
|
||||
// Note: at this point we don't need to worry about the tree being locked, because we only deal with
|
||||
// EntityItemIDs from here. The loadEntityScript() method is robust against attempting to load scripts
|
||||
// for entity IDs that no longer exist.
|
||||
|
||||
// for all of our previous containing entities, if they are no longer containing then send them a leave event
|
||||
foreach(const EntityItemID& entityID, _currentEntitiesInside) {
|
||||
|
@ -322,14 +327,12 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
|
|||
_currentEntitiesInside = entitiesContainingAvatar;
|
||||
_lastAvatarPosition = avatarPosition;
|
||||
}
|
||||
_tree->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void EntityTreeRenderer::leaveAllEntities() {
|
||||
if (_tree && !_shuttingDown) {
|
||||
_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);
|
||||
|
@ -344,7 +347,6 @@ void EntityTreeRenderer::leaveAllEntities() {
|
|||
// 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((float)TREE_SCALE);
|
||||
_tree->unlock();
|
||||
}
|
||||
}
|
||||
void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::RenderSide renderSide) {
|
||||
|
|
Loading…
Reference in a new issue