delta_time problem on Windows 7

acidemic

Member
In my game I am using delta_time variable. I have a persistent "obj_delta_control" object which has following code in the "Begin Step" event:
global.delta = 60 / 1000000 * delta_time;

Then I multiply "global.delta" variable to all speed, movement, delay, alarm... variables in the game.

The problem begins when the game runs in a window and when I start to drag the window around the screen (or just click the mouse on the window title bar) the Draw event in the game freezes and is not being updated. During this "delta_time" and my global.delta variables increase.... a lot. So it affects the movement of the game objects which rely on the "global.delta" variable. Their speed increase up to x100 or x200 times and more...(depends on how long I keep mouse pressed on the window title bar).

The game is being developed for the Android, but I want it to work consistently on the Windows as well. Is there any way to avoid this?

Another thing I should mentionis that "delta_time" is much higher (up to 8 times) in the first step after the "Room Start", but I managed to get round that.
 

jo-thijs

Member
Hi and welcome to the GMC!

It is kind of the point that these things hapen when you're using delta_time.
If this really is a problem, you could use min(delta_time, 1000000) instead of just delta_time.
 
E

elementbound

Guest
What I usually do in this case is to limit my game to 8 fps. This also negates fps spikes to some extent.
To give you an example ( although note that I do stuff a bit differently ):
Code:
t_elapsed = min(125, delta_time/1000 * t_factor);
t_current += t_elapsed;
Here, t_elapsed is the frame time in milliseconds.
The downside is that the game starts to run in slow-mo once you get under 8 fps. I don't see this as a problem, as playing under 8 fps is bad enough in itself.

You could also try to detect change in window position with window_get_x/y. If that changes, set your delta to zero, thus no motion happens for a single step. At decent framerates, this shouldn't be noticeable.
 

jo-thijs

Member
I don't get why turning your game to 8 fps would help at all,
but the checking of window_get_x/y/width/height over steps is a thing you can do.
 

hippyman

Member
The way you prevent the window from freezing while dragging it is by making it a borderless window and then creating your own window drag function.

I remember seeing a tech blog or a forum post from the older forums that showed how to prevent this. If I can find it I'll link it.
 
E

elementbound

Guest
I don't get why turning your game to 8 fps would help at all
Probably wrong wording on my part. I cap the game to at least 8 fps. So, by default, the game runs uncapped, so the frametime is free to change. For example, assume it runs around 40 fps, so the frametime is generally 25 ms. Then, a huge spike happens, the game falls down to 3 fps for a few frames, the frametime is 333 ms. If you check the code in my previous post, t_elapsed = min(125, 333 * 1) = 125. So, the game runs at 3 fps ( for a few frames ), but the simulation happens at 8 fps. This way, the simulation doesn't get out of hand because of the huge frametimes.
Now, you can also imagine the user dragging the window as a huge, one-frame spike.
 

acidemic

Member
Thank you everybody for the advices! It really helped me. I used the idea to use "min()" function and created an algorhytm which seems to solve the issue of delta_time becoming huge during the step when game window is frozen due to dragging that or moving around. The idea is to compare current step delta with previous step delta and use in game the smallest one of them. In this case if spike affects only one step it will be ignored and previous Delta will be used instead.

Complete code of my "obj_delta_control" object which can be useful for sombody. The object is persistent and created once during the game start. Also this object prevents from delta spike after the room start.

"Create" event:
Code:
// Initializing variables with default values
delta_prev = 1;
global.delta = 1;
"Begin Step" event:
Code:
var delta_real = 0.00006*delta_time;    // Current "real" Delta. I used 0.00006 instead of "60/1000000".
global.delta = min(delta_prev, delta_real);    // Delta which will be used in game calculations
delta_prev = delta_real;   // This will become previous "real" Delta at the next step
"Room Start" event:
Code:
global.delta = 1;  // Resetting Delta
alarm[0] = 1;  // Performing Alarm 1 in the next step
"Alarm 0" event:
Code:
global.delta = 1;  // Resetting Delta
 
I

icuurd12b42

Guest
this function tells you if the mouse is outside the window
http://pastebin.com/8VSWC3vF
global.delta = 60 / 1000000 * delta_time * (is_mouse_ouside() == false);

I use get_timer() and a global.oldtime instead of delta_time... Yep I noticed the error too...

room_start
global.oldtime = get_timer();
global.delta_t = 0;

begin step
var t = get_timer();
global.delta_t = t- global.oldtime;
global.oldtime = t;
global.delta = 60 / 1000000 * global.delta_t* (is_mouse_ouside() == false);
 
Top