1 / 20

Game Architecture in a nutshell

Game Architecture in a nutshell. Major Games Programming, February 2010 Jan Verhoeven. Contents. Game loop Games in Windows Design Patterns State machine Links. Game Architecture.

anneke
Télécharger la présentation

Game Architecture in a nutshell

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Game Architecturein a nutshell Major Games Programming, February 2010 Jan Verhoeven

  2. Contents • Game loop • Games in Windows • Design Patterns • State machine • Links

  3. Game Architecture Games are time-dependant interactive applications, consisting of a virtual world simulator that feeds real-time data, a presentation module that displays it, and control mechanisms that allow the player to interact with that world. See gamasutra.com: http://www.gamasutra.com/blogs/SimonLim/20100112/4097/Game_Architecture.php

  4. Real-Time loop • A game is a real-time interactive application with tasks running constantly: • The state of the world must be recomputed • The operator (player) must be allowed to interact with it • The resulting state must be presented to the player, using screen data, audio and so on

  5. Game Loop

  6. Games and Windows • In its default for, the message loop model of a Windows program is not one that will lend itself to game performance.  The reason is that the design philosophy behind a typical Windows application and a high performance game are totally different

  7. Windows Application Philosophy • Don't get in the way • Only take use of CPU when we are told to • Spend most of our time sleeping till someone wakes us • Be friendly to other applications and step aside • Things will get done when they need too, no hurry

  8. Game Philosophy : • Take all that you can get • We control all that you see and hear.... • Don't let up for a moment • We're on a deadline here - move it! • Only let others have control as it benefits us

  9. SO? (read it by yourself ;-)) • As you can see, these are two very different ways of thinking.  So, do we just replace our message loop with a game loop akin to the days of old?  The answer is a resounding NO!!!  • Taking complete and utter control of the system in the Windows world will not provide the performance we need.  Rather, it will bring the system to its knees.  The reason for this is simple : we are reliant on other services to provide access to the system, so we must let Windows run on. • So, is there a happy compromise to be found?  A way to insure our performance, while allowing the system to take care of things?  Yes, there is, but it will require a few changes.

  10. A typical Windows message loop • while( GetMessage( &msg, NULL, 0, 0 ) ) {TranslateMessage( &msg );DispatchMessage( &msg );} • GetMessage : This function is used to retrieve a message from the Message Queue.  If there is not a message available, calling this function causes the thread to sleep until a message is received. • TranslateMessage : This function provides translation of keyboard messages, and must be called on all messages before dispatching them. • DispatchMessage : Calls the appropriate handler or sends the message to the appropriate child window

  11. Keeping Awake (draft version) while (true) { // is there a message to process? if (PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) { // dispatch the message TranslateMessage(&mssg);DispatchMessage(&mssg); } else { // our game loop stuff will go here!!} }

  12. Game Loop with Timing • We want our game to run regardless of the underlying hardware and software, so with same speed and motions.

  13. Design Patterns -Singleton- Some useful programming patterns: A singletonis a global object for which only one instance exists in the whole application. See: http://gameprogrammingpatterns.com/singleton.html

  14. Design Patterns -Strategy- Imagine that you are developing a role-playing game where you want to move your characters around on the map. You are interested in supplying different algorithms for movement for different types of characters. For instance, a human character needs to avoid collision with trees etc. while a ghost character can move right through buildings and a wizard character can teleport himself.

  15. Design Patterns -Strategy-

  16. Design Patterns And many more: • Composite, • Factory, • State, • And so on …… See: http://gpwiki.org/index.php/Category:Design_patterns

  17. State Machines • Very important subject • Chapter 2 in your AI study book (read it!!) and/or see http://www.ai-junkie.com/architecture/state_driven/tut_state1.html and next 2 pages

  18. FSM Example: Ghost in Pac-Man Player re-spawns Time to exit Center Room Move Randomly Chase Player Player dies Player eats Pellet Pellet wears off Player eats Ghost Run from Player Rise Die Eyes reach Center Room

  19. Links • Game Programming Wiki: http://gpwiki.org/index.php/Game_Programming_Wiki • Game Programming Wikipedia: http://en.wikipedia.org/wiki/Game_programming • GameDev.net: http://www.gamedev.net/ • Amit’s Game Programming Information: http://www-cs-students.stanford.edu/~amitp/gameprog.html • University of Houston: http://games.cs.uh.edu/ • And of course …

  20. About Game Design • Read this very interesting presentation: http://www.cs.rutgers.edu/~nealen/game/gameworkshop.pdf • Why should you study game programming? http://esminfo.prenhall.com/computing/PHIT2/mencher.ppt

More Related