satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
57 stars 13 forks source link

New chunks sometimes don't generate/load on web client (world gaps) - remove browser threading? #75

Open satoshinm opened 7 years ago

satoshinm commented 7 years ago

They do in the native client, but not web, sometimes. Maybe a symptom of sqlite? https://github.com/satoshinm/NetCraft/issues/2

View from orthographic mode ("f" key):

screen shot 2017-04-24 at 8 39 36 am

This does not matter much for my first use case (https://github.com/satoshinm/WebSandboxMC, since it only shows a small section of the world, all sent by the server using "B," commands, not generated on the client), but it is important for playing the game locally, or potentially also using remote Python servers.

satoshinm commented 7 years ago

Curiously, new chunks generate sometime, but not always (web only - still thinking this is related to some port. Maybe tinycthread?):

screen shot 2017-04-24 at 8 54 17 am
satoshinm commented 7 years ago

There seems to be fewer holes when changing #define WORKERS 4 to 1 in src/main.c, but have not confirmed

satoshinm commented 7 years ago

Maybe remove tinycthread and generate (client) chunks synchronously for now (shouldn't affect online mode, when the server generates the chunks). Wouldn't mind having one fewer dependency.

satoshinm commented 7 years ago

Trying with -s USE_PTHREADS=1 to emcc, rebuilding:

Scanning dependencies of target craft
[  4%] Building C object CMakeFiles/craft.dir/src/item.c.o
[  9%] Linking C executable craft.html
INFO:root:generating system library: libc-mt.bc... (this will be cached in "/Users/admin/.emscripten_cache/asmjs/libc-mt.bc" for subsequent builds)
INFO:root: - ok
INFO:root:generating system library: pthreads.bc... (this will be cached in "/Users/admin/.emscripten_cache/asmjs/pthreads.bc" for subsequent builds)
INFO:root: - ok
INFO:root:generating system library: dlmalloc_threadsafe.bc... (this will be cached in "/Users/admin/.emscripten_cache/asmjs/dlmalloc_threadsafe.bc" for subsequent builds)
INFO:root: - ok
[100%] Built target craft

the client immediately fails with:

no such block found: Cobble (oops, separate issue: https://github.com/satoshinm/NetCraft/issues/162)

exception thrown: TypeError: Argument 9 ('pixels') to WebGLRenderingContextBase.texImage2D must be an instance of ArrayBufferView,texImage2D@[native code]
_glTexImage2D@file:///Users/admin/games/wasm/NetCraft/build/craft.js:9357:23
_load_png_texture@file:///Users/admin/games/wasm/NetCraft/build/craft.js:30928:15
_load_main_texture@file:///Users/admin/games/wasm/NetCraft/build/craft.js:30945:19
_main@file:///Users/admin/games/wasm/NetCraft/build/craft.js:27093:20
file:///Users/admin/games/wasm/NetCraft/build/craft.js:65743:24
callMain@file:///Users/admin/games/wasm/NetCraft/build/craft.js:66127:30
doRun@file:///Users/admin/games/wasm/NetCraft/build/craft.js:66191:60
file:///Users/admin/games/wasm/NetCraft/build/craft.js:66202:12
TypeError: Argument 9 ('pixels') to WebGLRenderingContextBase.texImage2D must be an instance of ArrayBufferView

Threads are not even strictly needed on the web client because receiving network data occurs asynchronously anyway, and terrain generation occurs remotely.

satoshinm commented 7 years ago

This may be obviated at least when online with https://github.com/satoshinm/NetCraft/issues/188, but for completeness ought to still fix offline local mode world holes, probably by removing tinycthread in emscripten

satoshinm commented 7 years ago

With https://github.com/satoshinm/NetCraft/issues/172 the world holes now have a visible lower layer, due to the bedrock:

screenshot-netcraft-2017-06-10t03_37_30 397z