Pages

Tuesday, December 27, 2011

Improvements to my game

Hey Everyone,

Just giving an update to the game I've been developing :)

I successfully created a real time map chunk generator that scans nearby isometric chunk coordinates using a C++ map data set. I designed it on the idea of a central chunk with eight surrounding chunks, I then calculate the isometric coordinates from the camera offset and divide it by the chunk size; shifting it into unit chunk space. After detecting a coordinate change, I then recalculate the central and eight surrounding chunks; generating new ones when they are not found in the map and then once everything is generated I store the new set of chunks in memory to make rendering more efficient. During the generation process I shift the sampling rectangle of the Libnoise engine that I use to calculate the tile biomes in respect to the coordinates of the chunks so that the tiles connect seamlessly with the adjacent chunks. After I got the maths working for the generator, I noticed a pause on the generation which I suspected would happen due to the amount of data generated for each chunk. So I decided today would be the day that I finally implement multi-threading into my game; something I've never actually done before, so I researched a few open source and free multi-threading APIs and stumbled upon the OpenThreads API. I linked the API into my engine and managed to get it to work, but it didn't support processor core affinity which I wanted to use so my map generator would run on a different core. The multi-threading worked perfectly and the map would generate without choking the main thread. Later I discovered that the API was outdated and a much improved version had been moved into a project called OpenSceneGraph as a sub project. So I downloaded the new version and sure enough it supported affinity for cores but for some reason whenever I moved around my map, parts of the map would get corrupted and show tiles where they shouldn't have been. I played around and decided to move back to the older version but for some reason I could never make the linker happy again and I couldn't compile the game. After an hour or two I decided to pull all the code I needed from the library and incorporate it directly into my engine so I could finally compile the game again; I cleaned up a lot of the redundant code it had and brought over the affinity system in the new engine so I could set processor affinity with the older version, I fixed a few bugs with the code and cleaned up the thread killing system too. Finally I upgraded the Mutex class to utilise the critical section that the new code uses to lock memory before making changes. Overall I'm very happy with how it turned out and it's working very well.

After the success with the map generator I felt it appropriate to start working on the isometric tile selection system next. It took a lot of searching to find an algorithm that worked with the design of my map structure but I finally stumbled upon This Site that showed how to calculate isometric coordinates from cartesian coordinates and select tiles. The example was based on Java but thanks to the generic nature of maths I could easily bring it over to C++ and see if I could get it to work. It took a few tries and I had to change the maths slightly so that the coordinates conformed to my map structure but I managed to get isometric tile selection working by the end of the day; just a matter of applying the right offsets in respect to the chunk's position and negating the camera's offset and here is the result :)


Now that I have isometric tile selection built into the engine I feel much closer to the game than I had done before and that I've reached a milestone where I can finally begin implementing game play mechanics into the game. Just to prove to myself that the tiles are really interactable with the mouse, I decided to make a hello world for mouse picking and allow the tile type to change when I click with the mouse and as you can see I'm very happy with it:

That's all I have for today :)
Ashton.

No comments:

Post a Comment