Using Lua to Build a Component-based Architecture for Game Apps

077b906e1080962b3989c1d598dab852?s=47 Jheng Wei Ciao
August 05, 2013
1.6k

Using Lua to Build a Component-based Architecture for Game Apps

Presented on COSCUP 2013 http://coscup.org/2013/en/

077b906e1080962b3989c1d598dab852?s=128

Jheng Wei Ciao

August 05, 2013
Tweet

Transcript

  1. Using Lua to Build a Component-based Architecture for Game Apps

    半路 / Jheng Wei Ciao
  2. Component Based Architecture

  3. Lua

  4. Pitfalls of Object-Oriented Design ?!

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

  6. Player Enemy WalkableObject Actor CollidableObject

  7. None
  8. FlyableObject Player Enemy Actor WalkableObject CollidableObject

  9. CollidableObject FlyableObject FlyingEnemy Actor WalkableObject How?

  10. CollidableObject FlyableObject FlyingEnemy FlyingActor How?

  11. Pitfalls of IBA Deep and tangled hierarchies Diamond ring inheritance

    Copy-paste code here and there Special cases Magic: don’t touch it
  12. Component-based Architecture Each functionality is a game component Data-driven method

    for objects creation Design Patterns: “Favor composition over inheritance”
  13. Player WalkableObject CollidableObject FlyableObject Enemy WalkableObject CollidableObject FlyableObject

  14. WalkableObject CollidableObject FlyableObject Game Components

  15. WalkingEnemy FlyingEnemy WalkableObject CollidableObject CollidableObject FlyableObject

  16. Don’t use CBA... yet CBA can’t save 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
  17. None
  18. Who Are Using Lua

  19. Advantages of Lua Lightweight Extensible Cross-platform Robust Openness Community

  20. Drawbacks of Lua Most editors don’t support auto-completion code Goodbye

    to debuggers & breakpoints Hello to loggers & print() No excuse for coffee break time
  21. Pitfalls of Lua Naming convention for global variables Do garbage

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

    Boost Luabind depends: template programming
  23. 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
  24. Player Transform BoundingBox Quad

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

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

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

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

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

  31. Interpolator GC 0 255 0.1 1.0 SetAlpha() SetScale()

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

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

    Button Progress Bar
  34. Widgets = Container Widgets Button Render/Update Movement Scale Up/Down Fade

    In/Out Sprite Motion Transform Fade
  35. MainMenu Button Sprite Interpolator Input Events

  36. Lua + CBA = 100% Awesome!

  37. [Launching Xcode] Live Demo

  38. Live Game Apps?

  39. Lua for Game Apps

  40. CBA for Game Apps

  41. Lua + CBA ......?

  42. We’re recruiting one Android engineer

  43. Open Mind, Happy Coding, Make Great Games!