Skip to content

Move minecraft protocol into worker! #319

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
wants to merge 91 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
3051cc3
up pkg
zardoy Jan 29, 2025
aed5b40
use local
zardoy Jan 29, 2025
380c214
make it finally pass grim checks!
zardoy Jan 30, 2025
044153c
up ver
zardoy Jan 30, 2025
5376584
use gen mineflayer
zardoy Jan 30, 2025
2848ab6
disable silly creative fly patching
zardoy Jan 31, 2025
8db6b5b
fix library versions
zardoy Jan 31, 2025
c626d10
use actually useful server
zardoy Jan 31, 2025
2d7ec12
Merge branch 'next' into nextgen-physics
zardoy Feb 3, 2025
7e74633
Merge branch 'next' into nextgen-physics
zardoy Feb 3, 2025
fb10179
set 1.19.4 for now!
zardoy Feb 3, 2025
9356daa
Merge branch 'next' into nextgen-physics
zardoy Feb 13, 2025
638dd67
Merge branch 'next' into nextgen-physics
zardoy Feb 15, 2025
34972e4
Merge branch 'next' into nextgen-physics
zardoy Feb 27, 2025
c65db9a
a working refactor
zardoy Mar 4, 2025
4381ef4
removing bobbing & panorama
zardoy Mar 4, 2025
d8294d5
even more appViewer usage
zardoy Mar 4, 2025
1861edf
delayLoadUntilFocus
zardoy Mar 4, 2025
d197859
big resourcemanager refactor
zardoy Mar 5, 2025
cefdf53
Merge branch 'next' into nextgen-physics
zardoy Mar 7, 2025
0597a3d
make library versions less annoying
zardoy Mar 9, 2025
7cc562b
Merge remote-tracking branch 'origin/next' into nextgen-physics
zardoy Mar 14, 2025
3a9e2aa
fix
zardoy Mar 14, 2025
8a3c847
test flying!
zardoy Mar 14, 2025
847314d
hide hand in spectator
zardoy Mar 14, 2025
4d4637f
Merge remote-tracking branch 'origin/next' into nextgen-physics
zardoy Mar 15, 2025
d74d860
Merge remote-tracking branch 'origin/next' into renderer-rewrite
zardoy Mar 15, 2025
f230763
Merge remote-tracking branch 'origin/next' into nextgen-physics
zardoy Mar 18, 2025
67d90a5
Merge remote-tracking branch 'origin/next' into renderer-rewrite
zardoy Mar 18, 2025
6eb50cd
last dont crash
zardoy Mar 18, 2025
dc073cd
Merge remote-tracking branch 'origin/next' into renderer-rewrite
zardoy Mar 18, 2025
400f598
update server data for index 0
zardoy Mar 20, 2025
5364085
fix possible crash on non existing server data update
zardoy Mar 20, 2025
f2f1c25
10x inventory performance
zardoy Mar 20, 2025
e851f4f
Merge remote-tracking branch 'origin/next' into nextgen-physics
zardoy Mar 20, 2025
de3edda
a lot of imports update, data cleanup, add thousands errors
zardoy Mar 20, 2025
c1a7765
final code cleanup i think
zardoy Mar 20, 2025
ccb0004
fix reload hand
zardoy Mar 20, 2025
9fedafe
move threejs entities & cursor block to renderer
zardoy Mar 21, 2025
136b051
smooth camera movement!
zardoy Mar 21, 2025
f88e9c8
Refactor renderer state management and move vr
zardoy Mar 21, 2025
cae2b61
fix all remaining reactive state linking
zardoy Mar 21, 2025
82d0638
Merge remote-tracking branch 'origin/next' into renderer-rewrite
zardoy Mar 21, 2025
b483923
rm unused three imports
zardoy Mar 21, 2025
dc2ad7c
disable signs, disable playground since its not used by anyone
zardoy Mar 21, 2025
8ee4dc3
disable displaying unknown non interactible entitites
zardoy Mar 21, 2025
11abbfc
disable check
zardoy Mar 21, 2025
5eedb3c
disable playground
zardoy Mar 21, 2025
8ddac97
dont use bot
zardoy Mar 21, 2025
853e0e1
up readme
zardoy Mar 21, 2025
d450a31
fix typo
zardoy Mar 21, 2025
b579ee1
Revert "disable playground"
zardoy Mar 21, 2025
ed04197
disable in other way
zardoy Mar 21, 2025
e917764
fix lint
zardoy Mar 21, 2025
e2b7833
Merge remote-tracking branch 'origin/renderer-rewrite' into nextgen-p…
zardoy Mar 21, 2025
b501893
ip pkgs
zardoy Mar 23, 2025
9888bd5
fix: allow to go back when not crashed game
zardoy Mar 21, 2025
2056974
fix mesher config pass
zardoy Mar 21, 2025
2630a57
renderers cleanup
zardoy Mar 21, 2025
6a5ac4f
make initial resource pack load optimised, rework it
zardoy Mar 21, 2025
9cede6d
final fixes
zardoy Mar 21, 2025
bf9c47d
fix test
zardoy Mar 21, 2025
547658f
Merge remote-tracking branch 'origin/next' into nextgen-physics
zardoy Mar 25, 2025
9057d3a
revert stuff
zardoy Mar 25, 2025
14e20a2
Merge remote-tracking branch 'origin/next' into nextgen-physics
zardoy Mar 26, 2025
e7c2406
up
zardoy Mar 26, 2025
0648d55
pick only necessary changes
zardoy Mar 26, 2025
b472583
revert unknown chaange
zardoy Mar 26, 2025
e743a03
Merge branch 'nextgen-physics' into protocol-worker
zardoy Mar 26, 2025
b9ca057
restore
zardoy Mar 26, 2025
bc9ca18
restore2
zardoy Mar 26, 2025
07e7c6f
revert physics for test
zardoy Mar 26, 2025
0839889
Merge remote-tracking branch 'origin/next' into nextgen-physics
zardoy Mar 30, 2025
bb6faf9
Merge remote-tracking branch 'origin/nextgen-physics' into protocol-w…
zardoy Mar 30, 2025
07e9725
.
zardoy Mar 31, 2025
290e641
Merge remote-tracking branch 'origin/next' into protocol-worker
zardoy Apr 10, 2025
0787440
.
zardoy Apr 10, 2025
bdcf3d6
finishing! fix all known bugs! chat! websockets! fix ping & username …
zardoy Apr 11, 2025
316fdd8
Merge remote-tracking branch 'origin/next' into protocol-worker
zardoy Apr 11, 2025
4483b73
revert
zardoy Apr 11, 2025
980779c
revertconfig
zardoy Apr 11, 2025
b50215b
fix build
zardoy Apr 12, 2025
92d444a
fix one build, break another
zardoy Apr 12, 2025
df2a337
try fixing single file, no more tries for now
zardoy Apr 12, 2025
ccd1130
Update rsbuild.config.ts
zardoy Apr 12, 2025
4a949d3
Update rsbuild.config.ts
zardoy Apr 12, 2025
475d990
patch
zardoy Apr 12, 2025
d9f1efd
fix
zardoy Apr 12, 2025
1fe6239
Merge branch 'next' into protocol-worker
zardoy Apr 18, 2025
cd84acb
fix single file build
zardoy May 1, 2025
139ee9a
Revert "fix single file build"
zardoy May 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@
"no-bitwise": "off",
"unicorn/filename-case": "off",
"max-depth": "off",
"unicorn/no-typeof-undefined": "off"
"unicorn/no-typeof-undefined": "off",
"unicorn/relative-url-style": "off"
},
"overrides": [
{
Expand Down
10 changes: 10 additions & 0 deletions renderer/rsbuildSharedConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ export const appAndRendererSharedConfig = () => defineConfig({
],
tools: {
rspack (config, helpers) {
if (process.env.SINGLE_FILE_BUILD === 'true') {
config.module.rules.push({
test: /\.worker\.(js|ts)$/,
loader: "worker-rspack-loader",
options: {
inline: "no-fallback",
},
})
}

const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'))
const hasFileProtocol = Object.values(packageJson.pnpm.overrides).some((dep) => (dep as string).startsWith('file:'))
if (hasFileProtocol) {
Expand Down
6 changes: 6 additions & 0 deletions renderer/viewer/lib/simpleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ export function sectionPos (pos: { x: number, y: number, z: number }) {
const z = Math.floor(pos.z / 16)
return [x, y, z]
}
// doesn't support snapshots

export const toMajorVersion = version => {
const [a, b] = (String(version)).split('.')
return `${a}.${b}`
}
30 changes: 27 additions & 3 deletions renderer/viewer/lib/workerProxy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
export function createWorkerProxy<T extends Record<string, (...args: any[]) => void>> (handlers: T, channel?: MessagePort): { __workerProxy: T } {
export function createWorkerProxy<T extends Record<string, (...args: any[]) => void | Promise<any>>> (handlers: T, channel?: MessagePort): { __workerProxy: T } {
const target = channel ?? globalThis
target.addEventListener('message', (event: any) => {
const { type, args } = event.data
const { type, args, msgId } = event.data
if (handlers[type]) {
handlers[type](...args)
const result = handlers[type](...args)
if (result instanceof Promise) {
void result.then((result) => {
target.postMessage({
type: 'result',
msgId,
args: [result]
})
})
}
}
})
return null as any
Expand All @@ -23,6 +32,7 @@ export function createWorkerProxy<T extends Record<string, (...args: any[]) => v
export const useWorkerProxy = <T extends { __workerProxy: Record<string, (...args: any[]) => void> }> (worker: Worker | MessagePort, autoTransfer = true): T['__workerProxy'] & {
transfer: (...args: Transferable[]) => T['__workerProxy']
} => {
let messageId = 0
// in main thread
return new Proxy({} as any, {
get (target, prop) {
Expand All @@ -41,11 +51,25 @@ export const useWorkerProxy = <T extends { __workerProxy: Record<string, (...arg
}
}
return (...args: any[]) => {
const msgId = messageId++
const transfer = autoTransfer ? args.filter(arg => arg instanceof ArrayBuffer || arg instanceof MessagePort || arg instanceof ImageBitmap || arg instanceof OffscreenCanvas || arg instanceof ImageData) : []
worker.postMessage({
type: prop,
msgId,
args,
}, transfer as any[])
return {
// eslint-disable-next-line unicorn/no-thenable
then (onfulfilled: (value: any) => void) {
const handler = ({ data }: MessageEvent): void => {
if (data.type === 'result' && data.msgId === msgId) {
onfulfilled(data.args[0])
worker.removeEventListener('message', handler as EventListener)
}
}
worker.addEventListener('message', handler as EventListener)
}
}
}
}
})
Expand Down
3 changes: 1 addition & 2 deletions renderer/viewer/lib/worldrendererCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import { WorldBlockProvider } from 'mc-assets/dist/worldBlockProvider'
import { generateSpiralMatrix } from 'flying-squid/dist/utils'
import { subscribeKey } from 'valtio/utils'
import { dynamicMcDataFiles } from '../../buildMesherConfig.mjs'
import { toMajorVersion } from '../../../src/utils'
import { ResourcesManager } from '../../../src/resourcesManager'
import { DisplayWorldOptions, GraphicsInitOptions, RendererReactiveState } from '../../../src/appViewer'
import { SoundSystem } from '../three/threeJsSound'
import { buildCleanupDecorator } from './cleanupDecorator'
import { HighestBlockInfo, MesherGeometryOutput, CustomBlockModels, BlockStateModelInfo, getBlockAssetsCacheKey, MesherConfig } from './mesher/shared'
import { chunkPos } from './simpleUtils'
import { chunkPos, toMajorVersion } from './simpleUtils'
import { addNewStat, removeAllStats, removeStat, updatePanesVisibility, updateStatText } from './ui/newStats'
import { WorldDataEmitter } from './worldDataEmitter'
import { IPlayerState } from './basePlayerState'
Expand Down
28 changes: 27 additions & 1 deletion rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ const appConfig = defineConfig({
if (singleBuildFiles.length !== 1 || singleBuildFiles[0] !== 'index.html') {
throw new Error('Single file build must only have index.html in the dist/single folder. Ensure workers are imported & built correctly.')
}
// check if dist/static/js/async is empty
if (fs.existsSync('./dist/static/js/async')) {
const asyncFiles = fs.readdirSync('./dist/static/js/async')
if (asyncFiles.length > 0) {
throw new Error('dist/static/js/async must be empty. Ensure workers are imported & built correctly.')
}
}

// process index.html
const singleBuildHtml = './dist/single/index.html'
Expand All @@ -224,8 +231,9 @@ const appConfig = defineConfig({
// write output file size
console.log('single file size', (fs.statSync(singleBuildHtml).size / 1024 / 1024).toFixed(2), 'mb')
} else {
patchWorkerImport()
if (!disableServiceWorker) {
const { count, size, warnings } = await generateSW({
const { count, size, warnings } = await generateSW({
// dontCacheBustURLsMatching: [new RegExp('...')],
globDirectory: 'dist',
skipWaiting: true,
Expand Down Expand Up @@ -254,3 +262,21 @@ export default mergeRsbuildConfig(
appAndRendererSharedConfig(),
appConfig
)

const patchWorkerImport = () => {
const workerFiles = fs.readdirSync('./dist/static/js/async').filter(x => x.endsWith('.js'))
let patched = false
for (const file of workerFiles) {
const filePath = `./dist/static/js/async/${file}`
const content = fs.readFileSync(filePath, 'utf8')
const matches = content.match(/importScripts\([^)]+\)/g) || []
if (matches.length > 1) throw new Error('Multiple importScripts found in ' + filePath)
const newContent = content.replace(/importScripts\(\w+\.\w+/,
"importScripts(location.pathname.split('/').slice(0, -4).join('/')+'/'")
if (newContent !== content) {
fs.writeFileSync(filePath, newContent, 'utf8')
patched = true
}
}
if (!patched) throw new Error('No importScripts found in any worker files')
}
Loading