• Inan Evin

#4 Lina Engine: Basic Time Class

In this post, I will be talking briefly about the time implementation in Lina Engine. Now folks, in the previous posts we talked about the core loop, and it's correlated importance with time implementation between frames to provide frame independency throughout all the updated systems. This time I would like to talk a bit more about it and provide some more extra detail. For now, our time class is only responsible for returning the system time at timestep t, in nanoseconds. I see that some people have been using milliseconds instead of nano, however using nanoseconds gives more precision and control over the time. So I thought it would be best to get the current time in nanoseconds, then clip it down if necessary to milliseconds or seconds, depending on the implementation logic. Below is the method that returns the time as a long type, in nanoseconds.

And now throughout any system, I can get the time to use. I can keep track of a particular amounts of seconds passed by dividing the returned value to 1000000, or I can just keep the track in nanoseconds to apply precise time based values.

In our time class, we have an extra value, called deltaTime. It's the time that it took for the last frame to render, as explained in the Core Loop post. For now, we set it to our pre-designated frame time in the core loop, which is 0.002, to avoid some frame-related dependencies that we will be doing further on the road. However, once we complete our calculations on the time involving physics steps, we will change this from the pre-designated to time the actual frame time passed.

So yeah, basically this is it about our time class for now, not much to see yet. Hopefully I will write about the extended features in the future. See you then!

4 views0 comments