Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Actors with orphaned ownership will properly update upon new authoritative user #743

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions packages/sdk/src/core/contextInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ export class ContextInternal {

public onSetAuthoritative = (userId: Guid) => {
this._rigidBodyOrphanSet.forEach(
(value) => {
if (value === this._rigidBodyDefaultOwner) {
const actor = this.actorSet.get(value);
actor.owner = userId;

this._rigidBodyOwnerMap.set(value, userId);
}
})
(actorId) => {
const actor = this.actorSet.get(actorId);
actor.owner = userId;
this._rigidBodyOwnerMap.set(actorId, userId);
}
)
this._rigidBodyOrphanSet.clear();
this._rigidBodyDefaultOwner = userId;
};
Expand Down Expand Up @@ -531,22 +529,23 @@ export class ContextInternal {
this.context.emitter.emit('user-left', user);

if (userId !== this._rigidBodyDefaultOwner) {
this._rigidBodyOwnerMap.forEach( (value, key) => {
if (value === userId) {
const actor = this.actorSet.get(key);
actor.owner = this._rigidBodyDefaultOwner;
this._rigidBodyOwnerMap.set(key, this._rigidBodyDefaultOwner);
this._rigidBodyOwnerMap.forEach(
(ownerId, actorId) => {
if (ownerId === userId) {
const actor = this.actorSet.get(actorId);
actor.owner = this._rigidBodyDefaultOwner;
this._rigidBodyOwnerMap.set(actorId, this._rigidBodyDefaultOwner);
}
}
})
)
} else {
this._rigidBodyOwnerMap.forEach(
(value, key) => {
if (value === userId) {
const actor = this.actorSet.get(key);
actor.owner = this._rigidBodyDefaultOwner;
this._rigidBodyOrphanSet.add(key);
(ownerId, actorId) => {
if (ownerId === userId) {
this._rigidBodyOrphanSet.add(actorId);
}
})
}
)
}
}
}
Expand Down