[zscript] Finding the adjacent linedef

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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
kodi
 
 
Posts: 1361
Joined: Mon May 06, 2013 8:02 am

[zscript] Finding the adjacent linedef

Post by kodi »

I have a pointer to a line (through an iterator). I want to as efficiently as possible check if another line connected to one of it's two vertices has the same angle/normal. How do I find the next or previous line?
(alternatively, some other way of achieving the goal is fine too)
gramps
Posts: 300
Joined: Thu Oct 18, 2018 2:16 pm

Re: [zscript] Finding the adjacent linedef

Post by gramps »

I think your only option is to look at every single line, check if it shares a vertex, then check the angle.

But, depending on what you're doing, it might be good enough to only check the lines in the same two sectors as the first line. Or, check those two sectors and any neighboring sectors. That could still miss a few pairs of lines that are connected and have the same angle, but maybe those pairs of lines aren't important to you (if you're trying to figure out if you should put a decal there, or something like that, two adjacent lines not sharing a sector or in neighboring sectors might not matter to you).

If you really need to unconditionally find any neighbor lines with the same angle, it might be worth it to precompute all matching pairs when the level loads, or at map init time.
User avatar
kodi
 
 
Posts: 1361
Joined: Mon May 06, 2013 8:02 am

Re: [zscript] Finding the adjacent linedef

Post by kodi »

Or, check those two sectors and any neighboring sectors.
How can I get neighboring sectors in a cheap way?
if you're trying to figure out if you should put a decal there, or something like that, two adjacent lines not sharing a sector or in neighboring sectors might not matter to you)
What I want to do is only exclude lines that part of an unbroken segmented line from a particular function call.
If you really need to unconditionally find any neighbor lines with the same angle, it might be worth it to precompute all matching pairs when the level loads, or at map init time.
Since there doesn't seem to be a magic trick or something I've overlooked available, I'll probably do this.

Would be nice if the vertex struct contained pointers to any lines that connect to it!
gramps
Posts: 300
Joined: Thu Oct 18, 2018 2:16 pm

Re: [zscript] Finding the adjacent linedef

Post by gramps »

You should be able to get the first two sectors by looking at the first line's sidedefs, and then get neighboring sectors by doing the same thing with all the lines in those two sectors. I think the only common thing this would miss would be something like two separate rooms sharing one corner, assuming you want to count angle and opposite angle as being the same.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49230
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [zscript] Finding the adjacent linedef

Post by Graf Zahl »

The blockmap may be more efficient for finding an adjacent line. You only need to iterate through the block containing the vertex you want to check.
User avatar
kodi
 
 
Posts: 1361
Joined: Mon May 06, 2013 8:02 am

Re: [zscript] Finding the adjacent linedef

Post by kodi »

A blocklinesiterator centered on the vertex with some extremely low radius you mean?
Edit: yeah that works, but apparently you can't nest blockline iterators :P
Post Reply

Return to “Scripting”