Compare pointers (Decorate, ACS)

Moderator: GZDoom Developers

User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Compare pointers (Decorate, ACS)

Post by FDARI »

EDIT: I am planning to make this submission obsolete. It's intended purpose should be covered by new submissions using a slightly different approach.
Spoiler: Original: compareptr.zip
I have updated this. New definition:

Core submission - modifications of the original

ACS: bool ComparePointers(int ptr_selector, int ptr_compare); (returns true if two equal pointers are retrieved; treats two NULL-results (no actor) as equal)
To check that two actors are equal and that they do both exist: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE) && !ComparePointers(AAPTR_SOMETHING, AAPTR_NULL)

Decorate: A_ComparePointers(state jumpto, int ptr_selector, int ptr_compare)
Same rules as the ACS function. Jumps to the chosen state if the actors are equal.

To jump only for non-null equality:
... A_ComparePointers(2, AAPTR_SOMETHING, AAPTR_NULL)
... A_ComparePointers("dest", AAPTR_SOMETHING, AAPTR_ELSE)
......

The non-null checks are not needed when (a) you want to jump if both are null, (b) you can be sure that at least one of them is non-null.

String/Name features (Imports feature from http://forum.zdoom.org/viewtopic.php?f=34&t=30806)

int StringID(str stringConstant): Constant decorate expression returning an int that can be resolved to stringConstant. For "name" strings, that int is unique to that string.
int ClassID([int ptr_selector]): Decorate expression returning an int that can be resolved into a class name. For "name" strings, that int is unique to that string.

ptr_selector: Default = AAPTR_DEFAULT (self).

ClassID() returns the string id for the calling actor's class.
ClassID(AAPTR_TARGET) returns the string id for the calling actor's target's class, or NAME_None (0) if there is no target.

ClassID(a) == ClassID(b) is conclusive evidence that two actors are of the same class
StringID("ClassName") == ClassID(a) is conclusive evidence that an actor is of class ClassName.

(( StringID and ClassID are designed for use with A_JumpIf(), but also work with A_ChangeFlag() and any other int-accepting function ))

The ACC/ZDOOM patch contains an extension (from http://forum.zdoom.org/viewtopic.php?f=34&t=30806) to the print syntax: g:x. It resolves a ClassID(x) or StringID("x") from its integer value and back to the string.

PS: I believe you can use StringID("something") in const-declarations. Didn't try, but it should work. (You would often not need that. But the possibility is there.)

... Summary ...
ACS bool ComparePointers(int ptr_selector, int ptr_compare)
Decorate A_ComparePointers(state jumpto, int ptr_selector, int ptr_compare)
Decorate constant int StringID(str stringLiteral) -- int is a stringID-entry, unique to that string
Decorate int ClassID([int ptr_selector]) -- int is a StringID-entry, unique to that string
ACS print syntax g:x converts a stringID to a string.

Possible modification: Make comparisons return false if either actor is NULL. Why? Because it might be more useful to determine both that the actor is not null and that it is equal to another actor, than just to determine one. I'm not sure the loss of flexibility is such a cost.
Attachments
StringsAndPointers.zip
New
(4.03 KiB) Downloaded 118 times
compareptr.zip
Old
(1.44 KiB) Downloaded 99 times
Last edited by FDARI on Thu Sep 25, 2014 3:32 pm, edited 5 times in total.
User avatar
Major Cooke
Posts: 8206
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: Compare pointers (Decorate, ACS)

Post by Major Cooke »

I'm slightly confused... Think you could expand a little more about the A_ComparePointers and what it does exactly?

Because for your example, you could just do an A_JumpIfTargetInLOS check.
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: Compare pointers (Decorate, ACS)

Post by FDARI »

For Target and Master you can always do A_JumpIfTargetInLOS with nosight and (optional) bundles of other flags. Missile typed actors can also use this to check their Tracer.
However A_JumpIfTargetInLOS cannot be elegantly expanded to make use of pointer selectors, and it is not available in ACS.

You can also use it to test whether or not two retrieved values are the same.

Want to react if master and target happen to be the same? A_ComparePointers("ohnoes", AAPTR_MASTER, AAPTR_TARGET)
Similar idea in ACS: if (ComparePointers(AAPTR_MASTER, AAPTR_TARGET)) { /* ohnoes */ } else { /* ohyes */ }

Does it make sense? And is there already a better way to do that? (Particularly interested if there is already a way to check for equality between intended target and most likely victim; even though this feature isn't specialised enough to solve that perfectly. It just checks if something else might be directly ahead, which you might have been aiming over or under.)
User avatar
Major Cooke
Posts: 8206
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: Compare pointers (Decorate, ACS)

Post by Major Cooke »

Can you have an actor check if it's target is the same as itself with A_ComparePointers("ohnoes",AAPTR_DEFAULT,AAPTR_TARGET)?
User avatar
NeuralStunner
 
 
Posts: 12328
Joined: Tue Jul 21, 2009 12:04 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: capital N, capital S, no space
Contact:

Re: Compare pointers (Decorate, ACS)

Post by NeuralStunner »

As far as making sure the target "under fire" is the intended one, I'd like to see a function specifically tailored to that calculation.
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: Compare pointers (Decorate, ACS)

Post by FDARI »

MC: You can, but that particular check is almost never worthwhile. None of the new functions permit you to assign an actor to its own pointer.
NS: Me too, but I'm only now beginning to move into the body of raytracing and target detection (as opposed to calling it with no real knowledge of what goes on). It is among my many possible future endeavours.

The most unique thing about this feature would be the ability to store a pointer at one point in code, and check it against another pointer later. I have wanted that ability on a few occations. I'll make sure to mention it if any relevant cases come up.
Spoiler: I use this for timed effects that require "concentration":
User avatar
Major Cooke
Posts: 8206
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: Compare pointers (Decorate, ACS)

Post by Major Cooke »

What I meant was, can you check to see if it's target is the same type of "class" as itself?

This also makes me wonder, would it be possible to make a function like:

A_CheckActor(state jump, source pointer, target pointer, str "classname",flags, state jump (secondary))
  • State Jump = The state to jump to if the criteria matches.
  • Source pointer = The calling actor's source of whom it's making the first comparison.
  • Src2 = The source pointer's code pointer to check, can only be a target, master, or tracer or default (self).
  • Target pointer = The thing whom the calling actor is comparing against.
  • Tgt2 = Target ponter's code pointer to check, can only be a target, master, or tracer, or default (self).
  • Classname = Performs a check against the target pointer to see if the defined classname is the same as the source.
  • Secondary Jump = Occurs only if:
    1. CPT_UNIQUE is used
    2. the classname is matching
    3. The destination pointer (target pointer) is not identified as the unique one stored in the source's specified pointer.

    Flags:
  • CPT_UNIQUE - Checks to see if the target pointer is the exact same target as before for the stored source pointer. This allows for more unique singling out for things such as a specific imp causing a zombie to infight. If it's a different imp, it fails.
  • CPT_REVERSE - Causes the target pointer to perform the check. If they have the specified state available to jump to, the target will jump to it. Otherwise, no jump is performed.
  • CPT_LINETARGET - Can it see them? (note, I meant to base this off of the AAPTR_GET_LINETARGET flag)
Yeah, I got that idea from looking at A_TransferPointer.

-----

So an example would be, say, checking for familiar monkeys.

This guy checks his tracer after storing it right as he has his banana stolen from him, and in fact the monkey who steals it spawns an actor who stores the monkey (it's master) in the guy's tracer pointer.

It searches the target, and only the target with this code. It could, however, be used to search it's branches to check for a match such as the target's master/target/tracer codes.

Code: Select all

TNT1 A 0 A_CheckActor("Recognized",AAPTR_DEFAULT,AAPTR_TRACER,AAPTR_TARGET,AAPTR_DEFAULT,"Monkey",CPT_UNIQUE|CPT_LINETARGET,"Unfamiliar")
Goto NotAMonkey

Recognized:
TNT1 A 0 A_PrintBold("OI! You're the sneaky little turd who stole my banana!")
Goto Chasing

Unfamiliar:
TNT1 A 0 A_PrintBold("Hmm, you're not the monkey I'm looking for...")
Goto KeepLooking

NotAMonkey:
TNT1 A 0 A_PrintBold("Nope, not what I'm looking for. It's definitely a monkey, and no other being at that.")
Goto KeepLooking
User avatar
Major Cooke
Posts: 8206
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: Compare pointers (Decorate, ACS)

Post by Major Cooke »

Would the above be better as another suggestion in the suggested features section?
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: Compare pointers (Decorate, ACS)

Post by FDARI »

I'm not sure what it would be. If I get it, I think it isn't going to be such a good function. It might be better to execute a purpose specific ACS script from a library for such a complex and specific piece of logic.
User avatar
Major Cooke
Posts: 8206
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: Compare pointers (Decorate, ACS)

Post by Major Cooke »

Hm, okay... I think I may indeed have been confusing myself.

What I really think would help is a function like this:

A_CheckActor(state jump, selector, str classname)

It checks to see if an actor in it's code pointer of choice is "classname". In a way, this can be used to replicate A_JumpIfInventory, only without the need of inventory tokens made strictly for identification so we can finally have a good reason to stop making those, and that's just one example.

I personally see that as something that can go hand in hand with A_ComparePointers, to do a lot of things together.
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: Compare pointers (Decorate, ACS)

Post by FDARI »

That one I can see. Yes, that is something I'd need inventory tokens or trickier methods for today. (Trickier methods involve strparam(n:0) and char-by-char comparison against an acs table.)
User avatar
Major Cooke
Posts: 8206
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: Compare pointers (Decorate, ACS)

Post by Major Cooke »

So is it feasible? Think it could be done? It would be one hell of a compliment to A_ComparePointers, I know this much.
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: Compare pointers (Decorate, ACS)

Post by FDARI »

Check the update. Summary:

ACS bool ComparePointers(int ptr_selector, int ptr_compare)

Decorate A_ComparePointers(state jumpto, int ptr_selector, int ptr_compare)

Decorate constant int StringID(str stringLiteral) -- int is a stringID-entry, unique to that string

Decorate int ClassID([int ptr_selector]) -- int is a StringID-entry, unique to that string

ACS print syntax g:x converts a stringID to a string.

I borrowed a trick from here: http://forum.zdoom.org/viewtopic.php?f=34&t=30806
Purpose: Make class checking a bit more flexible. (Compare with a string constant, or with the class name of another actor, and use the comparison in other things than jump function, and use non-equality as well as equality.)
User avatar
Major Cooke
Posts: 8206
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: Compare pointers (Decorate, ACS)

Post by Major Cooke »

Okay, out of curiousity, what's this part doing?

Code: Select all

VerifyInvalidityOfSyntaxes:
			TNT1 A 0 ACS_ExecuteWithResult( cos(1) )
			TNT1 A 0 ACS_ExecuteWithResult( sin(1) )
			TNT1 A 0 ACS_ExecuteWithResult( ClassID() )
			TNT1 A 0 ACS_ExecuteWithResult( ClassID(AAPTR_DEFAULT) )
			stop
I have a feeling it's just there to debug some ACS, or something. That part is the only thing I'm slightly confused on.
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: Compare pointers (Decorate, ACS)

Post by FDARI »

That one contains syntax constraint checks, and are purely for testing purposes on my end, not really a demo of any sort. Checks that cos() and sin() require exactly 1 parameter, and that ClassID() accepts 0 or 1 parameters.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”