My Message close
GAME JOBS
Latest Jobs
spacer View All     Post a Job     RSS spacer
 
May 19, 2013
 
Sony Computer Entertainment America LLC
Sr. Network Systems Engineer
 
Amazon Game Studios
Sr. Game Designer
 
Treyarch / Activision
Technical Animator
 
Amazon Game Studios
Quality Assurance Manager
 
Amazon Game Studios
Lead 3D Environment Artist
 
Amazon Game Studios
Game Graphics Engineer
spacer
Blogs

  Designing a Component-based Architecture in Lua for Game Apps
by Jheng Wei Ciao on 01/16/13 08:30:00 pm   Expert Blogs   Featured Blogs
2 comments Share on Twitter Share on Facebook RSS
 
 
The following blog was, unless otherwise noted, independently written by a member of Gamasutra's game development community. The thoughts and opinions expressed here are not necessarily those of Gamasutra or its parent company.

Want to write your own blog post on Gamasutra? It's easy! Click here to get started. Your post could be featured on Gamasutra's home page, right alongside our award-winning articles and news stories.
 


Hi there, I'm Wei Ciao. Before becoming an iOS developer, I was a game programmer working for a company making MMO genre games. My primary skills and fondness in programming languages are C++ and Lua. As a game developer, I’ve dug deeply in Lua and developed a game framework based on it.

Here is the combination of programming languages utilized in my game apps:

  • C++: General abstract framework can be used in cross-platforms.
  • Objective-C: Handling iOS platform-specific details and OpenGL ES implementation.
  • Lua: Data description. User interfaces. Game logic. Anything else.

With Lua, I can easily describe a game object simply based on components. In the example above, the game object, Player, is composed of 3 components, which are:

  • Transform: In charge of translation, rotation and scaling in game world.
  • Quad: A simple quad drawn in 2D plane to represent the object.
  • BoundingBox: Collision detecting in box-shaped.

 

One object can comprise several components, however, not every component needs to be updated and/or rendered. Unlike traditional object-oriented architecture, in component-based architecture we can update and render the game objects accordingly.


What we called a game object, actually is nothing more than a container. Game object doesn’t need to be involved in how specific game components function. It merely contains and manages them in an abstract way and all tasks are assigned to its components. Powers are delegated to the game components.


For example, when a game object consists of Interpolator game component, we can interpolate a variable between the starting value and the ending value, and then apply it to image alpha or scaling. Interpolator will make your objects and interfaces look bouncing and vivid if used properly.

As for memory management, Lua takes no responsibility. All dynamically memory-allocated objects are created in C++ and passed-by-reference for Lua to utilize. Lua only gets pointers. Lua could perform complex memory management tasks, but a clear separation between C++ and Lua helps making memory management less error-prone.

Lua is lightweight, robust and cross-platform. Programming in Lua can save you a lot of compile-time for source files, and the coding process has a quick turnover rate. The higher turnover rate is, the more iterations you can get. In the process of game development, more iterations help increasing work efficiency and improving game quality.

If you are wondering how it works in game apps, you may check out my latest game Bonnie's Brunch 2 and upcoming Jade Ninja.

Live well, happy coding and make great games! :D


Download full slides
https://speakerdeck.com/halflucifer/designing-a-component-based-architecture-in-lua-for-game-apps

Tutorial: 
Introduction to Component Based Architecture in Games 


(The article has been posted originally on Monkey Potion dev blog)

 Follow me on @MonkeyPotion

 
 
Comments

Jack Mahogany
profile image
Thanks for sharing! Are there any other links you have that have helped you with component-based architecture? (The two at the bottom were great) Keep up the good work!

Jheng Wei Ciao
profile image
Glad you like it!

I learned my component-based architecture knowledge mostly by books, such as Game Programming Gems series. There are several great articles in GPG series cover component-based architecture very well.


none
 
Comment:
 




 
UBM Tech