Skip to content

feat: convert simulation to native float32 math - #7

Merged
HashimTheArab merged 8 commits into
mainfrom
agent/native-float32
Jul 21, 2026
Merged

feat: convert simulation to native float32 math#7
HashimTheArab merged 8 commits into
mainfrom
agent/native-float32

Conversation

@HashimTheArab

@HashimTheArab HashimTheArab commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • move all bedsim movement state, inputs, results, vectors, scalars, and hot-path helpers to native float32 math
  • use Dragonfly’s cube.BBox32 for all simulation-side geometry through the maintained fork
  • restore the original float32 Minecraft sine table and epsilon behavior
  • migrate tests and golden expectations to float32-appropriate tolerances

Why

The Bedrock client performs movement arithmetic in 32-bit floats and the protocol carries float32 positions and velocities. Running the simulator in float64 changes rounding before epsilon-sensitive collision, on-ground, penetration, and stepping branches, which can produce discrete client-parity failures.

Breaking changes

Provider collision APIs now exchange Dragonfly cube.BBox32 values, movement vectors use mgl32, and simulation scalars—including block friction and correction thresholds—use float32. BBoxFromDragonfly is provided for conversion at Dragonfly model/provider boundaries.

Validation

  • go build ./...
  • go vet ./...
  • go test ./... -count=1
  • git diff --check
  • rg 'mgl64|float64' --glob '*.go' returns no matches

Summary by CodeRabbit

  • Improvements
    • Movement, collision, and liquid simulation now use consistent 32-bit precision for more stable results near tight boundaries.
    • Bounding-box conversion improves rounding at provider/edge boundaries.
  • Bug Fixes
    • More consistent collision resolution and liquid-flow outcomes in precision-sensitive situations.
  • API Changes
    • Public math/geometry types and key interfaces now use 32-bit vectors/boxes, including friction, collision/clipping inputs, simulator thresholds, and simulation result vectors.
    • Updated exported tuning constants to float32.
  • Tests
    • Updated and extended tests to validate the 32-bit behavior.
  • Chores
    • Go toolchain and module versions were updated.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR migrates movement, collision, liquid, and simulator math from float64 to float32, introduces float32 cube and math dependencies, updates public state and provider contracts, and adjusts regression tests and coordinate conversions.

Changes

Float32 physics migration

Layer / File(s) Summary
Float32 contracts and state types
go.mod, constants.go, interfaces.go, input.go, movement.go, result.go, math.go, bbox.go, block.go
Public movement state, input, result, provider interfaces, bounding boxes, constants, friction, and math helpers use float32 and updated cube types.
Float32 collision and movement execution
collision.go, simulation.go
Collision clipping, movement resolution, gliding, stepping, teleport interpolation, and supporting-block calculations use float32 math and vectors.
Float32 liquid simulation
liquid.go
Liquid detection, swimming, gravity, flow, and liquid-provider position handling use float32 math and bounding boxes.
Float32 regression and simulator validation
liquid_test.go, liquid_hardening_test.go, simulator.go, simulator_test.go, native_float32_test.go
Test worlds, expected vectors, friction checks, collision scenarios, provider fixtures, and conversion tests validate the updated float32 behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • oomph-ac/bedsim#2: Both changes modify bbox.go hitbox handling and related swimming behavior.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 65.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: converting the simulation to native float32 math.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/native-float32

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@simulation.go`:
- Line 1024: Update the cobweb collision check around IntersectsWith to use the
already world-space collision box directly, removing the additional
Translate(posVec3(pos)) call. Preserve the existing intersection behavior while
ensuring BlockCollisions results are not offset twice.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6dec3eee-c345-4427-9c91-fbef994f2012

📥 Commits

Reviewing files that changed from the base of the PR and between 3a517d7 and 6ad5a87.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (17)
  • bbox.go
  • block.go
  • collision.go
  • constants.go
  • go.mod
  • input.go
  • interfaces.go
  • liquid.go
  • liquid_hardening_test.go
  • liquid_test.go
  • math.go
  • movement.go
  • native_float32_test.go
  • result.go
  • simulation.go
  • simulator.go
  • simulator_test.go

Comment thread simulation.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@liquid_test.go`:
- Around line 57-76: Update liquidWorld.BlockCollisions to return the collision
box in block-local coordinates without translating by pos. In
liquidWorld.GetNearbyBBoxes, translate each returned local box by the
corresponding block position before intersecting with aabb and appending it,
ensuring consumers receive world-space boxes while avoiding double translation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f2665d84-3c7e-4fd3-8c30-5b17140d68b4

📥 Commits

Reviewing files that changed from the base of the PR and between f5ffaac and f185c7a.

📒 Files selected for processing (12)
  • bbox.go
  • block.go
  • collision.go
  • interfaces.go
  • liquid.go
  • liquid_hardening_test.go
  • liquid_test.go
  • math.go
  • movement.go
  • native_float32_test.go
  • simulation.go
  • simulator_test.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • native_float32_test.go
  • bbox.go
  • math.go
  • collision.go
  • simulator_test.go

Comment thread liquid_test.go
@HashimTheArab
HashimTheArab merged commit 82a19cb into main Jul 21, 2026
1 check passed
@HashimTheArab
HashimTheArab deleted the agent/native-float32 branch July 21, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant