17
Game Engine Architecture Game Engine Architecture Spring 2017 Spring 2017 0. Introduction and overview 0. Introduction and overview 0. Introduction and overview 0. Introduction and overview Juha Vihavainen Juha Vihavainen University of Helsinki University of Helsinki [Gregory, Chapter 1. [Gregory, Chapter 1. Introduction, pp. 3 Introduction, pp. 3 - 62 62 ] ] [McShaffry, Chapter 2. [McShaffry, Chapter 2. What's in a Game What's in a Game ] On classroom etiquette On classroom etiquette Please, silence your cell phone while in class. Please, silence your cell phone while in class. Please, do not take or make phone calls in class. Please, do not take or make phone calls in class. Please, do not keep up discussions among each Please, do not keep up discussions among each other during lectures other during lectures really, the lectures are voluntary and ongoing really, the lectures are voluntary and ongoing 2 discussions disturb others wishing to listen discussions disturb others wishing to listen but, of course, do ask me questions . . but, of course, do ask me questions . . 25.1.2017 25.1.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki

Juha Vihavainen University of Helsinki · PDF fileJuha Vihavainen University of Helsinki [Gregory, Chapter 1. ... LargeLarge--scale C++ techniques in a games context scale C++ techniques

  • Upload
    doantu

  • View
    219

  • Download
    1

Embed Size (px)

Citation preview

Game Engine ArchitectureGame Engine ArchitectureSpring 2017Spring 2017

0. Introduction and overview0. Introduction and overview0. Introduction and overview0. Introduction and overview

Juha VihavainenJuha Vihavainen

University of HelsinkiUniversity of Helsinki

[Gregory, Chapter 1. [Gregory, Chapter 1. Introduction, pp. 3 Introduction, pp. 3 -- 62 62 ] ]

[McShaffry, Chapter 2. [McShaffry, Chapter 2. What's in a Game What's in a Game ]]

On classroom etiquetteOn classroom etiquette

�� Please, silence your cell phone while in class.Please, silence your cell phone while in class.

�� Please, do not take or make phone calls in class.Please, do not take or make phone calls in class.

�� Please, do not keep up discussions among each Please, do not keep up discussions among each other during lecturesother during lectures

�� really, the lectures are voluntary and ongoing really, the lectures are voluntary and ongoing

22

�� really, the lectures are voluntary and ongoing really, the lectures are voluntary and ongoing discussions disturb others wishing to listendiscussions disturb others wishing to listen

�� but, of course, do ask me questions . .but, of course, do ask me questions . .

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

Preliminary course outlinePreliminary course outline

�� Game engine subsystems and its general architecture Game engine subsystems and its general architecture

�� LargeLarge--scale C++ techniques in a games contextscale C++ techniques in a games context

�� C++11/14 features (for "modern" C++ programming)C++11/14 features (for "modern" C++ programming)

�� essential C++ programming techniquesessential C++ programming techniques

�� logical modularity (concepts) vs. physical modularity (files)logical modularity (concepts) vs. physical modularity (files)

�� on programming standards and C++ style ruleson programming standards and C++ style rules

�� Simplified engine and component cases Simplified engine and component cases

33

�� Simplified engine and component cases Simplified engine and component cases

�� Miscellanous game technology, tools, and techniquesMiscellanous game technology, tools, and techniques

�� Game engine subsystems: rendering, physics, audio, scripting..Game engine subsystems: rendering, physics, audio, scripting..

�� . . .. . .

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

Course prerequisitesCourse prerequisites�� General maturity in programmingGeneral maturity in programming

�� objectobject--oriented concepts, data structures, etc.oriented concepts, data structures, etc.

�� use of programming environments, and programming use of programming environments, and programming experience.. experience..

�� Some knowledge of C++ is requiredSome knowledge of C++ is required

�� Software Design Software Design C++ (2014), or similar skills..C++ (2014), or similar skills..

�� useruser--defined types, and basic OO idioms and patternsdefined types, and basic OO idioms and patterns

�� how to use pointers and manage memory in C/C++how to use pointers and manage memory in C/C++

44

�� how to use pointers and manage memory in C/C++how to use pointers and manage memory in C/C++

�� some material on C++ will be given in the lecture notessome material on C++ will be given in the lecture notes

�� Some knowledge on graphics programming is beneficial as Some knowledge on graphics programming is beneficial as background and motivation, and for optional future projectsbackground and motivation, and for optional future projects

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

The course The course textbooktextbooktextbooktextbook

25.1.201725.1.2017 55

Topics of GEA book includeTopics of GEA book include

�� largelarge--scale C++ software architecture in a games contextscale C++ software architecture in a games context

�� mathematics for game programmingmathematics for game programmingmathematics for game programmingmathematics for game programming

�� game development tools for debugging, source control and game development tools for debugging, source control and profilingprofiling

�� engine subsystems including engine foundation systems, engine subsystems including engine foundation systems, rendering, sound, collision, physics, character animation rendering, sound, collision, physics, character animation and game world object modelsand game world object models

multiplatform game enginesmultiplatform game engines�� multiplatform game enginesmultiplatform game engines

�� game programming in multiprocessor environmentsgame programming in multiprocessor environments

�� tools pipelines for game asset managementtools pipelines for game asset management

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 66

Jason Gregory: Jason Gregory: Game Engine Architecture Game Engine Architecture (2. ed., 2014)(2. ed., 2014)

Ch. 1 Ch. 1 IntroductionIntroduction

�� what is a game/game engine/cases..what is a game/game engine/cases..

Ch. 2 Ch. 2 Tools of the tradeTools of the trade

Ch. 9 Ch. 9 Tools for debugging and developmTools for debugging and developm. .

�� logging, tracing, debugging, cheats..logging, tracing, debugging, cheats..

Ch. 10 Ch. 10 Rendering engineRendering engineCh. 2 Ch. 2 Tools of the tradeTools of the trade

�� prog. envs, Visual Studio., version prog. envs, Visual Studio., version control, profiling, leak detection, etc.control, profiling, leak detection, etc.

Ch. 3 Ch. 3 Fundamentals of SE for gamesFundamentals of SE for games

�� C++ techniques and practicesC++ techniques and practices

Ch. 4 Ch. 4 3D math for games3D math for games

�� points, vectors, matrices, quaternions..points, vectors, matrices, quaternions..

Ch. 5 Ch. 5 Engine support systemsEngine support systems

�� memory, strings, startmemory, strings, start--up, configs.. up, configs..

Ch. 10 Ch. 10 Rendering engineRendering engine

�� the rendering pipeline, visual effectsthe rendering pipeline, visual effects

Ch. 11 Ch. 11 Animation systemsAnimation systems

�� skeletons, poses, skinning..skeletons, poses, skinning..

Ch. 12 Ch. 12 Collision and rigid body dynamicsCollision and rigid body dynamics

�� physics, collision detection, etc.physics, collision detection, etc.

Ch. 13 Ch. 13 AudioAudio (new in 2nd. edition)(new in 2nd. edition)

Ch. 14 Ch. 14 Introduction to gameplay systemsIntroduction to gameplay systems�� memory, strings, startmemory, strings, start--up, configs.. up, configs..

Ch. 6 Ch. 6 Resources and the file systemResources and the file system

Ch. 7 Ch. 7 Game loop and simulationGame loop and simulation

�� main loop, and dealing with time..main loop, and dealing with time..

Ch. 8 Ch. 8 Human interface devices Human interface devices (HID)(HID)

�� implementing game objects/worldsimplementing game objects/worlds

Ch. 15 Ch. 15 RunRun--time gameplay foundationstime gameplay foundations

�� object model architecturesobject model architectures

�� events and message passingevents and message passing

�� scripting, loading worlds..scripting, loading worlds..

Ch. 16 Ch. 16 There's moreThere's more??

Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 7725.1.201725.1.2017

Related teaching Related teaching in our departmentin our department

�� Introduction to Game ProgrammingIntroduction to Game Programming (Autumn 2016, 2017, 2nd period)(Autumn 2016, 2017, 2nd period)

�� Game Engine Architecture Game Engine Architecture (this course, now: 2017, 3rd period)(this course, now: 2017, 3rd period)

�� serves as "serves as "Game programming Game programming II"II"

�� requires/teaches programming skills in C/C++ requires/teaches programming skills in C/C++

�� TietokonegrafiikkaTietokonegrafiikka (Spring 2017, 4th period, Otto Nurmi)(Spring 2017, 4th period, Otto Nurmi)

�� computer graphics: rasterisation, shading, texturing..computer graphics: rasterisation, shading, texturing..

�� based on based on OpenGLOpenGL graphics library graphics library

�� Game Project Game Project course course (Spring 2017, 4th period)(Spring 2017, 4th period)

an optional project for IGP and GEA coursesan optional project for IGP and GEA courses�� an optional project for IGP and GEA coursesan optional project for IGP and GEA courses

�� Compiler design Compiler design & & Code generation Code generation courses (Spring 2018)courses (Spring 2018)

�� for understanding script languages and their implementation; for understanding script languages and their implementation; include practical implementation projects (interpreter, compiler)include practical implementation projects (interpreter, compiler)

Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 8825.1.201725.1.2017

Using C++ in game engine programmingUsing C++ in game engine programming

�� C++ is widely used in the game industry: "C++ is widely used in the game industry: "industrialindustrial--strength 3D strength 3D game engines are written primarily in C or C++, and any serious game engines are written primarily in C or C++, and any serious game programmer needs to know C++game programmer needs to know C++" [Gregory, p." [Gregory, p.XXIIXXII ]]

Games are complex applications to buildGames are complex applications to build�� Games are complex applications to buildGames are complex applications to build

�� multiple interactions within the program multiple interactions within the program

�� need to use visual, audio, and other resources and file formatsneed to use visual, audio, and other resources and file formats

�� interfacing with OS/hardware components/3rdinterfacing with OS/hardware components/3rd--party libsparty libs

�� Graphics libraries require programming knowledge of C/C++Graphics libraries require programming knowledge of C/C++

99

�� At least, rendering and scripting engines (VM) are written in C++At least, rendering and scripting engines (VM) are written in C++

�� Most C++ programming features and techniques are relevant for Most C++ programming features and techniques are relevant for game engine development(?)game engine development(?)

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

XNA XNA Game Studio / Game Studio / MonoGame MonoGame : a "graphic engine" : a "graphic engine"

A sample game framework and A sample game framework and scripting system (C#)scripting system (C#)

2D/3D games with a game engine2D/3D games with a game engine2D/3D games with a game engine2D/3D games with a game engine

�� predefined game skeleton, predefined game skeleton, components, and 2D spritescomponents, and 2D sprites

�� the engine provides support for the engine provides support for 2D images, IO, and audio2D images, IO, and audio

�� 3D scene is rendered on 2D 3D scene is rendered on 2D screen: needs to use the graphics screen: needs to use the graphics screen: needs to use the graphics screen: needs to use the graphics pipelinepipeline

�� set camera and view frustumset camera and view frustum

�� using 3D models, and shaders using 3D models, and shaders (GPU programs)(GPU programs)

101025.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

XNA Game Studio: a "graphic engine" XNA Game Studio: a "graphic engine" �� Free tool/libraries for creating 2D and 3D gamesFree tool/libraries for creating 2D and 3D games

�� Used Used C# C# as the scripting language (an interesting choice..)as the scripting language (an interesting choice..)

�� Integrated with Visual Studio C#Integrated with Visual Studio C#

�� use use Visual Studio 2010 Visual Studio 2010 for for XNA version 4 XNA version 4 (September 2010) (September 2010) --�� use use Visual Studio 2010 Visual Studio 2010 for for XNA version 4 XNA version 4 (September 2010) (September 2010) --either Express or Full version either Express or Full version

�� Hardware requirements are identical to Microsoft Visual StudioHardware requirements are identical to Microsoft Visual Studio

�� Games could be run on Windows freeGames could be run on Windows free

�� or on Xbox 360 but did require arrangements/costsor on Xbox 360 but did require arrangements/costs

�� But But

not as powerful as many other game engines (physics, GO model)not as powerful as many other game engines (physics, GO model)�� not as powerful as many other game engines (physics, GO model)not as powerful as many other game engines (physics, GO model)

�� was it really easy was it really easy -- required C# knowhow..required C# knowhow..

�� Engines were build on the XNA design, e.g., Engines were build on the XNA design, e.g., MonoGameMonoGame

�� Unity killed XNA ??Unity killed XNA ??

111125.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

XNA code sampleXNA code samplepublic class Game1 : Microsoft.Xna.Framework.Game {public class Game1 : Microsoft.Xna.Framework.Game {

GraphicsDeviceManager graphics;GraphicsDeviceManager graphics;

public Matrix public Matrix CameraViewCameraView { get; set; }{ get; set; }

public Matrix public Matrix CameraProjection CameraProjection { get; set; }{ get; set; }

public Vector3 public Vector3 CameraPositionCameraPosition ; . . .; . . .

public Game1 () {public Game1 () {

graphics = new GraphicsDeviceManager (this);graphics = new GraphicsDeviceManager (this);

Content.RootDirectory = "Content";Content.RootDirectory = "Content";

rotating 3D objects & moving camera rotating 3D objects & moving camera

Content.RootDirectory = "Content";Content.RootDirectory = "Content";

}}

protected override void protected override void InitializeInitialize () {() {

CameraPosition CameraPosition = new Vector3 (0.0f, 0.0f, 5000.0f); . . = new Vector3 (0.0f, 0.0f, 5000.0f); . .

CameraProjection CameraProjection ==

Matrix.CreatePerspectiveFieldOfView (Matrix.CreatePerspectiveFieldOfView (

MathHelper.ToRadians (45.0f), AspectRatio, MathHelper.ToRadians (45.0f), AspectRatio,

1.0f, float.MaxValue);1.0f, float.MaxValue);

new Ship {new Ship {

Position = new Vector3 (2000, 500, 50), Position = new Vector3 (2000, 500, 50),

Rotation = MathHelper.ToRadians (40f),Rotation = MathHelper.ToRadians (40f),

Scale = .75f }; . . .Scale = .75f }; . . .

base.Initialize ();base.Initialize ();

}}

protected override void protected override void UpdateUpdate ((GameTime gameTimeGameTime gameTime) {) {

if (Keyboard.GetState ().IsKeyDown (Keys.Up))if (Keyboard.GetState ().IsKeyDown (Keys.Up))

CameraPositionCameraPosition.Y += .Y +=

(float)gameTime.ElapsedGameTime.TotalMilliseconds * 5;(float)gameTime.ElapsedGameTime.TotalMilliseconds * 5;

. . .. . .

base.Update (gameTime);base.Update (gameTime);

} . . .} . . .

}} 121225.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

What is a What is a gamegame??

�� A "A " gamegame" is an interactive experience that provides the player with an " is an interactive experience that provides the player with an increasingly challenging sequence of patterns which he or she learns increasingly challenging sequence of patterns which he or she learns and eventually masters and eventually masters (Gregory quoting (Gregory quoting Koster, Koster, A Theory of Fun for A Theory of Fun for Game DesignGame Design, , 2004 [26]2004 [26]))Game DesignGame Design, , 2004 [26]2004 [26]))

