Duke4.net Forums: Determining closeness to a wall - Duke4.net Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Determining closeness to a wall

User is offline   Zaxtor 

#1

You know sometimes new codes emerges when Eduke32 updates.

How about we try to add ifwalldistl xxxx { do something else } like when the actor get soo close to the wall and then does something else.
0

User is offline   Hendricks266 

  • Weaponized Autism

  #2

iffloordistl and ifceilingdistl have been around since the DOS days because they are basically the same as

    getflorzofslope sprite[THISACTOR].sectnum sprite[THISACTOR].x sprite[THISACTOR].y temp1
    subvarvar temp1 sprite[THISACTOR].z

    ifvarl temp1 0
        mulvar temp1 -1

    ifvarl temp1 <value>
    {
        // do whatever
    }


Modern CON is powerful enough that you can make your own ifwalldistl with a whilevarvarn loop and a little math to calculate the shortest distance between the sprite point and the wall line segment. The key question is: Are you counting redwalls or not? Maybe only masked and blocking redwalls?
0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#3

Calculating the distance from walls is way more complicated. And like Hendricks pointed out, it raises the questions of how to achieve the effect, or what counts as a wall or not. With iffloordistl/Ifceilingdistl the game merely calculates the difference beetween the the z coordinates, and it has some flaws compared to a real 3D engine.
0

User is offline   Helixhorned 

  • EDuke32 Developer

#4

View PostHendricks266, on 03 January 2015 - 09:28 AM, said:

Maybe only masked and blocking redwalls?

That's indeed the central question -- which semantics do you want for your new "command" exactly? As Hendricks noted, it makes little sense to add commands when they can be emulated relatively efficiently with existing functionality. I'll just point out an inaccuracy in Hendricks' reply and mention an existing related command.

Quote

iffloordistl and ifceilingdistl have been around since the DOS days because they are basically the same as

    getflorzofslope sprite[THISACTOR].sectnum sprite[THISACTOR].x sprite[THISACTOR].y temp1
    subvarvar temp1 sprite[THISACTOR].z

    ifvarl temp1 0
        mulvar temp1 -1

    ifvarl temp1 <value>
    {
        // do whatever
    }


Not quite. iffloordistl and ifceildistl consult the actor[].floorz and actor[].ceilingz members, respectively, and scale the number to compare with 256. That is, a unit for these commands
corresponds to 256 Build z units, or 16 Build x/y units. Here's the relevant excerpt from gameexec.c:

        case CON_IFFLOORDISTL:
            insptr++;
            VM_CONDITIONAL((actor[vm.g_i].floorz - vm.g_sp->z) <= ((*insptr)<<8));
            continue;

        case CON_IFCEILINGDISTL:
            insptr++;
            VM_CONDITIONAL((vm.g_sp->z - actor[vm.g_i].ceilingz) <= ((*insptr)<<8));
            continue;

----------

CON (since Duke3D) already has a conditional ifawayfromwall. What it does is to check whether each of the four points located at an offset of (+-108, +-108) Build x/y units from the sprite is in the same sector as the sprite. Sadly, that's probably too limted for your needs: there's no way to use a different distance, and white and red walls are implicitly handled the same.
2

User is offline   Helixhorned 

  • EDuke32 Developer

#5

Thinking about it some more, I came up with an implementation using clipmovenoslide. The idea is to try to move the actor box[1] to each of the four cardinal directions by the same amount as the distance that it should be kept from a wall.[2] The result can be found in lunatic/test/checknearwall.con. During coding, I found that it was possible for the <return> value from clipmove and some other commands to be negative, contrary to what the wiki says. Revision 4874 remedies this, and is required for checknearwall.con to function correctly.

[1]I'm not sure whether it's really a box with its sides parallel to the world coordinate axes as with getzrange here, but it should not be of major importance.
[2]How this walldist that is ultimately used for the movement of a particular actor relates to sprite[].clipdist is a separate question. An initial attempt at documenting this is here.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


All copyrights and trademarks not owned by Voidpoint, LLC are the sole property of their respective owners. Play Ion Fury! ;) © Voidpoint, LLC

Enter your sign in name and password


Sign in options