Lua, game state and game loop

topright gamedev picture topright gamedev · Apr 21, 2010 · Viewed 11.8k times · Source
  1. Call main.lua script at each game loop iteration - is it good or bad design? How does it affect on the performance (relatively)?

  2. Maintain game state from a. C++ host-program or b. from Lua scripts or c. from both and synchronise them?

(Previous question on the topic: Lua and C++: separation of duties)

(I vote for every answer. The best answer will be accepted.)

Answer

Chris Becke picture Chris Becke · Apr 21, 2010

My basic rule for lua is - or any script language in a game -

  • Anything that happens on every frame: c++
  • asynchronous events - user input - lua
  • synchronous game engine events - lua

Basically, any code thats called at >33-100Hz (depending on frame rate) is C++ I try to invoke the script engine <10Hz.

Based on any kind of actual metric? not really. but it does put a dividing line in the design, with c++ and lua tasks clearly delineated - without the up front delineation the per frame lua tasks will grow until they are bogging processing per frame - and then theres no clear guideline on what to prune.