Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / SetVSync(1) - How To Modify Game To Run At Different Speeds?

Author
Message
TheFallenAngel
6
Years of Service
User Offline
Joined: 13th Feb 2018
Location: Long Island, New York, United States, Earth
Posted: 23rd Feb 2018 13:56
Hi!

We hit the game with a large hammer and have it running near full speed on HTML5.
SetVSync(1) sets the game at 60 FPS on 60Hz monitors and 120 FPS on 120Hz monitors.
We want the game to run at different FPS speeds which is configurable in the [Options].
How can we accomplish this with SetVSync(1)?

Our previous code is below:


You can play the almost full speed HTML5 version below:
http://fallenangelsoftware.com/stuff/files/SpaceSwap/HTML5/index.html

Code is open-source and can be viewed below on GitHub:
https://github.com/FallenAngelSoftware/AppGameKit2-SpaceSwap

Let us know, thanks!

Jesse
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 23rd Feb 2018 15:27
SetSyncRate(PlayingSyncRate,0)
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
TheFallenAngel
6
Years of Service
User Offline
Joined: 13th Feb 2018
Location: Long Island, New York, United States, Earth
Posted: 23rd Feb 2018 16:13
Hi,

SetSyncRate(PlayingSyncRate,0) //would not work on HTML5 with "SetVSync(1)".

Quote: "Note that on HTML5 the use of SetSyncRate is highly discouraged as it uses the Javascript SetTimeout function for timing, which can cause inaccurate frame rates and suttering. On HTML5 the prefered method of frame rate control is SetVSync. "


Is there a way to do the above with "SetVSync(1)" ?
Thanks!

Jesse
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 23rd Feb 2018 17:20 Edited at: 23rd Feb 2018 17:22
If you make everything framerate indepedent then you won't need to bother with specifying a rate at all although you still can.

Basically you calculate a frame time scale and all movement, timers etcs when incrementing, decrementing you apply the frame time scale modifier.

An example of this can be seen in the project attached to the posts in the thread on building an old school fps. The "game" will run the same on anywhere from about 15 fps up. Could be made to run the same even lower but I saw no need in doing so. My function to calculate the frame time scale also handles fast hardware by giving time back to the system each frame it can do so.

Anyway if you take this approach then you can just run it wide open at max frame rate in fact feel free to just take my function that calculates the frame time scale if you like.

If not of course that is fine too. But making everything framerate independent is a good way to go for game programming in general although it does mean you are always multiplying by a delta value which adds a bit of overhead in itself and bit of extra code it simplifies the kind of challenge you are looking at currently.

At any rate congrats on figuring out the cause and solving the performance issue!
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
TheFallenAngel
6
Years of Service
User Offline
Joined: 13th Feb 2018
Location: Long Island, New York, United States, Earth
Posted: 23rd Feb 2018 17:49
Nevermind,

smallg was correct, "SetSyncRate( x, 0 )" works!

Thanks!

Jesse
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 23rd Feb 2018 17:50
Great! Easy fix.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)

Login to post a reply

Server time is: 2024-11-21 19:59:31
Your offset time is: 2024-11-21 19:59:31