From 3ba219697ee6ae8b064ba974acec04a5d70886b6 Mon Sep 17 00:00:00 2001 From: David Allemang Date: Sat, 4 Jul 2026 18:07:55 -0400 Subject: [PATCH] block object --- blockstate.js | 3 - resource-cache.js => cache.js | 2 +- diorama.js | 12 ++-- engine.js | 14 ++--- index.html | 104 ++++++++++++++++++++++------------ world.js | 71 +++++++++++++++++------ 6 files changed, 136 insertions(+), 70 deletions(-) rename resource-cache.js => cache.js (96%) diff --git a/blockstate.js b/blockstate.js index 2626cc78..4dfb135c 100644 --- a/blockstate.js +++ b/blockstate.js @@ -37,8 +37,6 @@ export class Blockstate { this.variants = json.variants; this.multipart = json.multipart; - // Memoize evaluated property combinations to prevent console spam - // and speed up Sweep 2 recalculations. this._resolutionCache = new Map(); } @@ -95,7 +93,6 @@ export class Blockstate { } resolveParts(properties) { - // Create a deterministic cache key from the properties object const cacheKey = Object.keys(properties).sort().map(k => `${k}=${properties[k]}`).join(','); if (this._resolutionCache.has(cacheKey)) { diff --git a/resource-cache.js b/cache.js similarity index 96% rename from resource-cache.js rename to cache.js index e877ca7f..7213f096 100644 --- a/resource-cache.js +++ b/cache.js @@ -1,4 +1,4 @@ -export class ResourceCache { +export class Cache { constructor(root) { this.root = root; this.handlers = new Map(); diff --git a/diorama.js b/diorama.js index 19381cec..c2bab7ef 100644 --- a/diorama.js +++ b/diorama.js @@ -80,12 +80,12 @@ export class Diorama { let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity; for (const block of this.world.blocks.values()) { - minX = Math.min(minX, block.x); - minY = Math.min(minY, block.y); - minZ = Math.min(minZ, block.z); - maxX = Math.max(maxX, block.x + 1); - maxY = Math.max(maxY, block.y + 1); - maxZ = Math.max(maxZ, block.z + 1); + minX = Math.min(minX, block.pos[0]); + minY = Math.min(minY, block.pos[1]); + minZ = Math.min(minZ, block.pos[2]); + maxX = Math.max(maxX, block.pos[0] + 1); + maxY = Math.max(maxY, block.pos[1] + 1); + maxZ = Math.max(maxZ, block.pos[2] + 1); } this.target = [(minX + maxX) / 2, (minY + maxY) / 2, (minZ + maxZ) / 2]; diff --git a/engine.js b/engine.js index c6b404e7..dd59a6cd 100644 --- a/engine.js +++ b/engine.js @@ -1,6 +1,6 @@ // engine.js import {mat4Identity, mat4Translate} from './math.js'; -import {ResourceCache} from "./resource-cache.js"; +import {Cache} from "./cache.js"; import {Blockstate, BlockstateHandler} from "./blockstate.js"; import {ModelHandler} from "./model.js"; import {TextureHandler} from "./texture.js"; @@ -94,7 +94,7 @@ export class Engine { this.atlasTexture = gl.createTexture(); // --- Initialize the new Resource Pipeline --- - this.cache = new ResourceCache('assets'); + this.cache = new Cache('assets'); this.atlas = new TextureHandler(256); this.cache.register('blockstates', new BlockstateHandler()); this.cache.register('models', new ModelHandler()); @@ -143,7 +143,7 @@ export class Engine { addDiorama(diorama) { this.dioramas.push(diorama); - if (!this.observedWorlds.has(diorama.world)) { + if (!this.observedWorlds.has(diorama.worlds)) { this.observedWorlds.add(diorama.world); diorama.world.subscribe(() => this.requestUpdate()); } @@ -168,7 +168,7 @@ export class Engine { const parsedBlocks = []; for (const block of world.blocks.values()) { const state = await this.cache.get(block.id, 'blockstates'); - const parts = state.resolveParts(block.props); + const parts = state.resolveParts(block.state); parsedBlocks.push({block, parts}); for (const p of parts) uniqueModelIds.add(p.model); } @@ -190,12 +190,12 @@ export class Engine { } const matrix = mat4Identity(new Float32Array(16)); - mat4Translate(matrix, matrix, [block.x, block.y, block.z]); + mat4Translate(matrix, matrix, block.pos); const pool = instancePool.get(hash); pool.matrices.push(...matrix); - if (block.props.power) { - const p = parseInt(block.props.power, 10); + if (block.state.power) { + const p = parseInt(block.state.power, 10); pool.colors.push((0x4B + (p * 12)) / 255, 0.0, 0.0); } else { pool.colors.push(1.0, 1.0, 1.0); diff --git a/index.html b/index.html index 6eb833bc..e9337d80 100644 --- a/index.html +++ b/index.html @@ -25,16 +25,20 @@

Visualizer

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ullamcorper ut mauris sed tempor. Nunc - vehicula tempor purus, non vestibulum libero ornare non. Morbi fringilla sapien diam, sed rhoncus lacus egestas + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ullamcorper ut mauris sed + tempor. Nunc + vehicula tempor purus, non vestibulum libero ornare non. Morbi fringilla sapien diam, sed + rhoncus lacus egestas vel.

- Curabitur vestibulum vitae orci ac laoreet. Donec vel imperdiet tortor. Vestibulum lobortis aliquam tellus, - vitae viverra nisi porttitor quis. Pellentesque id efficitur arcu. Nunc laoreet pulvinar ligula eu maximus. + Curabitur vestibulum vitae orci ac laoreet. Donec vel imperdiet tortor. Vestibulum lobortis + aliquam tellus, + vitae viverra nisi porttitor quis. Pellentesque id efficitur arcu. Nunc laoreet pulvinar + ligula eu maximus. Mauris ullamcorper accumsan dui vel pulvinar.

@@ -44,11 +48,13 @@

- Curabitur tincidunt sapien et diam fringilla, eu accumsan odio faucibus. Orci varius natoque penatibus et magnis + Curabitur tincidunt sapien et diam fringilla, eu accumsan odio faucibus. Orci varius natoque + penatibus et magnis dis parturient montes, nascetur ridiculus mus.

-
+