Lua Patient Zero: Grim Fandango<br />Bret Mogilefsky<br />Formerly of LucasArts, now SCEA<br />
Setting the stage<br />One famous designer: Tim Schafer<br />One venerable game engine: SCUMM<br />Huge pedigree of belove...
Scripting not a new idea atLucasArts<br />SCUMM dated back to 1986<br />Example:<br />actor guybrush walk-to banana-tree<b...
Breaking with the past<br />SCUMM was long in the tooth and newb-hostile<br />SCUMM the language was inseparable from SCUM...
Why Lua<br />I was lucky!<br /><Insert pic of Dr. Dobb’s Journal><br />It was small, elegant, and ready to go<br />The man...
Lua as I found it<br />Started with Lua 2.5<br />Switched to Lua 3.1 beta before shipping<br />Very nice …but still lacked...
Why coroutines?<br />Independent characters and objects get programmed with isolated scripts controlling their actions<br ...
Lua modifications<br />Addition of coroutines<br />Made it re-entrant<br />Flattened the Lua stack<br />Implemented dump/r...
Lua re-entrancy<br />Took state out of global variables to make it thread-safe<br />First attempt was an array of Lua stat...
Lua’s recursive stack<br />Every Lua call also pushed a stack frame in C<br />A yield from one Lua instance to resume anot...
Flattening Lua’s stack<br />Instead of recursing, return a yield code, push a structure, and start the next function<br />...
Ways we used Lua<br />Engine extension<br />Command-line and console<br />Debugger, including tasking extension<br />Tool ...
Command-line and console<br />Copy and paste code into game on-the-fly<br />Iterate on a bugfix without restarting<br />Tr...
Debugger<br />Written by a scripter using the in-language line-hook and call-hook facility<br />Added the task-hook for ou...
Tool macro language<br />Developed choreography rehearsal tool alongside game<br />Stitched together assets into “costumes...
Patching<br />Blocker bugs in scripts were trivially replaced<br />Saved enormous amounts of burn time<br />Update to ship...
It wasn’t all roses<br />High memory requirements<br />Debugger went stale<br />Heavyweight garbage collection<br />So muc...
How’d we do?<br />Despite huge technical risks, we pulled it off<br />Great reviews, and the game remains beloved<br />Poo...
TheLua explosion<br />Concurrent success of QuakeC and UnrealScript had made scripting languages HOT!<br />GDC99 held a pa...
Why Lua endures<br />It’s small, simple, and proven<br />Lua turned “scripting language” into a commodity feature<br />You...
Lua patient zero   bret mogilefsky (scea)
Upcoming SlideShare
Loading in …5
×

Lua patient zero bret mogilefsky (scea)

