UltraEd icon indicating copy to clipboard operation
UltraEd copied to clipboard

Make deltaTime accessible by Actor Scripts

Open Byterset opened this issue 3 years ago • 4 comments

The example project runs at vastly different speeds on different emulators. I suggest to make a global variable deltaTime available to all actor scripts so that every script that potentially updates something has the time difference to the last frame available (so movement can be time based). Calculating this in every script you need it for every update seems like a waste of ressources

Byterset avatar Feb 03 '22 01:02 Byterset

Yeah that's a good idea. I guess I didn't worry at first about this since I was originally always testing on real hardware which would have the same clock speed regardless of who ran it (well hopefully!).

deadcast2 avatar Feb 16 '22 20:02 deadcast2

I think even on real hardware this would be a good addition, since games could run on different speeds depending on how much is going on in a level even on real hardware. By using a deltaTime approach you can ensure 1 second in real time is always equal to 1 second in the game no matter if it is lagging or not. :) the drawback with this approach is that with very extreme lag a player/actor could move very far between frames due to high deltaTime which can mess with collision detection. But I believe this was also the case with commercial titles like mario 64 (glitching through doors at high speed) and shouldn't be an issue of the engine

Byterset avatar Feb 16 '22 21:02 Byterset

Oh yeah you're right. There's the fixed processor speed but it's going to vary how much work is happening between each frame. So yeah the delta time would be beneficial. True that it could cause potential glitchy issues with collision and object movement but probably not too big of an issue to deal with. I guess it should be one of the special global variables that any actor can access through scripting.

deadcast2 avatar Feb 17 '22 01:02 deadcast2

Started on creating a global GetDeltaTime() method but no luck getting it to work yet. The important OS function osGetTime() is crashing things when I attempt to convert its returned CPU cycle count into microseconds via the OS_CYCLES_TO_USEC macro. Will have to keep playing around as to why mixing those two together causes a crash.

https://ultra64.ca/files/documentation/online-manuals/functions_reference_manual_2.0i/os/OS_CYCLES_TO_NSEC.html

deadcast2 avatar Mar 28 '22 02:03 deadcast2