Skip to content

177 deterministic sim 22 view code fenced off

Alex Diakovsky edited this page Nov 21, 2026 · 1 revision

177. Deterministic sim 22: the view code fenced off, the float lint at zero (stage S6.4d)

Question: after stage S6.4c the float lint still counted 632 uses in the simulation files. Most were not simulation at all: float properties that turn the integer state into degrees and units a second for the views, the tools and the computer players; the mod tool's channel poses; the tick-to-tick drawing bookkeeping. The rest were real simulation code: the controls arrived as floats, the shot specs carried float keys that the launch still fell back to, the Drone's tuning defaults and the handicap's ammunition share were floats, and the water test divided as a float. Which of the 632 decide what happens, what do they become on integers, and how does the lint keep the views from leaking back in (document 155, issue #133)?

The deterministic simulation series: document 155 is the plan. Documents 156 to 160 are stages S0 to S4, and documents 161 to 170 are S5. S6 takes the last floats out of the simulation files before the check goes into CI: S6.1 the height and water (document 171); S6.2 the Heli's take-off and landing (document 172); S6.3 the weapons (document 173); S6.4 the rest, in four parts: S6.4a the explosion damage boxes (document 174), S6.4b the road assist (document 175), S6.4c the dock test and the rest of the match controller (document 176), S6.4d the view code fenced off from the lint (this document); then S6.5 the CI runs.

The integers themselves were traced in the documents of S5 and S6.1 to S6.4c. This stage adds no new reading of the original: each change below either takes a number the original keeps as an integer from where the port already had it, or marks code the original has no counterpart for as a view.

Glossary

Term Meaning
16.16, raw As in document 161: 0x10000 is one unit.
raw angle 22 bits: 0x400000 is a full turn, 0x10000 one 5.625-degree step. 0 is north, clockwise.
view region #region view .. #endregion in a simulation file: code only the presenters, the sounds, the tools and the tests read. The lint does not count it, and simulation code may not read its names.
ai region #region ai: code only the computer players read (they choose input words; their own maths is not part of the simulated state). Treated as a view region.
load region #region load: code that turns pack data into the simulation's integers when a definition loads (a parameter table, a degrees-to-raw conversion). Not counted, and its names may be read.
view statement A call to a view function as a whole statement, its answer unused: _remember_drawn(). Simulation code may make one; it is how the views get their copies without the simulation reading them.
Pack.fx_of Pack.fx_of(d, key, raw_default): d[key] as 16.16, or raw_default (already 16.16) when the key is missing. The simulation files read their tuning numbers with it, so no float default is spelled there.

The answer, up front

  1. The controls are integers. Vehicle._get_controls() returns a Vector2i of -1, 0 or 1 for turn and thrust, straight from the decoded input word's flags (FUN_0042ce40: left 0x10, right 0x8, forward 0x2, back 0x4). The drives read controls.x and controls.y > 0 (document 138 traced the decode). The values are the same; only the type changed.
  2. A shot's launch reads only integers. Projectile.aim takes z_fx, pitch_fx / bonus_fx, heading_fx and position_fx; its float fallbacks are gone. The weapon modules build those keys and then add the float ones (heading, position, z, pitch_deg, bonus, the flash) in a view statement. The computer players' turned copy of a shot (AIGunner.pointed) now writes position_fx and heading_fx, rounded exactly as the old float setters rounded them.
  3. Tuning defaults are raw. The Drone's constants block (0x443118), the soldiers', the turrets' and the explosion boxes' defaults are spelled as the raw integers they always produced (0.4 -> 0x6666, 0.29998779296875 -> 0x4ccc, -3.5 -> -0x38000), through Pack.fx_of.
  4. The handicap's ammunition share is a whole percent. ammo_max = (ammo * pct + 99) / 100, which is the old ceil(ammo * share) for the shares the menu offers (100, 150, 200 percent). A 16.16 share would not be: 0.6 is 0x999a, and 10 x 0x999a is a hair over 6, which rounds up to 7.
  5. The water test's tile is floor division on whole units, (u - posmod(u, ts)) / ts, not a float floor.
  6. Everything else is a view and is fenced: the float properties (position, heading_deg, speed, z, hp, fuel, the Heli's heli_vel and bank_steps, the Drone's roll and pitch ...), the channels and poses of the mod tool, the per-second copies of the vehicle type's numbers (now filled by a _type_views statement), the wreck snapshot's float keys, TickDraw's prev_* (now a _remember_drawn statement), run_frames for a vehicle or shot no match steps, and Collision's float helpers, which only the computer players use (ai).
  7. The lint knows a component from a view. .z on a Vector3i is not the view named z: a dotted read counts as a view read only when no simulation file declares that name outside its view regions, and never for x, y, z, w. A bare name is still checked against the file's own views.

