by Dan East » Sep 10, 2001 @ 11:03am
Right, to my knowledge you can't just overload operators in C. However, being that the floating point is handled by emulation, I assume that there is a library that is linked to that contains the floating point software code. One could hack that library to replace the existing floating point math with their own code.<br><br>Early in the PQ project, after version 0.02 I think, I attempted a global replacement of all floating point math. I created duplicate vars / structs with FPM appended to the name. If you look through the PQ source, you will find thousands of such vars. They will all resolve down to fixedpoint_t in place of float. Check out the FixedPointMath.h header, which contains all the prototypes and macros I used in replacing the operators. I replaced the actual operators with macros, most of which resolve to functions.<br><br>So, for example, Quake's original dot product macro was:<br>[fixed]#define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])[/fixed]<br><br>My converted version (as found in mathlib.h) is:<br>[fixed]#define DotProductFPM(x,y) FPM_ADD3(FPM_MUL(x[0],y[0]),FPM_MUL(x[1],y[1]),FPM_MUL(x[2],y[2]))[/fixed]<br><br>I spent a very, very long time doing such conversions back in February. I converted everything, but there may of course be errors due to the tremendous volume involved. After the conversion it quickly became apparent that no single fixed point precision could meet the range requirement of every float in Quake, so I began smaller, localized conversions using varied fixed point precision depending on the needed range / precision, and the operators involved (just like you did with the optimizations you performed).<br><br>Dan East