180 likes | 365 Views
Object Oriented Game Framework Design. Riz Verghese Joj. Frameworks: What are they?. Semi complete applications Complete applications can be developed by inheriting from and instantiating parameterized framework components. Provide domain-specific functionality
E N D
Object Oriented Game Framework Design Riz Verghese Joj
Frameworks: What are they? • Semi complete applications • Complete applications can be developed by inheriting from and instantiating parameterized framework components. • Provide domain-specific functionality • Business, telecom, databases, games. • Exhibit inversion of control at run-time • Determines which objects and methods to invoke in response to events.
Benefits “The most profoundly elegant framework will never be reused unless the cost of understanding it and then using its abstractions is lower than the programmer’s perceived cost of writing then from scratch.” - Booch, Dr. Dobbs Journal, 1994.
Design Patterns “Each pattern describes a problem which occurs over and over again in our environment and then describes the core of the solution to that problem, in such a way that you can use the solution a million times over, without ever doing it the same way twice.” - Christopher Alexander, A Pattern Language, 1977.
Design Patterns … what are they? • A Solution to a problem in context • Provide experience reuse instead of code reuse. • Hundreds of patterns exists! • Vocabulary: Facilitates communication among developers • Lets you think at an architecture level, not implementation level. • Eg: Factory, Observer, Composite, Singleton
An example game framework • Classic arcade style games • 2D tile based games • Basic elementary collision • Supports dynamic class loading
The Design • Resource Manager • Resource Image • Resource Sound • Resource Sprite • Game board • Tile Indexer • Tile manager • Tiles • Immovable Tile • Movable Tile
Patterns • Resource Manager • Factory • Reads from an xml file • Dynamic creation of classes • Associate images and sounds with a tile • Tile Manager • Observer • Tiles created subscribes to the Tile Manager • Tile Manager tells the board where the tiles are • Tiles have to request movement from the Tile Manager.
Game specific patterns • Patterns aren’t limited to the framework • Game specific code can have lots of patterns • The Snake game: • Especially uses the composite pattern • Framework objects mostly follow the singleton pattern where as game specific objects do not.
How does the framework work? • Resource manager loads the tiles in memory from information in the XML file. • Level loader prepares an instance of the board, tiles and placement of the tiles on the board. • Game specific class maps input to tile action (usually movement) • Tile asks board if it can move to the desired place • Board lets tile move or not • Property of the tile determine what happens when two tiles occupy the same space • Collide, Consume, Cancel.
Implementation specifics • Two threads • The first allows the board to redraw/refresh • The second allows every tile to ‘think’ • The think method allows the tiles to • Keep moving • Keep falling • Know what to do on collision • Tells other tiles what to do
More specifics • Tiles can have relations • The observer/observable relationship • Eg: Acno game: Door disappears when key is eaten • Key tells door to disappear • Eg: Snake gets longer when apple is eaten • Apple tells snake body to spawn
Advantages • Allows you to step back and generalize • More time spent on the framework • Isn’t worth it for just one game • Allows you to spend time on the game (content) not the implementation • Saves a LOT of time for one particular game • Clean implementation • The framework code is generally hidden • Game specific code is small (from reusing framework components)
Disadvantages • Games are limited to the framework • Can’t build all games • Features Limited to framework provision and functionality • Sometimes overcome through ugly workarounds/tricks/hacks
References • The development of a Game Playing Framework using Interface-based programming, Mark Cohen, Issue 12.1, ACM Student Magazine, Fall 2005. • Object-oriented Game Development, Julian Gold, ISBN: 032117660X, Addison Wesley, 2004. • Introducing Object Oriented Frameworks, Taligent white paper. • Designing Reusable Classes, R. Johnson and B. Foote, Journal of Object-Oriented Programming, 1(2):22--35, June/July 1988 • Design patterns: Abstraction and reuse of object-oriented design, E. Gamma, R. Helm, R. Johnson, and J. Vlissides, In European Conference on Object-Oriented Programming Proceedings (ECOOP'93), volume 707 of Lecture Notes in Computer Science. Springer-Verlag, July 1993.
The end … Discussion