trufun101 Posted October 7, 2023 Share Posted October 7, 2023 Is there a way to calculate the time delta between updates? I've tried using rapSetClock(0) and rapClockHex, but that appears to be an integer value of whole seconds. Is there a way to keep time at the millisecond? I'm using JagStudio C. Thanks! Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/ Share on other sites More sharing options...
Sporadic Posted October 7, 2023 Share Posted October 7, 2023 https://reboot-games.com/jagstudio/ReferenceManual.html#general You will need to use rapNTSCFlag to determine if you are running on a PAL or NTSC console. This tells you if it should be 50 or 60 ticks per second. Then you'll need to look the the current rapTicks value. If you track the difference of rapTicks from your last frame, you can then divide with the 50 or 60 from above to work out timing. Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5329688 Share on other sites More sharing options...
trufun101 Posted October 7, 2023 Author Share Posted October 7, 2023 6 hours ago, Sporadic said: https://reboot-games.com/jagstudio/ReferenceManual.html#general You will need to use rapNTSCFlag to determine if you are running on a PAL or NTSC console. This tells you if it should be 50 or 60 ticks per second. Then you'll need to look the the current rapTicks value. If you track the difference of rapTicks from your last frame, you can then divide with the 50 or 60 from above to work out timing. Perfect, thank you! 1 Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5329822 Share on other sites More sharing options...
42bs Posted October 8, 2023 Share Posted October 8, 2023 On 10/7/2023 at 4:28 AM, trufun101 said: Is there a way to calculate the time delta between updates? I've tried using rapSetClock(0) and rapClockHex, but that appears to be an integer value of whole seconds. Is there a way to keep time at the millisecond? I'm using JagStudio C. Thanks! If 20 or 17 ms is to rough, you can always use one of th HW timers. Setting these up is no rocket science. Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5330000 Share on other sites More sharing options...
+CyranoJ Posted October 8, 2023 Share Posted October 8, 2023 2 hours ago, 42bs said: If 20 or 17 ms is to rough, you can always use one of th HW timers. Setting these up is no rocket science. It might be from BASIC.... Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5330030 Share on other sites More sharing options...
42bs Posted October 8, 2023 Share Posted October 8, 2023 6 hours ago, CyranoJ said: It might be from BASIC.... I see there is peek and poke. Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5330097 Share on other sites More sharing options...
trufun101 Posted October 17, 2023 Author Share Posted October 17, 2023 On 10/7/2023 at 9:00 AM, Sporadic said: https://reboot-games.com/jagstudio/ReferenceManual.html#general You will need to use rapNTSCFlag to determine if you are running on a PAL or NTSC console. This tells you if it should be 50 or 60 ticks per second. Then you'll need to look the the current rapTicks value. If you track the difference of rapTicks from your last frame, you can then divide with the 50 or 60 from above to work out timing. I think I'm doing something wrong. I'm trying to calculate the time delta (as a fraction of a second) and multiply that by the movement speed, but the character isn't moving. Here's what I've got: int ticksPerSec = 60; //NTSC by default int lastTicks = 0; if (!rapNTSCFlag) { ticksPerSec = 50; //PAL } //Main Loop for(;;) { float delta = (rapTicks - lastTicks) / ticksPerSec; lastTicks = rapTicks; ... //for movement... sprite[spriteIndex].x_ -= playerMoveSpeed * delta; //playerMoveSpeed == 40 So, let's say the delta is 3 ticks / 60 tps or 0.05. I would expect the character to move 2 pixels (40 * 0.05) with each update. Or am I going about this the wrong way? Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5334205 Share on other sites More sharing options...
JagMod Posted October 17, 2023 Share Posted October 17, 2023 2 hours ago, trufun101 said: I think I'm doing something wrong. I'm trying to calculate the time delta (as a fraction of a second) and multiply that by the movement speed, but the character isn't moving. Here's what I've got: int ticksPerSec = 60; //NTSC by default int lastTicks = 0; if (!rapNTSCFlag) { ticksPerSec = 50; //PAL } //Main Loop for(;;) { float delta = (rapTicks - lastTicks) / ticksPerSec; lastTicks = rapTicks; ... //for movement... sprite[spriteIndex].x_ -= playerMoveSpeed * delta; //playerMoveSpeed == 40 So, let's say the delta is 3 ticks / 60 tps or 0.05. I would expect the character to move 2 pixels (40 * 0.05) with each update. Or am I going about this the wrong way? float delta = (rapTicks - lastTicks) / ticksPerSec; Above statement is always 0 since you're doing integer division, change it to this... float delta = (float)(rapTicks - lastTicks) / (float)ticksPerSec; 1 Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5334280 Share on other sites More sharing options...
trufun101 Posted October 18, 2023 Author Share Posted October 18, 2023 4 hours ago, JagMod said: float delta = (rapTicks - lastTicks) / ticksPerSec; Above statement is always 0 since you're doing integer division, change it to this... float delta = (float)(rapTicks - lastTicks) / (float)ticksPerSec; Oh, duh. Thank you. I can't tell you how many times I've made that mistake in the past. It's just tougher without being able to step through the code. Speaking of which, is there a way to print the value of the int using js_r_textbuffer? Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5334396 Share on other sites More sharing options...
42bs Posted October 18, 2023 Share Posted October 18, 2023 Do not use float on the Jaguar. I really recommend to not even start using it for simple tasks like this. As a wild guess, it needs about 300 or more cycles. Rather use fixed point math or a completely different solution. 1 Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5334413 Share on other sites More sharing options...
LordKraken Posted October 18, 2023 Share Posted October 18, 2023 To elaborate on what @42bs just wrote, use rapTicks directly, just adjust your move speed directly. sprite[spriteIndex].x_ -= playerMoveSpeed * rapTicks; Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5334473 Share on other sites More sharing options...
42bs Posted October 18, 2023 Share Posted October 18, 2023 50 minutes ago, LordKraken said: To elaborate on what @42bs just wrote, use rapTicks directly, just adjust your move speed directly. sprite[spriteIndex].x_ -= playerMoveSpeed * rapTicks; I think you missed the delta. x -= playerMoveSpeedPerTick * delta; Of course we do not want float, so playerMoveSpeedPerTick = (40*256+20)/60; or playerMoveSpeedPerTick = (40*256+20)/50; then x -= (playerMoveSpeedPerTick * delta) >> 8; 1 Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5334482 Share on other sites More sharing options...
LordKraken Posted October 18, 2023 Share Posted October 18, 2023 yes my bad, of course i meant the number of ticks elapsed since last frame, not the absolute tick number Quote Link to comment https://forums.atariage.com/topic/355488-time-delta-in-milliseconds/#findComment-5334500 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.