Browse Source

Outlined talk, visual updates

* My whole talk is outlined, though not all slides are finished
* Added separate body text font atlas for code vs. text
* Added animations
master
Macoy Madson 5 months ago
parent
commit
0671b9d80f
  1. 164
      data/DrivingCodeWithData.cakedata
  2. 59
      src/Presentation.cake

164
data/DrivingCodeWithData.cakedata

@ -2,8 +2,10 @@
:slides
(array
(slide-data :heading "Driving code with data" :body "Macoy Madson")
(slide-data :heading "Setting the stage")
(slide-data :heading "Setting the stage"
:body "(Art by Pixel-boy. Creative Commons Zero license.)")
(slide-data :heading "First pass"
:is-code true
:body "if shouldShootFireball():
{
makeFireball();
@ -13,7 +15,9 @@ for each fireball:
{
updateFireballs();
}")
(slide-data :heading "What about ice storms?" :body "if shouldShootFireball():
(slide-data :heading "What about ice storms?"
:is-code true
:body "if shouldShootFireball():
{
makeFireball();
}
@ -36,6 +40,7 @@ heat seeker
...")
(slide-data :heading "We have a problem")
(slide-data :heading "Second pass: sharing code"
:is-code true
:body "for each projectile in projectiles:
{
updateProjectile(projectile);
@ -48,4 +53,157 @@ heat seeker
- Complexity spreads")
(slide-data :heading "What are computers good at?")
(slide-data :heading "Storing and manipulating data")
(slide-data :heading "Describe the behavior in data")))
(slide-data :heading "Describe the behavior in data"
:is-code true
:body "struct Power
{
struct OnActivate
{
String makeParticle;
vec2 startVelocity;
} onActivate;
struct OnUpdate
{
MovementType movement;
vec2 acceleration;
} onUpdate;
struct OnEnemyHit
{
StatusEffect effect;
int magnitude;
} onEnemyHit;
}")
(slide-data :heading "We now have templates"
:is-code true
:body "Power fireball =
{
.onActivate =
{
.makeParticle = \"fireball\",
.startVelocity = {5.f, 0.f},
},
.onUpdate =
{
.movement = MovementType_Projectile,
},
.onEnemyHit
{
.effect = StatusEffect_Damage,
.magnitude = 200,
},
}")
(slide-data :heading "Move all behaviors into the same handler")
(slide-data :heading "Design can now make variations"
:body "But all special new types need a programmer.
Lots of one-off booleans: doTheSpecialIceStormThing")
(slide-data :heading "Can we take the data approach even further?")
(slide-data :heading "Generic \"operation\" structure"
:is-code true
:body "struct Operation
{
}")
(slide-data :heading "Now we can do more")
(slide-data :heading "Great, but designers still want more!"
:body "I want it to do X only if Y is true
It should do X only sometimes, e.g. randomly")
(slide-data :heading "Our operations are data"
:body "What if operations change how they themselves are executed?")
(slide-data :heading "New operations"
:is-code true
:body "Label
GoToLabel
SetValue
IfValueEquals
Else
EndIf
...")
(slide-data :heading "Operations now change control flow"
:body "Manipulate the index while we iterate")
(slide-data :heading "Wow")
(slide-data :heading "We can now make huge variations")
(slide-data :heading "But people hate writing these"
:body "All those {} and , are slowing people down")
(slide-data :heading "Let's give them a better syntax"
:is-code true
:body "IfEqual distance 5
MakeParticle fireball
EndIf")
(slide-data :heading "How should we implement this?"
:is-code true
:body "for each word in file:
if word == \"IfEqual\":
operations.append({Operation_IfEqual, ...});
else if word == \"MakeParticle\"
...")
(slide-data :heading "Looks familiar?"
:is-code true
:body "for each word in file:
if word == \"IfEqual\":
operations.append({Operation_IfEqual, ...});
else if word == \"MakeParticle\"
...")
(slide-data :heading "We can do better!"
:is-code true
:body "struct OperationReader
{
String name;
OperationType type;
Array<ArgumentReader> arguments;
}
struct ArgumentReader
{
ArgumentDestination outputTo;
}
")
(slide-data :heading "Our parser is now data-driven"
:is-code true
:body "for each word, index in file:
for each reader in operationReaders:
if word == reader.name
Operation operation;
operation.type = reader.type;
operation.arguments = readArguments(reader, file, index)
function readArguments(reader, file, wordIndex):
for each argument in reader.arguments:
if argument.outputTo == String:
parseString(file[wordIndex])
if argument.outputTo == Number:
parseNumber(file[wordIndex])
wordIndex++")
(slide-data :heading "Now they're off to the races"
:is-code true
:body "
if blah: if blah:
blah blah blah blah 2
EndIf EndIf")
(slide-data :heading "We just made a programming language!"
:body "That wasn't so hard, was it?")
(slide-data :heading "There are problems with this approach"
:body "- Need tools for debugging
- Less expressive power than native language
- Performance impact
- Spreading to problems it wasn't designed for
- Feature creep without language redesign
- Non-programmers doing programming")
(slide-data :heading "Questions to ask")
(slide-data :heading "Can I express this problem with data?")
(slide-data :heading "Can I author that data in a better way?")
(slide-data :heading "How do I expect the problem, data,
and feature to grow?"
:body "How are they actually growing?")
(slide-data :heading "Am I building a complicated generic system
before knowing it is necessary?")
(slide-data :heading "In conclusion"
:body "Doing this is not hard,
knowing when to do this, and to what extent,
is hard.
That doesn't mean it shouldn't be done, but does
mean it should be done carefully.")
(slide-data :heading "Questions?"))

59
src/Presentation.cake

@ -22,10 +22,12 @@
(define-keybind s-quit-keybind (array SDL_SCANCODE_Q keybind-modifier-flags-ctrl))
(define-keybind s-next-slide-keybind (array SDL_SCANCODE_RIGHT)
(array SDL_SCANCODE_DOWN)
(array SDL_SCANCODE_SPACE)
(array SDL_SCANCODE_RETURN)
(array SDL_SCANCODE_PAGEDOWN))
(define-keybind s-previous-slide-keybind (array SDL_SCANCODE_LEFT)
(array SDL_SCANCODE_UP)
(array SDL_SCANCODE_BACKSPACE)
(array SDL_SCANCODE_PAGEUP))
@ -47,7 +49,9 @@
(def-introspect-struct slide-data
heading ([] 256 char)
body ([] 1024 char))
body ([] 1024 char)
;; Set body font to monospace
is-code bool)
(def-introspect-struct presentation-data
slides ([] 256 slide-data) ('array-allow-subset))
@ -84,12 +88,15 @@
6 6
2))
(var anim-wizard-idle animation (array 0 5 SDL_FLIP_HORIZONTAL))
(var anim-wizard-damage animation (array 31 35 SDL_FLIP_HORIZONTAL))
(var anim-wizard-attack animation (array 14 31 SDL_FLIP_HORIZONTAL))
(var spritesheet-boar spritesheet (array null
1434 1068
6 6
2))
(var anim-boar-idle animation (array 0 6 SDL_FLIP_HORIZONTAL))
(var anim-boar-jump-in animation (array 23 34 SDL_FLIP_HORIZONTAL))
(var anim-boar-damage animation (array (+ (* 3 6) 3) (+ (* 3 6) 5) SDL_FLIP_HORIZONTAL))
(var c-animation-frame-rate (const float) 0.1f)
@ -241,7 +248,8 @@
(var device-dpi (unsigned char) 144)
;; 1 point = 1/72". Accurate if device-dpi is properly set
(var font-size-points (unsigned char) 36)
(var large-font-size-points (unsigned char) 36)
(var small-font-size-points (unsigned char) 18)
(var code-font-size-points (unsigned char) 16)
(SDL_GL_SetAttribute SDL_GL_CONTEXT_MAJOR_VERSION 4)
@ -260,16 +268,30 @@
(return 1))
(defer (SDL_DestroyRenderer renderer))
(var ubuntu-regular-font-atlas font-atlas (array 0))
(defer (free-font-atlas (addr ubuntu-regular-font-atlas)))
(var ubuntu-regular-texture (* SDL_Texture) null)
(defer (when ubuntu-regular-texture (SDL_DestroyTexture ubuntu-regular-texture)))
(var ubuntu-regular-large-font-atlas font-atlas (array 0))
(defer (free-font-atlas (addr ubuntu-regular-large-font-atlas)))
(var ubuntu-regular-large-texture (* SDL_Texture) null)
(defer (when ubuntu-regular-large-texture (SDL_DestroyTexture ubuntu-regular-large-texture)))
(unless (make-font-atlas-and-texture renderer
(addr ubuntu-regular-font-atlas) (addr ubuntu-regular-texture)
(addr ubuntu-regular-large-font-atlas)
(addr ubuntu-regular-large-texture)
s-start-ubuntu-regular-font
(- s-end-ubuntu-regular-font s-start-ubuntu-regular-font)
device-dpi
font-size-points)
large-font-size-points)
(return 1))
(var ubuntu-regular-small-font-atlas font-atlas (array 0))
(defer (free-font-atlas (addr ubuntu-regular-small-font-atlas)))
(var ubuntu-regular-small-texture (* SDL_Texture) null)
(defer (when ubuntu-regular-small-texture (SDL_DestroyTexture ubuntu-regular-small-texture)))
(unless (make-font-atlas-and-texture renderer
(addr ubuntu-regular-small-font-atlas)
(addr ubuntu-regular-small-texture)
s-start-ubuntu-regular-font
(- s-end-ubuntu-regular-font s-start-ubuntu-regular-font)
device-dpi
small-font-size-points)
(return 1))
(var ubuntu-mono-font-atlas font-atlas (array 0))
@ -361,8 +383,8 @@
atlas (* font-atlas)
texture (* SDL_Texture))
(var atlases-to-draw ([] atlas-set)
(array (array (addr ubuntu-regular-font-atlas)
ubuntu-regular-texture)
(array (array (addr ubuntu-regular-large-font-atlas)
ubuntu-regular-large-texture)
(array (addr ubuntu-mono-font-atlas)
ubuntu-mono-texture)))
(each-in-array atlases-to-draw i
@ -391,14 +413,19 @@
(var slide (* slide-data) (addr (at current-slide-index (field presentation slides))))
(render-string
renderer (addr ubuntu-regular-font-atlas) ubuntu-regular-texture
(+ text-x (/ window-width 5)) (/ window-height 8)
renderer (addr ubuntu-regular-large-font-atlas) ubuntu-regular-large-texture
(+ text-x (/ window-width 8)) (/ window-height 8)
(path slide > heading))
(render-string
renderer (addr ubuntu-mono-font-atlas) ubuntu-mono-texture
(+ text-x (/ window-width 5)) (/ window-height 3)
(path slide > body))
(if (path slide > is-code)
(render-string
renderer (addr ubuntu-mono-font-atlas) ubuntu-mono-texture
(+ text-x (/ window-width 7)) (/ window-height 4)
(path slide > body))
(render-string
renderer (addr ubuntu-regular-small-font-atlas) ubuntu-regular-small-texture
(+ text-x (/ window-width 7)) (/ window-height 4)
(path slide > body)))
(scope
(var buffer ([] 256 char) (array 0))

Loading…
Cancel
Save