refactor: hot systems perf

This commit is contained in:
cha0s 2024-10-21 03:25:17 -05:00
parent 70cc56c7b6
commit a2a33536e7
2 changed files with 16 additions and 22 deletions

View File

@ -23,18 +23,16 @@ export default class IntegratePhysics extends System {
if (!Forces || !Position) {
return;
}
Position.lastX = Position.$$x;
Position.$$x += elapsed * (Forces.$$impulseX + Forces.$$forceX);
Position.lastY = Position.$$y;
Position.$$y += elapsed * (Forces.$$impulseY + Forces.$$forceY);
this.ecs.markChange(
entity.id, {
Position: {
x: Position.$$x,
y: Position.$$y,
},
},
);
const xd = elapsed * (Forces.$$impulseX + Forces.$$forceX);
if (xd) {
Position.lastX = Position.$$x;
Position.x = Position.$$x + xd;
}
const yd = elapsed * (Forces.$$impulseY + Forces.$$forceY);;
if (yd) {
Position.lastY = Position.$$y;
Position.y = Position.$$y + yd;
}
}
}

View File

@ -27,16 +27,12 @@ export default class ResetForces extends System {
if (!Forces) {
return;
}
Forces.$$impulseX = 0;
Forces.$$impulseY = 0;
this.ecs.markChange(
entity.id, {
Forces: {
impulseX: Forces.$$impulseX,
impulseY: Forces.$$impulseY,
},
},
);
if (Forces.$$impulseX) {
Forces.impulseX = 0;
}
if (Forces.$$impulseY) {
Forces.impulseY = 0;
}
}
}