summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-08-13 16:47:58 -0600
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-08-13 16:47:58 -0600
commit98e795029bcc404463ed151ff5255a72498bc641 (patch)
tree48e50d896d00761eae18c89f89e5dd0ef353b660 /engine
parentc6e9baa0009f7cce0f6ff156a3957ef04a8cb684 (diff)
downloadjumpstorm-98e795029bcc404463ed151ff5255a72498bc641.tar.gz
jumpstorm-98e795029bcc404463ed151ff5255a72498bc641.zip
Create network component and system
Diffstat (limited to 'engine')
-rw-r--r--engine/components/BoundingBox.ts6
-rw-r--r--engine/components/NetworkUpdateable.ts7
-rw-r--r--engine/components/index.ts1
-rw-r--r--engine/components/names.ts1
-rw-r--r--engine/structures/QuadTree.ts10
-rw-r--r--engine/systems/Collision.ts6
-rw-r--r--engine/systems/Input.ts2
-rw-r--r--engine/systems/NetworkUpdate.ts10
-rw-r--r--engine/systems/index.ts1
-rw-r--r--engine/systems/names.ts1
10 files changed, 36 insertions, 9 deletions
diff --git a/engine/components/BoundingBox.ts b/engine/components/BoundingBox.ts
index 5e21b2f..19967f7 100644
--- a/engine/components/BoundingBox.ts
+++ b/engine/components/BoundingBox.ts
@@ -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;
diff --git a/engine/components/NetworkUpdateable.ts b/engine/components/NetworkUpdateable.ts
new file mode 100644
index 0000000..73ceeba
--- /dev/null
+++ b/engine/components/NetworkUpdateable.ts
@@ -0,0 +1,7 @@
+import { Component, ComponentNames } from ".";
+
+export class NetworkUpdateable extends Component {
+ constructor() {
+ super(ComponentNames.NetworkUpdateable);
+ }
+}
diff --git a/engine/components/index.ts b/engine/components/index.ts
index 67f1259..90f4965 100644
--- a/engine/components/index.ts
+++ b/engine/components/index.ts
@@ -12,4 +12,5 @@ export * from "./WallBounded";
export * from "./Gravity";
export * from "./Mass";
export * from "./Moment";
+export * from "./NetworkUpdateable";
export * from "./names";
diff --git a/engine/components/names.ts b/engine/components/names.ts
index e2ee3d3..02ee064 100644
--- a/engine/components/names.ts
+++ b/engine/components/names.ts
@@ -12,4 +12,5 @@ export namespace ComponentNames {
export const Forces = "Forces";
export const Mass = "Mass";
export const Moment = "Moment";
+ export const NetworkUpdateable = "NetworkUpdateable";
}
diff --git a/engine/structures/QuadTree.ts b/engine/structures/QuadTree.ts
index d1ff3b1..a57c6e7 100644
--- a/engine/structures/QuadTree.ts
+++ b/engine/structures/QuadTree.ts
@@ -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();
diff --git a/engine/systems/Collision.ts b/engine/systems/Collision.ts
index 2bba03b..1366ef4 100644
--- a/engine/systems/Collision.ts
+++ b/engine/systems/Collision.ts
@@ -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
diff --git a/engine/systems/Input.ts b/engine/systems/Input.ts
index 4aa9844..35d2e1d 100644
--- a/engine/systems/Input.ts
+++ b/engine/systems/Input.ts
@@ -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>;
diff --git a/engine/systems/NetworkUpdate.ts b/engine/systems/NetworkUpdate.ts
new file mode 100644
index 0000000..dc7be20
--- /dev/null
+++ b/engine/systems/NetworkUpdate.ts
@@ -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) {}
+}
diff --git a/engine/systems/index.ts b/engine/systems/index.ts
index 6cb6f35..075fc4e 100644
--- a/engine/systems/index.ts
+++ b/engine/systems/index.ts
@@ -6,3 +6,4 @@ export * from "./Input";
export * from "./FacingDirection";
export * from "./Collision";
export * from "./WallBounds";
+export * from "./NetworkUpdate";
diff --git a/engine/systems/names.ts b/engine/systems/names.ts
index 23f31fc..cf66422 100644
--- a/engine/systems/names.ts
+++ b/engine/systems/names.ts
@@ -5,4 +5,5 @@ export namespace SystemNames {
export const Input = "Input";
export const Collision = "Collision";
export const WallBounds = "WallBounds";
+ export const NetworkUpdate = "NetworkUpdate";
}