Page 1 of 1

How to optimize my snake clone?

Posted: Tue Jan 18, 2005 9:27 pm
by Joakim Christiansen
How can I optimize my snake clone so it runs at the same speed on all computers and uses lowest system resources.

I set the frame rate at 85, that may very dumb in a such game?
Because it should only be redrawed at each "step".
Does SetFrameRate() make the game run at the same speed on all computers?

Just give me some tips or if possible give me an updated source-code.
Yeah, i'm a noob! :oops:

The source-code.

Nice

Posted: Sat Mar 12, 2005 11:17 am
by Rolands
Nice little game.
I don't have an answer on your question because I'm not that experienced in game coding.
Did you find a solution after all these weeks for your problem?
Would be nice to add some sounds to the game.

I've saved your code to my local storage of code to learn from it!


8) Roland

Re: How to optimize my snake clone?

Posted: Sat Mar 12, 2005 11:34 am
by Bonne_den_kule
Joakim Christiansen wrote:How can I optimize my snake clone so it runs at the same speed on all computers and uses lowest system resources.

I set the frame rate at 85, that may very dumb in a such game?
Because it should only be redrawed at each "step".
Does SetFrameRate() make the game run at the same speed on all computers?

Just give me some tips or if possible give me an updated source-code.
Yeah, i'm a noob! :oops:

The source-code.
60 frame rate is enough. Most flat screens (LCD) dosen't support higher then 60, so it is only waste of GPU power. And you cant see any difference beetween 60 and 85. Don't forget that the frame rate on the display and ont the graphic card use are two different things

SetFrameRate() is not the same as SetRefreshRate()

Posted: Sat Mar 12, 2005 7:58 pm
by Joakim Christiansen
Roland: It was'nt actually a problem. I was only wondering about some stuff since I was quite new to the language.
If you want to learn from the code then you could aslo take a look at the new version I made. (it's on my page)
There is still some "bad" coding in it, i'm now currently rewriting the whole game for the next version. (it will include more sounds, multiplayer, different game modes...)

Bonne_den_kule: Thanks for the info!

Posted: Thu Mar 31, 2005 11:33 am
by Nells
You can also make a multithreaded system, it's easy in PureBasic, so you have the main thread that draw (FlipBuffers()...) and a thread that make al the calculation every time step (i.e 25ms)

GetTickCount_() and ElapsedMilliseconds() are not really precise, better use QueryPerformanceCounter() (a bit more difficult but more than µs precision rather than ElapsedMillisecond < ms precision)

sample :

Code: Select all


Procedure ThreadCalculations()
Repeat

oldT = t
Repeat
QueryPerformanceCounter(@t)
Delay(1)
Until t > oldT + #TIMESLEEP

;calculations...

Until end
EndProcedure
Well, i know it's not as simple, but i have not my games sources know with me

and you may encounter problem using strings or accessing same linkedlists in different threads, u have to handle it...