Well, it’s been a really, really long time since my last post. The excuse is great this time, I swear! I got a job as a junior graphics programmer with Traveller’s Tales in the UK mid last year! It’s been amazing so far, it is so great to be able to work on a AAA game engine that supports multiple games on multiple platforms. I’ve learned sooo much, while also realising just how much I still have to learn (which I’m happy about, by the way, life would be boring if we stopped learning).
Returning to full time employment after a few months of unemployment (not to mention moving countries and now being in a long distance relationship) has been part of the reason for my lack of work on my little project. But the biggest reason is that I signed a non disclosure agreement as part of this new job and I’ve been too scared that I’ll accidentally break it by taking too much inspiration from how things are done at work.
However I think I’m at a point now where I understand enough that I can venture off on my own things without borrowing from what I see at work. I’m getting a more solid grasp on rendering concepts and how different engines fit all the pieces together.
Also I’ve been itching to take some time to really solidify my understanding of how all the pieces of a rendering engine are built. I don’t always get time for that at work when I’m bug fixing or adding tweaks to really specific areas, plus I learn better by doing and trying code, rather than just reading already existing code bases (which I’m obviously doing a lot of now).
It has been interesting looking at my code again after 8 months of extra experience. Some of it now seems like “baby’s first code”, but I have to remember that less than a year ago it didn’t seem like that at all. So I’m going to remind myself to keep explaining things even if they seem obvious, so that past me would be able to understand.
Jumping right back into it – I left off last time after having implemented a bit of a ResourceManager for myself. I can already see that there are some problems with this, but to be honest I’m writing this engine (at least these days) so I can practice being a better graphics programmer, so creating a robust, efficient resource pipeline is not really as important at the moment.
I did at least decide that I needed to implement what I mentioned last time – moving all my existing resources into the resource manager, and modifying it so that I can load and unload resources by level, rather than all of them hanging about in memory from the moment the game opens.
I think the biggest change I made here was to change my resource storage map to be an array of maps – one for each level. Then at the beginning of a level I can load everything I need for that level, and at the end of a level I can unload it again (though right now I doubt I’m unloading anything, see notes below). As I’m typing this though – I don’t think I really need this whole array, as I should never have resources for all levels loaded at the same time (maybe I’d want to have a loading screen level present while I’m loading in data for the next level, for example, but that’s about it). Hmm. I will need to revisit this I think.
I also created a Texture class that really just handles loading in a texture and separates that out a bit from the Sprite component (which is good, because textures are used for so many things apart from sprites – render targets, 3d meshes, etc). And I separated the font loading code out from the Font Component, though it still isn’t very neat and I think it could do with a bit more of a tidy up.
Random thoughts while doing all this: scoped enums (enum classes) are not implicitly convertible to ints as they are strongly typed. Irritating. At the moment I am casting them all over the place, but that isn’t very neat, so I might have to find another way of doing this. Namespaced regular enums? More research required about what is best.
All these raw pointers are making me nervous – I think I’m leaking memory all over the place at the moment, and it isn’t clear which class is responsible for which piece of memory. I think my next task will be converting them all to shared_ptr or something similar. I’m not super familiar with shared_ptr at the moment – will they cause some form of garbage collection to happen when I’m no longer referencing something? That doesn’t seem ideal if it happens mid-game. Perhaps I need to make sure the ResourceManager is in control of all the memory and also chooses when to delete things.
I sure am copying a loooot of data as I try to put things into the ResourceManager. This is bad, I should really be moving this data I think. Or just passing pointers once I no longer use raw pointers? Another task for next time.
Then I think GetResource can return a pointer, as I think it is making a copy of the resource at the moment each time I call it. Ew 😦
Right, it looks like I use FreeImage to allocate memory for my textures, but I am not releasing this memory at any point that I can see. I hope there’s a destructor somewhere in FreeImage that’s handling it, but I would like to be able to release the data for my textures when I unload a level.
Currently I’m loading all textures as GL_RGBA, but I’m sure at some point in the future I will want some different formats. This will definitely need overhauling as my project grows. To be honest at some point I’d love to write my own texture loading library anyway.
Anyway, after that wall of text I think I’m done for a bit. You can check out my code on GitHub, and please feel free to ask any questions you have, or let me know what you think about any of my decisions. Advice is always welcome 🙂