r/rust • u/Leadwerks • 4d ago
š seeking help & advice Should I add support for Rust?
Hi, I am the developer of Leadwerks Game Engine. I'm looking for a mid-difficulty language, somewhere in between C++ and Lua. C# would work nicely, but the lag spikes caused by the garbage collection seem like it ruins the language for realtime 3D games, especially for VR. I'm not that familiar with Rust but I hear a lot of good things about it, and it appears to use shared pointers, which eliminates the performance problems full garbage collection would introduce.
Support for Rust can be added by piping all the commands through a C interface and writing some structure/class code on the Rust side that wraps everything up nicely for the end user.
I'm aware of the open-source Bevy 3D engine, but it's lacking a visual editor. Leadwerks 5 has a very capable level editor / visual designer that's been refined over years with lots of user feedback. To be clear, Leadwerks is closed-source commercial software (with a low price point and no royalties).
Do you think Rust would be a good match for what we are looking for in a language? Would adding support for the Rust programming language would be of interest to developers here? Please let me know your thoughts and if you have any questions.
37
u/NullOfSpace 4d ago
Rust is a good language, but it isnāt a replacement for C#. Itās closer to C++ with most of the footguns removed, and honestly requires you to have a better understanding of what your code is actually doing in a lot of cases (so you can prove to the compiler that what youāre doing isnāt going to cause memory issues), so I donāt know if it fits the bill of a āmid-difficulty language.ā
That said, it definitely has the stuff youāre asking for from it. The C FFI is good (though you need unsafe blocks, since the compiler canāt guarantee memory safety using it), and it does support basically whatever memory management system you want (in the same way the C++ does, ābuild it yourself,ā but with some extra safety guarantees).
6
u/Leadwerks 4d ago edited 4d ago
"Footguns"...hahaha, yes I know these. The safety nature of Rust is interesting, since Leadwerks is used in many of the environments where this is important.
5
-8
u/velocityvector2 4d ago
Rust isn't close to C++. Rust is rust
9
u/Recatek gecs 4d ago
Rust's memory model and performance characteristics are much closer to those of C++ than C#.
-7
u/velocityvector2 4d ago
Rust has strict rules regarding memory management and is unlike C++. C++ is an OOP language; you cannot directly port the code you write to Rust. And C++ is a primitive language that doesn't even have a package manager. They are completely different in every aspect.
9
u/xvillifyx 4d ago
Youāre conflating features the language has with the resulting behavior of the actual machine code generated
1
u/pleaseihatenumbers 3d ago
most modern c++ code is not OOP and is closer to rust in that sense, which is probably part of why rust opted to not allow OOP altogether (as we have learned from the experience of c++ that OOP in a system's programming language is not such a nice paradigm)
1
u/velocityvector2 3d ago
I just said Rust isn't like C++, I don't understand why I was downvoted. Is that a lie? They are two languages āāthat are completely different in terms of OOP and memory management.
1
u/pleaseihatenumbers 3d ago
rust is absolutely not completely different to c++ in terms of memory management, i would say they are almost the same in that regard. rust has a very similar "mission" to c++ in my opinion, to be a system's programming language with higher level concepts such as powerful generics implemented with very low overhead. i agree that rust is not a c++ successor language but in my opinion the language which precedes rust which rust is the most similar to is c++, and most ways in which they are different are things rust has learned from c++'s mistakes (move semantics, non c-like syntax, doing away with oop altogether, package manager, traits [which c++ kinda copied with concepts] ...)
1
u/IceSentry 2d ago
People are explicitly calling out which parts of rust are similar to c++ and you just ignored it and doubled down on the parts that are different.
9
u/cynokron 4d ago
Is it a good match? Yes. Will rust developers use it? Not sure. A lot of people on this sub like fully rust solutions. C interop has overhead, particularly if you want to convert a rust string to a c string due to not needing null terminator in rust. There is probably a way to workaround it, but i havent bothered. A lot of rust users will have their own engine, or yes use bevy. A lot of bevy users might appreciate the editor, but you'll want to market your engine more than just having an editor.
Being closed source probably kills a lot of interest. Self serve bug fixing and "documentation" are extremely important to development.
2
u/Leadwerks 4d ago
Good information here, but I will point out that string interop will never realistically form a bottleneck for games. You have much bigger problems to worry about!
2
6
u/stumpychubbins 4d ago
C# has enough tools to control the GC that Iād be surprised if you canāt make it work. I think unity does some funky stuff to translate it to C++ (meaning it would use refcounting instead of a global GC) but even without that you can get pretty fine control over when the GC runs and how itās tuned
2
u/Leadwerks 4d ago
Is "doing funky stuff" a good strategy? What if we could build on something that wasn't fundamentally broken by design?
3
u/martindevans 3d ago
The "funky stuff" that Unity does is entirely due to legacy design decisions (Mono, Boehm GC) which they are now working very hard to undo with the CoreCLR migration they've been working on for a couple of years. It was a necessary design decision about 20 years ago, but it's unecessary now if you just use modern dotnet from the start!
A good GC is a tradeoff. Allocations are very cheap (just a bump allocator in gen0) compared to Rust (imagine if you used bumpalo for everything). The tradeoff is that an allocation can trigger a collection, which makes some allocations more expensive. Generally you have higher throughput with worse tail latency).
Unity with Boehm GC has none of these advantages, it is the worst of all words! It's conversative (has to scan the entire stack, can discover false roots), non moving (doesn't compact the heap so it can become fragmented), non generational (has to scan the entire heap, has expensive allocations like Rust). So do not take anything away from Unity, other than how not to do it.
[Rust] appears to use shared pointers, which eliminates the performance problems full garbage collection would introduce.
Reference counting is the least performant of all types of automatic memory management. Rust does a great job at avoiding most of the cost of RC by using lifetimes more most allocations. But if you ever find yourself reaching for
Rc<T>orArc<T>, you're in a worse position than using a proper GC.It's worth pointing out that even allocations managed entirely by lifetimes can absolutely cause stutters. If you drop the root of a large object graph it will immediately walk that entire graph, calling
freeon every object. This could be significantly more expensive than an equivalent GC collection in the worst case.Do you think Rust would be a good match for what we are looking for in a language?
Coming back to answer the original question. No, I don't believe so. Approximately nobody in gamedev uses Rust, it's a great language for engine development but a bad choice for your scripting frontend unless you specifically want to be pushing adoption of the language. That's a worthy goal, but know what you're signing up for!
On the other hand C# is a very popular language in games development. The only downsides you list are the largely unfounded fear of GC stutters. This is addressable even in even in terrible state of current-day Unity (as demonstrated by a large number of successful games including very latency sensitive VR titles).
1
u/stumpychubbins 4d ago
No, I donāt think you should do what unity does. Just manually tuning the GC should be enough
3
u/Tall-Introduction414 4d ago
Can I just ask what you mean by "mid-difficulty" language? Isn't it more that you want the control that allows for a low latency pipeline?
I'm probably being pedantic. But I don't know why you would want a language to be "more difficult," except perhaps for novelty. :)
2
u/Leadwerks 4d ago
C++ is pretty brutal. The error reporting is cryptic. Header files are tedious. No reflection means you have to manually write a lot of loading code that is automated in Lua. I would like to offer something that is a step up from Lua but simpler than the user experience in C++.
3
u/xMAC94x 4d ago
Just had a look at your engine and got to say: nice work.
For providing rust-bindings: As a company you probably want to make money and rust is known for a abundance of game engines, but almost no games. So i doubt that it's a good short-term business decision.
Though rust can be an awesome language and might be a good fit for new tooling or parts of the engine one day.
2
u/Leadwerks 4d ago
Thanks, I appreciate the compliment. On one hand, I want people who want to make games to be able to do so, but on the other hand, it's not really my place to tell people how to use our software. Not everyone dreams of being a professional game developer. Many people just like bringing their ideas to life for no other purpose than to have fun.
1
u/catheap_games 4d ago
I can't speak for the market, but if you offered a paid editor with good developer experience for Bevy, I think, depending on the price, some people would be interested. Would it be worth the development time? ...let's be honest, probably not at this point in time. Most "hard core" developers already know what they want, and most other developers prefer the popular and convenient solutions, C#, GDscript, Python, Lua, JS/TS, or visual scripting.
Again, can't speak for others, but for $100, having an editor that would allow relatively fast prototyping, while letting me run the result fully in Bevy, with proper ECS and a full control over the code, that would be a no-brainer purchase. Getting a closed source engine that I can just "script" in Rust? Maybe 3 years ago I'd try, but right now Bevy is getting seriously good for my needs / workflow / game ideas, and if I wanted a quick something with an editor, I'd probably give Godot a go.
Rust ecosystem has a lot of tinkerers, and as others said, "more engines than games" is the classic joke, but fundamentally people who want raw Rust power and pretty good developer ergonomics (sans editor) go to Bevy, and people who want an engine+editor generally split between Unity and Godot, with Godot having the benefit of having an extension that allows using Rust. Maybe that could be a starting point for your research? https://godot-rust.github.io/
2
u/Leadwerks 4d ago
That sounds a lot like my program 3D World Studio. This was the precursor to the full game engine Leadwerks, and was actually used to make the game SCP Containment Breach.
1
u/Present-Knowledge-57 3d ago
Iād personally be interested in it, but Iām not sure if other game developers would be. for a mid-level language wanting to attract the widest audience, Iād consider C# anyway, even despite any alleged GC stutter. in my experience, I did game engine development in Java for months and never noticed any GC stutter that couldnāt be fixed in seconds.
1
1
u/Latin-Freak 2d ago
Have you considered exploring Goose instead? I am not an expert at all, but reading through your issue description I had a feeling that it can be a better fit than Rust, the main reason being that it natively supports C interoperability as Goose code actually compiles to C-like binaries https://aardappel.github.io/goose/
1
1
u/exDM69 2d ago
If you write a C interface to your engine it unblocks using it from any language, including Rust, but also Python, Ruby, whatever. C++ interop is much harder from any language.
When you have a C interface, you can build the Rust low level wrapper using bindgen and maybe a few helpful annotations.
But that won't be idiomatic Rust and you'd probably need to add at least some Rust code to benefit from Rust language features like safety. E.g. make a your RAII objects using Drop.
That said, language boundaries always bring impedance mismatch problems and creating an interface that's even close to idiomatic in two languages is a proper engineering challenge.
So yeah, maybe start with the C interface, can't go wrong with that and unblocks all the other languages too. Interfacing C++ and Rust code is a bigger challenge.
0
u/tabbekavalkade 4d ago
Godot had to create their own scripting language for this purpose. I suspect Rust does not fit. It is not a scripting language.
1
u/-Redstoneboi- 4d ago
there is a balance to be had between scripts and full-on performance code. gdscript is useful for most cases, but it is still interpreted and may stop being well-suited for a task if done across 100,000+ or a million entities. imagine if minecraft world generation was in gdscript.
natively compiled scripts are another option to make things run quickly if someone needs to squeeze every bit of performance they can get.
2
u/Leadwerks 4d ago
LuaJIT is a great example of that. :) I looked at the repo recently and I guess the main guy who created that is back at the wheel again.
1
u/TheRealScaramucci 1d ago
IMO C# strikes that balance the best. I think it gives you the best control over memory compared to any other garbage collection languages, excluding a couple of exceptions where the GC is optional (like D).
At the same time you don't need to understand any of that unless you want performance.
Java, often compared to it, doesn't even come close to that level.
-3
u/victor_crimea 4d ago
Don't you expect humans hand writing code with your framework? Optimize for ai generation. Thus Rust is the best choice since it provides the best guardrails to agents.
2
u/Leadwerks 4d ago
In my opinion, the jury is still out on the usefulness of LLMs in writing code. I'm open to the idea of integrating code assistance, but I have so far found these tools to be of very limited utility for my own purposes. Discussions with current users indicate they overwhelmingly prefer locally run models.
At this point in time I would not make API design decisions based on their suitability for AI usage.
47
u/dgkimpton 4d ago
Rust is way closer to c++ than lua/c#. It's not a bad language to support but I suspect most of the people that don't want to use your engine in c++ won't be much more likely to use it in rust.Ā