Presentation is loading. Please wait.

Presentation is loading. Please wait.

11 General Game Programming Approach. The program is event-driven The program is event-driven –Messages = events –So as all windows system (for example.

Similar presentations


Presentation on theme: "11 General Game Programming Approach. The program is event-driven The program is event-driven –Messages = events –So as all windows system (for example."— Presentation transcript:

1 11 General Game Programming Approach

2 The program is event-driven 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 We need a loop to check all incoming events The Loop The Loop –Check all incoming events (messages) –Handle the events –Check timing and do something in regular Incoming Events Incoming Events –Interrupts –System requests 2 Event-driven Programming (1/3)

3 Timers (do something in regular timing) 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 Events –Input devices »Mouse »Keyboard –Something coming from network –System requests »Re-draw »Losing/getting the input focus »…»…»…»… 3 Event-driven Programming (2/3)

4 Therefore, we have two types of jobs: Therefore, we have two types of jobs: –In regular »Timers callbacks –By requests »Input device callbacks Same as a game main program 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 »…»…»…»… 4 Event-driven Programming (3/3)

5 Single Player Single Player 5 Check game over Peek player input Implement timer callback Exit the loop Rendering Loop y n Game Loop (1/2)

6 Network Client Network Client 6 Check game over Peek user input Receive messages Send messages Timer callbacks Rendering Exit y n From network To network Loop Game Loop (2/2)

7 Check Win/Loose Check Win/Loose Check Quit Check Quit Objects Moving … Objects Moving … Play Character’s Motion to Next Frame Play Character’s Motion to Next Frame Play Animation to Next Frame Play Animation to Next Frame –Models –Textures –…–…–…–… Perform Some Game Calculation Perform Some Game Calculation Perform Geometry Calculation Perform Geometry Calculation –LOD Perform AI “Thinking” Perform AI “Thinking” Perform Collision Detection Perform Collision Detection Perform the 3D Rendering Perform the 3D Rendering … 7 Jobs in Regular (Typically)

8 Mouse Input Mouse Input –Press/release the mouse button –Drag –Double-click –Move Keyboard Input Keyboard Input –Hotkey –Typing Gamepad Gamepad –Same as the hotkey Network Network System System 8 Jobs By Request (Typically)


Download ppt "11 General Game Programming Approach. The program is event-driven The program is event-driven –Messages = events –So as all windows system (for example."

Similar presentations


Ads by Google