How to optimize my snake clone?

Advanced game related topics
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

How to optimize my snake clone?

Post 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.
Rolands
User
User
Posts: 39
Joined: Thu Jun 12, 2003 6:29 pm

Nice

Post 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
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Re: How to optimize my snake clone?

Post 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()
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post 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!
I like logic, hence I dislike humans but love computers.
Nells
New User
New User
Posts: 6
Joined: Tue Mar 02, 2004 12:43 pm

Post 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...
Post Reply