Fix calculations of server ping in in-game server list. Minimize floating
point calculations, using double instead of float, avoid calling timer
twice when receiving pong, and capture pong time more precisely.
Replaces calls to double-precision floating point trig functions with
calls to single-precision floating point trig functions as follows:
cos() -> cosf()
sin() -> sinf()
tan() -> tanf()
acos() -> acosf()
asin() -> asinf()
atan() -> atanf()
This allows the compiler to avoid generating unnecessary instructions
that convert a float to a double and then a double back to a float.
Signed-off-by: Peter Mitsis <[email protected]>
The classic solution to the quadratic equation ...
a*x*x + b*x + c = 0
is ...
-b +- sqrt(b*b - 4*ac)
x = ----------------------
2*a
This can be optimized by substituting b = 2*B.
-2*B +- sqrt((2*B)*(2*B) - 4*a*c)
x = ---------------------------------
2*a
This expands to ...
-2*B +- sqrt(4*B*B - 4*a*c)
x = ---------------------------
2*a
And simplifies to ...
-2*B +- 2*sqrt(B*B - 4*a*c)
x = ---------------------------
2*a
-B +- sqrt(B*B - a*c)
x = ---------------------
a
Signed-off-by: Peter Mitsis <[email protected]>
Uses an array of precalculated factorials that are accessed as a lookup table
instead of computing the factorials at runtime. This cuts down on compiled
code bloat (compiler was both unrolling and inlining the computation's loop)
everywhere it was used.
NOTE: The original implementation returned an 'int'. As a result, the largest
uncorrupted factorial it could compute was 12!. For this reason, the lookup
table only goes up to 12!.
Signed-off-by: Peter Mitsis <[email protected]>
Rejiggers the macros fl_radians() and fl_degrees() to avoid unnecessary
operations. The new placement of the parentheses permit the compiler to
evaluate (PI / 180.f) and (180.f / PI) at compile time rather than run time.
Signed-off-by: Peter Mitsis <[email protected]>
Instead of performing three consecutive divisions, vm_vec_avg_n() now performs
one division at the start and three multiplications at the end. Recall that
multiplication is faster than division.
Signed-off-by: Peter Mitsis <[email protected]>
The routine atan2_safe() already contains a test that checks if both parameters
are zero--that is the point of the routine. Thus, there is no need for the
caller of atan2_safe() to perform that same check.
Signed-off-by: Peter Mitsis <[email protected]>
The routine vm_vec_normalize() always returns a value greater than zero.
Thus, there is no need to test its return value for values that are less
than or equal to zero.
Signed-off-by: Peter Mitsis <[email protected]>
The routine vm_vec_copy_normalize() always returns a value greater than zero.
Thus, there is no need to test its return value for values that are less than
or equal to zero.
Signed-off-by: Peter Mitsis <[email protected]>
Not only is the routine vm_fvec_matrix_interpolate() unused, it does not appear
to have been used for the duration of the project. The only reference to it
found in the history was in a removed comment. That comment indicated that it
was implemented in 1997.
Signed-off-by: Peter Mitsis <[email protected]>
Uses an array of precalculated factorials that are accessed as a lookup table
instead of computing the factorials at runtime. This cuts down on compiled
code bloat (compiler was both unrolling and inlining the computation's loop)
everywhere it was used.
NOTE: The original implementation returned an 'int'. As a result, the largest
uncorrupted factorial it could compute was 12!. For this reason, the lookup
table only goes up to 12!.
Signed-off-by: Peter Mitsis <[email protected]>
Rewrites the macros to avoid unnecessary divisions. The compiler is now free
to precalculate the scaling ratio and perform it in a single multiply. Note
that the previous placement of the parentheses meant that the compiler (at
least GCC) was performing a multiply followed by a divide.
Signed-off-by: Peter Mitsis <[email protected]>
Instead of perform three consecutive divisions, vm_vec_avg_n() now performs one
division at the start and three multiplications at the end. Recall that
multiplication is faster than division.
Signed-off-by: Peter Mitsis <[email protected]>
The routine atan2_safe() already contains a test that checks if both parameters
are zero--that is the point of the routine. Thus, there is no need for the
caller of atan2_safe() to perform that same check.
Signed-off-by: Peter Mitsis <[email protected]>