Compensating for deactivated time

C

CrosisBH

Guest
I have a simple measure for ensuring that the game doesn't lag. I just deactivate the objects I can't see. My plan was to simulate the actions done by the object as they are activated.

Say something is rotating 1 degree a second, and It deactivates for 10 seconds. When reactivated, I want it to have 10 degrees added to it.

If I wasn't using Game Maker (I am because I am incapable of making a good game engine in Java), all nonplayer objects would be the child of a nonplayerobject abstract parent. This is doable in Game Maker of course, but what I would do is create an method, something like this in the parent object (Java)

Code:
public void forceUpdate(int ticks){
         for(int i = 0; i<ticks; i++)
                   update();
}
And simply when it's reactivated I would call this method, inputting the amount of time that it was spend inactive. I can calculate this by setting a timer on each object that ticks for how long the object is active.
And this would be called on anyone who is a child of the parent object, and do it's own separate ticking. Some would move, some would rotate, some would regen hp, etc. So I want a abstract way to invoke the step event for a certain amount of ticks. Is Game Maker just not for me in this situation, or is there a way to do this?
 

andulvar

Member
You could keep track of the ticks in the step event of a controlling object, a globalvar would work or a local one if you don't mind referencing the controlling object.
Then create a variable in the parent object of you moving instances called last_tick or something, on deactivation you would set this locally to the child object in last_tick.
On reactivation, you then get the current tick and use a math function to determine how much to move the instance.

For example if it was a rotating object and the last_tick was 5460, and the current tick is 6456, you know you need to rotate the instance 276 degrees on activation.
 
C

CrosisBH

Guest
You could keep track of the ticks in the step event of a controlling object, a globalvar would work or a local one if you don't mind referencing the controlling object.
Then create a variable in the parent object of you moving instances called last_tick or something, on deactivation you would set this locally to the child object in last_tick.
On reactivation, you then get the current tick and use a math function to determine how much to move the instance.

For example if it was a rotating object and the last_tick was 5460, and the current tick is 6456, you know you need to rotate the instance 276 degrees on activation.
I've considered that, but I was hoping for a more abstract approach. Say the object also has x+=4; and you have another object that rotates 5 degrees a second, and is has x+=2; y+=5;. Instead of calculating the ticks passed for each object and then repeating all it's events n amount of times separately for each object, I was hoping for a way to just say "repeat this object's step event n amount of times when reactivated." that's coded in the parent and can be invoked from the child. Maybe I'm think of this too much in a OOP way, which game maker is not.
 

andulvar

Member
I understand your approach but that's pretty heavy on the calculation side. It would work, but it seems more complex than you need it to be. It would work basically the same, where the parent would need to keep track of game ticks and then run the event_perform_object function on the child, a number of times equal the difference. It's a perfectly valid way to do it, but depending on your target platform and other requirements, it may cause performance issues.

Writing a script that take in variables for say (rotation, rotation_dir, x_dir, y_dir, z_dir, x_scale, y_scale, last_tick, current_tick) where each main variable is the amount of movement per step, would probably be an efficient way to do it. The script would then calculate and set the required values to the calling object.
 
Last edited:
C

CrosisBH

Guest
I understand your approach but that's pretty heavy on the calculation side. It would work, but it seems more complex than you need it to be. It would work basically the same, where the parent would need to keep track of game ticks and then run the event_perform_object function on the child, a number of times equal the difference. It's a perfectly valid way to do it, but depending on your target platform and other requirements, it may cause performance issues.

Writing a script that take in variables for say (rotation, rotation_dir, x_dir, y_dir, z_dir, x_scale, y_scale, last_tick, current_tick) where each main variable is the amount of movement per step, would probably be an efficient way to do it. The script would then calculate and set the required values to the calling object.
Hmm. Would it still be performance heavy if not a lot of objects are being made? It's not heavy on concentration of objects, but it will be a huge room with a lot of objects with lots of space between them
 

TheouAegis

Member
When an instance gets deactivated, that's already a slight performance hit, which you'd be increasing slightly by saving the current tick when it deactivated. It would only be calculating its updated positions once and only once when it reactivates. As long as you handle (de)activation properly, there shouldn't be a significant performance hit even with lots of instances.

Another way (or maybe this was said already) is to have a global timer counting up up up (you can have it loop back to 0 if you want, but you'd have to calculate the ideal time to do that) and base everything on algorithms around that timer. But that might be even slower than just dealing with updating variables upon activation.
 
C

CrosisBH

Guest
Thank with the responses everyone. I will try my original idea first, but if performance is an issue, I'll try what andulvar suggested
 
Top