Skip to content

Add dynamic instance buffers for runtime entity spawning - #1

Merged
basarkaman merged 1 commit into
masterfrom
claude/nervous-maxwell
Apr 15, 2026
Merged

Add dynamic instance buffers for runtime entity spawning#1
basarkaman merged 1 commit into
masterfrom
claude/nervous-maxwell

Conversation

@basarkaman

Copy link
Copy Markdown
Owner

Instance buffers were previously allocated to exactly the initial entity count, making it impossible to spawn or despawn entities at runtime without a panic in write_buffer.

Changes:

  • Add instance_capacity field to ModelEntry to track allocated slots
  • Allocate buffers at max(initial_count, 64).next_power_of_two() on startup so common cases (1 Sponza instance) get 64 slots of free headroom
  • In update(), detect when entity count exceeds capacity and recreate the buffer at count.next_power_of_two() slots before writing
  • Add State::world_mut() so game code can call world_mut().spawn(...) to add entities; buffers update automatically on the next frame

Instance buffers were previously allocated to exactly the initial entity
count, making it impossible to spawn or despawn entities at runtime without
a panic in write_buffer.

Changes:
- Add `instance_capacity` field to `ModelEntry` to track allocated slots
- Allocate buffers at `max(initial_count, 64).next_power_of_two()` on startup
  so common cases (1 Sponza instance) get 64 slots of free headroom
- In `update()`, detect when entity count exceeds capacity and recreate the
  buffer at `count.next_power_of_two()` slots before writing
- Add `State::world_mut()` so game code can call `world_mut().spawn(...)` to
  add entities; buffers update automatically on the next frame

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@basarkaman
basarkaman merged commit 2c6f3bf into master Apr 15, 2026
1 check passed
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