forked from PrismarineJS/prismarine-web-client
-
Notifications
You must be signed in to change notification settings - Fork 115
feat: Client Side Light Engine! #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zardoy
wants to merge
35
commits into
next
Choose a base branch
from
light-engine
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
245300f
init
zardoy d5c61d8
a working light
zardoy 48ead54
should work.
zardoy 037e297
Merge remote-tracking branch 'origin/next' into light-engine
zardoy ace45a9
not crash pls
zardoy ec6b249
Merge remote-tracking branch 'origin/next' into light-engine
zardoy 9f505f8
rm workaround
zardoy f18b3a1
Merge branch 'next' into light-engine
zardoy e10f610
humble and terrible progress
zardoy 0fa66e2
Merge remote-tracking branch 'origin/next' into light-engine
zardoy b1ba2cd
Merge remote-tracking branch 'origin/next' into light-engine
zardoy 3cd1ac3
Merge branch 'next' into light-engine
zardoy 1918c68
finish lighting
zardoy b4c72db
fix crash opt
zardoy 1f5b682
FINISH OPTIONS, FINISH RECOMPUTE, ADD LIGHT TO WATER
zardoy 5a57d29
Merge branch 'next' into light-engine
zardoy 2f6191a
Merge remote-tracking branch 'origin/next' into light-engine
zardoy f4eab39
finish lighting
zardoy 79f0fdd
fix lava rendering
zardoy 27c55b1
finish!
zardoy f4f5edd
fix lighting disabling
zardoy c97c7e0
finish combined computation, finish settings and strategies
zardoy c4b9c33
Update src/optionsStorage.ts
zardoy 7d224fb
Merge remote-tracking branch 'origin/next' into light-engine
zardoy d6f394f
hide cursor block in spectator
zardoy ddf0810
final step: move engine to another thread
zardoy 5720cfa
up light
zardoy 7dba526
Merge remote-tracking branch 'origin/next' into light-engine
zardoy e95f84e
fix lock
zardoy 90de0d0
up chunk?
zardoy f185df9
fix remaining issues with worker bundle with smart approach
zardoy 6be3c5c
Merge remote-tracking branch 'origin/next' into light-engine
zardoy 56aee16
Merge branch 'next' into light-engine
zardoy b8c8f8a
Merge branch 'next' into light-engine
zardoy 6a8d15b
[deploy] properly destroy world view
zardoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { LightWorld, createLightEngineForSyncWorld, convertPrismarineBlockToWorldBlock } from 'minecraft-lighting' | ||
import { world } from 'prismarine-world' | ||
import { WorldRendererCommon } from './worldrendererCommon' | ||
import { WorldDataEmitter } from './worldDataEmitter' | ||
|
||
let lightEngine: LightWorld | null = null | ||
export const getLightEngine = () => { | ||
if (!lightEngine) throw new Error('Light engine not initialized') | ||
return lightEngine | ||
} | ||
export const getLightEngineSafe = () => { | ||
return lightEngine | ||
} | ||
|
||
export const createLightEngineIfNeeded = (worldView: WorldDataEmitter) => { | ||
if (lightEngine) return | ||
lightEngine = createLightEngineForSyncWorld(worldView.world as unknown as world.WorldSync, loadedData, { | ||
minY: worldView.minY, | ||
height: worldView.minY + worldView.worldHeight, | ||
// writeLightToOriginalWorld: true, | ||
// enableSkyLight: false, | ||
}) | ||
lightEngine.externalWorld.setBlock = () => {} | ||
lightEngine.PARALLEL_CHUNK_PROCESSING = false | ||
globalThis.lightEngine = lightEngine | ||
} | ||
|
||
export const processLightChunk = async (x: number, z: number) => { | ||
const engine = getLightEngineSafe() | ||
if (!engine) return | ||
|
||
const chunkX = Math.floor(x / 16) | ||
const chunkZ = Math.floor(z / 16) | ||
// fillColumnWithZeroLight(engine.externalWorld, chunkX, chunkZ) | ||
|
||
const updated = engine.receiveUpdateColumn(chunkX, chunkZ) | ||
return updated | ||
} | ||
|
||
export const dumpLightData = (x: number, z: number) => { | ||
const engine = getLightEngineSafe() | ||
return engine?.worldLightHolder.dumpChunk(Math.floor(x / 16), Math.floor(z / 16)) | ||
} | ||
|
||
export const getDebugLightValues = (x: number, y: number, z: number) => { | ||
const engine = getLightEngineSafe() | ||
return { | ||
blockLight: engine?.worldLightHolder.getBlockLight(x, y, z) ?? -1, | ||
skyLight: engine?.worldLightHolder.getSkyLight(x, y, z) ?? -1, | ||
} | ||
} | ||
|
||
export const updateBlockLight = async (x: number, y: number, z: number, stateId: number, distance: number) => { | ||
if (distance > 16) return [] | ||
const chunkX = Math.floor(x / 16) * 16 | ||
const chunkZ = Math.floor(z / 16) * 16 | ||
const engine = getLightEngineSafe() | ||
if (!engine) return | ||
const result = await engine.setBlockUpdateChunkIfNeeded(x, y, z) | ||
if (!result) return | ||
console.log(`[light engine] updateBlockLight (${x}, ${y}, ${z}) took`, Math.round(result.time), 'ms', result.affectedChunks?.length ?? 0, 'chunks') | ||
return result.affectedChunks | ||
|
||
// const engine = getLightEngineSafe() | ||
// if (!engine) return | ||
// const affected = engine['affectedChunksTimestamps'] as Map<string, number> | ||
// const noAffected = affected.size === 0 | ||
// engine.setBlock(x, y, z, convertPrismarineBlockToWorldBlock(stateId, loadedData)) | ||
|
||
// if (affected.size > 0) { | ||
// const chunks = [...affected.keys()].map(key => { | ||
// return key.split(',').map(Number) as [number, number] | ||
// }) | ||
// affected.clear() | ||
// return chunks | ||
// } | ||
} | ||
|
||
export const lightRemoveColumn = (x: number, z: number) => { | ||
const engine = getLightEngineSafe() | ||
if (!engine) return | ||
engine.columnCleanup(Math.floor(x / 16), Math.floor(z / 16)) | ||
} | ||
|
||
export const destroyLightEngine = () => { | ||
lightEngine = null | ||
globalThis.lightEngine = null | ||
} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete light engine cleanup
The
destroyLightEngine
function only destroys the synchronous engine and not the worker-based one.Update the function to clean up both engine types:
📝 Committable suggestion