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
|
- ✔ React UI
|
||||||
- ❌ Multiple rooms
|
- ❌ Multiple rooms
|
||||||
- ❌ Send relevant entity URIs to client; cache and use instead of full transfer
|
- ❌ 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 informed and Packer::pack: don't use .map on immutables
|
||||||
- ❌ Optimize Damaging::tick
|
- ❌ Optimize Damaging::tick
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import {performance} from 'perf_hooks';
|
||||||
|
|
||||||
import * as I from 'immutable';
|
import * as I from 'immutable';
|
||||||
import immutablediff from 'immutablediff';
|
import immutablediff from 'immutablediff';
|
||||||
|
|
||||||
|
@ -103,7 +105,9 @@ export class Informed extends decorate(Trait) {
|
||||||
if (!(uuid in this._rememberedEntities)) {
|
if (!(uuid in this._rememberedEntities)) {
|
||||||
continue;
|
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.
|
// Take a diff from what the client remembers to now.
|
||||||
const currentState = state.getIn(
|
const currentState = state.getIn(
|
||||||
['room', 'layers', layerId, 'entityList', uuid]
|
['room', 'layers', layerId, 'entityList', uuid]
|
||||||
|
@ -163,7 +167,11 @@ export class Informed extends decorate(Trait) {
|
||||||
if (!remembered) {
|
if (!remembered) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._rememberedEntities[uuid] = remembered;
|
this._rememberedEntities[uuid] = {
|
||||||
|
entity: remembered,
|
||||||
|
// Remember entities for one minute.
|
||||||
|
rememeberFor: 60,
|
||||||
|
};
|
||||||
// Add overrides.
|
// Add overrides.
|
||||||
const overrides = this.entityOverrides(
|
const overrides = this.entityOverrides(
|
||||||
removal.get('path'),
|
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