67 points · by dntbrsnbl · 3y ago · 57 comments
Right. On the game engine side, there's the comment that Rust has 50 game engines and 5 games. A new GUI framework might not be what's needed.
I'd like to see some of the most used ones get finished. I'm waiting for the six-month WGPU overhaul to finish to unblock the Rend3 overhaul so I can use a newer version of egui. Egui botches layout if there's a line wrap in a scrollable window, for example. Basic stuff like that is broken.
Bingo.
The problem in the Rust ecosystem is that people are writing libraries instead of applications.
This is backwards. Until you have a couple of applications written, you have zero idea what to abstract.
I'll go further. The Rust GUI ecosystem is fundamentally doomed because they are absolutely insisting that any GUI thing must run on desktop, mobile, and web simultaneously. The abstractions required between those domains are fundamentally incompatible.
Desktop apps want "Give me all your cores. Now." Mobile is all about "Please, sir, can I have some battery?" Web is all about "Back in my day all we had was one damn thread so that's all you get and you'll like it."
I would personally cheer if we had one good Rust GUI framework for each of those cases.
[0]: https://avaloniaui.net/
[1]: https:/flutter.dev
[2]: https://platform.uno/
[3]: https://unity.com/
[4]: https://www.jetbrains.com/lp/compose-desktop/[1]: https://flutter.dev
[3]: https://unity.com/
And they all fail miserably in innumerable ways that make you reach for OS-specific solutions if those frameworks allow that.
Just the simple fact that mist mobile is touch-oriented small screens with imprecise controls, and desktop is mouse-and-keybord-oriented with big screens and precise controls make the two largely incompatible.
As a Rend3/Wgpu user, I'm very aware of that.
Web is very "you only have one thread and you will use async."
I totally second this.
Got the same feeling after developing https://glicol.org/
I could suggest that this is why capitalism works as a tool to improve society, but perhaps that extrapolates a bit too wildly.
So? They have the feedback from thousands of games and game developers so they focus on alleviating the pain points.
If you don't have feedback, you may as well not bother.
Ship your Rust game, then you know what the pain points are. Until you ship, you're guessing.
None of Rust libraries is even close of getting there, even the studios that apparently support Rust, are shipping on Unreal.
Here's my hot take of the day, as a Rust dev/fan/proponent who's done a few different GUI projects in the language: it's actually mostly fine, but Rust developers won't just settle for "just make it work".
There is true value in a cross-platform common wrapper of native widgets that nobody is really hitting. So many of these GUI attempts are scenarios where it feels like someone stumbled into "how do I build a GUI" and got fascinated by the problem, iterating until they hit a "good enough" point. The problem is that that level of "good enough" isn't actually good enough for a general purpose framework.
Arc/Rc the hell out of it, stop trying to get cute with the borrow checker and lifetime handling, and just make it work. 99% of applications that ship today don't need your novel approach to some virtual DOM diffing algorithm, they just need to reliably shit stuff out on a screen in a way that interacts cross-platform well enough.
Ooof, and now were back to what's a fundamental problem in a lot of "traditional" C++ game code bases I've seen (including my own stuff I wrote in the late 90's to early 2010's).
Refcounting overhead cannot be ignored when performance matters, and since refcounting usually 'infects' the entire code base, it's impossible to fix once it becomes a performance problem - because then it's too late since it would mean rewriting everything from scratch with a new approach to lifetime management.
The pattern I keep needing is single ownership with back pointers. That can be done with Rc and Weak, which pushes the checking to run time. I think it might be possible to do this statically with some extensions to the borrow checker. It's not keeping the forward and back links consistent that is hard. It's making sure that all code sections either have read access to owner and owned, or write access to owner or owned. That's a static analysis kind of problem.
Dangling pointers, null references, and duplicate mutable references all creep into an ECS. They just have new names since it’s all hidden behind Entity rather than a reference or pointer.
Rust will let you mutate state just like C++, but it's difficult to master in a timely way. So, when your time is better spent on the actual shaders and game logic, you have little patience to learn enough Rust to effectively use it.
Until I have to share a linked list between different things... But that's another story.
while the base concepts of shaders might be easy, IMHO are far far harder to use correctly and maintainable then rust
anyway I agree that for a lot of use cases you want a ready to go game engine where most of the code you write is in some form of scripting engine on top and only the perf relevant code is in whatever native language you use
through many people today start programming without knowing C++ and I would argue rust is much easier to learn then C++ with that one small problem that C++ can give you easily an illusion of having a proper understanding of it while still missing very essential parts which can not only lead to failing but also RCE security vulnerable code
Some points:
- UI frameworks and Game Engine tends to be huge when completed to a point where they are an easy choice for anything beyond some fun projects. The _huge_ majority of them have organizations/money backing in some form, through sometimes implicit. So the huge majority of open source versions of them no matter which language they are in will never be competitive.
- the state of established UI frameworks is kinda a mess, the divergence between the research world and what is practically used is in most places quite often humongous (e.g. what the blog post describes is conceptually a version of using continuations for GUI libraries and state handling in them, something well established as "a grate idea, if you can make it work nicely with the limitation of widely used programming languages" in computer since since I think 10+ years or so), and it's pretty common that patterns people are used to (e.g. inheritance for code reuse) are actually anti-patterns which kinda somewhat happens to be usable in that case but have serious issues you IMHO often don't notice until using them in larger projects (as in many people working on the software in parallel) where it's then often blamed on other things
- due the the mess the state handling in GUIs often ends up in it tends to profit from using a GC and the using borrows only in rust will likely fail. But then given the perf-characteristics and what tends to be a hot paths of GUIs _you really don't need to write borrows only code_, using an Rc/Arc and similar tends to be perfectly fine, i.e. the issue is in my experience more people obsessing over micro optimizations for that context
- on the other hand for game engine you often want to avoid GC for the engine/core parts themself (i.e. not dialog script and similar) and in general have a much stricter state handling using stuff like a ECS, there is no reason for rust to not handle that well. Through writing the ECS library might involve usafe code, due to it involving writing fundamental data structures. Most importantly in recent years "memory safety" of C++ has become an increasingly bigger issues for AAA-games, especially for multiplayer games where there is a risk of a hacking the users computer through the game client, and the money spend on combating that issue is non trivial to a point that you probably should avoid most code which conceptually works in C++ but couldn't work in rust due to the borrow checker (assuming you already have a well done ECS library with the right soundly implemented data structures).
- similar to writing fundamental data structures, writing a game engine proper is really really hard but seems simple as long as it's only a "toy", rust isn't good at that, sure. But also there is limited value at being good at writing throw away toys which can't be used in any production context IMHO. What does matter is if you can have a nicely usable production ready _maintainable_ game engine in rust, and AFIK yes you can somewhat already have.
While c# is a lot of applications with few libraries
My herd of yaks is only getting higher over time...
However, GUI frameworks are a nightmare of criss-crossing events and state, and in practice callbacks are the least of your worries. In other domains callback interfaces often force you to scatter what would otherwise be highly localized logic, but it's the nature of GUI frameworks that your event logic will tend to be short, chunked, and scattered regardless, which is demonstrated by the toy examples. Yes, the async pattern turned event pushes into event pulls syntactically, but that's it--there was no real payoff.
I'm sure somebody will eventually go the distance with this approach. I won't dispute that the exercise would be a fun ride.
Regarding this proposal, it wouldn't hurt to take a look at the implementations of `preact signal` and `vue3 ref`
In addition, the overly strict memory management of Rust is a disaster for GUI programming. GUI states are already complex enough, writing GUI in Rust is like adding an enemy called "compiler" to oneself.