SyntaxBomb - Indie Coders

Languages & Coding => Blitz2D, BlitzPlus, Blitz3D => Topic started by: JBR on July 02, 2020, 12:44:31 AM

Title: Setting the game frequency
Post by: JBR 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.
Title: Re: Setting the game frequency
Post by: col 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.
Title: Re: Setting the game frequency
Post by: Matty on July 02, 2020, 07:44:00 AM
Why shouldn't it work?
Title: Re: Setting the game frequency
Post by: Santiago 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.
Title: Re: Setting the game frequency
Post by: JBR 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.
Title: Re: Setting the game frequency
Post by: Dan 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


Title: Re: Setting the game frequency
Post by: Santiago on July 02, 2020, 10:29:32 PM
ohhhh, that is new for me  :o
Title: Re: Setting the game frequency
Post by: STEVIE G 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.
Title: Re: Setting the game frequency
Post by: GfK 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.
Title: Re: Setting the game frequency
Post by: Dan on July 03, 2020, 05:59:32 AM
How is delta timing calculated ?


Title: Re: Setting the game frequency
Post by: GfK 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.
Title: Re: Setting the game frequency
Post by: Dan on July 03, 2020, 01:18:02 PM
Thank you.
Title: Re: Setting the game frequency
Post by: Matty 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.
Title: Re: Setting the game frequency
Post by: STEVIE G 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.
Title: Re: Setting the game frequency
Post by: Steve Elliott 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.
Title: Re: Setting the game frequency
Post by: GfK on July 05, 2020, 11:47:21 AM
Trouble with aiming for the lowest spec PC you can think of, is that there's always plenty of people out there who will have worse.

i.e. "This gaming laptop* is pretty new, I only bought it six years ago from PC World".

* which was *never* a gaming laptop, and a bit shit on the day you bought it.
Title: Re: Setting the game frequency
Post by: hosch on July 05, 2020, 05:40:15 PM
I'm a bit late to the party, but that's the way I've done it for several years without running into problems:
Code: [Select]
Local fps% = CreateTimer(60)

Repeat

(your game code)

WaitTimer(fps)
Flip
Forever
Title: Re: Setting the game frequency
Post by: grindalf on July 05, 2020, 10:24:49 PM
Im not trying to hijack the thread but.....
I can CreateTimer and WaitTimer but is there anyway to get the current state of the Timer, like a GetTimer or something. There seems to be no commands for it in the helpfile and I find it very strange that it doesn't exist.
Title: Re: Setting the game frequency
Post by: Steve Elliott on July 05, 2020, 10:42:21 PM
GetFrameTime()
Title: Re: Setting the game frequency
Post by: grindalf on July 06, 2020, 07:41:28 AM
GetFrameTime()
That doesn't exist as a command
Title: Re: Setting the game frequency
Post by: Steve Elliott on July 06, 2020, 08:53:51 AM
https://www.appgamekit.com/documentation/Reference/Core/GetFrameTime.htm
Title: Re: Setting the game frequency
Post by: Dan on July 06, 2020, 10:38:39 AM
like a GetTimer or something. There seems to be no commands for it in the helpfile and I find it very strange that it doesn't exist.

Well, (As planed by the developer) Create/WaitTimer commands should make it easy to achieve a constant framerate.
I guess, Blitzbasic is using it internally, probably flip command is starting the timer, and waittimer() waits until the calculation has reached the target.

It is, because of the WaitTimer (which causes a delay in program execution), that GetTimer becomes useless in this case.
Title: Re: Setting the game frequency
Post by: grindalf on July 06, 2020, 06:31:47 PM
https://www.appgamekit.com/documentation/Reference/Core/GetFrameTime.htm
You do realize you are posting on a topic about Blitz3D right :P
Title: Re: Setting the game frequency
Post by: Steve Elliott on July 06, 2020, 07:18:13 PM
lol a lot here use AGK and the subject is universal.   :P
SimplePortal 2.3.6 © 2008-2014, SimplePortal