Foundations to FrontierBezhig

From the engine

Where an idea from a chapter runs in working code: a game engine, a satellite tracker, a landing-guidance lab, a shooter, and a browser game, all by the author.

25 notes in 25 chapters.

Each note quotes a short piece of real code, unedited, and says which idea from its chapter the code uses; most work a small example by hand. Every number in a note is checked by script, and each excerpt is copied from its project by a tool, not retyped.

Fate Engine

The C++ engine the author builds his games on, among them FateMMO, Undead Forever, and Crown Infinity: an archetype entity-component system, a job system, arena memory, and a batched sprite renderer.

  1. Module 03Two functions that undo each otherA tap lands on the screen in pixels, but the game reasons in world units, so Fate Engine’s 2D camera needs one function from screen to world and another from world to screen.
  2. Module 09Why a camera move starts and stops gentlyFate Engine’s cutscene timeline moves the camera from a to b by feeding an eased time s(t), the first function below, into a linear blend, a + (b - a) s(t), the second, for t from 0 to 1.
  3. Module 25A health bar that solves a differential equationWhen a target loses health, Fate Engine does not snap the bar to the new value.
  4. C06A hash table tuned for missesFate Engine finds the entities near a point by hashing the grid cell that contains it.
  5. C09Reserve the addresses now, pay for the pages laterFate Engine allocates short-lived data from arenas.
  6. C10A queue without a lockWorker threads in Fate Engine’s job system take work from a bounded queue that many threads may push to and pop from at once.
  7. C14The average frame is not the frame you feelFate Engine’s performance captures report frame times as percentiles, computed by the nearest-rank rule: sort the samples and take the one at rank ⌈ p n⌉.
  8. W03Walking columns instead of chasing objectsFate Engine stores game objects as rows in tables.
  9. W05Real time in, fixed steps outA simulation is only as trustworthy as its step size, and frames do not arrive at a fixed pace.
  10. A03Picking a sound with the right oddsFate Engine plays a slightly different sound each time an event repeats, choosing among variants by weight.
  11. T02Thousands of sprites, a dozen draw callsEach draw call has a fixed cost on the CPU and in the driver, so a 2D renderer wants as few as it can get.

Nightjar

A satellite-tracking lab: orbit propagation, collision probability, and the geometry of navigation satellites.

  1. Module 15Newton’s method finds a satelliteNightjar, the author’s satellite-tracking lab, needs a satellite’s position at a given time.
  2. Module 23An integral that reports its own errorNightjar integrates a probability density to find the chance that two satellites collide, and there an answer without an error estimate would be useless.
  3. A02How good is this sky? Least squares answersA satellite-navigation receiver solves for four unknowns, three of position and one of clock error, by least squares.
  4. A04Zero hits is not zero probabilityNightjar estimates a collision probability by simulation: draw many positions and count how many land inside the combined radius.

Alight

A powered-descent guidance lab for landing a rocket: closed-form bounds, simulation, and tests of numerical reproducibility.

  1. Module 20The rocket equation, integrated twiceAlight, the author’s powered-descent guidance lab, bounds what a rocket can do in a vertical burn.
  2. A05One rounding or two?Alight’s guidance results must be reproducible bit for bit, which rules out letting the compiler fuse a multiply and an add into one instruction.

Alight and Nightjar

The small numerics library the two labs share.

  1. A06Fourth order, in twenty linesAlight and Nightjar share a small numerics library, and its integrator is the classical fourth-order Runge–Kutta step for x’ = f(t, x).

ZeroVector

A tactical third-person shooter in development, with its own renderer, animation, and audio code.

  1. Module 04An elbow from three side lengthsZeroVector, the author’s tactical shooter, places a character’s arm so that the hand reaches a target.
  2. Module 12Position and velocity, written as a matched pairZeroVector throws dust, sparks, and chips with a closed-form model: a constant acceleration a and a drag proportional to velocity, so that v’ = a - kv with k measured per second.
  3. Module 26A geometric series in every textureA texture in ZeroVector is stored with a chain of smaller copies, each half the width and height of the one before, down to a single pixel, so a distant surface can be drawn from a copy near its size on screen.
  4. Module 33An echo is a mirror imageA gunshot in ZeroVector reaches the listener twice: directly, and after bouncing off the face of a building.
  5. C03A reference that knows when it has gone staleC++ will not stop you from using a pointer after its object is gone.
  6. W06Six planes from one matrixBefore drawing an object, ZeroVector asks whether it can be seen at all.

FateMMO: Awaken

The browser game at fatemmo.com/play.

  1. Module 14How far past the mark? An optimization in nine linesWhen a character in the browser game FateMMO: Awaken turns around, its art narrows to a sliver in 60 ms and springs open facing the other way in 80 ms, overshooting a little before it settles.