Author Topic: SECONDBASIC - How to implement delta time?  (Read 275 times)

Offline poundlander

  • Developer
  • Jr. Member
  • *****
  • Posts: 43
  • Country: ca
  • Karma: 4
    • View Profile
SECONDBASIC - How to implement delta time?
« on: January 20, 2020, 20:56:59 PM »
Hey!  I make games that need to run consistently on original, clone and emulation based systems.

Is there a way to calculate an appropriate player speed that looks about the same regardless of genesis variant?

I've tried fumbling with counters during the main loop and vblank but never got results.

Offline dra600n

  • Moderator
  • Full Member
  • *****
  • Posts: 122
  • Country: 00
  • Karma: 3
    • View Profile
Re: SECONDBASIC - How to implement delta time?
« Reply #1 on: January 21, 2020, 20:29:21 PM »
So the thing with keeping the exact same time across all machines, and regions, and being 100% the exact same speed just isn't possible (I don't think anyway) on the console without ancillary hardware inside of the cartridge (such as a clock). This is because you'd have to rely on everything to utilize the same code/hardware/standard, which there's no standard to keep things uniform.

That being said, you can get close by keeping a counter ticking during vblank. Here's some skeleton code of how to set that up:

Code: [Select]

Dim ClockSpeed As Integer
Dim Timer As Integer
Dim hours As Integer, minutes As Integer, seconds As Integer




If TvType() = 0 Then
ClockSpeed = 60
Else
ClockSpeed = 50
End If

On VBlank GoSub vblank_routine
Enable InterruptVBlank

While 1 'infinite loop
Locate 0,1: Print "Clockspeed: "; ClockSpeed
Locate 1,1: Print "Timer: "; timer; "                "
Locate 2,1: Print "Seconds: "; seconds; "    "
Locate 3,1: Print "Minutes: "; minutes; "    "
Locate 4,1: Print "Hours: "; hours


Wend




vblank_routine:
Timer++
If Timer = ClockSpeed Then
Timer = 0
seconds++
If seconds = 60 Then
seconds = 0
minutes++
If minutes = 60 Then
hours++
minutes = 0
End If
End If
End If
Return

Hope this helps

 

SimplePortal 2.3.7 © 2008-2020, SimplePortal