Top Banner
Game Architecture : wanna play a good game ? [ Wijanarko Sukma . Department of Informatics ]
27
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Game Architecture :wanna play a good

game ?

Page 2: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Taken from the Presentation slide of :

Jeff Ward

Associate Programmer

Bethesda Game Studios

Page 3: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

How can architecture help us :

Concurrency

Maintainability

Code Ownership

Usability

Performance

Stability

Architecture

Page 4: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Bad architecture creates problemsProduces side effects

Hard to follow

Hard to debug

Hard to reuse

Spend more time finding a way around the architecture than fixing the problem

OMG HAX!

Bad Architecture

Page 5: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Stability

Reusability

Cohesion

Orthogonally

Why do Architect (Design)

Page 6: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

A well architected system is easy to understand, change, debug, and reuse.

Page 7: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Principles of OOP (Object Oriented Programming)

Design Patterns

Best Practices

Know this first

Page 8: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Example Engine

Logic

State

Data File Loader

Output Input

Page 9: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

BasicsEncapsulation

Inheritance

Polymorphism

Principles of good designReduced coupling

Increased reliability

Increased reusability

orthogonality

OOP Principles

Page 10: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

“Encapsulation is a programming mechanism that binds together code and the data it manipulates, and that keeps both safe from outside interference and misuse.” – Schildt

Encapsulation is not just data hiding!

Implies each object should be a cohesive whole

Encapsulation

Page 11: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Accessing elements between instancesIt’s a convenience feature, not a good idea

“Always Design for Concurrency” – Tip 41 in The Pragmatic Programmer

Even if you don’t need it, a cleaner architecture results.

Instance Encapsulation

Creature Creature

Page 12: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Key overused concept of OOP“ Inherit not to reuse, but to be reused.”

“Is a” vs. “has a” vs. “needs to used as a”

Degrades performance

Prefer components over inheritanceCleaner architecture

Faster execution time and overhead

More flexibility

More encapsulated

Inheritance

Page 13: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Important as it relates to inheritance…Just realize that polymorphism goes two ways

Readable

Unreadable

Polymorphism

Page 14: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Book Design Patterns by “The Gang of Four” (Gamma Helm Johnson Vlissides)

The same problems keep coming up in CS

We keep solving them in the same (or similar) ways.

Is there a pattern here?

Intro to Design Patterns

Page 15: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Creational patternOnly one instance of the object exists

Private constructor with public accessor (usually Class::Instance())

Really nice name for a globalOften overused, and often not a real solution

Singletons translate well to factories

SingletonOr “Patterns Don’t Solve all Problems”

Page 16: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Singletons (or factories) welcome…Renderers

Resource managers

Memory managers

Message queues

Singleton Example

Page 17: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Behavioral patternInform multiple dependant objects of changes

Usually implemented as Subject and IListener objects

Listeners add themselves to subjects

When a subject changes, all listeners are notified.

Great for message queues

Observer / Listener

Page 18: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Architectural patternKeeps data and representation separate

Model = data, view = representationController is what sends messages to the model and view.

AdvantagesOne data, multiple views

Data manipulates data, and doesn’t care if its being viewed

Change renderers without changing anything else

MVCModel View Controller

Page 19: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Separate view from everything else

MVC Example

Renderer

3DObj

CreatureVs.

Creature Model

CreatureView

Renderer

3DObj

CreatureRadarView

Page 20: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Complete decoupling of logic from display

Easier to test, since you can watch just the logic

Easier to change (both the display and the logic)

Can run the view without the logic

Can run the logic without the view

Can distribute the logicSo long as instances are encapsulated

Advantages of MVC

Page 21: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

CommandAn object that represents stuff that should be done, as an object

Only needs to understand “Execute” and “Undo”Great for input handlers, macros, and undoable operations

FaçadeEncapsulate an entire system by providing a single coherent interface

ProxyA stand in for a concrete object.

Other Quick Patterns

Page 22: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Management ideaThat there is a technique that is more effective than any other technique at delivering positive results.

Something you don’t have to do, but it’s a good idea.

They’re like design patterns on a small scale.

Best Practices

Page 23: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Management Best PracticesUse version controlDo automated testingHave automated builds

Coding Best PracticesPrefer compile / link time errors to run time errorsGive one entity one cohesive responsibilityPrefer composition to inheritanceAlways code for concurrency (in terms of architecture)

Examples of Best Practices

Page 24: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Best PracticesAre key to your survival as a coder…

… and key to your code’s survival

Page 25: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Know what you’re doing and why.

Know that one approach to inheritance is better and know why.

Know when you’re coupling systems inadvertently

Know when you’re coupling instances

Know when to test

Know how to test

Know when to automate

Some Advices

Page 26: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Know when to refactor

Know when to rearchitect

Know that both are going to break everything

Final Words

Page 27: GD - 4th - Game Architecture

[ Wijanarko Sukma . Department of Informatics ]

Game Dev lecturers teamBy Wijanarko Sukma (5105100173)