80 likes | 91 Views
General Game Programming Approach. 1. Event-driven Programming (1/3). The program is event-driven Messages = events So as all windows system (for example : X window) We need a loop to check all incoming events The Loop Check all incoming events (messages) Handle the events
E N D
General Game Programming Approach 1
Event-driven Programming (1/3) • The program is event-driven • Messages = events • So as all windows system (for example : X window) • We need a loop to check all incoming events • The Loop • Check all incoming events (messages) • Handle the events • Check timing and do something in regular • Incoming Events • Interrupts • System requests
Event-driven Programming (2/3) • Timers (do something in regular timing) • The sub-system to handle timing • Must be precise to at least 1 ms or less • 30fps = 1/30 second = 33.333… ms • On win32 platform, we can use “performance counter” instead of the win32’s “WM_TIMER” message • For windows9x, WM_TIMER = 18.2 fps (maximum) • Events • Input devices • Mouse • Keyboard • Something coming from network • System requests • Re-draw • Losing/getting the input focus • …
Event-driven Programming (3/3) • Therefore, we have two types of jobs: • In regular • Timers callbacks • By requests • Input device callbacks • Same as a game main program • A game is an interactive application • A game is time-bound • Rendering in 30fps or 60fps • Motion data in 30fps • Game running in 30fps • …
Game Loop (1/2) Loop y Check game over Exit the loop n Peek player input Implement timer callback Rendering Single Player
Game Loop (2/2) Loop y Check game over Exit n Peek user input Receive messages From network Timer callbacks To network Send messages Rendering Network Client
Jobs in Regular (Typically) • Check Win/Loose • Check Quit • Objects Moving … • Play Character’s Motion to Next Frame • Play Animation to Next Frame • Models • Textures • … • Perform Some Game Calculation • Perform Geometry Calculation • LOD • Perform AI “Thinking” • Perform Collision Detection • Perform the 3D Rendering • …
Jobs By Request (Typically) • Mouse Input • Press/release the mouse button • Drag • Double-click • Move • Keyboard Input • Hotkey • Typing • Gamepad • Same as the hotkey • Network • System