�� Gregory: "Gregory: "a game is aa game is asoft realsoft real--timetime interactive interactive agentagent--basedbased computer computer simulationsimulation""

�� agentagent = = any game entity, very often implemented as an object in any game entity, very often implemented as an object in an objectan object--oriented programming languageoriented programming language

�� The The GEA textbook GEA textbook [Gregory] focuses on the implementation of a [Gregory] focuses on the implementation of a subset of games that comprise twosubset of games that comprise two-- and threeand three--dimensional virtual dimensional virtual subset of games that comprise twosubset of games that comprise two-- and threeand three--dimensional virtual dimensional virtual worlds with a small number of players (say, between 1worlds with a small number of players (say, between 1--16): 16):

�� primary focus will be on game engines capable of producing firstprimary focus will be on game engines capable of producing first--person shooters, thirdperson shooters, third--person action/platform games, racing games, person action/platform games, racing games, fighting games, and the likefighting games, and the like

1313

What is a What is a game enginegame engine??

�� The The game engine game engine term arose about the midterm arose about the mid--1990s 1990s

�� Doom Doom byby id Software id Software was a FPS architected with a wellwas a FPS architected with a well--defined defined separation between its (1) core software components (the rendering separation between its (1) core software components (the rendering system, the collision detection, the audio, etc.) and (2) the art assets, system, the collision detection, the audio, etc.) and (2) the art assets, system, the collision detection, the audio, etc.) and (2) the art assets, system, the collision detection, the audio, etc.) and (2) the art assets, game worlds, and rules of play game worlds, and rules of play

�� Developers began licensing games and remaking them into new Developers began licensing games and remaking them into new products by creating new art, world layouts, weapons, characters, products by creating new art, world layouts, weapons, characters, vehicles, and game rules with only minimal changes to the "engine" vehicles, and game rules with only minimal changes to the "engine" softwaresoftware

�� ThusThus, game engines provide a selected set of core components, , game engines provide a selected set of core components, including the rendering engine, the collision and physics engine, the including the rendering engine, the collision and physics engine, the animation system, the audio system, the game world object model, animation system, the audio system, the game world object model, the artificial intelligence system, etc.the artificial intelligence system, etc.

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1414

What is a What is a game enginegame engine? (cont.)? (cont.)

�� A "game engine" should be designed to be extensible and to be used as A "game engine" should be designed to be extensible and to be used as the foundation for many different games without major modification the foundation for many different games without major modification

�� a game containing harda game containing hard--coded logic, or any specialcoded logic, or any special--case code case code becomes difficult or impossible to reuse to make a different gamebecomes difficult or impossible to reuse to make a different gamebecomes difficult or impossible to reuse to make a different gamebecomes difficult or impossible to reuse to make a different game

�� Especially, a Especially, a datadata--drivendriven architecturearchitecture can separate a game engine can separate a game engine from a piece of software that is a game but not an engine; from a piece of software that is a game but not an engine; one definition for "dataone definition for "data--driven":driven":

