Firestorm Engine BrownBag Edits

20
Firestorm Engine ADVANCED GAME PROGRAMMING AND DATA-ORIENTED DESIGN

description

A presentation of my research on Game Engine Architecture

Transcript of Firestorm Engine BrownBag Edits

Page 1: Firestorm Engine BrownBag Edits

Firestorm EngineADVANCED GAME PROGRAMMING AND DATA-ORIENTED DESIGN

Page 2: Firestorm Engine BrownBag Edits

Motivation and Description of Work

What is a Game Engine?

The underlying technology of a game

Combines different libraries into a collected framework

Can be general purpose, or specific to a game.

Preferably Data-Oriented, such that non-programmers can design and edit game without having to dig into code.

What I want to gain from this project

Learn about the different choices made by Game Engine Engineers

Learn about how different systems interact to create a completed program

Page 3: Firestorm Engine BrownBag Edits

CSCI 345: Video Game Design

Made 2D games in SDL

Covered Object Oriented Programming, AI, networking, threading, physics, audio, and a little bit of art.

Definitely served its purpose as an introduction to game development. Very Comprehensive.

Many games used very “Viking code”

My term for game jam code. Essentially code not focused on elegance, just function.

Very Domain Specific

Many of the games had a specific set of levels. Expanding them to full-fledged games could only happen with great effort.

Lots of code refactoring

Page 4: Firestorm Engine BrownBag Edits

CSCI 445: Computer Graphics

Very broad covering of Computer Graphics and Computer Vision Needed to cover all aspects of how computers display graphics and look at

images.

Started with basic 3D Math

Vectors, matrices, transforms

Did some canvas programming in HTML5

Discussed differences between 3D art programs, parametric programs like OpenSCAD, and real-time programs like Unity3D

Projects varied from scripted 3D scenes to 3D games to oceanic simulations.

Not a lot of focus on real-time rendering or programming directly in a 3D stack like OpenGL or DirectX

Page 5: Firestorm Engine BrownBag Edits

Component-Entity System

A variant of the “Composite” Design Pattern

All game objects are treated as containers of components.

All components derive from a “component” interface.

Main functionality of the component interface is an update function.

All components link back to their parent Entity

Engine contains a list of all components in the scene, and loops through them every frame, calling their update function

Essentially all component subclasses are treated as components.

Page 6: Firestorm Engine BrownBag Edits

Component-Entity System

Easily Serialized

Each component has a serialize() function that outputs all public variables and any others needed to instantiate it into a textual format.

Can interact with editor via an inspector

Can be saved out to a scene file

Page 7: Firestorm Engine BrownBag Edits

Game Systems – Components for the Engine

Can also treat discrete systems as components.

Main systems are: Graphics, Input, Sound, Collision/Physics and Scripts

Can load systems independently of each other

Systems that don’t need to be linked together are kept separate

Can load a specific system for debugging

Can keep systems independent of components, if libraries are ever switched

Switching Renderers or Audio Libraries based on need

Can strip down for mobile if needed

Page 8: Firestorm Engine BrownBag Edits

Designing my own

Libraries used: OpenGL and SDL

Page 9: Firestorm Engine BrownBag Edits

Brief Summary of Real Time Computer Graphics

Before the GPU

Vector3’s or vertices are taken as points in model space

Multiplied through one or transformation matrices to get them into world space.

Vertices are mapped in groups of three to an array that holds which three vertices create a triangle

Passed into the GPU

Stage 1: Vertex Shader

All vertices pass through this function and are passed along in groups of three to the fragment shader.

Often where vertices are moved from world space to camera space, such that the camera is at 0,0,0 relative to all vertices.

Page 10: Firestorm Engine BrownBag Edits

Brief Summary of Computer Graphics

Fragment Shader

Also known as the Pixel Shader

Takes a fragment, or a triangle that’s on the screen, given by the vertex shader and processes each pixel.

Determines what color each pixel should be and outputs it to the monitor.

Bottlenecks

Amount of triangles – GPU bound

Complexity of Computations – GPU Bound

Many Objects – CPU Bound

