Game programming and quantity of timers
Asked Answered
U

1

9

I've made a simple 2D game engine using C# and DirectX and it's fully functional for the demo I made to test it. I have a Timer object that uses QueryPerformanceCounter and I don't know what's the better choice: use only one timer in the game loop to update everything in the game, or an independent timer in every object that needs one.

My worry is that when I try to implement threads, what will happen with timers? What happens with the sync?

Uphill answered 12/10, 2012 at 22:41 Comment(4)
I would lean towards a single timer which dispatched tasks (on different threads if needed)...but I'm no game programmer.Magic
I have a class to check the status for the keyboard and other for the mouse, also I have "game states" that do all the logic (e.g. intro, menu, game). Each one of that classes have a timer for his own, and the game loop have another. Every class manage his own timer.Uphill
Surprisingly enough, most game programming is not significantly different than any other programming. It requires a solid understand of the business logic, multithreading and synchronization, and algorithms... just like every other non-trivial programming position.Leukorrhea
@Leukorrhea +1. A strange attack of sanity. Unfortunately, being right does not make you/I popular, but I don't care:)Ceylon
A
2

You had better to have an Update (user interaction and other calculatings like hittest) and Draw functions for each game object. Your timer should call the topmost Update method and this method will call the update methods of each object. Drawing can be done with another timer or just a while loop until game ends. My choice is having only one timer for update. For the differences of timers; Comparing the Timer Classes

Appellate answered 13/10, 2012 at 13:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.