360 likes | 379 Views
Game Programming Design Principles. 2008/9/22 Kim, HyungSeok. Term Project Proposal. Presentation. Course Outline. 0. Introduction (Sep.) – Chap. 1 1. Game Architecture (Sep.) – Chap. 2 2. Design Principles (Sep.) – Chap. 4 3. Interactions (Sep./Oct.) – Chap. 5, Chap. 22
E N D
Game ProgrammingDesign Principles 2008/9/22 Kim, HyungSeok
Term Project Proposal • Presentation HyungSeok Kim, Konkuk University
Course Outline 0. Introduction (Sep.) – Chap. 1 1. Game Architecture (Sep.) – Chap. 2 2. Design Principles (Sep.) – Chap. 4 3. Interactions (Sep./Oct.) – Chap. 5, Chap. 22 4. AI (Oct.) – Chap. 6, 7, 8 5. Animation (Nov.) – Chap. 15, 16 6. Visualization (Nov.) – Chap. (11,) 12, 13, 14, (19, 20, 21) 7. Network programming (Dec.) – Chap. 10 HyungSeok Kim, Konkuk University
Game Development Process • Elementary process • Preproduction • Production • Maintenance HyungSeok Kim, Konkuk University
Game Development Process • Elementary process • Preproduction (indefinite time but usually less than 1 year) • Concept development • Elaboration of technology • Experiments… • Generates the first working prototype • Create detailed plan of development • Secure the funds • Production • Maintenance HyungSeok Kim, Konkuk University
Game Development Process • Elementary process • Preproduction • Production (1~3 years) • Develop a game following the development plan of preproduction • Software modules, Artworks, etc… • Iterative process of development • Getting approval from the publisher (also the licenser) • Testing (1~3 month) • Creating ‘Gold Master’ -> few weeks to publishing • Maintenance HyungSeok Kim, Konkuk University
Preproduction • Step 1: Initial idea • Should consider • Who is the player? • What are his/her goals? • What’s the genre? • How does the game play? • Ex: HyungSeok Kim, Konkuk University
Preproduction • Step 1: Initial idea • Creating definitive descriptions of the game-play or • Creating narrative descriptions or • Technology driven descriptions HyungSeok Kim, Konkuk University
Preproduction • “A lot of people ask me if I start designing games with a story in mind, … …, but actually I start on a much more basic level. … I start with some basic core experiments, testing out the action on the screen or a specific gameplay style.” • “When we started with Mario, all we had were some blocks onscreen, and we would try to make those blocks bounce around and jump as we intended them to do using the controller…” • - Shigeru Miyamoto HyungSeok Kim, Konkuk University
Preproduction • Step 2: feature sets • Which feature the game will have? • Expansion-contraction process • List-up • Categorization • Selection HyungSeok Kim, Konkuk University
Preproduction • Step 2: feature sets • Benefit and Cost based selection • Benefit • User-perceived value • Generality • Cost • Coding size • Coding difficulty • Four cases of selection HyungSeok Kim, Konkuk University
Productions • “Milestones are king” • Some considerable rules • More is not better • More features? More developers? • “On time” is better than “more ambitious” • Surgical teams and key members are a risk • Teams, backups • Order of execution • Priority of development HyungSeok Kim, Konkuk University
Maintenance • Goal • Maximize experiences of the player • Method examples • Release of new contents – extra units, … • Providing content creation tools – mods • Case of MMORPG • Documentation HyungSeok Kim, Konkuk University
Summary • Game production • Preproduction • Production • Maintenance HyungSeok Kim, Konkuk University
Game Design Patterns • Problems and solutions • Common problems in programming • Standard solutions? • Design pattern • A general repeatable solution to a commonly occurring problem in software design HyungSeok Kim, Konkuk University
Design Pattern • Example • Prototype pattern • Case: different objects with similar operations • Solution: abstract prototype HyungSeok Kim, Konkuk University
Design Patterns in Game • Architectural issues • How to make elegant architecture of the game engine? • Storage issues • How to efficiently manage storages? • Behavioral issues • How to effectively manage behaviors of objects? HyungSeok Kim, Konkuk University
Design Patterns in Game • Architectural issues • Singleton • Storage issues • Factory • Flyweight • Behavioral issues • Spatial index • Strategy • Composite HyungSeok Kim, Konkuk University
Architectural issues • In game engines, some objects needs to be accessed by other models • eg: player, input controller, object manger, … • How to? • Global variables • Hmm.. efficient but… • Dirty codes, module dependency, difficulties in module selection • Passing objects by parameters • Okay.. but hard to read… HyungSeok Kim, Konkuk University
Architectural issues • Singleton pattern • Use of one unified instantiation method • Centralize the request to one class • eg: class Singleton { public: static Singleton* Instance(); protected: Singleton(); static Singleton* m_pInstance; … }; --------------------------- Singleton* Singleton::m_pInstance = NULL; Singleton* Singleton::Instance() { if (m_pInstance == NULL) m_pInstance = new Singleton; return m_pInstance; } HyungSeok Kim, Konkuk University
Storage issues • Problem: • Construction and destruction • Need of centralize those memory allocation • Efficient memory allocations • Reusability and portability of types • How? • Factory pattern • Centralized creator of different objects HyungSeok Kim, Konkuk University
Factory Pattern • Abstract Factory • Creation of object, returning abstract type HyungSeok Kim, Konkuk University
Factory Pattern • Abstract Factory class Product; class Texture: public Product; class Mesh: public Product; class Item: public Product; class AbstractFactory { public: Product* Create(int id); } Product* AbstractFactory::Create(int id) { switch (id) { case TEXTURE: return new Texture; break; case MESH: return new Mesh; break; case ITEM: return new Item; break; } return NULL; } HyungSeok Kim, Konkuk University
Factory Pattern • (real) Factory class Factory { public: Texture* CreateTexture(); Mesh* CreateMesh(); Item* CreateItem(); }; HyungSeok Kim, Konkuk University
Storage issues • Problem #2: • Some objects are sharing most of contents with small differences (eg: soldiers) • Efficient memory usage is needed • How? • Separate abstract and real class • Abstract class: contains common data • Real class: contains instance specific data HyungSeok Kim, Konkuk University
Storage issues • Flyweight pattern • eg: characters in word processor • eg: soldiers in game class Soldier: public AbstractFlyweight { public: void methods(ExtrinsicParameters* ); protected: IntricsicParameters m_params; }; class SoldierInstance { public: void methods(); protected: ExtrinsicParameters m_info; }; class FlyweightFactory { public: AbstractFlyweight* GetFlyweight(int type); static FlyweightFactory* Instance(); protected: AbstractFlyweight* m_aFlyweight; AbstractFlyweight* Create(int type); … }; AbstractFlyweight* FlyweightFactory::GetFlyweight(int type) { if (m_aFlyweight[type] not exists) m_aFlyweight[type] = Create(type); return m_aFlyweight[type]; } void SoldierInstance::methods() { FlyweightFactory* ff = FlyweightFactory::Instance(); Soldier* soldier = ff->GetFlyweight(SOLDIER); soldier->method(m_info); } HyungSeok Kim, Konkuk University
Behavioral Issues • Problem #1 • How to know which one is near in complex and huge scene? • How? • Linear search? • O(n) HyungSeok Kim, Konkuk University
Solution • Spatial Index Pattern • 1. Linked list • 2. Regular grid • 3. Quadtree/Octree HyungSeok Kim, Konkuk University
Behavioral issues • Problem #2 • Different behavior in different situations • How to implement it? • switch()? • long and unreadable codes • Derived class • eg: fighter with fight, escape, patrol, idle behavior • Complex class hierarchy • Difficulties in algorithm change HyungSeok Kim, Konkuk University
Behavioral issues • Solution? • Algorithm as parameters class Fighter { public: Fighter(Strategy*); void recalc_AI(); void change_strategy(Strategy*); private: Strategy* m_pStrategy } void Fighter::recalc_AI() { m_pStrategy->recalc(…); } class Strategy { public: virtual void recalc(…); } class FightStrategy: public Strategy; class EscapeStrategy: public Strategy; … HyungSeok Kim, Konkuk University
Behavioral issues • Problem #3 • How to manage different types of object? • eg: scene graph • Similar behaviors as scene graph elements • Different properties • Solution • Abstract class and virtual functions HyungSeok Kim, Konkuk University
Behavioral issues • Composite pattern • a Composite is an object designed as a composition of one-or-more similar objects, all exhibiting similar functionality HyungSeok Kim, Konkuk University
Composite pattern example • List of airplanes in a airport • class plane • B747, A380, … HyungSeok Kim, Konkuk University
Composite pattern example • Objects to be in a scene graph • Player • EnemyFighter • Bullets • Obstacles • Functionalities as a scene graph node • getChild(); • addChild(); • removeChild(); • Functionalities for each object • Player: Shoot(); Move(); • EnemyFighter: Shoot(); Move(); • Bullets: Move(); • Obstacles: IsCollide(); HyungSeok Kim, Konkuk University
Design Pattern in UI • Shield • Input shielding • Confirmation • Additional actions • State (mode) changing • Visualizing modes • Automatic change of modes • Semantics and contexts • Magnetism • Focus • Deactivation • Progress HyungSeok Kim, Konkuk University
Design Pattern • Consideration • Right problem • Efficiency • Readability • Further readings • Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley, 1995. • Portland Pattern Repository, http://c2.com/ppr/ HyungSeok Kim, Konkuk University