fix: forget remembered entities after a while
This commit is contained in:
parent
19ff9e2293
commit
6db0c2bcdd
2
TODO.md
2
TODO.md
|
@ -3,6 +3,6 @@
|
|||
- ✔ React UI
|
||||
- ❌ Multiple rooms
|
||||
- ❌ Send relevant entity URIs to client; cache and use instead of full transfer
|
||||
- ❌ Forget remembered entities after a while
|
||||
- ✔ Forget remembered entities after a while
|
||||
- ❌ Optimize informed and Packer::pack: don't use .map on immutables
|
||||
- ❌ Optimize Damaging::tick
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import {performance} from 'perf_hooks';
|
||||
|
||||
import * as I from 'immutable';
|
||||
import immutablediff from 'immutablediff';
|
||||
|
||||
|
@ -103,7 +105,9 @@ export class Informed extends decorate(Trait) {
|
|||
if (!(uuid in this._rememberedEntities)) {
|
||||
continue;
|
||||
}
|
||||
const rememberedEntity = this._rememberedEntities[uuid];
|
||||
const rememberedEntity = this._rememberedEntities[uuid].entity;
|
||||
// Reset remembrance timeout.
|
||||
this._rememberedEntities[uuid].rememberFor = 60;
|
||||
// Take a diff from what the client remembers to now.
|
||||
const currentState = state.getIn(
|
||||
['room', 'layers', layerId, 'entityList', uuid]
|
||||
|
@ -163,7 +167,11 @@ export class Informed extends decorate(Trait) {
|
|||
if (!remembered) {
|
||||
return;
|
||||
}
|
||||
this._rememberedEntities[uuid] = remembered;
|
||||
this._rememberedEntities[uuid] = {
|
||||
entity: remembered,
|
||||
// Remember entities for one minute.
|
||||
rememeberFor: 60,
|
||||
};
|
||||
// Add overrides.
|
||||
const overrides = this.entityOverrides(
|
||||
removal.get('path'),
|
||||
|
@ -255,4 +263,14 @@ export class Informed extends decorate(Trait) {
|
|||
};
|
||||
}
|
||||
|
||||
tick(elapsed) {
|
||||
const rememberedEntities = this._rememberedEntities;
|
||||
for (const uuid in rememberedEntities) {
|
||||
const rememberFor = rememberedEntities[uuid].rememberFor -= elapsed;
|
||||
if (rememberFor <= 0) {
|
||||
delete rememberedEntities[uuid];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user