December 04, 2020, 05:41:09 AM

Author Topic: Setting the game frequency  (Read 903 times)

Offline JBR

  • Full Member
  • ***
  • Posts: 118
Setting the game frequency
« on: July 02, 2020, 12:44:31 AM »
Hi, just got a 144Hz laptop.

I have a few problems. I using B3D.

1) Flip <true> or <false> seems to be always True. I used to use False to check the speed of my code in fps.

2) I find things working well if I use Timer = CreateTimer(value). Set to 50Hz everything is super smooth. No tearing.

3) The intel cpu has a built in GPU which I think is interfering with the RTX2060. Maybe switching between CPU one and the discrete one. Maybe my imagination?

I don't want to go down the tweening road but will the createtimer() work with all pcs?

Thanks in advance, Jim.

Offline col

  • Sr. Member
  • ****
  • Posts: 467
Re: Setting the game frequency
« Reply #1 on: July 02, 2020, 03:55:48 AM »
Hiya,

Quote
will the createtimer() work with all pcs?
Probably, why not knock up a quick exe for people to try/verify.
To be is to be perceived.

https://github.com/davecamp

Offline Matty

  • Hero Member
  • *****
  • Posts: 1258
    • MattiesGames
Re: Setting the game frequency
« Reply #2 on: July 02, 2020, 07:44:00 AM »
Why shouldn't it work?

Offline Santiago

  • Sr. Member
  • ****
  • Posts: 283
  • Blitz3d
    • Indiesoft
Re: Setting the game frequency
« Reply #3 on: July 02, 2020, 07:51:12 PM »
what is createtimer()   is a own function?

i don't understand the question, but, check if you use millisecs(), some new computer have negative values.
that if in case you using millisecs() for yout timer functions.

Offline JBR

  • Full Member
  • ***
  • Posts: 118
Re: Setting the game frequency
« Reply #4 on: July 02, 2020, 09:10:37 PM »
Hi all,

Yes it's a Blitz3D function. Don't know how it works but if you put it in your main loop it keeps your frame rate fixed.

I'm going to stick it at 60Hz as that seems to be the lowest rate for monitors in general.

Not entirely sure where in the loop I should put it - at the start?

Cheers, Jim.

Offline Dan

  • Jr. Member
  • **
  • Posts: 36
Re: Setting the game frequency
« Reply #5 on: July 02, 2020, 09:23:17 PM »
Hi, here is the example from the help file:

Code: [Select]
; Create the timer to track speed
frameTimer=CreateTimer(60)

; Your main screen draw loop
While Not KeyHit(1)
WaitTimer(frameTimer) ; Pause until the timer reaches 60
Cls
; Draw your screen stuff
Flip
Wend


65536 GOTO Back2Basic

Offline Santiago

  • Sr. Member
  • ****
  • Posts: 283
  • Blitz3d
    • Indiesoft
Re: Setting the game frequency
« Reply #6 on: July 02, 2020, 10:29:32 PM »
ohhhh, that is new for me  :o

Offline STEVIE G

  • Sr. Member
  • ****
  • Posts: 498
Re: Setting the game frequency
« Reply #7 on: July 02, 2020, 10:33:22 PM »
Hi all,

Yes it's a Blitz3D function. Don't know how it works but if you put it in your main loop it keeps your frame rate fixed.

I'm going to stick it at 60Hz as that seems to be the lowest rate for monitors in general.

Not entirely sure where in the loop I should put it - at the start?

Cheers, Jim.

I find putting it after flip works best.

Offline GfK

  • Full Member
  • ***
  • Posts: 166
Re: Setting the game frequency
« Reply #8 on: July 02, 2020, 11:15:44 PM »
On slower systems, using this method will potentially cause your game to run in slow motion.

Deltatiming is a preferable method, though not without drawbacks of its own.
Intel I9-9900K 3.6-5.0GHz | GeForce RTX2070 8GB | 32GB RAM | 500GB NVMe M.2 SSD | 1TB HDD | Windows 10 x64.
MSI Apache Pro | I7-7700HQ | GeForce GTX1060 3GB | 8GB RAM | 128GB SSD | 1TB HDD | Windows 10 x64.

