Documentation
¶
Overview ¶
Package fixed provides a deterministic Q16.16 fixed-point number type and the trigonometric/root primitives the simulation needs.
The engine compiles to two targets: a native server build and a GOOS=js/GOARCH=wasm browser build. For client-side prediction to agree with the authoritative server, identical inputs must produce bit-identical outputs on both. Go's math package uses architecture-specific assembly for sin/cos/sqrt on amd64/arm64 but pure-Go fallbacks on wasm, so the two targets can disagree in the low bits. Everything here is integer-only (int64 arithmetic and shifts behave identically on every Go target), so the simulation never touches a hardware float and stays reproducible.
Index ¶
Constants ¶
const ( FullCircle int32 = 65536 HalfCircle int32 = 32768 QuarterCircle int32 = 16384 )
Angles use Total Annihilation's native unit: a full turn is 65536, matching the COB integer angle scale. Storing headings as int32 TA-angles (rather than radians) keeps the whole sim in integers and reproducible.
Variables ¶
This section is empty.
Functions ¶
func AngleToRadians ¶
AngleToRadians converts a TA-angle to radians for rendering/debug only.
func Atan2 ¶
Atan2 returns the TA-angle of the vector (x, y) measured the way the engine's heading convention expects: it mirrors JS Math.atan2(y, x). Pass the "sine-side" component as y and the "cosine-side" as x. Heading toward a target at delta (dx, dz) is therefore Atan2(dx, dz). The result is in [0, 65536).
func NormalizeAngle ¶
NormalizeAngle folds any TA-angle into [0, 65536).
func RadiansToAngle ¶
RadiansToAngle converts a radian float to a TA-angle. Boundary-only helper — never call inside the tick loop.
func ShortestArc ¶
ShortestArc maps a TA-angle delta into (-32768, 32768] — the shortest signed turn between two headings.
Types ¶
type Fixed ¶
type Fixed int64
Fixed is a Q16.16 signed fixed-point value stored in an int64. The wide backing integer keeps multiply intermediates from overflowing across the coordinate ranges Total Annihilation maps use (positions stay well under 2^15 world units).
const ( // FracBits is the number of fractional bits in the Q16.16 layout. FracBits = 16 // One is the fixed-point representation of 1.0. One Fixed = 1 << FracBits // Half is the fixed-point representation of 0.5. Half Fixed = One >> 1 // Zero is the fixed-point representation of 0.0. Zero Fixed = 0 )
func FromFloat ¶
FromFloat converts a float to fixed-point. This is the ONLY bridge from non-deterministic floats and must only be used at the system boundary (parsing FBI/asset values, decoding orders) — never inside the tick loop.
func Hypot ¶
Hypot returns sqrt(x*x + y*y) without the intermediate overflowing for the coordinate magnitudes the sim uses.
func SinCos ¶
SinCos returns the sine and cosine of a TA-angle as Q16.16 values in [-One, One]. It reduces to the first quadrant and applies exact symmetry, keeping CORDIC inside its convergence range.