Jump to content
  • Advertisement
Sign in to follow this  
schragnasher

entity lifetime

This topic is 3172 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im implementing a lifetime in each of my game entities so they will die once they reach their lifetime. My question is how precise theis really needs to be? My game loop updates 30 times per second, so how should i track lifetime? Milliseconds? How could i be precise in millsecs if i only update 30/sec?

Share this post


Link to post
Share on other sites
Advertisement
It needs to be exactly as precise as you want it to be - no more, no less.

Is there any reason for tracking exactly when within one frame an entity dies? If not, and your frame rate is constant, why not just measure lifetime in frames?

If your frame rate is (or becomes) variable, just measure it in milliseconds. You don't need to check for a precise match to the age each time. Just increase the entity's age each frame by the correct amount and do "if (current_age >= lifetime) kill_me();" to check it.

Share this post


Link to post
Share on other sites
Don't you hate it when you're playing a game, and an entity dies after 1023 milliseconds instead of 1000 milliseconds?

Share this post


Link to post
Share on other sites
lol you make a good point, i guess as long as my fixed timestep update checks for lifetime before doing anything else it wont effect the game, worst case i guess is you see the object rendered 33.33333 milliseconds longer than it should be since i have a variable framerate.

Share this post


Link to post
Share on other sites
Quote:

I'm implementing a lifetime in each of my game entities so they will die once they reach their lifetime. My question is how precise theis really needs to be? My game loop updates 30 times per second, so how should i track lifetime? Milliseconds? How could i be precise in millsecs if i only update 30/sec?


Exactly as you have said, you cannot be precise in ms, the closest precision you could hope for as you described is 30ms...

Quote:

If your frame rate is (or becomes) variable, just measure it in milliseconds. You don't need to check for a precise match to the age each time. Just increase the entity's age each frame by the correct amount and do "if (current_age >= lifetime) kill_me();" to check it.


my vote for best method... ever... period.

Quote:

Sneftel: Don't you hate it when you're playing a game, and an entity dies after 1023 milliseconds instead of 1000 milliseconds?

schragnasher: lol you make a good point, i guess as long as my fixed timestep update checks for lifetime before doing anything else it wont effect the game, worst case i guess is you see the object rendered 33.33333 milliseconds longer than it should be since i have a variable framerate.

You will *see* that object for 33ms longer....? HAHA!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!