
Valentin Galea - @valentin_galea
more than 10 years doing mobile, indie and AAA games
Currently at Splash Damage in London, UK
Mostly about AAA games…
Indie games
Mobile games
Scripting languages…
Tools
Building / Packaging game data
For various reasons, AAA development is covered in secrecy, source code included
Some of these reasons…
id software notably broke the trend and released the source code of all their Doom and Quake games
The rest of the industry didn’t follow suit. Even id stopped after being acquired by the publisher Bethesda
Some modern AAA game engines changed their licensing and they’re now open…
Studios sometimes release internal libraries for general use
EA/EASTL
, InsomniacGames/ig-cachesim
, Remedy-Entertainment/binderoo
etc
Note
|
Everything here based on my experience so far, YMMV! |
Note
|
I will unfairly concentrate on Epic’s UE4 :) * I worked with it for the past years * It does a lot of C++ questionable things |
Source code snippet from Doom 3
Source code snippet from CryEngine
Games need to run…
Everything is centered around achieving this - while…
Tradeoffs…
AAA studios…
legacy
of franchise games and sequels
…so amount of code quickly skyrockets…
Assassin’s Creed Unity:
Rainbow Six: Siege:
By far and large Windows centric development - even for consoles
MSVC
GCC
clang
Again, Microsoft drives it…
Visual Studio
Others
Compilation and linking are usually dreadfully slow
End result usually a single executable - size is ridiculous!
Optimizations are on by default, full debug builds have crawling FPS;
Various tricks:
#pragma optimize
on/off "islands"
Some mitigation methods…
Unity builds
.cpp
units
Various techniques
Distributed compilation
FastBuild
or Incredibuild
to effectively create compilation farms
Heed no warning!
Warnings are mopped under the floor - couple of favorite ones to disable…
T1
to T2
requires a narrowing conversion
T1
to T2
, possible loss of data
Use the __force!
Eternal hope that magically sprinkling inline
will make things faster…
inline, __inline, __forceinline __attribute__((always_inline))
Traditionally was very C++98 but by now changed…
UE4
enables it by default
if-with-initializer
seems a favorite, guaranteed RVO, std::optional
for errors etc
Due to differences in people’s experience, personality and time availability, adoption of the various new features and techniques is slow…
Personal way to help…
Every studio has a set of guidelines or a complete style guide.
Some of them recommend things that would really upset a C++ purist!
Example: Namespaces
CShooterComponent
, TShooterItem
, EShooterState
etc
Trivia
auto
destroys friendships
Preferred technique for game code - with some studios resisting!
Polymorphism
Object
ultimate base class
ECS
Entity
, Node
or Object
's
Update
, Tick
, Draw
or Render
Common communication methods
Need for multithreading continuously growing…
New/old paradigms
.Then()
, .With()
etc
future
and promise
- usually every game engine has own equivalents
Traditionally, there was a tendency to downplay templates - changing now with modern standards and mature compilers
Normal usage
Metaprogramming
enable_if
, void_t
, traits etc
Still a tendecy to use macros where template
or constexpr
functions would be more adequate
Adoption generally low…
Bespoke alternatives
std::string
- best example…
Bits & pieces…
Iterator
concept is copied and reimplemented - if nothing else just to enable ranged-for’s
EASTL from Electronic Arts - video game specific implementation of STL
Originally started 10 years ago for internal use, now open source (https://github.com/electronicarts/EASTL)
Normally follows the std::
nomenclature & style
Differences / Changes…
ring_buffer
, heap
, priority_queue
, etc
Finally game dev is officially recognized in the ISO C++ Standard committee!
SG14 group
Video games and embedded programming study sub-group
Tries to propose new, optimized containers, data structures even language changes
Proposals & Papers in-flight…
std::function
Very frowned upon and highly discouraged…
Reasons…
boost::hana
(but getting very close)
bcp
tool makes this easier
Almost never used due to speed penalties of throw
-ing and catch
-ing
A small (not totally fair) demonstration…
#include <stdexcept> int func() { throw std::exception(); }
Compiled with /O2
optimizations on VS 2017
Let’s see disassembly: https://godbolt.org/g/wQXmTi
Handling of errors…
Create
, Instantiate
, Begin
replacements
Seldom used - normally turned off by default because it bloats the modules size
Very rare use of dynamic_cast
- usually reimplemented manually via COM style interfaces
A lot of games have involved reflection systems…
Custom solutions…
Example from Unreal Engine 4…
Class member decorations…
The ugly insides…
There you have it - a short survey of C++ in game development!