Top Banner
8/6/2019 Intro to Architecture http://slidepdf.com/reader/full/intro-to-architecture 1/29 Intro to Game Architecture Jeff Ward  Associate Programmer Bethesda Game Studios
29

Intro to Architecture

Apr 07, 2018

Download

Documents

manoj manduva
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: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 1/29

Intro to Game Architecture

Jeff Ward

 Associate Programmer Bethesda Game Studios

Page 2: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 2/29

My Talk 

Your first engine

Why architect?

Principles of OOP Design Patterns

Best Practices

Page 3: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 3/29

 Y our Talk 

How can architecture help us with:

Concurrency

Maintainability

Code ownership

Usability

Performance

Stability

Page 4: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 4/29

Disclaimer

Sorry.

Page 5: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 5/29

AI

 Y our First Engine

 psst« this isn¶t real UML«

Renderer 

3DObj

2DObj

Player  Creature

Sound

3dSnd

Input

Items Bullets

File Loader 

Page 6: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 6/29

 W hy is that bad?

Bad architecture creates problems

Produces 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 H AX!

Page 7: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 7/29

 W hy Architect ( Design)?

Stability

Reusability

Cohesion Orthogonally

Page 8: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 8/29

 A well architected sy stem is easy  

to understand, change, debug,

and reuse.

Page 9: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 9/29

Principles of OOP

Basics

Encapsulation

Inheritance

Polymorphism Principles of good design

Reduced coupling

Increased reliability

Increased reusability $10 word - orthogonality

Page 10: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 10/29

Encapsulation

³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.

Page 11: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 11/29

Instance Encapsulation

 Accessing elements between instances

It¶s a convenience feature, not a good idea

³Always Design for Concurrency´ ± Tip 41 in ThePragmatic Programmer 

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

Creature Creature

Page 12: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 12/29

Inheritance

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 inheritance Cleaner architecture

Faster execution time and overhead

More flexibility

More encapsulated

Page 13: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 13/29

Poly morphism

Important as it relates to inheritance«

Just realize that polymorphism goes two ways

Readable

Unreadable

Page 14: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 14/29

Intro to Design Patterns

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?

Page 15: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 15/29

SingletonOr ´Patterns Don·t Solve all Problemsµ

Creational pattern

Only one instance of the object exists

Private constructor with public accessor (usuallyClass::Instance())

Really nice name for a global

Often overused, and often not a real solution

Singletons translate well to factories

Page 16: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 16/29

Singleton Example

Singletons (or factories) welcome«

Renderers

Resource managers

Memory managers

Message queues

Page 17: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 17/29

Observer / Listener

Behavioral pattern

Inform 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

Page 18: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 18/29

Message Queues

Built of one queue with multiple listeners

Player  Creature

Items Bullets

Vs.Player  Creature

Items Bullets

Queue

 NPCs

Page 19: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 19/29

MVCModel V iew Controller

 Architectural pattern

Keeps data and representation separate

Model = data, view = representation

Controller is what sends messages to the model andview.

 Advantages

One data, multiple views

Data manipulates data, and doesn¶t care if its being viewed Change renderers without changing anything else

Page 20: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 20/29

MVC Example

Separate view from everything else

Renderer 

3DObj

Creature

Vs.

Creature Model

CreatureView

Renderer 

3DObj

CreatureRadarView

Page 21: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 21/29

 Advantages of MVC

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 logic

So long as instances are encapsulated

Page 22: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 22/29

Other Quick Patterns

Command  An 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çade

Encapsulate an entire system by providing asingle coherent interface

Proxy  A stand in for a concrete object.

Page 23: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 23/29

Engine Improvements

AI

Renderer 

3DObj

2DObj

Player Model

Sound

3dSnd

Input File Loader 

Creature Model

Item Model

Bullet Model

Player View

Creature View

Item View

Bullet View

Queue

File Facade

IResource

Page 24: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 24/29

Best Practices

Management idea

That there is a technique that is more effective than anyother 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.

Two books:

Pragmatic Programmer by Andrew Hunt and DavidThomas

C++ Coding Standards: 101 Rules, Guidelines, and BestPractices by Herb Sutter and Andrei Alexandrescu

Page 25: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 25/29

Examples of Best Practices

Management Best Practices Use version control

Do automated testing

Have automated builds Coding Best Practices

Prefer compile / link time errors to run time errors

Give one entity one cohesive responsibility

Prefer composition to inheritance

 Always code for concurrency (in terms of architecture)

Page 26: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 26/29

Best Practices

 Are key to your survival as a coder«

« and key to your code¶s survival

Page 27: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 27/29

Final Thoughts

Know when to refactor 

Know when to rearchitect

Know that both are going to break everythingelse

Code, Test, Refactor, Test Cycle

Try to automate this

Code is better at testing code than you will ever be.

Page 28: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 28/29

Summary 

 Architect for cleaner, more stable, morereusable, and more understandable code.

Use the principles of OOP to your advantage,not your detriment

Utilize design patterns to avoid commonproblems

Understand best practices and apply them. Make great games.

Page 29: Intro to Architecture

8/6/2019 Intro to Architecture

http://slidepdf.com/reader/full/intro-to-architecture 29/29

Questions?

 [email protected]

http://www.jeffongames.com