2,629
-1

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,629
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
33
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Without virtual memory and large caches, we’d have been screwed
  • Lua patient zero bret mogilefsky (scea)

    1. 1. Lua Patient Zero: Grim Fandango<br />Bret Mogilefsky<br />Formerly of LucasArts, now SCEA<br />
    2. 2. Setting the stage<br />One famous designer: Tim Schafer<br />One venerable game engine: SCUMM<br />Huge pedigree of beloved games includedManiac Mansion, Secret of Monkey Island, Sam and Max, Day of the Tentacle, Full Throttle<br />One new game engine: Sith, for Jedi Knight<br />One naïve coder: Me, fresh out of Cal!<br />I stole from everyone!<br />
    3. 3. Scripting not a new idea atLucasArts<br />SCUMM dated back to 1986<br />Example:<br />actor guybrush walk-to banana-tree<br />wait-for-actoractor guybrush say-line “Mmm, bananas…”<br />wait-for-actor<br />actor guybrush face-camera<br />actor guybrush say-line “Wish I had a banana-picker”<br />Various attempts to unseat it had failed<br />Nobody stopped me, though they predicted doom<br />
    4. 4. Breaking with the past<br />SCUMM was long in the tooth and newb-hostile<br />SCUMM the language was inseparable from SCUMM the engine<br />I am as guilty of not-invented-here as anyone<br />Got sets, characters, lighting, animation, and audio in no time, but no scripting<br />Jedi Knight put me way ahead, but it wasn’t an adventure game<br />
    5. 5. Why Lua<br />I was lucky!<br /><Insert pic of Dr. Dobb’s Journal><br />It was small, elegant, and ready to go<br />The manual was small enough that you could hand it to someone and expect them to read it<br />It had no external dependencies<br />The embedding API was ideal<br />The code itself was approachable and readable<br />
    6. 6. Lua as I found it<br />Started with Lua 2.5<br />Switched to Lua 3.1 beta before shipping<br />Very nice …but still lacked coroutines<br />Any LEC adventure game required them!<br />
    7. 7. Why coroutines?<br />Independent characters and objects get programmed with isolated scripts controlling their actions<br />Think about what it would be like in C/C++!<br />Threads were too heavy for undead pigeons, flaming beavers, driving demons, and Pentium 90MHz processors<br />True concurrency wasn’t needed; just wanted to pick up where we left off last time each frame<br />
    8. 8. Lua modifications<br />Addition of coroutines<br />Made it re-entrant<br />Flattened the Lua stack<br />Implemented dump/restore of Lua state<br />
    9. 9. Lua re-entrancy<br />Took state out of global variables to make it thread-safe<br />First attempt was an array of Lua state structures looped over until a “yield()” was called, using a single thread<br />But… DISASTER!<br />
    10. 10. Lua’s recursive stack<br />Every Lua call also pushed a stack frame in C<br />A yield from one Lua instance to resume another might happen at a different stack depth<br />Welcome to Crash City<br /><Sequence diagram: C->Lua->C->Lua->C->Lua><br />
    11. 11. Flattening Lua’s stack<br />Instead of recursing, return a yield code, push a structure, and start the next function<br /><C->Lua->Lua->Lua><br />A couple years later, “Stackless Python” solved the same problem<br />It still exists, whereas Lua incorporated coroutines as part of the language<br />This would not have been possible if Lua wasn’t nice code to begin with<br />
    12. 12. Ways we used Lua<br />Engine extension<br />Command-line and console<br />Debugger, including tasking extension<br />Tool macro language<br /><ul><li>Patching</li></li></ul><li>Engine extension<br />All performance-critical code in C/C++<br />Renderer, animation, lighting, sound, save/load<br />All game-specific code in Lua<br />Engine just calls “BOOT()”, then loops tasks<br />Not just adventure gameplay<br />Controls, menus, dialog trees, puzzle mosaic<br />The scripting language is glue!<br />120K lines of code<br />
    13. 13. Command-line and console<br />Copy and paste code into game on-the-fly<br />Iterate on a bugfix without restarting<br />Trigger any condition as needed<br />This kind of productivity was unprecedented!<br />The compiler was small so we left it in<br />
    14. 14. Debugger<br />Written by a scripter using the in-language line-hook and call-hook facility<br />Added the task-hook for our coroutines<br />Fancy features like evaluating expressions at each step were trivial due to compiler in engine<br />
    15. 15. Tool macro language<br />Developed choreography rehearsal tool alongside game<br />Stitched together assets into “costumes” and coordinated timing<br />ChoreTool used Lua as a macro language<br />Example: Tie real game trigger logic to a menu item<br />Example: Automate insertion of keys at regular intervals<br />Some macros became permanent parts of the tool, saving lots of programmer time<br />
    16. 16. Patching<br />Blocker bugs in scripts were trivially replaced<br />Saved enormous amounts of burn time<br />Update to shipped game retro-patched save games as well<br />Probably not an issue if we’d saved differently<br />
    17. 17. It wasn’t all roses<br />High memory requirements<br />Debugger went stale<br />Heavyweight garbage collection<br />So much flexibility it was easy to write bugs<br />Typos in variable names not caught<br />Lacked languageconventions <br />No example code to examine<br />Savegames steadily grew larger as you progress…<br />
    18. 18. How’d we do?<br />Despite huge technical risks, we pulled it off<br />Great reviews, and the game remains beloved<br />Poor timing: We lost to Half-Life in “game of the year” categories over and over<br />The engine went on to ship Escape from Monkey Island (with lots of mods)<br />But really, the end of the adventure genre was upon us, and that was the end of the line for GrimE<br />
    19. 19. TheLua explosion<br />Concurrent success of QuakeC and UnrealScript had made scripting languages HOT!<br />GDC99 held a panel on them<br />Rob Huebner on Java in Vampire: The Masquerade<br />Kevin Bruner on writing your own for Obi-Wan<br />Seamus McNally on not using one for Treadmarks<br />200 miserable developers slumped in their chairs<br />“Or you could just use Lua…”<br />Furious scribbling followed by sudden influx on the mailing list<br />
    20. 20. Why Lua endures<br />It’s small, simple, and proven<br />Lua turned “scripting language” into a commodity feature<br />You would be crazy to write your own and expect to do better<br />
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×