HNHacker News
TopNewBestAskShowJobs

flohofwoe

23,650 karma · joined October 15, 2013

submissionscomments
flohofwoe··on MicroUI – A tiny, portable, immediate-mode UI library written in ANSI C
> - constant repainting (while literally nothing changes) -> constant CPU load

This doesn't explain a 100% CPU usage since requestAnimationFrame is vsync-throttled and rendering such a simple scene will do the per-frame work in a fraction of a frame duration.

And FWIW I cannot reproduce the issue in both demos (in Chrome on macOS). The sokol demo has a per-frame load of about 0.3ms per 8.333ms frame, and the demo hosted on vercel.app about 0.7ms, both pretty much within expecations.

flohofwoe··on MicroUI – A tiny, portable, immediate-mode UI library written in ANSI C
TL;DR: it can be all sorts of things, from 'half-pixel' positioning problems, to upscaling issues, to poor source data. I didn't put too much effort into getting the text rendering look good (and text rendering is hard).

More details:

The demo is using half-resolution on high-dpi displays (currently that's sokol-app's default setting, but not sure if that still makes sense in this day and age tbh), this half resolution amplifies all sorts of text rendering issues, and it gets especially bad when there's a fractional system-dpi-scale like 125% or 150%.

PS: another problem (maybe the main problem, even if everything else is correct) is that the demo's pre-baked font atlas texture isn't all that great since it has 'anti-aliasing' baked into the glyph pixels, and the font atlas texture has a very low resolution (glyph height is 10 pixels, which would be ok for a 'crisp' hand-drawn bitmap font, but not when the font atlas has been created from a regular TTF font, which this one seems to be).

Does this Dear ImGui demo look better on your setup? This is using the native display DPI and uses a TTF font instead of a bitmap font:

https://floooh.github.io/sokol-html5/imgui-highdpi-sapp.html

flohofwoe··on Lore – Open source version control system designed for scalability
We are legion ;)

SVN was actually quite decent for game development, definitely more robust and (non-technical-) user-friendly than git+lfs.

