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

Designing a Component-based Architecture in Lua for Game Apps

077b906e1080962b3989c1d598dab852?s=47 Jheng Wei Ciao
January 14, 2013
1.9k

Designing a Component-based Architecture in Lua for Game Apps

077b906e1080962b3989c1d598dab852?s=128

Jheng Wei Ciao

January 14, 2013
Tweet

Transcript

  1. Designing a Component- based Architecture in Lua for Game Apps

    半路 / Jheng Wei Ciao
  2. Pitfalls in Object-Oriented Design ?!

  3. Traditional OOD Object-Oriented Design Class Inheritance Virtualization Polymorphism Inheritance-based Architecture

  4. Player Enemy

  5. Actor Player Enemy

  6. Actor WalkableObject Player Enemy

  7. CollidableObject FlyableObject Player Enemy Actor WalkableObject

  8. CollidableObject FlyableObject FlyingEnemy Actor WalkableObject How?

  9. CollidableObject FlyableObject FlyingEnemy FlyingActor How?

  10. Pitfalls in IBA Deep and tangled hierarchies Diamond ring inheritance

    Copy-paste code here and there Special cases “Warning: don’t touch this!”
  11. Component-based Architecture Each functionality is a game component Data-driven method

    for objects creation Design Patterns: “Favor composition over inheritance” Game Engine: Unity 3D
  12. Player WalkableObject CollidableObject FlyableObject Enemy WalkableObject CollidableObject FlyableObject

  13. WalkableObject CollidableObject FlyableObject Game Components

  14. WalkingEnemy FlyingEnemy WalkableObject CollidableObject CollidableObject FlyableObject

  15. Why Lua?

  16. Advantages in Lua Lightweight, extensible, cross-platform Robust Freedom Simply love

    it Other programming languages?
  17. Drawbacks in Lua Most editors don’t support auto-completion code Goodbye

    to debuggers & breakpoints Hello to loggers & print() No excuse for coffee break time
  18. Don’t use CBA... yet CBA can’t save the (your) world

    OOD can do good things too Don’t make everything a component Leave messy code alone You might need an editor or tool
  19. Pitfalls in Lua Naming convention for global variables Do garbage

    collection manually Don’t forget to compile scripts & strip debug info
  20. My Lua Trilogy Lua 5.1.5 Luabind 0.9.1 Time-saver & OO-like

    Boost Luabind depends: template programming
  21. My Programming Trilogy C++ Generic framework Objective-C iOS platform-specific OpenGL

    ES implementation Lua Data description Game logic 10% 65% 25% C++ Lua Objectitve-C
  22. Basic Architecture & Components

  23. Player Transform BoundingBox Quad

  24. Meet Powerful ‘Table’ Player = {} Player[“Transform”] Player[“Quad”] Player[“Transform”]:SetTranslate(50, 100)

    Player[“Quad”]:SetSize(120, 120)
  25. None
  26. Traditional OOP Game Objects Update #1 #2 #3 #4 #5

    Game Objects Render #1 #2 #3 #4 #5
  27. Component-Based Architecture Game Components Update #1 #2 #3 #4 #5

    Game Components Render #1 #2 #3 #4 #5
  28. None
  29. None
  30. Game Object = Container Game Object Transform Bounding Sprite Motion

    StateMachine Timer
  31. Object Factory Game Component Templates Game Object Templates Game-based

  32. None
  33. Interpolator GC 0 255 0.1 1.0 SetAlpha() SetScale()

  34. Memory Management Lua Game Object Transform Sprite

  35. Memory Management C++ Transform Sprite ...... Lua Game Object Transform

    Sprite
  36. User Interfaces & Widgets Widgets Button Picture Text Number Radio

    Button Progress Bar
  37. Widgets Functionalities Widgets Button Render/Update Movement Scale Up/Down Fade In/Out

  38. Widgets = Container Widgets Button Sprite Motion Transform Fade

  39. MainMenu Button Sprite Interpolator Input Events

  40. Live Demo

  41. [Launching Xcode]

  42. Live Game Apps?

  43. 《Bonnie’s Brunch 2》

  44. 《Jade Ninja》 Jan. 2013 Coming Soon

  45. If you are into Lua... Step 1) Data description/serialization Step

    2) User interface Step 3) Game logic Warning: Don’t use Lua for everything
  46. Live Well, Happy Coding, Make Great Games!