• Register
Post news RSS Terrain and optimisation

Added terrain / loading maps from .pngs, optimised code, cleaned up user interface.

Posted by on

I added terrain (currently only trees but more can be added) and implemented loading maps from .png files.

I also optimised some of my code. Originally l was getting some problems with pathfinding, so I made the code pretty simple, basically looping through the entire map array 5-60 times. When the map was 30x30, this wasn’t too bad, but if I wanted to increase the size of the map, both the size of the array my pathfinding algorithm looped through, and the number of times it looped, increased significantly, and the game would crawl to a halt. There were a few other functions like this, such as the map updating method which basically deleted and rebuilt the map 60 times a second, which weren’t a problem until now.

That’s all fixed now, and the game can “comfortably” support maps up to 2048x2048, although a full map takes up about 500mb of ram. I tried a full 4096x4096 map, but the game crashed after filling up 1.5gb of ram. I doubt that would be a problem though, as it would take around 1600 turns, or 9 hours, to cross from the top left to the bottom right corner at that size, so I doubt anyone will want to play. Still, if you DO want to, you may be able to. Albeit with no AI, and a fairly empty map, at least for now. Maybe I can make some mmo/grand strategy-esque mode.

Moral of the story, clean up your code.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.