Development Update – Lighting and Saving

I am doing my best to avoid reinventing the wheel. This is quite obvious with my extensive use of third party libraries to help with nearly all aspects of the game engine – from rendering using SFML to randomly generating worlds using ANL. This backfired on me this past week.

At first I set out to work on the world lighting. After doing some research I stumbled upon Let There Be Light (LTBL), which helps with basic lighting and shadows. I began incorporating it into my game engine and quickly found that it had some fundamental bugs. I posted to the linked forum post above in hopes that the developer would fix these issues. I was pleasantly surprised at how quickly the developer fixed the issues. Not long after resuming I once again got caught up on something and had to wait for the developer’s response. The developer was great about replying and I’m really appreciative about it but I do doubt that this was the right path.

I know what I want for the game’s lighting. LBTL gets me about 70% of the way there with minimal effort but I have to tweak and bend the code to my design. This is going to take a great deal of time and in the end it may have been faster to just throw together my own lighting system. I may still do this using LTBL as an example.

There was progress made for lighting though. I setup a light and hull (shadow casting) components. This means that entities can have a light source attached to them and/or have a shadow casting convex hull attached to them. Here is an example with a hull attached to the player, which needs much work.

During my downtimes between the lighting, I would work on the world saving. I am using boost for much of my game engine and decided to use the boost serialization library to do all saving/loading. This library has some really cool features but these features come with a heavy cost in code complexity. Before too long I realized that I did not need these features and so I was back to square one. I decided to do my own and within no time I had the basics working.

I started doing some testing. First I tried a small world of 100×100 tiles was saved to a 73kb file; this worried me. I want to have huge 8000×2000 worlds at least. So I tried a world at this size… 120MB! Additionally it took about 4-5 seconds to save. This is good for a first run but it is unacceptable and needs some serious optimization.

First I’m going to do compression on the data before saving it to disk. Fortunately this data is very compressible given that it is extremely repetitive. I tested this by zipping the small world save file. It went from 73kb to 1kb. This is promising! This helps with disk size but it is going to hurt the time. My plans for fixing the time is to reduce saving data that hasn’t changed. Right now the entire world is saved every time but the reality is that only a small portion of the world is going to change in a minute. One of the cheapest ways to do this is the same way Minecraft does it – split the world up into separate files.

This week I’m going to work on finishing up the saving/loading, which is going to take a little longer than I initially thought. What doesn’t though? If things go well then I will get back to working on the lighting. Before too long I’ll be able to have some visual to show off!

Leave a Reply