by m00dy · 5y ago · 0 comments
https://github.com/ec-/Quake3e/blob/2c96f6d58619a29589bac577...
classic
It's legitimately a part of history, specifically the dawn of FPS gaming, and utterly brilliant besides. The comment even helps reassure the new programmer that they're not alone in thinking that at that line.
But, if you were computing 1/sqrt(x), I highly doubt the quake3 style rsqrt(x) was slower than that. If both implemented with software floats, rsqrt(x) would be strictly less work. They're almost the same computation, except you'll probably get a better initial guess for rsqrt (the "what the fuck" line), and each iteration produces more accuracy.
The AVR was reading a 6 axis IMU chip and estimating attitude using a floating point quaternion based complementary filter, at 100hz. Sqrt was used when normalizing vectors and quaternions, probably two or three times per cycle.
It was also reading 6 channels from the radio receiver, and producing 6 RC PWM outputs. I believe the output was synchronized to the input, so that the throttle and servos would go limp if the radio went out of reception, rather than have the plane just keep flying level into the sunset.
I vaguely remember it using about half the available CPU cycles doing all that. I even managed to get it talking to an RC simulator, so I could debug it without crashing my real plane. It worked perfectly on the first test flight!