(and SVN isn't really compatible with the work-from-home era unfortunately, you really needed a big server on a gigabit LAN)

flohofwoe··on MicroUI – A tiny, portable, immediate-mode UI library written in ANSI C
Minimal debugging/controller overlays for games would be the most obvious use case (e.g. similar to dat.gui for web).
flohofwoe··on MicroUI – A tiny, portable, immediate-mode UI library written in ANSI C
The demo uses a simple prebuilt fixed-size font atlas texture and renders the entire UI (including character quads) via batched glDrawElements calls (one draw call per clip-rect).

But the way how text rendering is delegated to the user is quite flexible, microui basically calls these three user-provided functions:

    int r_get_text_height(void)
    int r_get_text_width(const char* text, int len);
    void r_draw_text(const char* text, mu_Vec2 pos, mu_Color color);
...how r_draw_text() is implemented is then entirely up to you.
flohofwoe··on MicroUI – A tiny, portable, immediate-mode UI library written in ANSI C
It's a "bring your own renderer" UI framework, just like Dear ImGui or Nuklear. In some situation (e.g. when adding debugging UIs to a game) this is actually a big advantage compared to the renderer being baked into the library, since the game already has a renderer subsystem which the UI can easily hook into.
flohofwoe··on MicroUI – A tiny, portable, immediate-mode UI library written in ANSI C
Very different, starting at the line count:

Lvgl is 440kloc across 1134 files (in the src directory), while microui is 1121 lines of code in one .c and one .h file.

Microui is immediate mode, very minimal and 'bring your own renderer'. Probably most useful for adding a small debugging UI to a 3D game/app.

flohofwoe··on MicroUI – A tiny, portable, immediate-mode UI library written in ANSI C
I wrote a little demo to run microui on top of the sokol headers here, it's really interesting in how minimal it is.

WASM demo: https://floooh.github.io/sokol-html5/sgl-microui-sapp.html

Source code: https://github.com/floooh/sokol-samples/blob/master/sapp/sgl...

The renderer backend is just a bunch of C functions you need to provide:

https://github.com/floooh/sokol-samples/blob/3f4185a8578cd2b...

It's also interesting to compare the binary sizes:

microui sample (https://floooh.github.io/sokol-html5/sgl-microui-sapp.html): 79.6 KBytes compressed download

Nuklear sample (https://floooh.github.io/sokol-html5/nuklear-sapp.html): 155 kb compressed download

Dear ImGui sample (https://floooh.github.io/sokol-html5/imgui-sapp.html): 491 KB compressed download

flohofwoe··on Lore – Open source version control system designed for scalability
I guess you never worked with anything but git? The devil is in the details, and those details generally suck more in git (or generally: distributed version control systems) than in traditional centralized VCS's.

Also git-lfs is a crutch that breaks more often than it works :/

(I agree though that for small game projects, git is mostly 'good enough', even without lfs).

flohofwoe··on Lore – Open source version control system designed for scalability
That's fine for database-like meta-data (e.g. game entity properties), but not for images, videos or audio files. Just writing those as hex dumps into text files doesn't make them any easier to merge.
flohofwoe··on Google Chrome update will close the door on ad blockers
+1, Lite is mostly fine. The main difference seems to be that YouTube videos sometimes start a couple seconds late. Not quite annoying enough yet to switch browsers (tbh though, Firefox is totally fine these days, main downside for me is that the WebGPU implementation lags quite a bit behind Chrome and Safari).
flohofwoe··on Russian artist and Putin critic shot dead in Poland
As for German citizens: a red cross employee, an immigration lawyer, a 'political scientist' and a tourist who apparently tried to smuggle six gummy bears coated with canabis oil into Russia:

https://en.wikipedia.org/wiki/2024_Ankara_prisoner_exchange

(also various US and UK citizens)

flohofwoe··on Ported my C game to WASM, here's every bug that I hit
I would recommend the VSCode WASM DWARF debugging extension instead of the Chrome extension nowadays:

https://marketplace.visualstudio.com/items?itemName=ms-vscod...

This allows to setup an IDE-like 'press F5 to build and start into a debug session' in VSCode, with the debuggee running in Chrome.

E.g. see:

https://floooh.github.io/2023/11/11/emscripten-ide.html

flohofwoe··on Ported my C game to WASM, here's every bug that I hit
> The bridge will add more latency when there is a transition between JS and wasm.

This would be similar to how NaCl/PNaCl communicated with the JS side (via message passing), and that really sucked and would also be prohibitively slow for talking to 'high frequency APIs' like WebGL2 or WebGPU (or the DOM heh).

flohofwoe··on Ported my C game to WASM, here's every bug that I hit
I already posted the link in another reply, but this is a good overview why wasm32 is usually the better choice over wasm64:

https://spidermonkey.dev/blog/2025/01/15/is-memory64-actuall...

TL;DR: wasm64 has slower memory load/store operation because it requires 'software bounds checking', so unless you absolutely need more than 4 GB RAM, wasm32 is the better choice.

flohofwoe··on Ported my C game to WASM, here's every bug that I hit
> WASM kind of inherited some of that legacy.

It didn't. WASM has true 64 bit integers (or specifically, the base types of WASM are: i32, i64, f32 and f64 - where the integer types are 'sign agnostic' like CPU registers).

flohofwoe··on Ported my C game to WASM, here's every bug that I hit
> struct layout is well specified

Technically that's not true at least for booleans and enums, the C standard doesn't define specific sizes for those (bools are commonly 1 byte though, but for enums at least MSVC likes to disagree with Clang and GCC).

Using a direct struct memory layout for persistency and then expecting it to work across compilers, CPUs and ABIs is almost guaranteed to cause problems.

flohofwoe··on Ported my C game to WASM, here's every bug that I hit
Because 64-bit WASM can be quite a bit slower than 32-bit WASM:

https://spidermonkey.dev/blog/2025/01/15/is-memory64-actuall...

TL;DR: wasm64 requires explicit heap bounds checks, while in wasm32 the memory mapping hardware does it for free.

E.g. quote:

"The only reason to use Memory64 is if you actually need more than 4GB of memory.

Memory64 won’t make your code faster or more “modern”. 64-bit pointers in WebAssembly simply allow you to address more memory, at the cost of slower loads and stores."

flohofwoe··on Ported my C game to WASM, here's every bug that I hit
> Wasm still doesn't let you make native user interfaces

That's currently only not possible because nobody wants to do the work to create something like wasi-gfx (https://wasi-gfx.dev/), but for native UI frameworks instead of 3D APIs.

The inconvenient truth is that even "native" cross-platform applications hardly ever go through the trouble to target the platform-native UI framework (and instead they go through non-native frameworks like Qt or a webview wrapper).

flohofwoe··on Ported my C game to WASM, here's every bug that I hit
Using WASM to make cross-platform code run in browsers isn't any more weird/esoteric than targeting Android via the Android NDK. The least painful way is to do some things in the 'native' platform language (e.g. Javascript or Java/Kotlin). Emscripten's FFI features for calling out into Javascript code snippets (even JS snippets that are directly embedded in C/C++ source files) is actually really nice, much better than any other FFI solution I've seen so far (and light years ahead of anything offered by the Android NDK).

In the end the web is just another platform, but a platform that is quite a bit different from the UNIX/Windows duopoly we're used to.

flohofwoe··on Ported my C game to WASM, here's every bug that I hit
> I had no idea WASM is 32bit until I read your article!

WASM(32) is a hybrid 32/64 bit architecture. The address range (and thus pointer size) is 32 bits, but it has native 64-bit integers. E.g. it's similar to the Linux x32 ABI.

There is also a 'true' 64-bit wasm, but that's still too recent to be used in real-world code:

https://caniuse.com/wf-wasm-memory64

(but wasm64 doesn't really make sense unless you really need an address space greater than 32 bits, because the downside is slower performance)

flohofwoe··on Anthropic flies staff to D.C. to clean up White House fight
That was seriously what I thought the headline is about. Anthropic flying in their employees to clean up the trash after Trumps birthday party for free to demonstrate their obedience with a good show of licking the Dear Leader's boots.

Extremely silly of course, but entirely in line with all the other news currently coming out of the US ;)

flohofwoe··on The Future of wasi-gfx and wasi:webgpu
...and GLFW, winit, RayLib, SFML, sokol_app.h etc etc... ;)

It just offloads all the pain and hassle to the SDL maintainers. Also SDL is a pretty big beast (partly because it needs to accumulate a lot of hacks and workaround for buggy drivers and window systems). It would be nice when all those accumulated hacks wouldn't be needed in the first place.

For the idea of portable gfx applications in WASI it's also not really an option to base the window system glue standard on SDL (I guess though that SDL could be the base for one specific implementation of the WASI window system glue interface).

flohofwoe··on Orthodox C++ (2016)
> It's a direct call to not use many features, and claiming that to do otherwise is a mistake.

I think you are thouroughly misunderstanding the blog post. It's not an aggressive "you must start using this now" thing, but mainly a definition of what "Orthodox C++" is so that communication about coding styles is simplified.

When somebodies says "this project is using the Orthodox C++ style" then it is immediately clear to everybody what exactly that entails (and if not they can google the term it and find the blog post). It's also a counter proposal to some of "Modern C++" madness (like "almost always auto") that was all the rage around a decade ago when that post was first written.

FWIW I wrote a fairly similar blog post in 2013 to describe what our team coding style looked like back then:

https://floooh.github.io/2013/06/21/sane-c.html

(PS: back then I still thought that C++ could be salvaged)

flohofwoe··on Orthodox C++ (2016)
Memory corruption magnets like iterator invalidation, std::string_view or std::span are on a whole different level than the footguns that were inherited from C. At least with C style raw pointers you know that you have to be careful when you see one, in C++ the unsafety is lurking in hidden places sprinkled all over the stdlib and comes in all shapes and forms.
flohofwoe··on Orthodox C++ (2016)
> Malloc and memory allocation methods are at least 10k+ lines of code for instance.

Only the really big ones, e.g. here is Emscripten's allocator that focuses on small binary size and is implemented in about 1.5 kloc (ignoring comments and whitespace it's actually under 1 kloc), and that allocator is perfectly fine for most use cases (especially C code bases which typically don't have a high allocation frequency):

https://github.com/emscripten-core/emscripten/blob/main/syst...

...and Seb Aaltonen's offset allocator (used for allocating GPU buffers in his Vulkan API wrapper) has under 500 lines of code:

https://github.com/sebbbi/OffsetAllocator/blob/main/offsetAl...

Right tool for the job etc... big general-purpose allocators like jemalloc or mimalloc are usually a bandaid to somewhat salvage a failed memory management strategy.

flohofwoe··on Orthodox C++ (2016)
You don't need iterators for the range-based for loop, just a .begin() and .end() method which returns a raw pointer is enough.

E.g.:

https://github.com/floooh/oryol/blob/eb08cffe1b1cb6b05ed14ec...

(don't use that project though because it's been archived, I've switched back to plain old C in the meantime)

flohofwoe··on Orthodox C++ (2016)
> for (auto const & ess : esses) {

This is allowed by Orthodox C++

> dynamic_cast<Derived> (base_ptr)

This isn't because it requires RTTI, but dynamic_cast is also a typical code smell.

Orthodox C++ isn't generally against new C++ features, it only advices to wait about 5 years (or at least one C++ version) for stabilization and to apply some common sense before adopting them.

The notes about not using RTTI, exceptions and stdlib features that allocate under the hood are all justified by painful experience with those things in the context of game development.

In general, the restrictions outlined in the post make a lot of sense when considering that Branimir (of BGFX fame: https://github.com/bkaradzic/bgfx) is coming out of the game dev hemisphere, and from that PoV none of the restrictions are controversial - on the contrary, it would be highly controversial to suggest going all in on Modern C++ features ;)

flohofwoe··on The Future of wasi-gfx and wasi:webgpu
IMHO: totally. Asm.js developed into WASM, which is better in any aspect than PNaCl (e.g. just one disadvantage is that PNaCl was an ossified subset of LLVM bitcode, this would resulted in the same quagmire that the DX team found themselves in when they based the DXC shader compiler and HLSL bytecode (DXIL) on a snapshot of the LLVM toolchain and bitcode - in the end the only realistic way out for D3D was to switch to a SPIRV flavour).
flohofwoe··on The Future of wasi-gfx and wasi:webgpu
That's the situation today, but in 2013 when asm.js was invented Firefox was still relevant.
← PreviousPage 18 of 34Next →