Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions docs/noise/entity-generation-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,44 @@ placement stream.** So a chunk's stream depends only on the fields, the tile
masks, the tile restrictions and the chunk position, never on entity
collisions.

### Inside `Surface::collide` (READ as decompiled C, 2026-11-12)

Read from Ghidra's decompiler, not from objdump: the 2.1.23 binary imported
with only the DWARF and GNU demangler analyzers (about 5 minutes), and
signatures rebuilt from the mangled names. The `decompiling-with-ghidra` skill
in `wormeyman/wormeyman-skills` has the script and the steps. As a control,
`generateEntities` decompiled to the same arbitration compare that section 2
read by hand. Struct offsets below are as the C shows them; field names are
not in the debug info.

`Surface::collide(box, mask, entity, forPlayer)`, `0x18eea40`, 487 bytes:

- A box whose `left_top` equals its `right_bottom` (zero area) never collides.
- **Tiles are tested first** (`constCollideWithTile`). A tile hit returns at
once, as result kind 4, before any entity is looked at.
- Only then `collideWithEntity(box, mask, entity, filter, <empty filter>)`. A
hit returns kind 3 with that entity.

`Surface::collideWithEntity`, `0x18eec80`, 909 bytes:

- If bit `0x4` of the mask's flag byte (`mask + 0x20`) is set, no entity is
tested at all. Which named flag that is was not read (INFERRED:
`colliding_with_tiles_only`).
- Candidates come from the box's `getAABB`, with both corners shifted right
by 9 (positions are in 1/256 tile, so the buckets are 2 by 2 tiles), both
ends inclusive. Each chunk (bucket index shifted right by 4) holds a
linked list per bucket.
- `entity` is skipped by identity. `mapGeneratorWouldCollide` passes
`nullptr`, so this does not matter for map generation.
- **No shared layer means no collision**: the other entity's mask comes from
`CollisionMaskIndex::indexToCollisionMask` (index at entity `+0x6c`), and
all four 64-bit ANDs zero skips it. With a shared layer, three flag-bit
rules can still skip it; one is "both masks identical and bit `0x1` clear in
both". The meaning of bits `0x1`, `0x4` and `0x8` here was not decoded.
- **The overlap test belongs to the entity already on the surface**: its
vtable slot `+0x248` is called with the new box. Which method that is was
not resolved, so how a rotated box is tested is still open.

## 8. Resource against simple-entity, and Aquilo's specifics

| | resource (fluorine-vent, lithium-brine, crude-oil) | simple-entity iceberg (huge, big) |
Expand Down Expand Up @@ -513,12 +551,12 @@ Two smaller gaps in the Aquilo inputs:

## What is not settled

1. **`Surface::collide` internals (not read).** Only the call and its
arguments were read. That it tests existing entities by their own boxes,
that masks must share a layer, and that it includes tiles are INFERRED.
The edge rule (touching collides) is MEASURED above, on Aquilo only. To
read it, start at `Surface::collide(BoundingBox const&, CollisionMask
const&, Entity const*, ForPlayerControlledMovement)` at `0x18eea40`.
1. **`Surface::collide` internals (partly read, see "Inside
`Surface::collide`" in section 7).** That it includes tiles, tests them
first, and needs a shared layer is now READ. Still open: the existing
entity's box test (vtable `+0x248`), and the meaning of the mask flag bits
that skip a shared-layer pair. The edge rule (touching collides) is
MEASURED above, on Aquilo only.
2. **Order of chunks in apply.** Row-major is MEASURED above on one surface,
generated by `request_to_generate_chunks({0, 0}, 8)` and
`force_generate_chunk_requests()`. The order comes from the chunk
Expand Down
Loading