• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

optimised loading screen

D

Drepple

Guest
Hello,

I'm working on a project with a random room renerator. I created a second project to see how I would go about loading/generating and make sure it's optimised, by which I mean the game will perform as much calculations as it can untill the fps drops below 60, after which the game will wait till the next step to continue generating the world.

To do this, I used "while true". The break statement would only be called if the fps drops below 60 or the game has finished generating the world. here's the problem: game maker only gets the fps once per step (same thing goes for fps_real). So the while statement sees the fps is above 60 and generates the whole world in one step, because even if the game is lagging, the fps will return the same number during every cycle of the while loop untill the next step. I don't want to use the repeat function because it limits the amount of calculations per step.

Is there any way for game maker to get the fps at any given time, perhaps with the asynchronous event?
Here's the code I'm using:

Code:
while true {
    if !complete {
        if (fps >= room_speed) {
            board[# j_or, i_or] = choose(0,1);
            j_or ++;
            if j_or >= width {
                j_or = 0;
                i_or ++;
            }
            if i_or >= height {
                complete = true;
            }
        } else {
            break;
        }
    } else {
        break;
    }
}
thanks in advance
 
Last edited by a moderator:
D

Drepple

Guest
Yes, that's exactly what I'm doing, and like I said; fps_real has the same problem. Wherever you refer to them in the step event, they will show the same value, even if halfway through the step event there have been too much calculations and the game has started lagging. Basically, the while loop can repeat millions of times per step but the fps is only retrieved once per step. I'm looking for a way to see if the game is lagging while the step event is being executed. Still, thanks for the reply.
 

FrostyCat

Redemption Seeker
Put a time limit on the loop, say 14-16ms for 60 FPS, and enforce it by checking the difference between get_timer() before the loop and the current value. Then you can monitor fps_real after the loop is done, and adjust the time limit for the next step if it's too low to keep up or high enough to tolerate a hike.
 
D

Drepple

Guest
Thanks so much, this worked perfectly!

I implemented the solution a little bit different tho;
For anyone else having this problem, at the beginning of every while cycle I checked if 1/60th of a second had passed since the beginning of the while statement. If so, the break statement would be called.
So even for the first step the game runs perfectly.

Code:
var time = get_timer();
while true {
   if !(get_timer()-time > 16000) {
 
Top