• Create Account

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

### #1NigelMan1010  Members

116
Like
0Likes
Like

Posted 02 November 2013 - 01:35 PM

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:

http://pastebin.com/NimyKncC

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.

5832
Like
0Likes
Like

Posted 02 November 2013 - 02:17 PM

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.

Edited by Paradigm Shifter, 02 November 2013 - 02:18 PM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.