Page 11: Firestorm Engine BrownBag Edits

My OpenGL Graphics System

What you usually have to do:

Create Data Buffers

Vertices, Triangles, Normals, Textures

Bind the buffers to the GPU

Send the data

Get the locations for shader program data

Pass in data to the shader functions

Enable the attribute arrays

Draw the vertices

Disable the attribute arrays

Bind data for the new object

Send the data

Enable the attribute arrays again

Draw the new vertices

Set the new program

Create new data buffers

Draw new arrays

Page 12: Firestorm Engine BrownBag Edits

My OpenGL Graphics System

What I want to do:

For meshes: component.update();

For the graphics system: system.update();

Much abstraction is needed.

Page 13: Firestorm Engine BrownBag Edits

Abstracting OpenGL Into Something Manageable

Transform Class – Holds locational data for an object

Has reference to its parent transform, so that objects can have children and parents

Mesh Class – Relevant mesh data

Vertices, triangles, normal

Shader Class – Compiled GPU Program

Material Class – Link to Shader and the data for the pointer like textures

Mesh Renderer Class – Points to Mesh and Material classes, actually sends data to GPU and draws it.

Page 14: Firestorm Engine BrownBag Edits

Graphics System

Engine-side system used to manage all graphical data

Holds window, context, and other GPU Specific data and pointers

Solely responsible for holding graphical settings.

Also handles any post-processing effects that affect the entire screen

All this discussion is probably boring, so let’s look at some examples!

Page 15: Firestorm Engine BrownBag Edits

Case Study: Unity 3D

Technically now just Unity 5

Lots of books, lots of games, lots of documentation. Can be ported to basically anything.

Pillars of Eternity Highlights everything good and bad about Unity

The good

Ridiculously versatile. Pillars uses a combination of pre-rendered backgrounds and 3D rendered characters to create an isometric effect.

The Bad

Poorly Optimized. Not only is the game rife with bugs, but for skeletal characters, each bone is considered a separate object, creating lots of needless overhead. When the game has to display a lot of characters, the game chugs.

Maintenance is not simple. Once the game is packaged, all assets are stored in binary files for quick access. Patching requires a rebuild, instead of patching a script or two.

Page 16: Firestorm Engine BrownBag Edits

Case Study: Unreal Engine 4

Even more Games, even more documentation, few books

Hundreds of games made by hundreds of developers.

This is the everyman’s engine for AAA developers, and has been for nearly two decades.

Source code Access via Epic Games’ Github

Essentially unlimited moddability, as long as you’re willing to modify the source code.

Not very scalable for weaker machines.

Learning Curve can be a bit high.

Page 17: Firestorm Engine BrownBag Edits

Case Study: XNA and Monogame based Engines

James Silva and John Sedlak: Building XNA 2.0 Games

Focuses on 2D

Uses modern animation ideas rather than focusing on pixel art

Focuses around building reusable tools and an editor, rather than building a specifc vertical slice of a game.

Limitations of this approach:

Scope limited game engine

Page 18: Firestorm Engine BrownBag Edits

Final Case Study: Overgrowth

A game engine and game made by David Rosen over the last 7 years(!!)

Ninja Rabbit Combat!

Extremely well-featured. Includes a complex procedural animation system, an extremely in-depth game editor, and lots of neat graphical and physics features

Used to make a couple variations of itself, a fighting game, and an action-adventure game, primarily.

Very scope-limited to its own game, although within already implemented mechanics, very versatile.

Page 19: Firestorm Engine BrownBag Edits

Conclusion of Game Engine Studies

An engine can be

Portable to different kinds of games

Well Optimized

Scalable

Useable

Pick 3. That’s what’s realistic for you to implement

Unreal Engine Unity 3D Phoenix Engine (Overgrowth)

Well OptimizedPortable to different gamesUseable

Portable to Different Kinds of GamesScalableUseable

Well OptimizedScalableUseable

Page 20: Firestorm Engine BrownBag Edits

Choices I would make Knowing what I know now

C# and Monogame, not C++

2D, not 3D

General-Purpose engines are interesting, but not practical to create

Making engines is hard