GetZAt Decorate Function

Moderator: GZDoom Developers

Post Reply
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

GetZAt Decorate Function

Post by Major Cooke »

Pull Request

float GetZAt(x, y, angle, flags, pick_pointer);
Gets the floor z at x distance ahead and y distance to the side in relative form from the calling actor pointer. Flags are as follows (GZF_ prefix):
  • CEILING: Returns the ceiling z instead of floor.
  • ABSOLUTEPOS: x and y are absolute positions.
  • ABSOLUTEANG: angle parameter does not add the pointer's angle to the angle parameter.
  • 3DRESTRICT: Ignore midtextures and 3D floors whose floorz is above the actor's z.
  • NOPORTALS: Don't check through portals.
  • NO3DFLOORS: Ignore all 3D floors.
Why?

As it stands, I have in one of my projects a VERY unwieldy system that calls A_Warp to move an actor towards a location, grab the floorz, and head back to the origin. After a while, mounting the A_Warp calls slowly becomes a BIT expensive when relying on multiple actors to get the job done.

Cutting out the need to move at all can enhance this performance by removing the unneeded overhead. So I came up with this. It's basically GetSectorFloor/CeilingZ for DECORATE, but better and enhanced with the same genious relativity of A_SpawnItemEx.

A test sample:

Code: Select all

Actor Da
{
	+NOINTERACTION
	States
	{
	Spawn:
		TNT1 A 35 NoDelay
		{
			A_Log("My FloorZ Is");
			A_Warp(AAPTR_PLAYER1,x,y,z,0,WARPF_NOCHECKPOSITION|WARPF_ABSOLUTEPOSITION,"Null");
			A_LogFloat(FloorZ);
			A_LogFloat(GetZAt(0,0));
			A_Log("50 Units From Me Is");
			A_LogFloat(GetZAt(50,0));
			
		}
		Stop
	}
}
Last edited by Major Cooke on Thu May 12, 2016 12:34 pm, edited 3 times in total.
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: GetZAt Decorate Function

Post by Major Cooke »

Slightly offtopic, but Graf, is there an equivalent way to get the highest floor or lowest ceiling by chance? I know one exists for a vertex but I'm looking for an opposite of GetLowestFloor function in the source.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: GetZAt Decorate Function

Post by Graf Zahl »

I don't think that your submission is really usable, it's missing both 3D floor and portal handling. And that's also the reason why no GetHighestCeiling function exists.
The functions that should be used are:

double HighestCeilingAt(const DVector2 &a, sector_t **resultsec = NULL);
double LowestFloorAt(const DVector2 &a, sector_t **resultsec = NULL);
double NextHighestCeilingAt(double x, double y, double bottomz, double topz, int flags = 0, sector_t **resultsec = NULL, F3DFloor **resultffloor = NULL);
double NextLowestFloorAt(double x, double y, double z, int flags = 0, double steph = 0, sector_t **resultsec = NULL, F3DFloor **resultffloor = NULL);

which are all portal-aware, and the 'Next...' variants also 3D floor aware.
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: GetZAt Decorate Function

Post by Major Cooke »

What should I be using for bottomz and topz? Looks like the actor's Z and their Top... Not sure.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: GetZAt Decorate Function

Post by Graf Zahl »

Precisely that. It really only matters if an actor intersects with a 3D floor.
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: GetZAt Decorate Function

Post by Major Cooke »

Done. I added a couple more flags to disable 3D floor, portal, and midtexture checking in case someone needs it (I can tell this will be handy).
  • 3DRESTRICT: Ignore midtextures and 3D floors whose floorz is above the actor's z.
  • NOPORTALS: Don't check through portals, only the original sector designated.
  • NO3DFLOORS: Ignore all 3D floors.
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: GetZAt Decorate Function

Post by Edward-san »

Imho the name of the enum should be GZAFlags, not GZFlags, with the enum elements having GZAF_ as prefix (the action function is called GetZAt, not GetZat, then the question would be `what's a Zat?`). Also that sounds too familiar with GZDoom :P
Last edited by Edward-san on Thu May 12, 2016 1:15 pm, edited 1 time in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: GetZAt Decorate Function

Post by Graf Zahl »

Why do you use secnum instead of the pointer that was returned by P_PointInSector?
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: GetZAt Decorate Function

Post by Major Cooke »

Graf Zahl wrote:Why do you use secnum instead of the pointer that was returned by P_PointInSector?
Was using the same code as GetSectorFloorZ in ACS. Changed it. Is that better?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: GetZAt Decorate Function

Post by Graf Zahl »

Better, yes. But since P_PointInSector will always return something valid the 'if (sec)' isn't really needed. Good enough, though.
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: GetZAt Decorate Function

Post by Major Cooke »

Ah okay. Still, thanks a ton! :mrgreen:
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”