tailieunhanh - Object oriented Game Development -P4

Object oriented Game Development -P4: There’s a better than 50% chance that you have picked this title off the shelf in a bookshop and are wondering if it’s going to be another one of those ‘secrets of the inner circle’ type of titles. You know, the ones that promise to tell you unspoken truths on how to write really cool games but in reality offer up a rehash of a manual you may already have for free anyway. | 76 Object-oriented game development up with a satisfactory structure for supporting arbitrary primitive types - virtual functions are too inefficient because primitives are quite low-level and there are therefore lots of them in a typical scene which rather knocks inheritance of a primitive abstract type on the head. This leaves us with the following associations Renderer Transform Texture Screen Camera Mesh Model Frame Position Rotation Viewport Triangle Quad Palette Colour Light Ambient Directional Spotlight. Their relationships are shown in Figure . Figure Class diagram for a basic renderer. Patterns Patterns were made popular in the 1990s by the Gang of Four GoF book Gamma et al. 1994 . They represent the logical relationships between classes that just keep appearing in your software irrespective of whether you are writing spreadsheets missile-guidance systems or resource managers. Patterns are at the very least interesting and more often than not they are extremely useful. Often you re sitting there trying to work out how to get func Object-oriented design for games 77 tionality from one class to be utilised by another without violating encapsulation or how to construct mechanisms to perform complex functions and a flick through the GoF book is all you need to gain the required insight. But this is only half the battle - we still need to implement the pattern and writing useful pattern code still takes a bit of thought and effort. This section looks at a few of the useful patterns and shows how they can be implemented with a reasonable degree of generality and efficiency. The interface Also known as protocol compilation firewall pimpl The first pattern we ll look at is both simple and important. Remember earlier we were concerned about dependencies in common components When a common component s header file changed all the dependent source modules had to be recompiled. Any action adding a method changing an implementation detail or indeed the .