Lua, game state and game loop

前端 未结 9 1288
慢半拍i
慢半拍i 2021-01-31 10:13
  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 fro

9条回答
  •  无人及你
    2021-01-31 10:31

    IMHO Lua scripts are for specific behaviours, it's definitely going to hurt performance if you are calling a Lua script 60 times per second.

    Lua scripts are often to separate stuff like Behaviour, and specific events from your Game Engine logic (GUI, Items, Dialogs, game engine events, etc...). A good usage of Lua for example would be when triggering an explosion (particle FX), if the Game Character walks somewhere, hard-coding the output of that event in your engine would be a very ugly choice. Though, making the engine trigger the correct script would be a better choice, decoupling that specific behavior off your engine.

    I would recommend, to try to keep your Game State in one part, instead of upscaling the level of complexity of keeping states synchronized in two places (Lua and Engine), add threading to that, and you will end up having a very ugly mess. Keep it simple. (In my Designs I mostly keep Game State in C++)

    Good luck with your Game!

提交回复
热议问题