DConf 2016, Berlin Ethan Watson, Senior Generalist Programmer

Содержание

Слайд 2

AAA GAMING WITH SOME D CODE

AAA GAMING WITH SOME D CODE

Слайд 3

QUANTUM BREAK WHAT THIS TALK WILL COVER Integrating D A major

QUANTUM BREAK
WHAT THIS TALK WILL COVER

Integrating D
A major use case
Getting it

shipped
Where to for the future?
Слайд 4

Third person cinematic action game with integrated live action TV show

Third person cinematic action game with integrated live action TV show
Xbox

One, Windows 10
#1 selling game on week of release in 8 countries including UK, Italy, France, and Switzerland
Biggest selling new Microsoft IP this console generation

QUANTUM BREAK
WHAT IS IT?

Слайд 5

INTEGRATING D

INTEGRATING D

Слайд 6

PREVIOUSLY AT DCONF 2013 USING D ALONGSIDE A GAME ENGINE

PREVIOUSLY AT DCONF 2013
USING D ALONGSIDE A GAME ENGINE

Слайд 7

Code as data D code exists as data in our pipeline,

Code as data
D code exists as data in our pipeline, allowing

new logic to be shipped out without creating a new build
Export functions between C++ and D
Use D language features to avoid the pain that doing the same in C++ would introduce
Reloading code for rapid iteration
Compile time code inspection and generation to serialise and deserialise D objects

CODE AS DATA
DYNAMIC BINDING BETWEEN C++ AND D

Слайд 8

D’S COMPILE TIME FEATURES WHAT DID I GET MYSELF IN TO?

D’S COMPILE TIME FEATURES
WHAT DID I GET MYSELF IN TO?

Слайд 9

Mark up functions/interfaces with version numbers Variable inside @(Export) and @(Import)

Mark up functions/interfaces with version numbers
Variable inside @(Export) and @(Import) UDA

in D, #define parameter in C++
Matching versions has the nice benefit of solving Windows DLL Hell

VERSIONING
BECAUSE CODE AND DATA NEVER MATCH NICELY

Слайд 10

Stagger submitting D code until new build is published Shelve D

Stagger submitting D code until new build is published
Shelve D code
Submit

C++ code
Email team
Publish C++ code
Submit D code
Pain for programmers, seamless for everyone else
(Well, mostly seamless, still requires a data sync with a new build which isn’t always done)
Not a problem with Unity/Unreal thanks to going whole hog with treating code as data
There is a better solution to be found for our needs

VERSIONING
BECAUSE CODE AND DATA NEVER MATCH NICELY

Слайд 11

BINARY COMPATIBILITY IT JUST WORKS! @( Version( 3 ) ) struct

BINARY COMPATIBILITY
IT JUST WORKS!

@( Version( 3 ) ) struct DebugGraph
{
@(

AddedVersion( 2 ) ) Vector2 m_vTopLeft;
@( AddedVersion( 3 ) ) Vector2 m_vBottomRight;
@( Import ) void start( const( char )* pLabel, ref const( Vector2 ) vTopLeft, ref const( Vector2 ) vBottomRight );
@( Import ) void plot( const( Vector2 )* pPoints, int iPointCount, ref const( Color ) color );
final void start( string label, ref const( Vector2 ) vTopLeft, ref const( Vector2 ) vBottomRight ) { ... }
final void start( in Vector2[] points, ref const( Color ) color ) { ... }
}
class SomeObject
{
version( SomeObjectDebug ) DebugGraph graph;
mixin ExportClass;
}
Слайд 12

BINARY COMPATIBILITY IT JUST WORKS!

BINARY COMPATIBILITY
IT JUST WORKS!

Слайд 13

Creating bindings to do code in D – 30+ minutes and

Creating bindings to do code in D – 30+ minutes and

the staggered submit hassle
Doing the same code in C++ - 5 minutes and everyone can just wait for the new build
Catch 22!
A problem with the plugins/binding system, not the D language itself
(But we can solve some of the problems with D by using a compile-time parser that reads C++ header files and auto-generates binary compatible structs and bindings for us…)

PLUGINS AND BINDINGS FOR RAPID ITERATION
or MAINTENANCE SUCKS

Слайд 14

A MAJOR USE CASE

A MAJOR USE CASE

Слайд 15

Our Morpheme setup required code and data to be in sync

Our Morpheme setup required code and data to be in sync
Code

publish time of a day or more is bad

ANIMATION – NO ONE MOVES WITHOUT IT
LIFE BEFORE D

Слайд 16

D plugins? Well, they solve some problems! Generic component system written,

