refactor: more sensible implementation
This commit is contained in:
parent
6d5b00b44c
commit
4744df90d9
|
@ -32,8 +32,6 @@ function createConnectionListener(avocadoServer) {
|
|||
// Create and track a new entity for the connection.
|
||||
const entity = createEntityForConnection(socket);
|
||||
entityList.addEntity(entity);
|
||||
// Right in the middle. TODO: camera.
|
||||
entity.listLocator = () => [640, 360];
|
||||
// Listen for events.
|
||||
socket.on('message', createMessageListener(avocadoServer, socket));
|
||||
socket.on('disconnect', createDisconnectionListener(avocadoServer, socket));
|
||||
|
@ -150,7 +148,8 @@ function createMainLoop(avocadoServer) {
|
|||
}
|
||||
// All informed entities get their own slice.
|
||||
for (const entity of informables) {
|
||||
const reduced = entity.reduceStateDiff(diff);
|
||||
const CAMERA_LOCATION = [640, 360];
|
||||
const reduced = entity.reduceStateDiff(diff, CAMERA_LOCATION);
|
||||
entity.inform(reduced);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,9 +26,10 @@ class InformedBase extends Trait {
|
|||
delete this._socket;
|
||||
}
|
||||
|
||||
reduceStateDiffForEntityList(diff) {
|
||||
reduceStateDiffForEntityList(diff, position) {
|
||||
// Reduce the entity list.
|
||||
const nearbyEntities = this.entity.entitiesToInform();
|
||||
const informSize = this.entity.informSize.toJS();
|
||||
const nearbyEntities = this.entity.nearbyEntities(informSize, position);
|
||||
const reducedEntityList = {};
|
||||
let nearby = I.Set();
|
||||
for (const entity of nearbyEntities) {
|
||||
|
@ -78,11 +79,6 @@ class InformedBase extends Trait {
|
|||
methods() {
|
||||
return {
|
||||
|
||||
entitiesToInform: () => {
|
||||
const informSize = this.entity.informSize.toJS();
|
||||
return this.entity.nearbyEntities(informSize);
|
||||
},
|
||||
|
||||
inform: (diff) => {
|
||||
// Remove dead updates.
|
||||
if (0 === Object.keys(diff).length) {
|
||||
|
@ -98,8 +94,8 @@ class InformedBase extends Trait {
|
|||
});
|
||||
},
|
||||
|
||||
reduceStateDiff: (diff) => {
|
||||
return this.reduceStateDiffForEntityList(diff);
|
||||
reduceStateDiff: (diff, position) => {
|
||||
return this.reduceStateDiffForEntityList(diff, position);
|
||||
},
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user