�� all game contents & logic are driven by external data sourcesall game contents & logic are driven by external data sources

Note that there is also a separation between logical and physical Note that there is also a separation between logical and physical �� Note that there is also a separation between logical and physical Note that there is also a separation between logical and physical software architecture: the inheritance/component hierarchy software architecture: the inheritance/component hierarchy vsvs. the . the source and binary file structure (very relevant for C/C++ programs)source and binary file structure (very relevant for C/C++ programs)

�� Within each game component, a number of semiWithin each game component, a number of semi--standard design standard design alternatives are emerging (we can hope..)alternatives are emerging (we can hope..)

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1515

What is a What is a game enginegame engine? (cont.)? (cont.)�� Originally, game engines were designed to run a particularOriginally, game engines were designed to run a particular--style game style game

(of a given "(of a given "genregenre") on a particular hardware platform") on a particular hardware platform

�� Now game engines are trying to support multiple Now game engines are trying to support multiple platformsplatforms, e.g., , e.g., UnrealUnreal: : Windows, Xbox 360, PlayStation 3, Mac OS X, Wii U, iOS, Windows, Xbox 360, PlayStation 3, Mac OS X, Wii U, iOS, UnrealUnreal: : Windows, Xbox 360, PlayStation 3, Mac OS X, Wii U, iOS, Windows, Xbox 360, PlayStation 3, Mac OS X, Wii U, iOS, Android..Android..

�� The more generalThe more general--purpose a game component is, the less optimal it purpose a game component is, the less optimal it may be for a particular game on a particular platformmay be for a particular game on a particular platform

�� as usual, optimal efficiency may require customization and tradeas usual, optimal efficiency may require customization and trade--offs (offs (bindingsbindings) based on assumptions about target hardware) based on assumptions about target hardware

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 1616

...

The main components of a game engineThe main components of a game engine

�� Scene graphs Scene graphs (i.e., a hierarchical spatial representation of a (i.e., a hierarchical spatial representation of a graphical scene/level)graphical scene/level)

�� may well need multiple different versions depending on may well need multiple different versions depending on �� may well need multiple different versions depending on may well need multiple different versions depending on level characteristics (outdoors, dungeon, or whatever)level characteristics (outdoors, dungeon, or whatever)

�� A A rendering engine rendering engine for 2D and/or 3D graphicsfor 2D and/or 3D graphics

�� A A physics engine physics engine for morefor more--oror--less realistic world simulation less realistic world simulation and collision detection (strongly interrelated and used together)and collision detection (strongly interrelated and used together)

�� Sound and musicSound and music

1717

�� Sound and musicSound and music

�� CharacterCharacter animationanimation

�� Artificial intelligence Artificial intelligence

�� ScriptingScripting

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

These may also be realized as kind of subengines

Game engine (pros and cons)Game engine (pros and cons)Benefits Benefits (mostly the same as general ones for software reuse)(mostly the same as general ones for software reuse)�� provides simplified access to underlying technologies provides simplified access to underlying technologies

�� organizes and speeds up development processorganizes and speeds up development process

�� reusing the same game engine (software) to create multiple reusing the same game engine (software) to create multiple �� reusing the same game engine (software) to create multiple reusing the same game engine (software) to create multiple different games different games

�� less testing and debuggingless testing and debugging

�� many features directly availablemany features directly available