The float lint counts 0 uses in the 36 simulation files (from 632), and no simulation code reads a view name. The golden match hashes are identical before and after.

Step 1: the controls

// FUN_0042ce40, the decode (document 138, DecompileMany.java 0x0042ce40), the throttle and turn part
if (word & 0x40000000) s |= 2;  else if (word & 0x80000000) s |= 4;  else s |= 1;   // forward / back / neither (friction)
if (word & 0x10000000) s |= 0x10;                       // left
if (word & 0x20000000) s |= 8;                          // right

The drives only ask whether each flag is set: a key is on or off, never a fraction.

## Returns (turn, thrust), each -1, 0 or 1 (right and forward positive).
func _get_controls() -> Vector2i:
	...
	if controls != null:
		# the decoded turn and throttle flags (FUN_0042ce40): left 0x10, right 0x8, forward 0x2, back 0x4
		return Vector2i(int(input_state & InputWord.TURN_RIGHT != 0) - int(input_state & InputWord.TURN_LEFT != 0),
				int(input_state & InputWord.FORWARD != 0) - int(input_state & InputWord.BACK != 0))
# vehicle_modules/ground_drive.gd
	var controls := Vector2i(0, 1) if v.rolling_off else v._get_controls()   # the roll's forced word: forward only
	if b("turn_accelerates") and controls.y == 0 and controls.x != 0:
		controls.y = 1   # FUN_0040db80 (document 62): turning without a throttle key accelerates
	var turn := controls.x

The float version took int(signf(controls.x)); the integer one is that value already.

Step 2: a shot's launch

FUN_004148f0 launches a shot from the object's own fields: its 16.16 place and height, its raw heading and pitch, and the launcher's 16.16 speed added to the type's (document 163). The port's aim took those from the spec's _fx keys when they were there, and from float keys otherwise. Every weapon module already sent the _fx keys; the one caller that did not was the computer players' gunner, which turns a copy of the shot to where it means to aim and erased the _fx keys so the copy would fly from the float values.

## A shot spec's launch (what the weapon modules emit): its integer keys only (stage S6.4d, wiki document 177): height `z_fx`, the
## pitch and launcher speed `pitch_fx` / `bonus_fx` when it has a pitch, heading `heading_fx` and muzzle point `position_fx`.
func aim(spec: Dictionary) -> void:
	z_fx = int(spec["z_fx"])
	if spec.has("pitch_fx"):
		start_pitched_fx(int(spec["pitch_fx"]), int(spec.get("bonus_fx", 0)))
	heading_fx = int(spec["heading_fx"]) & 0x3fffff
	pos_fx = spec["position_fx"]
	prev_fx = pos_fx
	prev_z_fx = z_fx
# ai/ai_gunner.gd, AIGunner.pointed
	var at: Vector2 = about + (_muzzle(spec) - about).rotated(d)
	s["position"] = at
	s["heading"] = heading
	# the copy flies along the turned heading from the turned place: as integers, which is all a shot's launch reads
	s["position_fx"] = Vector2i(roundi(at.x * 65536.0), roundi(at.y * 65536.0))
	s["heading_fx"] = Projectile.raw_angle(heading + 90.0) & 0x3fffff

