web: Add Standalone Mode for Web Backend - #815
Conversation
Include CORS-related fixes for standalone web mode by falling back to main-thread web.js when SharedArrayBuffer/Atomics/crossOriginIsolated/OffscreenCanvas are unavailable. Also install web.js for web-standalone builds and add standalone wasm compatibility imports (wasm_wait_event, wasm_canvas_info) in web.js for fallback execution.
|
I'm a bit confused. Can you say more about how this differs from the existing web stuff? "Standalone" to me implies the code owns the mainloop, which is not a thing in the browser right? Is this more about web workers? Is it offloading running the dvui stuff into a separate web worker? |
|
@david-vanderson I'm extremely sorry for this very late response as I have some things going on in my life.
The key difference from existing web path is:
How worker loop works (concrete path):
So to your direct question: yes, it is offloading DVUI execution to a worker when available, but the main goal is enabling standalone-style app ownership on web, with worker/fallback as implementation detail for browser constraints. |
No problem at all.
Thanks for the detailed layout. I was able to test it locally using a hacked python3 server: I'm trying to follow the code, but some things are not clear to me. Examples:
I had to make these changes so it would compile in zig 0.16.0: -var gpa_instance = std.heap.GeneralPurposeAllocator(.{}){};
-const gpa = gpa_instance.allocator();
+pub var gpa: std.mem.Allocator = std.heap.wasm_allocator;- allocator: std.mem.Allocator = gpa,
+ allocator: std.mem.Allocator = std.heap.wasm_allocator, |
…/dvui_update with blocking main function. Text input and resizing are bugged.
… and transferFromImageBitmap.
…8encoder/utf8decoder into web-common.js to deduplicate code and fix syntax error in web.js
…k.renderPresent() calls from web-standalone.zig. These are now handled internally by win.end(.{}) since the upstream merge added manage_backend: true to Window.endOptions. This fixes the UI only rendering when the cursor is moving over it.
|
@david-vanderson Changes made:
Desktop Browser Compatibility
Mobile Browser Compatibility
Atomics.store(signalArray, SIGNAL_INDEX, 1);
Atomics.notify(signalArray, SIGNAL_INDEX);Do note that this doesn't prevent the worker from using self.postMessage, which is the mechanism used to process input events and transfer the bitmap.
Unaddressed FeedbackThe check for
Nitpicks
|
|
Thanks for addressing the feedback! In general I'm okay with adding this kind of web worker example, but realistically the amount of refactoring going on here is tough to review. For example, just the small changes to build.zig around the raylib thing bring up the question of what is going on there, and why is it combined with unrelated web stuff? To make progress here the refactoring stuff is going to have to be separated so it can be reviewed independently. Javascript stuff in particular takes a lot of time to test across different OS/browser combinations. |
|
Hi.
Is this good? Do you have a better solution? Thanks for your patience. |
The split PR approach sounds good. Thank you! |
|
im curious about this but im not sure if i understand it, whats the usecase for it? and does it have any upsides to the current web approach? |
I'm not an experienced developer, but off the top of my head, a user-defined main function allows for more granular control over initialization/deinitialization, for example being able to fetch resources during a loading screen. Another benefit is to promote feature parity between platforms, so that an existing SDL standalone codebase could be run on web without introducing a dvui_update pattern to run in app mode, which might be a great hassle if the codebase didn't have this in mind during development. |
Added support for writing standalone mode apps for the web backend.
Added web-standalone.zig example to demonstrate features.