Page 2 of 2

Posted: Sat Jan 17, 2004 5:27 pm
by chris_b
J. Baker wrote:Interesting, my max fps is 61 and this won't go higher. There must be a set room speed of 61. If anyone has got any different, please respond.
That's the default framerate with a windowed screen. You can change it with the SetFrameRate() function.

Posted: Sun Jan 18, 2004 5:34 am
by J. Baker
chris_b wrote:
J. Baker wrote:Interesting, my max fps is 61 and this won't go higher. There must be a set room speed of 61. If anyone has got any different, please respond.
That's the default framerate with a windowed screen. You can change it with the SetFrameRate() function.
Hey, thanks for the tip. :D

Posted: Sun Jan 18, 2004 8:32 am
by DriakTravo
Can anyone tell me how to display the framerate using openscreen()?

Posted: Sun Jan 18, 2004 12:44 pm
by Danilo
DriakTravo wrote:Can anyone tell me how to display the framerate using openscreen()?

Code: Select all

;- procedures
Procedure InitGameTimer() 
  Shared _GT_DevCaps.TIMECAPS 
  timeGetDevCaps_(_GT_DevCaps,SizeOf(TIMECAPS)) 
  timeBeginPeriod_(_GT_DevCaps\wPeriodMin) 
EndProcedure 

Procedure StopGameTimer() 
  Shared _GT_DevCaps.TIMECAPS 
  timeEndPeriod_(_GT_DevCaps\wPeriodMin) 
EndProcedure 

;- _program start
;- _Init
If InitSprite()=0 Or InitKeyboard()=0
  MessageRequester("ERROR","Cant init DirectX !",#MB_ICONERROR):End
EndIf

If OpenScreen(800,600,32,"Timing")=0
  If OpenScreen(800,600,24,"Timing")=0
    If OpenScreen(800,600,16,"Timing")=0
      MessageRequester("ERROR","Cant open screen !",#MB_ICONERROR):End
EndIf:EndIf:EndIf

; timer initialisieren
InitGameTimer()
time = TimeGetTime_()

;- _game loop
Repeat
  ; calc framerate
  If TimeGetTime_()-time >= 1000
    time   = TimeGetTime_()
    FPS    = Frames-1
    Frames = 1
  Else
    Frames+1
  EndIf

  ClearScreen(0,0,0)

  ; show framerate
  StartDrawing(ScreenOutput())
    DrawingMode(1):FrontColor($80,$FF,$00)
    Locate(50,50):DrawText(Str(FPS))
  StopDrawing()

  ExamineKeyboard()
  FlipBuffers()
Until KeyboardPushed(#PB_KEY_ESCAPE)

;- _program end
StopGameTimer()

You move sprites with the same speed on different PCs with
the following 'multiplicator' calculation:

Code: Select all

;- procedures
Procedure InitGameTimer() 
  Shared _GT_DevCaps.TIMECAPS 
  timeGetDevCaps_(_GT_DevCaps,SizeOf(TIMECAPS)) 
  timeBeginPeriod_(_GT_DevCaps\wPeriodMin) 
EndProcedure 

Procedure StopGameTimer() 
  Shared _GT_DevCaps.TIMECAPS 
  timeEndPeriod_(_GT_DevCaps\wPeriodMin) 
EndProcedure 


;- variables
Global player1_move.f, player1_x.f, player1_y.f

;- _program start
;- _Init
If InitSprite()=0 Or InitKeyboard()=0
  MessageRequester("ERROR","Cant init DirectX !",#MB_ICONERROR):End
EndIf

If OpenScreen(800,600,32,"Timing")=0
  If OpenScreen(800,600,24,"Timing")=0
    If OpenScreen(800,600,16,"Timing")=0
      MessageRequester("ERROR","Cant open screen !",#MB_ICONERROR):End
EndIf:EndIf:EndIf

If CreateSprite(1,32,32)=0
  CloseScreen()
  MessageRequester("ERROR","Cant create sprite !",#MB_ICONERROR):End
Else
  StartDrawing(SpriteOutput(1))
    Box (0,0,32,32,$00FFFF)
    Line(0,0,32,32,$000000)
    Line(32,0,0,32,$000000)
  StopDrawing()
EndIf

player1_speed.f = 0.350

; timer initialisieren
InitGameTimer()
StartTime = TimeGetTime_()
time      = StartTime

;SetFrameRate(75)

;- _game loop
Repeat
  ; calculate multiplicator
  multiplicator.f = StartTime
  StartTime = TimeGetTime_()
  multiplicator   = StartTime - multiplicator

  ; calc framerate
  If TimeGetTime_()-time >= 1000
    time   = TimeGetTime_()
    FPS    = Frames-1
    Frames = 1
  Else
    Frames+1
  EndIf

  ClearScreen(0,0,0)

  ; show framerate
  StartDrawing(ScreenOutput())
    DrawingMode(1):FrontColor($80,$FF,$00)
    Locate(50,50):DrawText("FrameRate: "+Str(FPS))
  StopDrawing()

  ExamineKeyboard()
  
  ; calc move-step for player1
  player1_move = player1_speed * multiplicator
  
  If KeyboardPushed(#PB_KEY_LEFT)
    player1_x - player1_move : EndIf
  If KeyboardPushed(#PB_KEY_RIGHT)
    player1_x + player1_move : EndIf
  If KeyboardPushed(#PB_KEY_UP)
    player1_y - player1_move : EndIf
  If KeyboardPushed(#PB_KEY_DOWN)
    player1_y + player1_move : EndIf

  If player1_x < -32 : player1_x = 800 : EndIf
  If player1_x > 800 : player1_x = -32 : EndIf
  If player1_y < -32 : player1_y = 600 : EndIf
  If player1_y > 600 : player1_y = -32 : EndIf

  DisplaySprite(1,player1_x,player1_y)

  FlipBuffers()
Until KeyboardPushed(#PB_KEY_ESCAPE)

;- _program end
StopGameTimer()
The sprite moves with same speed on all PCs, whatever you
use: 60, 72, 85, 100 FPS...

Posted: Sun Jan 18, 2004 1:33 pm
by DriakTravo
Thank you alot! :D

Posted: Mon Jan 19, 2004 1:51 am
by coma
Danilo > what does exactly do InitGameTimer() ?
If I remove it, "I got exactly the same result.

Posted: Mon Jan 19, 2004 2:13 am
by Danilo
coma wrote:what does exactly do InitGameTimer() ?
If I remove it, "I got exactly the same result.
It initializes the highres timer to the lowest possible value
thats available, usually 1ms - but on some old systems
like Win95 and Win98 it *can* be higher, like 5ms.
On NT-Systems (NT4,2k,XP) it should always be 1ms.

It works on most systems without the initialization, but its
the correct way to do it - and i like correct programming if possible. ;)

I've seen the difference on my dual-PIII-1000, some code
didnt work correctly. I wondered, read some MSDN, and
found the correct way.
With the correct initialization it works fine everywhere.

Posted: Mon Jan 19, 2004 2:24 am
by coma
thank you for such details :)
I will add it to my code.