These are the two conversions the float setters position and heading_deg made, so the copy flies the same path as before. The gunner is not a simulation file: it chooses input words, and its maths stays float.

The modules build the integer spec and then call a view statement for the rest:

# vehicle_modules/cannon.gd
	var spec := {"heading_fx": heading, "type": int(params["projectile"]), "position_fx": pos, "z_fx": z_fx}
	if pitch != 0:
		spec["pitch_fx"] = pitch
	_spec_views(spec, v, m, pitch)
	return spec

VehicleModule.add_spec_views derives heading, position and z from the _fx keys; each module's _spec_views adds its pitch_deg, bonus and muzzle flash. The vehicle's own spec no longer starts with a float heading.

Step 3: raw tuning defaults

Document 169 read the Drone's constants block at 0x443118 as integers the code uses directly, for example:

// document 169: FUN_0040a280 (the attack) picks the turn rate, FUN_0040a480 (the flight) the roll and pitch
if (off < 0x100001 || 0x2fffff < off) rate = T[1];          // ahead
else if (T[4] < d)                    rate = T[3];          // behind, far
else                                  rate = T[2];          // behind, close
FUN_004319e0(&obj->roll,  mul(mag, (T[5] >> 16) * row(i).x), T[6]);
FUN_004319e0(&obj->pitch, mul(mag, (T[7] >> 16) * row(i).y), T[8]);

T[0] is 0x3d7, T[9] and T[10] are 0x4ccc and the aim window is 0xe38e; the pack has carried these exact values since document 169. What stayed float was the port's fallback for a key the pack leaves out.

