Re: Programming a game
Re: Programming a game
- Subject: Re: Programming a game
- From: Matthew Cox <email@hidden>
- Date: Sun, 16 Nov 2003 09:40:01 -0500
On Sunday, November 16, 2003, at 08:06 AM, Denis Vaillant wrote:
Hi every one,
I am trying to program a little game in OpenGL : I have a timer which
is
running every 1/30s. The timer checks every time keyboard or mouse
inputs
and calcutes the new position of the players in the view. Once this is
done,
the NSOpenGLView is updated.
Are you trying to run the game full screen? I don't know if this
applies to windowed mode as much as full screen, but you shouldn't lock
into a static time interval, you need to sync your repaints to the
monitor's vertical blanking interval. This VBL syncing helps make the
animation look far smoother. The way to do this is somewhat like double
buffering, its called page flipping. Any number of game sites have good
introductions to it. I personally like flipcode.com, but it's window's
orientated to a large extent.
My problem is that on slow computers, the view in not updated as fast
as the
timer is going and so the players are not moving at the right speed.
I suggest applying a little MVC-logic here. Separate the model of your
game (the kinematics and position stuff) from the view (the opengl
drawing.) Update your model as often as you want, because it will
probably not be an intensive process. Then, have the view try to draw
itself as often as possible using fresh data from the model each time,
making sure to draw only to the VBI's beat.
The way it should be working (like any game I believe), is that all the
calculations are done within a timer and then, if the processor has
free
memory, the view is updated. How can I do that in my code ?
Not so much that the processor has free memory, but more that it has
free time slices. I'd suggest multithreading, but that's really up to
you.
Cheers for your help (as usual :))
Denis
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.