So I've been working on a small game project in js for a few months now, and I've realized that the way I've structured my game loop doesn't allow for the game to jump ahead a frame if there is lag.
This means that if the game uses up the cpu, it will start to slow down and run slower, rather than just skipping frames
This is the way I implemented it
<script src="./processing.js"></script>
<script>
var canvas = document.getElementById("mycanvas"),
ctx = canvas.getContext("2d");
var sketchProc = function(processingInstance) {
with (processingInstance) {
size(2560, 1800);
frameRate(30);
var draw = function(){
runGame();
}
}}
var canvas = document.getElementById("mycanvas");
var processingInstance = new Processing(canvas, sketchProc);
I now know that the better way to do this is to calculate how much time has passed between every loop, and then passing that value into the game update function, Eg
tFrame = calculateTimeframe();
updateGame(tFrame);
However, I didn't realize this when I started the project. Meaning that nothing is structured in a way that will allow me to update this.
Is there any way for me to fix this without manually rewriting thousands of lines of code?
(also I am using the processing.js library for this, I know it is outdated, im looking into swapping to p5js in the future)