D plugins? Well, they solve some problems!
Generic component system written, specialised

for animation networks
Manually go through and port C++ code to D components
Roll out the system, keep C++ code for fallback, then nuke the C++ code from orbit
Submitting new D code with new data became a regular occurance, and minor maintenance of code logic didn’t need a whole new build. Win!

ANIMATION – NO ONE MOVES WITHOUT IT
D + PLUGINS = WIN!

Слайд 17

GETTING IT SHIPPED

GETTING IT SHIPPED

Слайд 18

core.stdc.stdlib alloc/calloc/realloc/free gc_rawAlloc, gc_rawCalloc, gc_rawRealloc, gc_rawFree Hooking up our engine’s allocation

core.stdc.stdlib alloc/calloc/realloc/free
gc_rawAlloc, gc_rawCalloc, gc_rawRealloc, gc_rawFree
Hooking up our engine’s allocation functions required

staggering DLL initialisation

SHIPPING WITH D
MEMORY MANAGEMENT

Слайд 19

SHIPPING WITH D MEMORY MANAGEMENT extern( Windows ) BOOL DllMain( HINSTANCE

SHIPPING WITH D
MEMORY MANAGEMENT

extern( Windows ) BOOL DllMain( HINSTANCE hInstance, ULONG

ulReason, LPVOID pvReserved )
{
final switch( ulReason )
{
case DLL_PROCESS_ATTACH:
g_hInstance = hInstance;
break;
case DLL_THREAD_ATTACH:
// Regularly called before the Setup function with multiple threads active!
}
}
export extern( Windows ) void Setup( AllocFunc allocMem, CAllocFunc callocMem, ReallocFunc reallocMem, FreeFunc freeMem )
{
setAllocFunctions( allocMem, callocMem, reallocMem, freeMem );
dll_process_attach( g_hInstance, true );
}
Слайд 20

The GC itself wasn’t “solved” Far stricter memory requirements than normal

The GC itself wasn’t “solved”
Far stricter memory requirements than normal programs
Industry

standard is to have clear construction and destruction phases and budget time accordingly

SHIPPING WITH D
MEMORY MANAGEMENT

Слайд 21

The GC itself wasn’t “solved” Automatic Reference Counting is our preferred

The GC itself wasn’t “solved”
Automatic Reference Counting is our preferred method
Attempted

to add compiler frontend support myself
Wasn’t confident that I caught everything, put it to the side

SHIPPING WITH D
MEMORY MANAGEMENT

Слайд 22

The GC itself wasn’t “solved” GC has 32MB, never collects, increments

The GC itself wasn’t “solved”
GC has 32MB, never collects, increments in

8MB chunks
This is quite clearly rubbish and needs a proper solution

SHIPPING WITH D
MEMORY MANAGEMENT

Слайд 23

Runtime porting still needs work LoadLibrary -> LoadPackagedLibrary Auto-packaged files as

Runtime porting still needs work
LoadLibrary -> LoadPackagedLibrary
Auto-packaged files as data only

work from deployment project FFFFFFFFFFFFFFFFFFFFFFFF
std.datetime reghacks instead of using Windows APIs
core.sys.windows.threadaux needs a new implementation
We didn’t do it, but we get by without it

SHIPPING WITH D
UNIVERSAL WINDOWS PLATFORM REQUIREMENTS

Слайд 24

QUANTUM BREAK XBOX ONE & WINDOWS 10 FIRST AAA GAME WITH

QUANTUM BREAK
XBOX ONE & WINDOWS 10

FIRST AAA GAME WITH D CODE

TO SHIP ON XBOX ONE AND WINDOWS 10
Слайд 25

Wasn’t used enough, could have done it in C++ More the

Wasn’t used enough, could have done it in C++
More the fault

of the plugin system, statically linking code would have been far simpler
For the future though? High amount of interest
Natural threading boundaries make a task-based system safer to implement
No solid way to enforce boundaries in C++
AI wants to “script” behaviours with it, code gen around it to fit in to frameworks
Render effects in D
Speaking of scripting…
Internal scripting language used by level designers
Lacks modern features and no debugger
Why have a scripting language at all when we already treat code as data?

WAS IT WORTH IT?
LOOKING TO THE FUTURE

Слайд 26

Almost! Few areas that need tightening up ARC support please please

Almost!
Few areas that need tightening up
ARC support please please please please

please
“Official” console support (PS4, Xbox One)
PS4 especially is critical for AAA gaming
Single instance of D runtime for entire application would be very beneficial
Open sourcing our binding system?

D FOR AAA GAMING
IS IT READY?