gam 200 club. how to game engine gam 200 club zachary nawar

34
GAM 200 Club

Upload: lorin-shaw

Post on 05-Jan-2016

222 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

GAM 200 Club

Page 2: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

How to Game EngineGAM 200 ClubZachary Nawar

Page 3: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

DISCLAIMERThere are many methods and ways of going

about and creating a Game Engine, this is a very simple yet useful method for starting to build

your engine

Page 4: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 1: Object Architecture

Inheritance based VS Component based• Very generic base

object• Each object inherits• Tons of abstract objects• Simple and easy• UE3 is a great example

• One object class• Components add

logic• Faster iteration• More complicated to

do

Page 5: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar
Page 6: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar
Page 7: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 2: Object Management

Decide on what method to use for object management:

> Single Game SpaceEach object exists in the same “space” or

collection of objects> Multiple Game Spaces

Multiple “spaces” which contain their own sets of objects

Page 8: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Now to build our Engine

I build from small to large

Page 9: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

When declaring and defining your functions imagine what you want the end user (Your team) to experience when

they try to do things in your engine

Page 10: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Engine / Game Space / Game Object

Page 11: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 3: The (Base) Component

Base Component has very basic stuff!• Constructor / Destructor• Initialize / Update / Remove functions• ptr to the owning Space (optional)• ptr to the owning Object• TypeID (enum, int, const char*, you choose!)

Keep it simple, clean, and virtualReal components inherit from this

Page 12: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar
Page 13: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 4: The Game Object

What put inside?• Constructor / Destructor• Initialize / AddComponent / GetComponent /

Update / Remove functions• Array of Component pointers• Global ID (?)• More complicated things*

• Object Parenting info• Archetype names

Page 14: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar
Page 15: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 5: The Game Space

Think of it as an object manager• Constructor / Destructor• Update function• Array of Objects pointers• Other helper functions

• Cleanup, Clear, AddObject

Page 16: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar
Page 17: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 6: The Engine Core

• The core of your entire engine• Home to your Init, AddSystem, Loop, Shutdown

• No need to implement these just yet• Stores all of your Game Spaces

• Array of pre-allocated spaces?• Array of pointers?

• Pointer to additional Systems• Make a global pointer to your Core

Page 18: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar
Page 19: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

We have now achieved our desired structure

Page 20: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 7: The “Object Factory”

We need a way to make Objects!• Our “Object Factory” does exactly this• Could be a class full of static functions

• Just have the first parameter take a GameSpace*

• CreateObject()• Allocates space for an object• Adds object to game space• Returns the new object

Page 21: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 7.1: Serialization

The Factory is a great place to load objects

• Allocate object• Load file• File says what components to add to object• File says what to set variables in components to• Add object to game space• Return the object (No need to really)

Data driven! yay!CS225 should cover JSON serialization

• Also could be covered in future presentation

Page 22: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Making Objects in C++

Page 23: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 8: Engine Systems

Currently all we have is an object engineWe should add features to our engine!

• Graphics, Physics, Audio, GameLogicI call these “Systems” or “Modules”

• Expand and provide functionality to the engine

• Makes our Game Engine capable of running games

Page 24: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 8.1: Base Engine System

This is the base/generic system• Constructor / Destructor• Init / Update / Shutdown functions• Name (optional)

Remember to keep it virtualEvery system we add (Graphics, Physics…) inherits from this basic system

Page 25: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar
Page 26: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 8 Example

Graphics SystemSetTransform(MATRIX33 m) // Sets matrix to use when drawingSetDrawMode(DMODE_ENUM dm) // Sets draw modeSetTexture(D3DTexture tex) // Sets the texture to drawDrawSprite() // Draws a sprite using transform, drawmode, textureStartFrame() // Starts a frameEndFrame() // Ends the current frame, swaps buffersUpdate() // Iterate through spaces/objects/components call Draw if

we can?

Page 27: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 9: Back to the Engine Core

Implement those engine functions!• AddSystems• Initialize• Loop

Page 28: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 9.1: AddSystem

void Core::AddSystem(ISystem* sys)Responsible for adding a system pointer into the Engine Core list of systems

Push pointer into back of system pointer array/vector

Page 29: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 9.2: Init

void Core::Init(void)Responsible for Initializing all engine systems

Iterate through each System in array of SystemsCall Init function

Page 30: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Step 9.3: Loop / MainLoop / Updatevoid Core::Loop(void)Responsible for keeping the game running, the game loop● While RUNNING

○ If Framerate controller says go■Iterate through systems in systems list

●Call Update function

Page 31: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Something that’s missing: GameLogic

GameLogic can/should be a system too• Iterates through all game spaces

• Update Game Space• Iterate through all Objects

• Update Object• Iterate through all Components

• Update Component

This method is simple and works

Page 32: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar
Page 33: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Invoking our Engine

1. Create Engine Core2. Create and add engine systems3. Initialize Engine Core4. Load a game level or something5. Call Loop function6. Call Shutdown function7. Exit program

Page 34: GAM 200 Club. How to Game Engine GAM 200 Club Zachary Nawar

Things to work on next:

• Handle manager• Messaging (Hooks, Events, ect.)• Cache friendly memory management• Archetypes• Saving and Loading levels• Introspection and Serialization• Scripting languages