sqrt for DECORATE

Moderator: GZDoom Developers

Post Reply
User avatar
DavidPH
Posts: 382
Joined: Fri Aug 28, 2009 1:46 pm

sqrt for DECORATE

Post by DavidPH »

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.)
Attachments
dec-sqrt.7z
(3.2 KiB) Downloaded 41 times
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: sqrt for DECORATE

Post by NeuralStunner »

Thank you!

Much needed for those times I need to get an actor's overall velocity...
User avatar
Nash
 
 
Posts: 17513
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: sqrt for DECORATE

Post by Nash »

Hopefully the rewrite will pave way to easier extensions...
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: sqrt for DECORATE

Post by Graf Zahl »

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.)
User avatar
printz
Posts: 2649
Joined: Thu Oct 26, 2006 12:08 pm
Location: Bucharest, Romania
Contact:

Re: sqrt for DECORATE

Post by printz »

What about (pseudocode): DoubleToFixed(sqrt(FixedToDouble(f)))?

EDIT: oh, sorry, I wasn't paying attention that this feature got [added].
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: sqrt for DECORATE

Post by Gez »

Now that this system is in, it'll be possible to add other such as tan(x), log(x, base), ln(x), etc.
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: sqrt for DECORATE

Post by NeuralStunner »

Quick note to anybody interested (and an explanation of what I wanted this for):

Code: Select all

Sqrt((VelX*VelX)+(Vely*VelY))
Returns absolute horizontal velocity (regardless of direction).

Code: Select all

Sqrt((VelX*VelX)+(VelY*VelY)+(VelZ*VelZ))
The same, but in all 3 dimensions.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”