Elm is a purely Functional Reactive Programming language, which happens to have the best current implementation of a Time Travelling Debugger (see Bret Victor's Inventing on Principle [https://vimeo.com/36579366] from 12:25) and is ideally suited for games and UIs. We'll see how FRP, a strong yet simple(r than Haskell) type system and the interactive programming workflow make developing a small game much more pleasant compared to the mainstream game engines experience.
Claudia Doppioslash - Time Travel for game development with Elm
1. Time TravelTime Travel
for Game Developmentfor Game Development
with Elmwith Elm
byby @doppioslash@doppioslash
20th of November 2015 - Codemotion - Milan
3. Table of ContentsTable of Contents
GameDev workflow = hell
Time Travelling Debugger?
Meet Elm
Structuring programs in Elm
Time Travelling Demo
Gotchas
4. What is the single mostWhat is the single most
soul destroying thing insoul destroying thing in
game development?game development?
5. What is the single most soulWhat is the single most soul
destroying thing in gamedestroying thing in game
development?development?
C++?C++?
6.
7. What is the single most soulWhat is the single most soul
destroying thing in gamedestroying thing in game
development?development?
Having to redo a 10Having to redo a 10
moves combo everymoves combo every
time you check iftime you check if
the bug is gone?the bug is gone?
8.
9. What is the single most soulWhat is the single most soul
destroying thing in gamedestroying thing in game
development?development?
Projects gettingProjects getting
canned?canned?
10.
11. Slow Iteration timesSlow Iteration times
What is the single most soulWhat is the single most soul
destroying thing in gamedestroying thing in game
development?development?
14. 1. Write some code1. Write some code
Example CommonExample Common
Game Development WorkflowGame Development Workflow
15. 2. Playtest it2. Playtest it
(in the Unity Editor)(in the Unity Editor)
Example CommonExample Common
Game Development WorkflowGame Development Workflow
16.
17.
18. Now to test thatNow to test that
same change onsame change on
mobile devices:mobile devices:
Example Common Game DevelopmentExample Common Game Development
Workflow (starring Unity)Workflow (starring Unity)
19. Make a change and test onMake a change and test on
DeviceDevice
1. Start build1. Start build
20.
21. Make a change and test onMake a change and test on
DeviceDevice
3. load the ipa/apk3. load the ipa/apk
on deviceon device
22. Make a change and test onMake a change and test on
DeviceDevice
4. playtest until your4. playtest until your
code runscode runs
23. Make a change and test onMake a change and test on
DeviceDevice
5. Find new and5. Find new and
exciting bugsexciting bugs
(only on device)(only on device)
27. Slow Iteration timesSlow Iteration times
Error prone forest ofError prone forest of
build settingsbuild settings
28.
29. Slow Iteration timesSlow Iteration times
Deadline panic 10xDeadline panic 10x
increaseincrease
(suffering together at late hours might be team-building
but surely we don't need this :P)
39. Inventing on PrincipleInventing on Principle
Hot reloadHot reload::
reload changes to thereload changes to the
code without stoppingcode without stopping
the gamethe game
40. Inventing on PrincipleInventing on Principle
Time TravelTime Travel::
being able to scrubbeing able to scrub
to any point in theto any point in the
sessionsession
41. Inventing on PrincipleInventing on Principle
OmniscienceOmniscience::
see all the statesee all the state
in the sessionin the session
72. The Functional TriforceThe Functional Triforce
Union TypesUnion Types
define the Model:define the Model:
type Tile
= Door Size
| Column
| BackGround BackGroundTile
| Shadow ShadowTile
73. The Functional TriforceThe Functional Triforce
MaybeMaybe
gets rid of NULL errorsgets rid of NULL errors
type Maybe a
= Just a
| Nothing
74. The Functional TriforceThe Functional Triforce
Pattern MatchingPattern Matching
String.toInt : String -> Maybe Int
toMonth : String -> Maybe Int toMont
h rawString =
case String.toInt rawString of
Nothing ->
Nothing
Just n ->
if n > 0 && n <= 12 then Ju
st n else Nothing
80. ModelModel
type alias UserInput = {}
userInput : Signal UserInput
userInput = Signal.constant {}
type alias Input =
{ timeDelta : Float
, userInput : UserInput
}
81. ModelModel
type alias UserInput = {}
userInput : Signal UserInput
userInput = Signal.constant {}
type alias Input =
{ timeDelta : Float
, userInput : UserInput
}
TypeType
signaturesignature
82. ModelModel
type alias UserInput = {}
userInput : Signal UserInput
userInput = Signal.constant {}
type alias Input =
{ timeDelta : Float
, userInput : UserInput
}
A recordA record
Type aliasType alias
SignalSignal
92. UpdateUpdate
stepGamestepGame uses theuses the
currentcurrent InputInput
(which is(which is UserInputUserInput and aand a
timeDeltatimeDelta))
to make a newto make a new GameStateGameState
108. What are Signals?What are Signals?
a different way ofa different way of
thinking aboutthinking about
variablesvariables
109. What are Signals?What are Signals?
an explicit model ofan explicit model of
variable mutation invariable mutation in
timetime
110. What are Signals?What are Signals?
non-awkward way ofnon-awkward way of
structuring callbacksstructuring callbacks
111.
112. What are Signals?What are Signals?
they are wired inthey are wired in
signal graphssignal graphs
(directed acyclic(directed acyclic
graphs)graphs)
114. What kind ofWhat kind of
functions can wefunctions can we
apply on signals?apply on signals?
115. What kind of functions canWhat kind of functions can
we apply on signals?we apply on signals?
: Signal a ->
Signal a -Signal a ->> Signal aSignal a
merge
116. What kind of functions canWhat kind of functions can
we apply on signals?we apply on signals?
:: (a(a ->-> Bool)Bool) ->-> aa ->->
Signal aSignal a ->-> Signal aSignal a
filterfilter
117. What kind of functions canWhat kind of functions can
we apply on signals?we apply on signals?
:: (a(a ->-> result)result) ->-> Signal aSignal a --
>> Signal resultSignal result
mapmap
applies a function on a signalapplies a function on a signal
returns another, transformed, signalreturns another, transformed, signal
118. What kind of functions canWhat kind of functions can
we apply on signals?we apply on signals?
:: (a(a ->-> bb ->-> result)result) ->->
Signal aSignal a ->-> Signal bSignal b ->->
Signal resultSignal result
map2map2
applies a function on two signalsapplies a function on two signals
119. What kind of functions canWhat kind of functions can
we apply on signals?we apply on signals?
makes a signal that depends on themakes a signal that depends on the
past values of a signalpast values of a signal
: (a -> state -> state) -
> state -> Signal a ->
Signal state
foldp
132. How Elm Reactor worksHow Elm Reactor works
changes to typeschanges to types
will break hotwill break hot
swappingswapping
133. also if a changealso if a change
doesn't compiledoesn't compile
How Elm Reactor worksHow Elm Reactor works
134. Why is Elm goodWhy is Elm good
for Time Travelling?for Time Travelling?
135. Why Elm Reactor worksWhy Elm Reactor works
Applying the sameApplying the same
inputs will return theinputs will return the
same outputsame output
(referential transparency)(referential transparency)
136. Why Elm Reactor worksWhy Elm Reactor works
No side effectsNo side effects ==
can replay codecan replay code
137. Why Elm Reactor worksWhy Elm Reactor works
All mutable state isAll mutable state is
stored in the foldpstored in the foldp
150. Why use staticallyWhy use statically
typed pure Functionaltyped pure Functional
languages in Gamelanguages in Game
Development?Development?
151. Why it's worth to use new language researchWhy it's worth to use new language research
in Game Developmentin Game Development
No runtimeNo runtime
exceptionsexceptions
152. Why it's worth to use new language researchWhy it's worth to use new language research
in Game Developmentin Game Development
No raceNo race
conditionsconditions
153. Why it's worth to use new language researchWhy it's worth to use new language research
in Game Developmentin Game Development
Better toolsBetter tools
154. Why it's worth to use new language researchWhy it's worth to use new language research
in Game Developmentin Game Development
Less codeLess code
155. Why it's worth to use new language researchWhy it's worth to use new language research
in Game Developmentin Game Development
Ease ofEase of
parallelisationparallelisation