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

Post on 05-Jan-2016

222 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

GAM 200 Club

How to Game EngineGAM 200 ClubZachary 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

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

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

Now to build our Engine

I build from small to large

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

Engine / Game Space / Game Object

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

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

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

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

We have now achieved our desired structure

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

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

Making Objects in C++

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

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

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?

Step 9: Back to the Engine Core

Implement those engine functions!• AddSystems• Initialize• Loop

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

Step 9.2: Init

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

Iterate through each System in array of SystemsCall Init function

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

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

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

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

top related