If this is your first visit, be sure to check out the FAQ by clicking the link above. You have to register before you can post.

If you have recently signed up, please make sure you log in so that your activity is registered. This is required for automatic promotions to work and to ensure your account is not deleted during the registration process.

AthenaOfDelphi

Moderation Process Reminder

Since this appears to be a problem, please be aware that some areas of the site are moderated. When you post to these areas, you will be told that your post is awaiting moderation.

You will not be able to see posts that you have made that are waiting to be moderated.

Do not think that because your post has not appeared that an error has occurred. If this happens an error message will be displayed (you should note this and report it in the 'Site News/Feedback' forum.

Re: PyroGineび｢ Game Engine

Hi,

It only gets called once per frame as do any OnUpdate and OnRender methods. The problem your having is because aElapsedTime does not represent the value that you're expecting. The TPGTimer class in PGE uses frame-based timing. If you call TPGTimer.Init(35.05, 2), this tells the timer that you want your simulation to run at 35 fps and to try and maintain this rate if the rate drops by two times. So then what does aElapsedTime represent? If the current frame is running at 17.5 fps, in order to keep the simulation running at 35 fps, aElapsedTime would be a value of 1.5 so when you multiply your object speed by aElapsedTime then it will speed the objects up to keep the overall simulation at 35 fps. If the frame rate go to 60+ fps then aElapsedTime would be around 0.5. It will continue to try to do this if the frame drops/increases by two frames.

The TPTimer class (PG.Timer) already has methods to help you with the timing your trying to do. You can use the TPTimer.FrameSpeed method. You use it like this:

The timer variable is used so that you track different timing speeds if needed. So, when doing your timing, keep in mind that aElapsedTime will return a value to represents a quantity that will keep objects in your simulation running at the specified desired simulation rate. By default TPTimer will set to 35 fps. This is a historical value that I've used the past 8+ years. In general I've found that optimal and silky smooth animation is better if your simulation rate is multiple of your monitors refresh rate. 60Hhz is a standard refresh rate for all monitors and it tends to be the default. So running at slightly above half this rate has proven to produce good results. You can of coarse change the simulation timing to what ever value you choose, but keep in mind the things I've outlined here.

So in this case your simulation is running a 35 fps. What you should do is this:

Re: PyroGineび｢ Game Engine

Im saying that PG.Timer.DesiredFPS is the value that you set when PG.Timer.Init was called. Since aElapsedTime will always be a quantity associated with DesiredFPS then if you multiple aElapsedTime by 1.0 it will normalize it one second in this case. When the accumulated value become greater than PG.Timer.DesiredFPS (35) then one second of time has passed. If you wanted to check for 1/2 second then yes it would be 1/2 that (17.5).

Re: PyroGineび｢ Game Engine

Originally Posted by PyroGine Development

Im saying that PG.Timer.DesiredFPS is the value that you set when PG.Timer.Init was called. Since aElapsedTime will always be a quantity associated with DesiredFPS then if you multiple aElapsedTime by 1.0 it will normalize it one second in this case. When the accumulated value become greater than PG.Timer.DesiredFPS (35) then one second of time has passed. If you wanted to check for 1/2 second then yes it would be 1/2 that (17.5).

Ok, I think I understand

Expanding on this, I have a bunch of other objects in my game that I want to control using the elapsed frame time in seconds (or fractions thereof) by passing in this time into their .Update() method...

To pass in the number of seconds into these methods, do I do this kind of thing?

Re: PyroGineび｢ Game Engine

All you objects should be updated based on aElapsedTime. The overall effect is that your simulation will be be updated at a know and predictable rate while the game loop can update as fast as the host machine can process the loop. If you you need to do timing based on a specific fps independent of the current simulation rate then just use TPGTimer.FrameSpeed which allows you to specify a specific fps independent of the simulation rate. What your doing is decoupling rendering from physics. The extra cycle per frame on faster machines will have no notable effects on your simulation while generating smoother graphics and more cycle can be devoted to AI and other processing. On slower machines, if you keep simulation a magnitude lower than the refresh rate of your monitor, then the frame can drop without any noticeable effects.

Any way if what your trying to do is working then keep going, but keep in mind what I've outlined as the proper way of using frame-based timing in PGE.