Skip to content

Commit ca9b79d

Browse files
Fix tests
1 parent 0c21b6b commit ca9b79d

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

app/.server/data/flight.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ export const flight = t.router({
143143
resume: t.procedure.send(({ ctx }) => {
144144
if (ctx.flight) {
145145
ctx.flight.paused = false;
146-
// Convert nanoseconds to milliseconds
147-
ctx.ecs.lastUpdate = Bun.nanoseconds() / 1_000_000;
146+
ctx.ecs.lastUpdate = ctx.ecs.now();
148147
ctx.flight.state = "in-progress";
149148
ctx.flight.stateReason = "";
150149
pubsub.publish.flight.active();

app/.server/systems/__test__/PowerDistributionSystem.test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,8 @@ describe("PowerDistributionSystem", () => {
319319
return system;
320320
});
321321

322-
if (typeof Bun === "undefined") {
323-
const time = performance.now();
324-
ecs.update(16);
325-
expect(performance.now() - time).toBeLessThan(1);
326-
} else {
327-
const time = Bun.nanoseconds() / 1_000_000;
328-
ecs.update(16);
329-
expect(Bun.nanoseconds() / 1_000_000 - time).toBeLessThan(1);
330-
}
322+
const time = ecs.now();
323+
ecs.update(16);
324+
expect(ecs.now() - time).toBeLessThan(1);
331325
});
332326
});

app/utils/ecs/ecs.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ECS {
2828
* Count how many updates have been done.
2929
*/
3030
updateCounter = 0;
31-
lastUpdate = Bun.nanoseconds() / 1_000_000;
31+
lastUpdate = this.now();
3232
rng: RNG;
3333
maxEntityId = 1;
3434
componentCache = new Map<ComponentIds, Set<Entity>>();
@@ -153,13 +153,20 @@ class ECS {
153153

154154
this.entitiesSystemsDirty.clear();
155155
}
156+
now() {
157+
if (typeof Bun === "undefined") {
158+
return performance.now();
159+
}
160+
// Convert nanoseconds to milliseconds
161+
return Bun.nanoseconds() / 1_000_000;
162+
}
156163
/**
157164
* Update the ecs.
158165
*
159166
* @method update
160167
*/
161168
update(testElapsed?: number) {
162-
const now = Bun.nanoseconds() / 1_000_000;
169+
const now = this.now();
163170
const elapsed = testElapsed ?? now - this.lastUpdate;
164171
if (this.entitiesSystemsDirty.size > 0) {
165172
this.cleanDirtyEntities();

0 commit comments

Comments
 (0)