Skip to content

Commit

Permalink
XeroName/Deltatime: don't report delta time of 0 (#1741)
Browse files Browse the repository at this point in the history
If projects do things like "5 / delta time", they'll break horribly when
delta time is 0, so let's not return that.
  • Loading branch information
GarboMuffin authored Nov 2, 2024
1 parent 399a894 commit c8c2a10
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion extensions/XeroName/Deltatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@

vm.runtime.on("BEFORE_EXECUTE", () => {
const now = performance.now();
deltaTime = previousTime === 0 ? 0 : (now - previousTime) / 1000;

if (previousTime === 0) {
// First frame. We used to always return 0 here, but that can break projects that
// expect delta time to always be non-zero. Instead we'll make our best guess.
deltaTime = 1 / vm.runtime.frameLoop.framerate;
} else {
deltaTime = (now - previousTime) / 1000;
}

previousTime = now;
});

Expand Down

0 comments on commit c8c2a10

Please sign in to comment.