intro to game architecture
Download
Skip this Video
Download Presentation
Intro to Game Architecture

Loading in 2 Seconds...

play fullscreen
1 / 29

Intro to Game Architecture - PowerPoint PPT Presentation


  • 103 Views
  • Uploaded on

Intro to Game Architecture. Jeff Ward Associate Programmer Bethesda Game Studios. My Talk. Your first engine Why architect? Principles of OOP Design Patterns Best Practices. Your Talk. How can architecture help us with: Concurrency Maintainability Code ownership Usability

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Intro to Game Architecture' - mareo


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
intro to game architecture

Intro to Game Architecture

Jeff Ward

Associate Programmer

Bethesda Game Studios

my talk
My Talk
  • Your first engine
  • Why architect?
  • Principles of OOP
  • Design Patterns
  • Best Practices
your talk
Your Talk
  • How can architecture help us with:
    • Concurrency
    • Maintainability
    • Code ownership
    • Usability
    • Performance
    • Stability
your first engine
Your First Engine

AI

Creature

Renderer

Player

3DObj

Items

Bullets

2DObj

Sound

Input

File Loader

3dSnd

psst… this isn’t real UML…

why is that bad
Why 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 HAX!
why architect design
Why Architect (Design)?
  • Stability
  • Reusability
  • Cohesion
  • Orthogonally
principles of oop
Principles of OOP
  • Basics
    • Encapsulation
    • Inheritance
    • Polymorphism
  • Principles of good design
    • Reduced coupling
    • Increased reliability
    • Increased reusability
    • $10 word - orthogonality
encapsulation
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.
instance encapsulation
Instance Encapsulation
  • Accessing elements between instances
    • It’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.

Creature

Creature

inheritance
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
polymorphism
Polymorphism
  • Important as it relates to inheritance…
    • Just realize that polymorphism goes two ways
      • Readable
      • Unreadable
intro to design patterns
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?
singleton or patterns don t solve all problems
SingletonOr “Patterns Don’t Solve all Problems”
  • Creational pattern
    • Only one instance of the object exists
    • Private constructor with public accessor (usually Class::Instance())
    • Really nice name for a global
      • Often overused, and often not a real solution
      • Singletons translate well to factories
singleton example
Singleton Example
  • Singletons (or factories) welcome…
    • Renderers
    • Resource managers
    • Memory managers
    • Message queues
observer listener
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
message queues
Message Queues
  • Built of one queue with multiple listeners

Creature

Creature

Player

Player

Queue

Vs.

Items

Bullets

Items

Bullets

NPCs

mvc model view controller
MVCModel View Controller
  • Architectural pattern
    • Keeps data and representation separate
    • Model = data, view = representation
      • Controller is what sends messages to the model and view.
      • Advantages
        • One data, multiple views
        • Data manipulates data, and doesn’t care if its being viewed
        • Change renderers without changing anything else
mvc example
MVC Example
  • Separate view from everything else

CreatureRadarView

Renderer

Creature Model

Renderer

Creature

CreatureView

Vs.

3DObj

3DObj

advantages of mvc
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
other quick patterns
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 a single coherent interface
  • Proxy
    • A stand in for a concrete object.
engine improvements
Engine Improvements

AI

Renderer

Player View

Player Model

Queue

Creature View

Creature Model

3DObj

Bullet View

Bullet Model

2DObj

Item View

Item Model

IResource

File Facade

Sound

Input

File Loader

3dSnd

best practices
Best Practices
  • Management idea
    • That 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.
  • Two books:
    • Pragmatic Programmer by Andrew Hunt and David Thomas
    • C++ Coding Standards: 101 Rules, Guidelines, and Best Practices by Herb Sutter and Andrei Alexandrescu
examples of best practices
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)
best practices26

Best Practices

Are key to your survival as a coder…

… and key to your code’s survival

final thoughts
Final Thoughts
  • Know when to refactor
  • Know when to rearchitect
  • Know that both are going to break everything else
    • Code, Test, Refactor, Test Cycle
    • Try to automate this
      • Code is better at testing code than you will ever be.
summary
Summary
  • Architect for cleaner, more stable, more reusable, and more understandable code.
  • Use the principles of OOP to your advantage, not your detriment
  • Utilize design patterns to avoid common problems
  • Understand best practices and apply them.
  • Make great games.
questions

Questions?

[email protected]

http://www.jeffongames.com

ad