Primarily this is a patch to add sqrt to DECORATE expressions. However, to do so I extended FxGlobalFunctionCall into a generalized base class for DECORATE functions so that they can be added quickly and easily without hacking them in like abs. Or incurring an on-evaluation-lookup cost like the current FxGlobalFunctionCall.
It is my sincere hope that this rewrite is actually suitable for future additions to DECORATE expressions. Especially given the probably large number of functions that would be considered useful. (Such as, say, a CheckInventory for DECORATE.) So if there is anything I can do to further that goal, I am entirely willing to do so myself if asked. (Two things in particular that I'd like to change from the patch as-is is to break up cos/sin and to change abs to use the new system.)
(As a side note, I used a separate file because I think thingdef_expression.cpp is quite large enough already. If adding the code there would be preferred I could rewrite the patch to do so.)
sqrt for DECORATE
Moderator: GZDoom Developers
sqrt for DECORATE
- Attachments
-
dec-sqrt.7z- (3.2 KiB) Downloaded 41 times
- 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: sqrt for DECORATE
Thank you!
Much needed for those times I need to get an actor's overall velocity...
Much needed for those times I need to get an actor's overall velocity...
Re: sqrt for DECORATE
Hopefully the rewrite will pave way to easier extensions...
- Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: sqrt for DECORATE
Ok, just a few things:
git patches are a mess and need manual adjustment to make them work. Please use svn diff in the future.
A square root of an integer value should still be a float. The strange errors people would get if it was truncated to an integer would be endless.
Better use the plain C interface to the CRT unless it's absolutely necessary to do otherwise (math.h instead of cmath.)
git patches are a mess and need manual adjustment to make them work. Please use svn diff in the future.
A square root of an integer value should still be a float. The strange errors people would get if it was truncated to an integer would be endless.
Better use the plain C interface to the CRT unless it's absolutely necessary to do otherwise (math.h instead of cmath.)
Re: sqrt for DECORATE
What about (pseudocode): DoubleToFixed(sqrt(FixedToDouble(f)))?
EDIT: oh, sorry, I wasn't paying attention that this feature got [added].
EDIT: oh, sorry, I wasn't paying attention that this feature got [added].
Re: sqrt for DECORATE
Now that this system is in, it'll be possible to add other such as tan(x), log(x, base), ln(x), etc.
- 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: sqrt for DECORATE
Quick note to anybody interested (and an explanation of what I wanted this for):
Returns absolute horizontal velocity (regardless of direction).
The same, but in all 3 dimensions.
Code: Select all
Sqrt((VelX*VelX)+(Vely*VelY))Code: Select all
Sqrt((VelX*VelX)+(VelY*VelY)+(VelZ*VelZ))