Telling sectors apart once they're joined

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Duvo
Posts: 47
Joined: Thu Dec 26, 2019 4:17 am

Telling sectors apart once they're joined

Post by Duvo »

Hi guys, I have an issue I can't solve for the life of me. I have a script that identifies sectors by id and then compares their geometry, but I found out the hard way that if a person decides to join two sectors together in doom builder, you can have two sectors under 1 index, with separate characteristics. What I'd like to know is, once you join two sectors together, is there still a way to get them by some kind of reference?
User avatar
phantombeta
Posts: 2195
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Telling sectors apart once they're joined

Post by phantombeta »

They're not actually two sectors under one index, merging sectors in Doom Builder makes a single sector made up of two separate shapes. There's no built-in way to easily tell these separate shapes apart inside GZDoom.
User avatar
fakemai
Posts: 408
Joined: Mon Feb 12, 2018 12:26 am
Location: Australia

Re: Telling sectors apart once they're joined

Post by fakemai »

I'm not clear what the purpose of the script is. The two shapes are one sector, what one does the other does, and you can't break it apart in-game. If you were trying to do something like an area calculation it might be possible to figure out the individual shapes from the sector struct since it knows what lines (and then vertexes and sidedefs) are associated with it, but I expect some map design tricks or plain malformed maps may disallow this.
User avatar
Duvo
Posts: 47
Joined: Thu Dec 26, 2019 4:17 am

Re: Telling sectors apart once they're joined

Post by Duvo »

It's an edge walking algorithm. Normally i could walk the outer hulk of the sector and then walk the inner holes separately and I'd know that the inner ones were holes because there would still be vertices to track once i arrived at the start, but if two outer hulls are separate it will count the second outer sector area as a hole in error. It's a puty there isn't, but that's a limitation of wads themselves i suppose. I will try something else
User avatar
phantombeta
Posts: 2195
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Telling sectors apart once they're joined

Post by phantombeta »

You can find the sector shapes by walking the lines, you just need to determine which polygons are within which afterwards- one polygon inside the other is a hole, polygons at 0 depth are separate shapes.

Polygons can be nested deeper than one level deep, in which case, even depths are actually fully separate shapes and should be hoisted up to depth 0. Then these shapes should themselves be checked for any shapes that need to be hoisted up too.

The only issue with this is that a lot of early Doom maps are malformed. More modern ones tend to be fine, but older ones often have unclosed sectors, even the IWAD maps. Some of these are mistakes where a line was made that added an extra vertex instead of actually closing the shape, but some are indeed missing whole lines needed to close the shape.
User avatar
fakemai
Posts: 408
Joined: Mon Feb 12, 2018 12:26 am
Location: Australia

Re: Telling sectors apart once they're joined

Post by fakemai »

I think older versions of doom2.wad had an unclosed sector in Courtyard, the one with the cell pack, but even the more recent ones have that door that has two-sided lines on the side walls into void space. Anyway it shouldn't be too hard to determine if a shape is unclosed at least, and you can filter out lines that are internal just by checking if both sidedefs point to the sector. Attached an example of some slightly unusual sectors arrangements, all of the sectors use a unique flat and the marble one is part of a closed room outside, but an even better trial for what you're doing would probably be something like 10 Sectors or any other mapset that has to work to such strict limitations.
Attachments
stupid.wad
(16.2 KiB) Downloaded 3 times
User avatar
Duvo
Posts: 47
Joined: Thu Dec 26, 2019 4:17 am

Re: Telling sectors apart once they're joined

Post by Duvo »

phantombeta wrote: Sat Nov 08, 2025 4:45 pm You can find the sector shapes by walking the lines, you just need to determine which polygons are within which afterwards- one polygon inside the other is a hole, polygons at 0 depth are separate shapes.

Polygons can be nested deeper than one level deep, in which case, even depths are actually fully separate shapes and should be hoisted up to depth 0. Then these shapes should themselves be checked for any shapes that need to be hoisted up too.

The only issue with this is that a lot of early Doom maps are malformed. More modern ones tend to be fine, but older ones often have unclosed sectors, even the IWAD maps. Some of these are mistakes where a line was made that added an extra vertex instead of actually closing the shape, but some are indeed missing whole lines needed to close the shape.
I was afraid of that.. I had already considered that a map could have irregular geometry, especially if it was edited with a text editor. In the future I may include a cleanup script or at least an audit.

After mulling about my problem for the weekend I think I might have a solution. I could run a constrained Delaunay triangulation algorithm on the map, sector to sector. Then, I flood fill each area to make my subcomponents. After that it's a matter of drawing a border strictly around those shapes and then using a handful of formulas to find out what shapes exist in others. I think I'll still have trouble identifying holes when sectors with the same ids overlap multiple times but it's the best I've got right now
Post Reply

Return to “Scripting”