[Added] sqrt for DECORATE

Moderator: Developers

sqrt for DECORATE

Postby DavidPH » Fri Apr 13, 2012 5:54 pm

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 15 times
DavidPH
<shamelessplug>
 
Joined: 28 Aug 2009

Re: sqrt for DECORATE

Postby NeuralStunner » Fri Apr 13, 2012 7:25 pm

Thank you!

Much needed for those times I need to get an actor's overall velocity...
User avatar
NeuralStunner
O'Neill with it.
 
Joined: 21 Jul 2009
Location: The Colonies

Re: sqrt for DECORATE

Postby Nash » Sat Apr 14, 2012 12:23 am

Hopefully the rewrite will pave way to easier extensions...
User avatar
Nash
http://twitter.com/ISurvivorGame
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: sqrt for DECORATE

Postby Graf Zahl » Sun Apr 22, 2012 3:10 am

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
Graf Zahl
 
Joined: 19 Jul 2003
Location: Germany

Re: sqrt for DECORATE

Postby printz » Sun Apr 22, 2012 9:09 am

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

EDIT: oh, sorry, I wasn't paying attention that this feature got [added].
User avatar
printz
Nothing can be shared from the desktop.
 
Joined: 26 Oct 2006
Location: Bucharest, Romania

Re: sqrt for DECORATE

Postby Gez » Mon Apr 23, 2012 10:03 am

Now that this system is in, it'll be possible to add other such as tan(x), log(x, base), ln(x), etc.
Gez
 
Joined: 06 Jul 2007

Re: sqrt for DECORATE

Postby NeuralStunner » Mon Apr 23, 2012 12:23 pm

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

Code: Select allExpand view
Sqrt((VelX*VelX)+(Vely*VelY))
Returns absolute horizontal velocity (regardless of direction).

Code: Select allExpand view
Sqrt((VelX*VelX)+(VelY*VelY)+(VelZ*VelZ))
The same, but in all 3 dimensions.
User avatar
NeuralStunner
O'Neill with it.
 
Joined: 21 Jul 2009
Location: The Colonies


Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests