Today’s aim was to start implementing some of the ideas I had to clean-up the lua code end users will code using. My goals were:
- To create a set of globals to access common parts of the engine. So
assets
to do any asset loading, andrenderer
to draw things for example. - Switch to a reference counting system for loading assets.
I’ve been putting the 2nd one off for days now as I was worried removing a system that works well could break the codebase to the point where I wouldn’t be able to repair it. However I think my anxiety on the subject was a bit of an over reaction.
It took me 3 hours to make the changes in the end, and it works well. Essentially this means instead of lua passing a string nickname to a loaded asset, the asset manager gives lua psudo-pointer style integers instead. So the following:
game.assets.load\_texture("texture1", "texture1.png", 0, 0)
becomes:
texture1 = assets.load_texture("texture1.png", TX_RGBA, TX_REPEAT)
Where texture1
is an integer (usually 0 if its the first texture loaded). And TX_RGBA
plus TX_REPEAT
are enum flags.
When lua wants to use an asset, it sends an integer for lua to store as a variable. As this stops us using a string every time we want to refer to an asset, it cuts down the bandwidth used in cross-talk between languages, which is a nice benefit. However it also helps do something very important in that it’s vastly easier to understand.
To me one of the main pillars of Xentu needs to be approachability. I want people to see examples like the above, and be at-least able to guess at what it does. In the first example you can see it’s loading a texture, but there is no hint as to what each of the arguments do. In the second it looks like we need to pass a filename, something to do with colour, and something to do with repeating. So the 2nd one clearly works better.
On a personal note, it’s a big relief to have gotten over this hurdle. I’ve been stressed to the point where I didn’t want to even start coding in fear of messing up, but like I said before it looks like I was thinking too hard.
I think keeping a devlog like this is probably the best port of call, and perhaps maybe publishing a summary of these once a week should give me an outlet to show anyone who cares that I am making progress.
Next item to check off is finishing the Lua class templates such as Sprite, and getting the final elements of the new Lua concept file completed.