Create network component and system
This commit is contained in:
parent
c6e9baa000
commit
98e795029b
@ -47,8 +47,9 @@ export class BoundingBox extends Component {
|
||||
{ x: this.dimension.width / 2, y: this.dimension.height / 2 },
|
||||
{ x: this.dimension.width / 2, y: -this.dimension.height / 2 },
|
||||
]
|
||||
.map((vertex) => rotateVector(vertex, this.rotation))
|
||||
.map((vertex) => rotateVector(vertex, this.rotation)) // rotate
|
||||
.map((vertex) => {
|
||||
// translate
|
||||
return {
|
||||
x: vertex.x + this.center.x,
|
||||
y: vertex.y + this.center.y,
|
||||
@ -56,9 +57,10 @@ export class BoundingBox extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
public getRotationInPiOfUnitCircle() {
|
||||
public getRotationInPiOfUnitCircle(): number {
|
||||
let rads = this.rotation * (Math.PI / 180);
|
||||
if (rads >= Math.PI) {
|
||||
// Physics system guarantees rotation \in [0, 360)
|
||||
rads -= Math.PI;
|
||||
}
|
||||
return rads;
|
||||
|
7
engine/components/NetworkUpdateable.ts
Normal file
7
engine/components/NetworkUpdateable.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { Component, ComponentNames } from ".";
|
||||
|
||||
export class NetworkUpdateable extends Component {
|
||||
constructor() {
|
||||
super(ComponentNames.NetworkUpdateable);
|
||||
}
|
||||
}
|
@ -12,4 +12,5 @@ export * from "./WallBounded";
|
||||
export * from "./Gravity";
|
||||
export * from "./Mass";
|
||||
export * from "./Moment";
|
||||
export * from "./NetworkUpdateable";
|
||||
export * from "./names";
|
||||
|
@ -12,4 +12,5 @@ export namespace ComponentNames {
|
||||
export const Forces = "Forces";
|
||||
export const Mass = "Mass";
|
||||
export const Moment = "Moment";
|
||||
export const NetworkUpdateable = "NetworkUpdateable";
|
||||
}
|
||||
|
@ -41,17 +41,16 @@ export class QuadTree {
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public insert(id: number, dimension: Dimension2D, center: Coord2D): void {
|
||||
const box: BoxedEntry = { id, center, dimension };
|
||||
public insert(boxedEntry: BoxedEntry): void {
|
||||
if (this.hasChildren()) {
|
||||
this.getQuadrants(box).forEach((quadrant) => {
|
||||
this.getQuadrants(boxedEntry).forEach((quadrant) => {
|
||||
const quadrantBox = this.children.get(quadrant);
|
||||
quadrantBox?.insert(id, dimension, center);
|
||||
quadrantBox?.insert(boxedEntry);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.objects.push({ id, dimension, center });
|
||||
this.objects.push(boxedEntry);
|
||||
|
||||
if (
|
||||
this.objects.length > this.splitThreshold &&
|
||||
@ -66,6 +65,7 @@ export class QuadTree {
|
||||
|
||||
public clear(): void {
|
||||
this.objects = [];
|
||||
|
||||
if (this.hasChildren()) {
|
||||
this.children.forEach((child) => child.clear());
|
||||
this.children.clear();
|
||||
|
@ -63,7 +63,11 @@ export class Collision extends System {
|
||||
dimension = boundingBox.getOutscribedBoxDims();
|
||||
}
|
||||
|
||||
this.quadTree.insert(entity.id, dimension, boundingBox.center);
|
||||
this.quadTree.insert({
|
||||
id: entity.id,
|
||||
dimension,
|
||||
center: boundingBox.center,
|
||||
});
|
||||
});
|
||||
|
||||
// find colliding entities and perform collisions
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
import { Game } from "../Game";
|
||||
import { KeyConstants, PhysicsConstants } from "../config";
|
||||
import { Action } from "../interfaces";
|
||||
import { System, SystemNames } from "./";
|
||||
import { System, SystemNames } from ".";
|
||||
|
||||
export class Input extends System {
|
||||
private keys: Set<string>;
|
||||
|
10
engine/systems/NetworkUpdate.ts
Normal file
10
engine/systems/NetworkUpdate.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { System, SystemNames } from ".";
|
||||
import { Game } from "../Game";
|
||||
|
||||
export class NetworkUpdate extends System {
|
||||
constructor() {
|
||||
super(SystemNames.NetworkUpdate);
|
||||
}
|
||||
|
||||
public update(_dt: number, _game: Game) {}
|
||||
}
|
@ -6,3 +6,4 @@ export * from "./Input";
|
||||
export * from "./FacingDirection";
|
||||
export * from "./Collision";
|
||||
export * from "./WallBounds";
|
||||
export * from "./NetworkUpdate";
|
||||
|
@ -5,4 +5,5 @@ export namespace SystemNames {
|
||||
export const Input = "Input";
|
||||
export const Collision = "Collision";
|
||||
export const WallBounds = "WallBounds";
|
||||
export const NetworkUpdate = "NetworkUpdate";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user