static func constants(config: Dictionary) -> Dictionary:
	var fl: Dictionary = config.get("flight", {})
	var gn: Dictionary = config.get("gun", {})
	return {
		"velocity_step": Pack.fx_of(fl, "velocity_step", 0x3d7),
		"turn_ahead": Pack.fx_of(fl, "turn_ahead", 0x6666),
		"turn_behind_close": Pack.fx_of(fl, "turn_behind_close", 0x3333),
		...
		"roll_gain": Pack.fx_of(fl, "roll_gain", -(6 << 16)) >> 16,
		"pitch_gain": Pack.fx_of(fl, "pitch_gain", -0x38000) >> 16,
		"accel": Pack.fx_of(fl, "accel", 0x4ccc),

Each default is roundi(old_float * 65536), the value Pack.fx made of it before; the pack's own numbers, when present, are read as before. The soldiers (speed, frame_rate 0x3333; idle_distance 256, throw_max 96 and throw_min 64 units), the turrets (0x3333 and 0xa3d) and the explosion boxes (0x4000 a tick for 0x10000) are the same change.

Step 4: the ammunition share

The handicap (#131, document 153) is a port feature: the original has no share. The match now hands the vehicle a whole percent.

# vehicle.gd, _apply_type
	for i in 2:
		ammo_max[i] = (int(am[i]) * ammo_share_pct + 99) / 100   # rounded up
# ai/ai_handicap.gd
## The ammunition share in whole percent (what a vehicle holds: Vehicle.ammo_share_pct).
func ammo_share_pct() -> int:
	return roundi(ammo_share * 100.0)

Step 5: the water tile

FUN_0042f280 asks the water map's tile under the vehicle (document 62). The tile size is whole units, so the floor division needs no float:

	var ux := pos_fx.x >> 16
	var uy := pos_fx.y >> 16
	var tx := (ux - posmod(ux, ts)) / ts   # floor division, as the float did
	var ty := (uy - posmod(uy, ts)) / ts

Step 6: the views

Each fenced name was checked for simulation readers first; where the simulation used one, the integer it is a view of was used instead:

  • respawn, set_vehicle_type and _reset_water zero speed_fx, heli_omega_fx, heli_vel_fx, heli_wobble_fx and bank_fx (they set the float views to 0.0).
  • _apply_type zeroes heli_rotor_fx, reads the record's numbers with Pack.fx and sink_depth_fx with Pack.fx_of(t, "sink_depth", 14 << 16), and leaves the per-second copies, the float shape and sink_depth to the _type_views(t) statement.
  • _die builds the wreck snapshot from the integers (sink_depth_fx is the vehicle's own, not Pack.fx(sink_depth)) and adds the float keys in _wreck_views(info).
  • sim_step records the drawing state in _remember_drawn(); a debug run's fixed heading (RF_DEBUG_HEADING) is applied in _apply_debug_heading().
  • The Tank's default shape constants (HIT_HALF_WIDTH, HIT_HALF_LENGTH, HIT_Z) are pack-format numbers that Collision.shape_fx turns into 16.16: a load region.
  • Unused float names went: Vehicle._terrain_speed_scale, Projectile.SHELL_Z, the modules' TICK_HZ, Gate.OPEN_MAX.
  • Fx.to_float is a view.

Step 7: the lint's dotted reads

	var sim := {}     # names some simulation file declares as its own state or code: `.name` may be that, so it is not taken for a view
	...
				# bare: this file's own view; dotted: some object's, so a view only when no simulation file has the name too
				if not ((not dotted and own[f].has(n)) or (dotted and all.has(n) and not sim.has(n))):
					continue

The self-test adds the case: another file's view drawn read as o.drawn is caught; o.age is not when some simulation file has an age of its own, and p.z on a Vector3i is not.

The golden check

The determinism harness's computer-vs-computer match on the synthetic fixture (1500 ticks, seed 20261118, skill "normal": both computer players drive, aim with error, fire, and the soldiers throw grenades), recorded once on the S6.4c commits and once on these, one SimHash per tick: identical in everything the simulation does, with one expected difference on every tick. The handicap's share is now a hashed integer under a new name, so tick 1 onwards differs only in that line:

< slots[0].vehicle.ammo_share = 1.0 [000000000000f03f]
> slots[0].vehicle.ammo_share_pct = 100

(and the same for slots[1]). The full hashed state was dumped and diffed at ticks 1, 700 and 1500: no other line differs. The action stats agree too: 681 ticks with a shot in flight, 3 hits, 2 deaths, the vehicles moved 236.76 tiles, 6 soldiers moved, 3 grenades.

Tests

  • Engine suite: all 61 checks pass, no script errors.
  • openfire suite: 77 pass, 0 fail, no script errors.
  • Float lint: 0 uses in the 36 simulation files; the baseline (tests/fixtures/float_lint_baseline.json) is written with every count at zero.

Known differences from the original, kept

  • The ammunition share is a port feature (#131); whole percent is its unit.
  • The computer players stay float: they choose input words, which is all the simulation takes from them (document 155's "The computer players are not on this list").

Where the code is

  • Engine game/vehicle.gd: _get_controls, _apply_type, _type_views, _die, _wreck_views, _remember_drawn, respawn, _reset_water; the view regions.
  • Engine game/projectile.gd: aim, configure, _remember_drawn; game/ai/ai_gunner.gd: pointed; game/ai/ai_handicap.gd: ammo_share_pct.
  • Engine game/vehicle_modules/: vehicle_module.gd (fx, raw_angle_of, add_spec_views), cannon.gd, heli_guns.gd, rocket_salvo.gd (_spec_views), ground_drive.gd, rotor_drive.gd, gun_mount.gd.
  • Engine game/pack.gd: fx_of; game/drone.gd: constants; game/soldier.gd, game/turret.gd, game/explosion_box.gd, game/water.gd, game/collision.gd (the ai region).
  • Engine tests/float_lint_check.gd: the dotted-read rule; tests/fixtures/float_lint_baseline.json: all zero.
  • openfire tools/tests/vehicle_behaviour_trace_check.gd, tools/tests/vehicle_definitions_check.gd: the scripted vehicles' controls as Vector2i.

Commits: engine 0fe2af4, openfire 66e54bf.

S6.4d is done: the float lint's allow-list is empty. Next: S6.5, the determinism check in CI on Linux, Windows and a web export (document 178).

Clone this wiki locally