Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Game Development and Ruby

Game Development and Ruby

A presentation on opportunities of Ruby in the Game Development industry, including building games in Ruby, building game engines with Ruby, and using Ruby as a Scripting Languages for non-ruby Game Engines. Presented at RubyConf 2012.

Andrew Nordman

November 03, 2012
Tweet

More Decks by Andrew Nordman

Other Decks in Programming

Transcript

  1. UnrealEd • Level Design • Event Trigger System • Particle

    Effect Manager • One-click Playtesting Saturday, November 3, 12
  2. UnrealScript • Inspired by Java • Rather Verbose • Awkward

    OO Principles • Lacking in Language Functionality Saturday, November 3, 12
  3. class MyPawn extends UDNPawn dependson(UDNPawn); simulated function Tick (float DeltaTime)

    { local vector tmpLocation; super.Tick(DeltaTime); tmpLocation = Location; tmpLocation.Y = 275; SetLocation(tmpLocation); } DefaultProperties { ControllerClass=class'MyGame.SuperBot' MaxStepHeight=15.0 MaxJumpHeight=65 } class MyGameInfo extends UTGame; DefaultProperties { MapPrefixes(0)="MYG" DefaultPawnClass=Class'MyGame.MyPawn' BotClass=class'MyGame.SuperBot' HUDType=class'MyGame.SimpleHUD' bUseClassicHUD = true DefaultInventory(0)=none } <UDK_DIR>\Development\Src\MyGame\Classes\MyGameInfo.uc <UDK_DIR>\Development\Src\MyGame\Classes\MyPawn.uc Example UnrealScript Code Saturday, November 3, 12
  4. Unreal Development Kit (UDK) • UnrealEd 3.0 • Designed for

    Mods & Full-on games • Extensive UnrealEd Improvements • UnrealScript Mostly Unchanged Saturday, November 3, 12
  5. UnrealRb • CoffeeScript-inspired language compiler • Written in Ruby •

    Ruby code in • UnrealScript out Saturday, November 3, 12
  6. UnrealRb Problems • Poor Performance • Interfacing Bugs with UDK

    • Still bound by UnrealScript structure • Devolved into primitive DSL Saturday, November 3, 12
  7. However... What if Ruby could be used in Game Development

    more directly? Saturday, November 3, 12
  8. Three Paths in Game Development • Game Libraries • Using

    Existing Engines • Building a Game Engine Saturday, November 3, 12
  9. Game Libraries • Abstracts Low-Level Game Internals • Input Collection

    • Rendering Interface • Iteration Timing • Minimum Level of Code to Start Saturday, November 3, 12
  10. Ruby Game Libraries • Most Built on 1 of 2

    Projects • Rubygame • Gosu • Several Derivatives/Extensions Saturday, November 3, 12
  11. Rubygame • http://github.com/rubygame/rubygame • Pure Ruby Implementation • Uses SDL

    for Rendering Interface • Not Actively Maintained Saturday, November 3, 12
  12. Gosu • https://github.com/jlnr/gosu/ • C++ Library • Ruby wrapper uses

    SWIG to call C++ • Uses OpenGL for Rendering • Actively Maintained Saturday, November 3, 12
  13. Anatomy of a Game with Gosu • Create subclass of

    Gosu::Window • Create ONE instance of this subclass • Subclass implements 3 Methods Saturday, November 3, 12
  14. Resource Manager • Creation/Deletion of Resource Handles • Removes binding

    to Game Loop • Game State Manager Communication Saturday, November 3, 12
  15. Game State Manager • Contains Game Logic • Contains UI

    Elements • Contains Events / Input Handler • Relays Information to Game Loop Saturday, November 3, 12
  16. Resource Manager Game State Manager Primary Game Loop Game State

    Game Logic Rendering Input Handling Game State Game Logic Rendering Input Handling Game State Game Logic Rendering Input Handling Saturday, November 3, 12
  17. Entities • Building Block of Game Objects • Base class

    in traditional engines • Any interaction player has is with Entities Saturday, November 3, 12
  18. Gamebox • https://github.com/shawn42/gamebox/ • Built on top of Gosu •

    Designed for Rapid Game Development Saturday, November 3, 12
  19. Gamebox Structure • Gosu::Window becomes a Stage • Entities are

    represented as Actor objects • Game States are represented as Scenes • StageManager coordinates Scenes • Stagehands micromanage for Stage Manager Saturday, November 3, 12
  20. Gamebox Stagehands • Resource Manager • Input Manager • Physics

    Manager • Configuration Manager Saturday, November 3, 12
  21. Game Libraries • Great starting point for Developers • Boilerplate

    is quickly due to complexity • Requires not overly performant Saturday, November 3, 12
  22. Building Ruby Games with Engines Game Libraries are Game Engines

    with minimal component implementation Game Engines allow game developers to focus on game-specific logic, not low-level internals Saturday, November 3, 12
  23. Slick2D • Java Library -- Accessible via JRuby • Mature,

    Active Development • Easily package-able Saturday, November 3, 12
  24. Breakout • https://github.com/cadwallion/breakout • Classic Breakout game • Extension of

    Slick2D Pong by @peterc • http://www.rubyinside.com/video-game- ruby-tutorial-5726.html Saturday, November 3, 12
  25. New Components • Breakout has multiple levels • Physics calculations

    • More intense rendering through animation Saturday, November 3, 12
  26. Breakout Tech • GameContainer vs Game • Input Handler is

    part of GameContainer • Direct Access to Renderer Object • Direct Access to GameContainer • Implicit Window context for Images More Exposure to Engine Internals Saturday, November 3, 12
  27. jMonkeyEngine • Popular 3D Game Engine • Written in Java

    • Closer to Traditional Game Engine Saturday, November 3, 12
  28. jMonkeyEngine Component • SimpleApplication • simpleInit() • simpleUpdate() • simpleRender()

    • AppStates • Multithreading via Thread Pools Saturday, November 3, 12
  29. Building Game Engines with Ruby • Full-featured Game Component Library

    • Handles non-game-specific work • Provides hooks for game code What is a Game Engine? Saturday, November 3, 12
  30. Components of a Game Engine Engine Setup Game Loop Game

    States Input Handler Resource Manager Rendering Physics Networking Sound System Scripting System Entities Hardware Saturday, November 3, 12
  31. Ruby Engine Challenges • Concurrency • Cross-Platform Support • Library

    Interfacing Support • Memory Management / Performance • Code Compilation / Obfuscation Saturday, November 3, 12
  32. Concurrency Certain components need to be non-blocking. Without a proper

    concurrency system, bad things like the networking blocking the renderer, or the renderer blocking input handling will occur. Saturday, November 3, 12
  33. ZOMGTHREADS?! • Spin up some threads • Offload Rendering to

    Thread • GameLoop negotiates Interactions Saturday, November 3, 12
  34. GIL • GIL = Bad News Bears for Games •

    Ruby Implementations without a GIL • JRuby • Rubinius • MacRuby Saturday, November 3, 12
  35. Cross-Platform Support with Ruby • Great Linux/OSX support • Mediocre

    Windows Support • Lots of gotchas spread across core/stdlib • JRuby/JVM helps mitigate these issues Saturday, November 3, 12
  36. Cross Platform Idea Could we pick our Ruby Implementation based

    on the operating system the game is being developed on? Saturday, November 3, 12
  37. OS Input Interfacing • Ruby + Mouse Events = •

    C/C++ Extensions • JRuby can interface • MacRuby can too! Saturday, November 3, 12
  38. Memory Management MRI 1.9 GC is not well optimized for

    long-running processes and rapid object creation/deletion JRuby has great tools for performance tuning the runtime and GC Saturday, November 3, 12
  39. Code Obfuscation JRuby can MITIGATE this concern by packaging via

    Warbler... ...but this does not ELIMINATE the potential. Saturday, November 3, 12
  40. Ruby as a Scripting Language Using Ruby as the high-level

    scripting language provides the benefits of Ruby while allowing other languages to handle the lower-level mechanics. Saturday, November 3, 12
  41. Benefits • DSL Creation • Ruby Features • Easy for

    Game Modders • Code Obfuscation no longer a concern • Logic Mixins, Game State Injections, etc Saturday, November 3, 12
  42. mruby • Lightweight Footprint (~500K) • Alternative to Lua •

    Embeddable Implementation • Subset of Ruby Implementation • Easily bridged to C/C++ • No assumption of an OS Saturday, November 3, 12
  43. https://github.com/iij/mruby • Adds Kernel#require • Adds IO • Adds Socket,

    TCPSocket, UDPSocket • Extends String Saturday, November 3, 12
  44. Ruby Engine Initiative • C++ Internals • OpenGL Rendering •

    mruby embedded engine • Development starts next week Saturday, November 3, 12