Skip to content

Commit

Permalink
another fix for correct view distance in p-viewer
Browse files Browse the repository at this point in the history
emit error when resourecpack size exceeds browser limit
worker models: improve perf when loading big number of chunks (still not ideal, should be a setting I think as I like more prev behavior)
  • Loading branch information
zardoy committed Oct 16, 2023
1 parent 0381379 commit 83f7aee
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"test-mc-server": "tsx cypress/minecraft-server.mjs",
"lint": "eslint \"{src,cypress}/**/*.{ts,js,jsx,tsx}\"",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
"build-storybook": "storybook build",
"watch-worker": "node prismarine-viewer/buildWorker.mjs -w"
},
"keywords": [
"prismarine",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions prismarine-viewer/viewer/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ function renderElement (world, cursor, element, doAO, attr, globalMatrix, global
if (neighbor) {
if (cullIfIdentical && neighbor.type === block.type) continue
if (!neighbor.transparent && neighbor.isCube) continue
} else {
continue
}
}

Expand Down
5 changes: 4 additions & 1 deletion prismarine-viewer/viewer/lib/worldDataEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class WorldDataEmitter extends EventEmitter {
const [botX, botZ] = chunkPos(this.lastPos)
const dx = Math.abs(botX - Math.floor(pos.x / 16))
const dz = Math.abs(botZ - Math.floor(pos.z / 16))
if (dx < this.viewDistance && dz < this.viewDistance) {
if (dx <= this.viewDistance && dz <= this.viewDistance) {
const column = await this.world.getColumnAt(pos['y'] ? pos as Vec3 : new Vec3(pos.x, 0, pos.z))
if (column) {
// todo optimize toJson data, make it clear why it is used
Expand All @@ -124,6 +124,9 @@ export class WorldDataEmitter extends EventEmitter {
this.emitter.emit('loadChunk', { x: pos.x, z: pos.z, chunk, blockEntities: column.blockEntities, worldConfig })
this.loadedChunks[`${pos.x},${pos.z}`] = true
}
} else {
// todo should not happend in singleplayer
console.log('skipped loading chunk', dx, dz, '>', this.viewDistance)
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/texturePack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ export const genTexturePackTextures = async (version: string) => {

const imgSize = texSize * tileSize

const MAX_CANVAS_SIZE = 16_384
if (imgSize > MAX_CANVAS_SIZE) {
throw new Error(`Texture pack texture resolution is too big, max size is ${MAX_CANVAS_SIZE}x${MAX_CANVAS_SIZE}`)
// texSize = nextPowerOfTwo(Math.ceil(Math.sqrt(textureFiles.length / 2)))
}
const canvas = document.createElement('canvas')
canvas.width = imgSize
canvas.height = imgSize
Expand Down

0 comments on commit 83f7aee

Please sign in to comment.