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) { if (!Forces || !Position) {
return; return;
} }
Position.lastX = Position.$$x; const xd = elapsed * (Forces.$$impulseX + Forces.$$forceX);
Position.$$x += elapsed * (Forces.$$impulseX + Forces.$$forceX); if (xd) {
Position.lastY = Position.$$y; Position.lastX = Position.$$x;
Position.$$y += elapsed * (Forces.$$impulseY + Forces.$$forceY); Position.x = Position.$$x + xd;
this.ecs.markChange( }
entity.id, { const yd = elapsed * (Forces.$$impulseY + Forces.$$forceY);;
Position: { if (yd) {
x: Position.$$x, Position.lastY = Position.$$y;
y: Position.$$y, Position.y = Position.$$y + yd;
}, }
},
);
} }
} }

View File

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