Level Generation is Very Slow
Author: Logan Audrain
This week, I got the map expansion working. It was a good moment to watch the map grow for the first time after spending so long working on the level generator. There was a massive problem, though. The whole game froze for about a second the first time it expanded, and would freeze for longer and longer periods of time each time it happened. After a while I of testing, I came to the relazation that because of the way the map expands, by adding to the outer ring of the map each time, the level while increasing linearly in size is actually placing exponentially more tiles each time it grows. For example, if the map starts off as a 100x100 grid with a total of 10,000 tiles and is increasing by 100x100 every expansion, it expands into a 200x200 grid with 40,000 tiles after the first expansion. Even though the dimensions grow linearly by simply adding to the original size, very quickly the level generator is trying to spawn so many tiles that it simply can't handle it.
So what's the solution? Well, efficiency in a game is a sort of death by a 1000 cuts, and therefore, the solution requires about 1000 bandages. The first thing I did is spread out the creation of tile info onto worker threads, which allowed much of the heavy work of calculating transforms for thousands of tiles to be taken off the main game thread. The second thing I did is the tiles no longer all spawn at once. Game objects in unreal must be spawned on the game thread so multi-threading was not an option, so I instead created a struct that holds spawn data for tiles, and a queue for that data to be drawn for. Queues in unreal can be set to be "multiple writers, one reader" which means all the worker threads can add data to the queue at the same time that the game thread is removing data from the queue and it is completely thread safe. When worker threads add data to the queue, the "Tick" function for the generator is switched on, and the generator will remove a set amount of tiles per tick from the queue and spawn them into the level. If you've seen version 0.0.3 of our game, then you've seen this process happen at the start of the game as all the tile loading is spread out across several frames. The final solution to the problem is to remove the expoential growth problem all together. Instead of adding rings around the map, the generator will instead spawn set chunks into the map. This solution is currently in the works.
Get Real-Time Skeletons
Real-Time Skeletons
Status | In development |
Author | TailByte |
Genre | Strategy |
Tags | Hex Based, Indie, Medieval, rts, Singleplayer, Unreal Engine |
More posts
- Issues with AI 3: Return of the Electric Sheep2 days ago
- More Command things2 days ago
- Widget Component Misalignment in RTS UI2 days ago
- Issues with AI 2: Electric Boogaloo8 days ago
- Level Generator Ramp Placement8 days ago
- UI Timer Trouble10 days ago
- Issues with AI15 days ago
- Basic Level Generator15 days ago
- Pause Menu15 days ago
Leave a comment
Log in with itch.io to leave a comment.