�� better focus on the game design aspectsbetter focus on the game design aspects

�� enables the game to run on multiple platforms (consoles, enables the game to run on multiple platforms (consoles, operating systems) operating systems)

1818

operating systems) operating systems)

Drawbacks Drawbacks (potential costs and complexity)(potential costs and complexity)�� dependencies on the quality of design, available features, dependencies on the quality of design, available features,

implementation decisions, licensing schemes, thirdimplementation decisions, licensing schemes, third--party librariesparty libraries

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

Other general game engine tasksOther general game engine tasks

�� InitializationInitialization: linking/using multiple different APIs and libraries: linking/using multiple different APIs and libraries

�� Managing the Managing the game loop game loop and real/simulation time (and real/simulation time (system clocksystem clock))

�� Reading input Reading input (and giving it meaning for game control/mechanics)(and giving it meaning for game control/mechanics)

�� Managing memory, and string/name managementManaging memory, and string/name management

�� File systems, and resource caching File systems, and resource caching (make resources available (make resources available -- but but hide, e.g., level loading; prefetch for speed optimization)hide, e.g., level loading; prefetch for speed optimization)

�� Dynamically loaded libraries Dynamically loaded libraries (DLLs), e.g., to delay loading or (DLLs), e.g., to delay loading or to replace renderer engine or some other subsystem or subengineto replace renderer engine or some other subsystem or subengine

ThreadsThreads and thread synchronizationand thread synchronization

1919

�� ThreadsThreads and thread synchronizationand thread synchronization

�� parallel execution: multiparallel execution: multi--core, GPU, physics card (?)core, GPU, physics card (?)

�� NetworkNetwork communicationcommunication

�� ShutdownShutdown

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

Game engine API

Your game

Hardware abstraction layer – DirectX, OpenGL, …

Graphicsengine

Soundengine

Physicsengine

AIengine

Scriptingengine. . .

2020

Hardware layer - sound card, graphics card (physics card?)

For a bit more detailed architecture, see the following slides [Gregory, p. 33] .25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

There are hundreds of game engines, e.g.:There are hundreds of game engines, e.g.:

�� Unreal Engine Unreal Engine 44 (free for making free games, otherwise royalties) (free for making free games, otherwise royalties)

�� Unity Unity 5 5 (free/professional versions)(free/professional versions)

�� CryENGINECryENGINE also also free for nonfree for non--commercial use..commercial use..

OGREOGRE graphics engine (open source)graphics engine (open source)�� OGREOGRE graphics engine (open source)graphics engine (open source)

�� BlenderBlender game engine (completely free)game engine (completely free)

