Jump to content
  • Advertisement
Sign in to follow this  

How to determine if a 3D voxel-based room is sealed, efficiently

This topic is 2181 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello there,


I've been having some issues with efficiently determining if large rooms are sealed in a voxel-based 3D rooms. I'm at a point where I have tried my hardest to solve the problem without asking for help, but not tried enough to give up, so I'm asking for help.


To clarify, sealed being that there are no holes in the room. There are oxygen sealers, which check if the room is sealed, and seal depending on the oxygen input level.


Right now, this is how I'm doing it:


- Starting at the block above the sealer tile (the vent is on the sealer's top face), recursively loop through in all 6 adjacent directions

- If the adjacent tile is a full, non-vacuum tile, continue through the loop

- If the adjacent tile is not full, or is a vacuum tile, check if it's adjacent blocks are, recursively.

- Each time a tile is checked, decrement a counter

- If the count hits zero, if the last block is adjacent to a vacuum tile, return that the area is unsealed

- If the count hits zero and the last block is not a vacuum tile, or the recursive loop ends (no vacuum tiles left) before the counter is zero, the area is sealed


If the area is not sealed, run the loop again with some changes:


- Checking adjacent blocks for "breathable air" tile instead of a vacuum tile

- Instead of using a decrementing counter, continue until no adjacent "breathable air" tiles are found.

- Once loop is finished, set each checked block to a vacuum tile.


Here's the code I'm using:



The problem: 


I'm running this check every 3 seconds, sometimes a sealer will have to loop through hundreds of blocks, and a large world with many oxygen sealers, these multiple recursive loops every few seconds can be very hard on the CPU.


I was wondering if anyone with more experience with optimization can give me a hand, or at least point me in the right direction.

    Thanks a bunch.

Share this post

Link to post
Share on other sites

Why do you need to do it continuously? It would only change if vents are opened or voxels are filled/unfilled.


Anyway, close all the vents (treat them as doors) and flood fill each empty tile, connected tiles get the same ID. Repeat (incrementing the ID each time you run out of tiles to fill) until all empty space is filled. When a vent is opened that connects the rooms. If you destroy a wall section and it tunnels into another area then you combine the area IDs, otherwise give it the same ID as the room you tunneled from. You can build a connectivity graph if you want by examining rooms IDs on each side of a vent.


See this thread too http://www.gamedev.net/topic/648766-computational-geometry-algorithms-to-determine-rooms-in-a-dungeon-or-a-building/

Edited by Paradigm Shifter

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!