Download Game! Currently 85 players and visitors. Last logged in:ValkristBrurinCordobaSpick

Blitzer's Blog >> 72139

Back to blogs index
Posted: 06 Sep 2026 11:13 [ permalink ]
Here is the technical specification for the VOXEL_MEMORY_ARENA. We will design
this using a strict, flat-memory architecture, utilizing bitwise operations
and a single 32-bit integer per voxel.
This approach completely eliminates JavaScript object allocation overhead and
guarantees deterministic, cache-friendly data structures that can be
seamlessly transferred to Web Workers.
1. The Chunk Architecture
Instead of allocating thousands of individual CCubeData objects, we will
divide the world into fixed-size chunks, perfectly mirroring your original
bufferMaxSize parameters.
 * Chunk Dimensions: 8x8x8 grid (bufferMaxSizeX/Y/Z = 8).
 * Volume: 512 voxels per chunk.
 * Memory Structure: A single flat Uint32Array(512) per chunk.
 * Spatial Indexing: 1D array offset calculated via x + (y * 8) + (z * 64).
2. The 32-Bit Voxel Bitmask (Uint32)
We will pack all state data into a single 32-bit integer. This unified format
is highly efficient for the worker to parse during the geometry compilation
phase.
| Bit Range | Size | Description | C++ Equivalent |
|---|---|---|---|
| 0 | 1 bit | Filled Flag: 0 = Empty, 1 = Solid | CCubeData::filled |
| 1-4 | 4 bits | Point Type: Maps to the ECubePointType enum (0 = Normal, 1 =
SmoothX, etc.) | CCubePoint::type |
| 5-16 | 12 bits | Texture ID: Maps to the atlas slot coordinate (allows up to
4096 textures) | CCubeData::texture_kludge / CCubeSide::textureSlot |
| 17-23 | 7 bits | Visible Faces: Bitmask representing which faces are exposed
to air (calculated automatically) | CCubeSide::visible |
| 24-31 | 8 bits | Reserved: Space for future MVP lighting, damage states, or
arbitrary flags | N/A |
3. Asynchronous IPC (The Edit Queue)
To prevent main-thread stutter when the user modifies the terrain, the
EDITING_OPERATIONS must not mutate the chunk arrays directly while the Web
Worker is reading them.
 * Command Buffer: We will implement a SharedArrayBuffer as an SPSC
(Single-Producer, Single-Consumer) ring buffer.
 * Instruction Format: Edits are pushed as fixed-width opcodes: [COMMAND_ID,
CHUNK_ID, VOXEL_INDEX, NEW_VALUE].
 * Execution Flow: The main thread pushes a user edit to the ring buffer. The
Web Worker consumes the buffer, mutates its local Uint32Array, flags the chunk
as dirty, and reconstructs the Float32Array geometry.
4. Implementation Test Strategy
Before writing rendering logic, we will build a headless CLI test suite. We
will instantiate a chunk, write bitwise macros to insert a 3x3 block, and read
the Uint32Array values back to ensure the bit shifting perfectly matches your
original C++ bounds.
Does this specification look solid enough for you to copy into a new session
for the actual code generation, or should we refine the bitmask mapping for
the texture slots first?