top of page

Internship - Week 2 - Room generation

Hey there,

This week I started off by having a look at the random room generator. This generator creates a number of rooms depending on the parameters given to the generator. The algorithm will pick a random point on the map and try to place a room there, if the new room is overlapping any other room it cannot be placed and the algorithm will pick another random point to spawn a room.If the new room is not overlapping any other room, it can be placed and the algorithm will change the tiles of which the room will consist.

I spent some time trying to restructure and optimize the code for this generator. When I started out this code was using a two-dimensional array of booleans for every tile on the map. This was used to check if a spot was empty and available for spawning a room. I tried to change this so it would use some very simple AABB (Axis-Aligned Bounding Box) collision detection (http://tinyurl.com/nmbzmyj). The AABB works well but there are some disadvantages that the array doesn’t have. For every room added you need to do another AABB check which takes time, so when you have a large map with a couple hundred rooms, this is going to be quite slow, unless you’re using something like a quad tree (http://tinyurl.com/ol38llw). The array doesn’t have this problem, you only need to check the spot where the room is going to be. With a maximum room size of 25 tiles, this will be a lot quicker than doing a couple hundred Collision Checks. So in the end we didn’t change to using AABB collision checks, but this wasn’t going to stop me from making the generator faster.

The generator would check every tile the new room was going to contain. With the size constraints of the rooms being a minimum size of 5 tiles and a maximum size of 25 tiles, this is obviously unnecessary. The code could be changed so it would only check every 5th tile and then it would still find every room it is overlapping. This made the code a lot faster.

Left: every tile being checked, Right: every 5th tile being checked.


Featured Posts
Recent Posts
Archive
Search By Tags
No tags yet.
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square

Lars Temmink

Game Programmming Portfolio

bottom of page