Jump to content
IGNORED

Time delta in milliseconds?


Recommended Posts

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. 

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!

  • Like 1
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.

  • 2 weeks later...
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?

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;

  • Thanks 1
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?

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.

  • Like 1
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;

 

  • Like 1

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...