Offline Dan

  • Jr. Member
  • **
  • Posts: 36
Re: Setting the game frequency
« Reply #9 on: July 03, 2020, 05:59:32 AM »
How is delta timing calculated ?


65536 GOTO Back2Basic

Offline GfK

  • Full Member
  • ***
  • Posts: 166
Re: Setting the game frequency
« Reply #10 on: July 03, 2020, 12:20:22 PM »
Deltatime is just the time difference between now and the last frame.  You multiply all translations/scaling/rotations by this factor to get your game to run at a [near] constant speed, using all frames if the hardware is fast enough, and skipping frames when it isn't.

You also need to change your way of thinking slightly.  Where you might be moving an object at, say, 20 pixels per frame, you need to switch your brain over to thinking of it as a velocity of 20 pixels per second.  By applying deltatime to everything, the sprite will move more or less the same distance over a period of time, no matter how many frames are rendered.

Here's the article which explained a few methods of doing it pretty well to a lot of Blitz programmers back in the day: https://gafferongames.com/post/fix_your_timestep/

It's old, but, maths is maths.  It still applies.
Intel I9-9900K 3.6-5.0GHz | GeForce RTX2070 8GB | 32GB RAM | 500GB NVMe M.2 SSD | 1TB HDD | Windows 10 x64.
MSI Apache Pro | I7-7700HQ | GeForce GTX1060 3GB | 8GB RAM | 128GB SSD | 1TB HDD | Windows 10 x64.

Offline Dan

  • Jr. Member
  • **
  • Posts: 36
Re: Setting the game frequency
« Reply #11 on: July 03, 2020, 01:18:02 PM »
Thank you.
65536 GOTO Back2Basic

Offline Matty

  • Hero Member
  • *****
  • Posts: 1258
    • MattiesGames
Re: Setting the game frequency
« Reply #12 on: July 03, 2020, 11:22:50 PM »
There is another method which I use:
Create a game which on the lowest spec machine will not fall below your target frame rate desired.

In other words limit your game's fx and such that it will never fall below the target frame rate.

Then in your loop after rendering call a delay with the number of millisecs being those remaining to make up a full frame time.

Works perfectly.

Offline STEVIE G

  • Sr. Member
  • ****
  • Posts: 498
Re: Setting the game frequency
« Reply #13 on: July 04, 2020, 12:03:01 PM »
There is another method which I use:
Create a game which on the lowest spec machine will not fall below your target frame rate desired.

In other words limit your game's fx and such that it will never fall below the target frame rate.

Then in your loop after rendering call a delay with the number of millisecs being those remaining to make up a full frame time.

Works perfectly.

This is pretty much what waittimer does automatically. I always found deltatime jerky. My rig is v low end deliberately, including the worst gfx card (gfx710) so my (probably flawed) theory is that if I can run  it at 100 fps then everyone should be able to play it at least 60fps.

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2873
  • elgol 2021
Re: Setting the game frequency
« Reply #14 on: July 04, 2020, 04:57:25 PM »
@Matty, that would work for the sort of games you write, but not for all types of games.

@Stevie, that's why your games only run ok smoothly on monitor refresh rates above 60hz rather than silky smooth, and don't take advantage of the more powerful systems to deliver smoother results over slow systems.  Plus you're basically stopping the computer from doing anything for a time, which seems kinda wasteful.  You now do the maths and give options in-menu to people with 75hz monitor refresh rates - and you could expand that, so not a bad strategy I guess.  Delta-time has always given me the smoothest results (and without having to set options for every monitor refresh rate) but can be tricky to get right, and you certainly must clamp the frame speed differences between consecutive frames to a maximum level to avoid temporary spikes.

I'm very hard to please on this matter so keep trying to produce something that is a perfect solution.  In a 3D game with lots happening on-screen you won't notice any lack of smoothness.  But with a 2D scroller you will.  Maybe I've been spoilt by old systems with a set piece of computer hardware syncing perfectly to a set Monitor/TV refresh rate, but I do very much notice any stutter.
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry Pi 400, Pi4, C64, ZX Spectrum Next.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal