Refactor backend to use commands

This commit is contained in:
Schmelczer András 2020-11-06 21:10:08 +01:00
parent 503c99cb1f
commit 7cf33b9f1a
18 changed files with 144 additions and 156 deletions

View file

@ -4,19 +4,19 @@ import { BoundingBoxTree } from './bounding-box-tree';
import { Physical } from '../physicals/physical';
import { StaticPhysical } from '../physicals/static-physical';
import { DynamicPhysical } from '../physicals/dynamic-physical';
import {
GeneratesPoints,
generatesPoints,
} from '../../objects/capabilities/generates-points';
import { timeDependent } from '../../objects/capabilities/time-dependent';
import { Command, CommandReceiver } from 'shared';
export class PhysicalContainer {
export class PhysicalContainer extends CommandReceiver {
private isTreeInitialized = false;
private staticBoundingBoxesWaitList: Array<StaticPhysical> = [];
private staticBoundingBoxes = new BoundingBoxTree();
private dynamicBoundingBoxes = new BoundingBoxList();
private objects: Array<Physical> = [];
protected defaultCommandExecutor(c: Command) {
this.objects.forEach((o) => o.handleCommand(c));
}
public initialize() {
this.staticBoundingBoxes.build(this.staticBoundingBoxesWaitList);
this.isTreeInitialized = true;
@ -41,29 +41,10 @@ export class PhysicalContainer {
this.dynamicBoundingBoxes.remove(object);
}
public stepObjects(deltaTime: number) {
this.objects.forEach((o) => timeDependent(o) && o.step(deltaTime));
}
public resetRemoteCalls() {
this.objects.forEach((o) => o.gameObject.resetRemoteCalls());
}
public getPointsGenerated(): { decla: number; red: number } {
return this.objects
.filter((o) => generatesPoints(o))
.reduce(
(sum, o) => {
const { decla, red } = ((o as unknown) as GeneratesPoints).getPoints();
return {
decla: sum.decla + decla,
red: sum.red + red,
};
},
{ decla: 0, red: 0 },
);
}
public findIntersecting(box: BoundingBoxBase): Array<Physical> {
return [
...this.staticBoundingBoxes.findIntersecting(box),