�� Check out online sources (Check out online sources (http://www.devmaster.net/engines/http://www.devmaster.net/engines/))

�� Why so many graphic APIs & game engines?Why so many graphic APIs & game engines?

�� possibly for differing target applications and requirementspossibly for differing target applications and requirements�� realreal--time vs. nontime vs. non--realreal--time applicationstime applications

2121

�� realreal--time vs. nontime vs. non--realreal--time applicationstime applications�� provide application specific optimizationsprovide application specific optimizations�� provide genreprovide genre--specific game entities and functionalityspecific game entities and functionality

�� provide custom provide custom platformplatform optimizations and dependenciesoptimizations and dependencies�� open source vs. open source vs. manufacturermanufacturer--specific specific APIsAPIs

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

Game engine Game engine architecture by architecture by [Gregory, p. 33] [Gregory, p. 33] (sorry, it (sorry, it isis bigbig))

A simplified GE architecture A simplified GE architecture ((Antti Hietasaari, 2016)Antti Hietasaari, 2016)

(Game-specific subsystems)

(Game-engine subsystems)

(Game-engine core systems)

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2323

(Utility subsystems)

(Resource files)

(mem. mgt, testing, math, strings, platform independence,

3rd-patry llibraries)

GameplayGameplay foundation systemsfoundation systems

�� Provide the (most direct) support for implementing the game logic Provide the (most direct) support for implementing the game logic

�� ""GameplayGameplay" = the rules of a game world, the abilities/properties of " = the rules of a game world, the abilities/properties of

(Parent/child model)

�� ""GameplayGameplay" = the rules of a game world, the abilities/properties of " = the rules of a game world, the abilities/properties of the player and other entities in the world, and goals and objectivesthe player and other entities in the world, and goals and objectives

�� Related "Related "software object modelsoftware object model" = the specific way to " = the specific way to implementimplement this this engine: what language? use inheritance/components/templates? how engine: what language? use inheritance/components/templates? how to refer/identify entities (to refer/identify entities (GUIDGUID), create, update, and destroy objects..), create, update, and destroy objects..

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2424

Scripting engines in game programsScripting engines in game programs�� Potential advantages Potential advantages ((depending on the scripting languagedepending on the scripting language))::

�� a convenient higha convenient high--level language to level language to control a gamecontrol a game

�� strongly promotes "strongly promotes "datadata--driven designdriven design": a ": a game engine should not game engine should not contain any gamecontain any game--specific codespecific code

�� can change the game rules/behaviour while the game is runningcan change the game rules/behaviour while the game is running

�� can provide state machines, configuration, and option set up..can provide state machines, configuration, and option set up..

�� A script can provide parameters and actions for a gameA script can provide parameters and actions for a game

�� data parameters: timedata parameters: time--ofof--day => determine overall lighting etc., day => determine overall lighting etc., object mass/friction, game options, AI goals and objectivesobject mass/friction, game options, AI goals and objectives

�� behavior: set lights, move objects, select path, calculate decisions behavior: set lights, move objects, select path, calculate decisions

2525

�� behavior: set lights, move objects, select path, calculate decisions behavior: set lights, move objects, select path, calculate decisions (e.g., state machines in script)(e.g., state machines in script)

�� ProblemsProblems: how to bind scripts to game logic and objects? performance? : how to bind scripts to game logic and objects? performance? custom languages may lack mature custom languages may lack mature developmentdevelopment supportsupport tools (IDEs); tools (IDEs); we may have learning curve for (yet another) new languagewe may have learning curve for (yet another) new language

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

GameGame--specific subspecific subsystemsystemss�� On top of the gameplay foundation and the other lowOn top of the gameplay foundation and the other low--level level

components, we implement the components, we implement the actual game actual game itselfitself

�� Typical game entities includeTypical game entities include

�� static background geometry (buildings, roads, terrain), rigid static background geometry (buildings, roads, terrain), rigid �� static background geometry (buildings, roads, terrain), rigid static background geometry (buildings, roads, terrain), rigid bodies (rocks, cans, chairs), player & nonbodies (rocks, cans, chairs), player & non--player characters, player characters, weapons, powerweapons, power--ups, projectiles, vehicles, lights (dynamic/ ups, projectiles, vehicles, lights (dynamic/ static), gamestatic), game--tailored camerastailored cameras

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2626

Tools and the Tools and the asset pipelineasset pipeline�� 3D modeling tools use very complex 3D modeling tools use very complex internalinternal data formats are rarely data formats are rarely

suitable for direct use in game softwaresuitable for direct use in game software

�� they support, e.g., full hierarchy of 3D transformations (position, they support, e.g., full hierarchy of 3D transformations (position, orientation, scale, shear), interconnections as a directed acyclic orientation, scale, shear), interconnections as a directed acyclic graph (DAG) of scene nodes, edit history (for undo/redo)graph (DAG) of scene nodes, edit history (for undo/redo)graph (DAG) of scene nodes, edit history (for undo/redo)graph (DAG) of scene nodes, edit history (for undo/redo)

�� are often too slow to read at game run time are often too slow to read at game run time

�� in some cases use a closed proprietary custom formatin some cases use a closed proprietary custom format

�� A game engine typically only needs a tiny fraction of all such A game engine typically only needs a tiny fraction of all such information in order to render the model ininformation in order to render the model in--game; a 2game; a 2--way process:way process:

1.1. Data produced by a tool is first Data produced by a tool is first exportedexported to a more accessible to a more accessible standardized format, or another custom file format standardized format, or another custom file format

2.2. Exported data is further processed before being sent to the Exported data is further processed before being sent to the game engine game engine -- possibly differently for each target platform possibly differently for each target platform

�� Each engine needs such an Each engine needs such an aasset conditioning pipeline sset conditioning pipeline of its ownof its own

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2727

[Gregory, Fig.1.35, p.55]

direct data flow

dependencies, use

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 2828Tools and the asset pipeline.

Approaches to tool architecture (in different engines)Approaches to tool architecture (in different engines)

1. 2.

1.1. Standalone tools architectureStandalone tools architecture3.

1.1. Standalone tools architectureStandalone tools architecture

2.2. Tools share a framework with Tools share a framework with gamesgames

3.3. Unreal EngineUnreal Engine's tool architecture's tool architecture

2929[Gregory, Fig.1.36-8, p.60-61]

Applying "modelApplying "model--view" architecture for gamesview" architecture for games

�� ModelModel--viewview architecture (a MVC variant, here V includes C)architecture (a MVC variant, here V includes C)

�� separate content (data = "model") from view & input processingseparate content (data = "model") from view & input processing

�� use the proven "standard" solution for GUI systemsuse the proven "standard" solution for GUI systemsuse the proven "standard" solution for GUI systemsuse the proven "standard" solution for GUI systems

�� Goals and principles for game programmingGoals and principles for game programming

�� provide multiple views on the same shared data (game state)provide multiple views on the same shared data (game state)

�� loose coupling between parts: loose coupling between parts: update events update events are used for notification are used for notification of changesof changes

�� human players, AI agents, network views can be uniformly treatedhuman players, AI agents, network views can be uniformly treated

an event system can provide centralized debugging/logging etc.an event system can provide centralized debugging/logging etc.

3030

�� an event system can provide centralized debugging/logging etc.an event system can provide centralized debugging/logging etc.

�� Implementation may not be so simple Implementation may not be so simple

�� need to provide a general message system (using need to provide a general message system (using callbackcallbacks, or s, or applying the applying the Observer Observer design pattern)design pattern)

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

"Ideal model"Ideal model--view" game architecture (sketch)view" game architecture (sketch)

Game logic

Game view. . .

Game view (Human)

easy to add/replace views; provide symmetric handling of game views

Game logicstate & data

physics, eventscommand interpreter

Game view (Human) display, audioinput handling

Application support layer

Game view (AI agent)stimulus interpreter

decision system

game state &commandsgame world simulation

3131

Application support layer

Devices:input, files RAM, time

OS: PLs, DLLthreads

networking

Game lifetime:core libs, main

loop, init&shutdown

Modified from [McShaffry, 2013]

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

Example data flow in modelExample data flow in model--view systemview system

�� The The support layersupport layer gets lowgets low--level input from physical devices and level input from physical devices and creates input events/commandscreates input events/commands

�� the interpreter of the the interpreter of the human viewhuman viewtransforms input to general transforms input to general game events/commands game events/commands game events/commands game events/commands

�� The interpreter of the The interpreter of the game logicgame logicreceives messages and updates the receives messages and updates the state of the game accordinglystate of the game accordingly

�� can handle can handle uniformlyuniformly messages messages fromfrom all the views: input system, all the views: input system, AI agents, the scripting engine, a playback file, or network AI agents, the scripting engine, a playback file, or network connectionsconnections

3232

�� can also allow user commands from a screen can also allow user commands from a screen command console command console (txt commands using a script engine, or a custom AST interpreter)(txt commands using a script engine, or a custom AST interpreter)

�� sends notifications to separatesends notifications to separate viewsviewsto be processed locally (or to be processed locally (or possibly to be forwarded)possibly to be forwarded)

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki

SummarySummary�� Computer games are a very specialized application areaComputer games are a very specialized application area

�� can be small (casual games), or very complicated commercialcan be small (casual games), or very complicated commercial--quality interactive 3D realquality interactive 3D real--time simulation systemstime simulation systems

Game engines provide the foundation on which to build new game Game engines provide the foundation on which to build new game �� Game engines provide the foundation on which to build new game Game engines provide the foundation on which to build new game programs (very similarly to programs (very similarly to applications frameworksapplications frameworks))

�� provide concepts/models for a game world and its entitiesprovide concepts/models for a game world and its entities

�� reuse libraries and components (also managing and hiding new reuse libraries and components (also managing and hiding new versions of libraries and updating for such versions)versions of libraries and updating for such versions)

�� reuse design ideas and experiencereuse design ideas and experience

�� Some problems are by nature general and can (possibly) be solved by Some problems are by nature general and can (possibly) be solved by standard software practices (style rules, testing, patterns,..)standard software practices (style rules, testing, patterns,..)

�� Hopefully, also some gameHopefully, also some game--specific techniques and ideas can be specific techniques and ideas can be identified and used as working solutionsidentified and used as working solutions

25.1.201725.1.2017 Juha Vihavainen / University of HelsinkiJuha Vihavainen / University of Helsinki 3333