• Register

How far can you make it? Battle through randomly generated lands and 1000 randomly generated dungeons. Slay monsters, gather resources, and craft new an powerful weapons. All to see just how far you can go. Die in dungeon 999? Start over from one. This is a war of perseverance.

Post news Report RSS World Generation and Rendering

The world generation algorithm has been converted from Java to C++ and integrated into the Torque2D engine. This gives us the ability to access the functionality from Torque Script while leveraging the speed and power of C++.

Posted by on

World generation, and the rending of the world, has been completed. There where a number of errors in the initial conversion of the generation code, most relating to not having my head in C++ and still in Java. I programmed web applications in Java for 15 years, so sometimes it is hard to break the thought patterns. All in all, the issues were not too difficult and integrating the functionality with Torque was a breeze. The randomly generated world is now on the screen in all it’s 32x32 pixel tile glory.


In creating the rendering of the map, I got a chance to use the Torque2D CompositeSprite class for the first time. This beats the old TileMap style of doing things hands down. I still get to work with a single object like the TileMap, but it is much easier to just deal with Sprite objects. Every world is comprised of 10,000 tiles and the new batch render functionality in Torque2D handles that with virtually no slow down at all. It has really been smooth and easy working with the new Torque2D.

One of the things I noticed in the map generation, is that the random number generator in C++ is quite different from the one in Java. In a lot of the lower parts of the map, I would see a lot of random single tiles of a specific type. The way the random world generation works is via setting “seed” tiles of each type at random places in the map and then “growing” those seed tiles in successive loops through the map until all tiles have been filled. I didn't see this kind of single tile proliferation in the Java code. I ended up adding an additional step to go through the tiles and clean out any singles still hanging around. This helped the worlds looks less randomly generated, but I think the worlds from the Java implementation looked better. I may play around with some various random number generators and see if something gives a better distribution of the initial seeds.

Next step will be conversion of the dungeon generation. Stay tuned, and as always, you can find out more at the Bloody Tongue website, or follow use on Twitter.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: