I have a 2D infinite tile map game in which the player can place floors and walls to construct "buildings".
I'm trying to think of an efficient way to determine whether the player is inside a "complete" building, meaning it's fully enclosed by walls and a door.
Normally, the logic isn't difficult since it's easy to tell if the walls fully encircle an area - but in the case of an infinite map, the "building" may extend into unloaded areas of the game.
For example, if a player makes a complete rectangular building, 10x100 tiles long, only some of the chunks it covers will be loaded at once.
I have a few ideas:
- If a player is near candidate walls, follow them and load all necessary chunks to check completeness. This would work, but could load a moderate number of unused chunks.
- Cache a list of "complete" buildings as they're completed. So option #1 is applied only as the player builds the building. This would have to saved/loaded, and updated when integral walls/doors are removed, so it trades efficiency for a little overhead, which might be OK.
- Using a different metric to determine "indoors". I can't think of one though.
Anyone have any other ideas? Has this ever been implemented somewhere else, something I can at least use as an example?