Compare pointers (Decorate, ACS)

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Compare pointers (Decorate, ACS)

Re: Compare pointers (Decorate, ACS)

by FDARI » Sun Sep 28, 2014 6:22 am

Superseded by alternate implementation.
Pull requested.

https://github.com/rheit/zdoom/pull/112
https://github.com/rheit/acc/pull/9

Re: Compare pointers (Decorate, ACS)

by Major Cooke » Tue Apr 23, 2013 8:55 am

Say, FDARI, would you be capable of updating this to the current version of Zdoom's revision? I sincerely think this would be extremely useful.

Re: Compare pointers (Decorate, ACS)

by Major Cooke » Sat Dec 17, 2011 4:25 pm

Yeah. I'm only looking at it for player 1, but I'll keep this in mind.

Re: Compare pointers (Decorate, ACS)

by FDARI » Sat Dec 17, 2011 4:09 pm

That's not good in concept, although it could work out. Conceptual problems: You depend on a specific player to be in the game, and you depend on that player to be of the appropriate class. If player 1 is guaranteed to be present and of the WhateverPlayer class, it will work.

A few portable utility functions for decorate can be designed in ACS.
Spoiler: Excerpt of my ACS/Decorate interop

Re: Compare pointers (Decorate, ACS)

by Major Cooke » Sat Dec 17, 2011 2:05 pm

Out of curiousity, would it be possible to do A_JumpIf(ClassID(AAPTR_TARGET) == ClassID(AAPTR_PLAYER1),"ItsAPlayer")? I'm guessing that it is, though I haven't tried doing that yet, as I'm currently hog-tied with a bunch of experiments. Still, I just wanted to ensure that it's possible to do a comparison to check and see if the player is it's target.

Re: Compare pointers (Decorate, ACS)

by FDARI » Sat Dec 17, 2011 8:02 am

If an actor that has no target or tracer compares AAPTR_TARGET and AAPTR_TRACER with this function, they will be treated as equal, because they are both null references. Is that the best behaviour? In most situations, you will want to "act" only if they are the same and non-null. If you'd end up adding && !ComparePointer(AAPTR_TARGET, AAPTR_NULL) a lot, you might be happier with a function that returns false/does not jump, if an actor is NULL. I could rewrite it that way, but you'd have to go a little further to check specifically for null, and to allow two null-pointers to be equal.

Current methods:
Pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE)
Pointer is null: ComparePointers(AAPTR_SOMETHING, AAPTR_NULL)
Non-null pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE) && !ComparePointers(AAPTR_SOMETHING, AAPTR_NULL)

Alternative methods:
Pointer equality: Not built in
Pointer is null: Not built in
Non-null pointer equality: ComparePointers(AAPTR_SOMETHING, AAPTR_ELSE)

For specific needs you could complement the alternative method (non-null pointer equality only) with an ACS library / function:
Spoiler: Pointer existence tests

Re: Compare pointers (Decorate, ACS)

by Major Cooke » Fri Dec 16, 2011 9:16 pm

Okay, that definitely gave me a wave of relief. Thank you.

I would say, this feature is picture perfect! That is, aside from any other code maintenance you might do to it, if any, but that's for you to decide.

Re: Compare pointers (Decorate, ACS)

by FDARI » Fri Dec 16, 2011 4:25 pm

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.

Re: Compare pointers (Decorate, ACS)

by Major Cooke » Fri Dec 16, 2011 3:12 pm

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.

Re: Compare pointers (Decorate, ACS)

by FDARI » Fri Dec 16, 2011 3:03 pm

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.)

Re: Compare pointers (Decorate, ACS)

by Major Cooke » Fri Dec 16, 2011 8:05 am

So is it feasible? Think it could be done? It would be one hell of a compliment to A_ComparePointers, I know this much.

Re: Compare pointers (Decorate, ACS)

by FDARI » Fri Dec 16, 2011 2:41 am

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.)

Re: Compare pointers (Decorate, ACS)

by Major Cooke » Thu Dec 15, 2011 3:51 pm

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.

Re: Compare pointers (Decorate, ACS)

by FDARI » Thu Dec 15, 2011 12:03 pm

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.

Re: Compare pointers (Decorate, ACS)

by Major Cooke » Thu Dec 15, 2011 11:09 am

Would the above be better as another suggestion in the suggested features section?

Top