fullscreen
timer
qrcode
plickers
selector
edit
reset

Systems

COS 486 - Game Engine Architecture

slide deck credit

original slide content prepared by Roger Mailler, Ph.D., Assoc Prof of Computer Science, University of Tulsa

overview

  1. subsystem startup and shutdown
  2. memory management
  3. containers
  4. strings and localization
  5. engine configuration

systems

subsystems startup and shutdown

startup and shutdown

singleton

a common pattern for game engine components is to create managers using a singleton

class RenderManager {
    public:
    RenderManager() {
        // start up the manager
    }
    ~RenderManager() {
        // shut down the manager
    }
};

// singleton instance
static RenderManager gRenderManager;
singleton
a software design pattern that restricts the instatiation of a class to one
wikipedia ]

initialization and singleton

controlling the singleton

One trick you can use is that a static variable declared within a method is not initialized at startup

class RenderManager {
    public:
    static RenderManager& get() {
        static RenderManager sSingleton;
        return sSingleton;
    }
    RenderManager() {
        VideoManager::get();
        TextureManager::get();
    }
    ~RenderManager() {
        // shut down the manager
    }
};

This works pretty well, but you cannot control the shutdown at all

do it directly

Godot

Godot splits startup across several functions

systems

memory management

memory management

The performance of your game engine is associated not only with your algorithms but the way you use memory

dynamic allocation

stack-based allocator

stacks

double-ended stack

Another method uses a double-ended stack

pool allocator

aligned allocation

single or double frame

fragmentation

fragmentation

if you need random allocation/deallocation, you may require a defragmentation routine

defrag

defrag

cache

i-cache

taking advantage

high-performance code

systems

containers

containers

game developers use many different data structures

many of these can be found in STL (standard template library)

container operations

Containers store, retrieve, and operate on data

remember that different containers have different costs for these various operations!

iterators

void processList(std::list<int>& container) {
    std::list<int>::iterator pBegin = container.begin();
    std::list<int>::iterator pEnd   = container.end();
    std::list<int>::iterator p;
    for(p = pBegin; p != pEnd; p++) {
        int element = *p;
        // do stuff
    }
}

building custom containers

Many reasons to build your own custom containers

standard template library

Benefits

Drawbacks

rules for using STL

be aware of the performance and memory characteristics

use STLPort if you plan to create multiplatform games

note: big-Oh notation hides constant factors that could be huge! this is why we used tilde notation in COS265

boost

Boost is another library with aim to extend and work with STL

Benefits

Drawbacks

Some companies have strict development policies against using boost

Loki

Loki is a C++ library of designs, containing flexible implementations of common design patterns and idioms.

systems

strings and localization

Strings

Strings are extremely important in games

They are far from simple to manage

string classes

unique ids

Objects within the game need a way to be identified

hashed string ids

We can use hash functions to map our strings to numbers

These are sometimes referred to as string id

implementation ideas

localization

unicode

UTF-32

UTF-8

utf-16

ucs-2

char and wchar_t

Unicode on Windows

ANSI WCS MBCS
strcmp() wcscmp() _mbscmp()
strcpy() wcscpy() _mbscpy()
strlen() wcslen() _mbstrlen()

unicode on consoles

other localization concerns

id english french
p1score "Player 1 Score" "Grade Joueur 1"
p2score "Player 2 Score" "Grade Joueur 2"
p1wins "Player one wins!" "Joueur un gagne!"
p2wins "Player two wins!" "Joueur deux gange!"

final notes on localization

systems

engine configuration

engine configuration

most engines require the ability to save and load config files

many ways to do this

game vs user options

examples

×