-
Notifications
You must be signed in to change notification settings - Fork 13
Timer module #21
Comments
My opinion is that maybe we should have some sort of global object that anything can read from. e.g:
I'd also like to throw my stopwatch module in the running to facilitate this. AFAIK, it should run on mobile platforms since it tries to use Nim code, but I'm not 100% if it does as I haven't tested it. |
I'm trying to refrain from having globals the user has to manage, thus keeping everything very module based and just exposing functions to the user - if that makes sense. How about another module called timer which holds these globals and exposes a function called nextUpdateFrame() or whatever? Is there a reason you'd prefer to have a global object? It's just a bit different from the current implementation is all I'm trying to get at. |
eh, I just like objects. |
I'd like to bump this ticket and give it the highest priority to work on right now. As I'm starting to work on sprite rendering I'll need this for when it comes time to animate, which is going to be pretty soon. |
I'd also like to say I'd like to deal with deltas as floating point numbers. E.g. at 60 FPS, we'd give them a value of |
I'll work on this after work today. |
What do you think about something like - import sdl2
var
startTime, currentTime, previousTime, updateTime: float64
ticks: uint
proc getTicks*(): uint =
ticks
proc getDeltaTime*(): float64 =
updateTime
proc getTimeSinceLastTick*(): float64 =
currentTime - previousTime
proc getTimeElapsed*(): float64 =
currentTime - startTime
proc getTime*(): float64 =
currentTime
proc tick*() =
currentTime = float64(sdl2.getPerformanceCounter()*1000) / float64 sdl2.getPerformanceFrequency()
updateTime = currentTime - previousTime
previousTime = currentTime
inc(ticks)
proc init*() =
startTime = getTime()
currentTime = startTime Anything you'd like to see added? I don't understand this whole logic tick component you referred to in your example. I figured that'd be left up to the user to implement? |
Yeah, this looks pretty good right now. A few tiny things:
We also need some documentation to explain what is the different between a |
I saw your commit and left some notes inline. Please take a look at them: |
As a side note, next time can you make a separate branch then make a PR for it instead? I'd rather do review there than do it inline with a commit in master. |
Hey, I tried out what you have put in the timer module right now and it's kind of incorrect. E.g. I though we were going to have the You might need to go back and adjust your examples, though it shouldn't be too hard. |
As mentioned in a few commit comments and issue zacharycarter#21, the first round of the timer module looked a little wrong (e.g. it was giving us milliseconds for `deltaTime()` when it should have been giving us seconds instead). This commit fixes that and removes a little cruft. Under the hood all of the times are measured in hard integers, but the programmer is given a floating point interface to using the time. On top of that, the timer module now has a `Timer` object. The rationale for this is two fold: 1. This makes the `Timer` less tied into the engine internals (i.e. independant). 2. Users may need timers for other things (e.g. spell cooldowns, time trials in racing scenarios, making a day n' night cycle; the list goes on). Before we only had one global timer. Now we've got many that the user can use (and resuse). I've also added some documentation better explaining things. (I should maybe add some drawings too). closes zacharycarter#21
Continuing discussion from : #13
The text was updated successfully, but these errors were encountered: