Even though adding scripting language to the engine was in DEEP FUTURE plans, once I realized how easy it would be to just rewrite one text line, hit enter and spawn particles with slightly tweaked velocities instead of recompiling the whole game again I finally decided that that time had come. Ladies and gentlemen, Brace yourself for…
The Story of adding Lua:
Adding lua itself was the easiest thing, simply add statically native lua lib and that was it, then I used ConsoleWindow template found in imgui_demo.cpp and suddenly I could use Lua console within the game itself :D
The real pain, unfortunately, had yet to come. To use it to interact with the engine and with a world eventually, I needed to register and hook some C++ methods to be accessible by lua. I immediately added ND_INFO() to print messages using native lua lib. So far so good. Then I realized that’s too much of the work and that I would use some third-party libs that would bridge that gap for me.
And with the biggest tool in the shed I went: SWIG.(Simplified Wrapper and Interface Generator). It generates C++ files called e.g. classname_wrapper.cxx or something. special method in those files needs to be called and then you have working lua-c++ interface Yay…
For a while my desire was satisfied. Then I though about some more simple or elegant method (which was the begging of the end (my end)). I searched and found luabind, an awesome library that seems to provide simple interface to easily bind classes to lua as well (btw SWIG can do that too). I tried to compile it with the engine but compiler was so nice and politely informed me that I hadn’t read the READMEs.
Well this lib seems to need a Boost?. That was actually my first encounter with the vast library of libraries so I naively thought I could just include it in my project and guess what… It didn’t work. Up to this day I still haven’t find a way to successfully import it (“one day I swear I will beat you!”). With this option out of the way I tried the deboostified version of luabind for which the linker found the courage to tell me about his inability to found some symbol definition which I was deeply sure was happily contained in one cpp file. And so I dropped the idea of using luabind completely… Farewell.
In the end after possibly 1 week of trials and errors I settled with an incredibly simple lib LuaBridge that doesn’t need anything and uses templates. What a great adventure! LuaBridge helped me to bind glm::vectors to lua as well as method World::spawnParticle() and with that I could finally make a loop and spawn as many goddamned particles as I wanted. The End (at least for now)
And now other important XMas presents:
Finally the long awaited Items have arrived:
Items have unique string ids (uint64_t hashed versions are used to speed up the lookup time) using FNV-1a
Added EntityItem which represents item dropped in the world
Apart from inventory system also HUD system was made:
HUD is a GUIWindow to which you can register GUIEntities
GUIEntities have nothing to do with world and can represent for example HealthBar, ManaBar, ActionInventorySlots, CraftingInventory, ChestSlots …
It’s important to note that its mandatory for gui system and world system to be “decoupled” (the world shouldn’t care if HealthBar is showed) (on the other hand GUIEntity needs to communicate with World/entities)
-> This is due to the fact that in the future, there might be multiplayer where server will definitely not care about some puny pathetic GUI stuffAnd about Christmas, SnowmanEntity can be spawned using pumpkin stacked onto a pile of snow. Slippery ice blocks were added as well. That’s all for now. Happy XMAS.
In the pic: ItemEntities circling around the player. You wouldn’t have guessed how easy it is to get to the stable orbital position :D