Veloren – Open-source MMORPG written in Rust
veloren.net
veloren.net
I've also read the code looking for examples of how to do things in Rust, and found it quite pleasant.
edit: reply to one of the comments below regarding the argument Rust = good therefore great for gaming. This. Neither does a good engine. For me I stopped UE4 and went to Unity because of the sheer lack of documentation and community support behind C++ with UE4. C++ is a powerful language but man was it hard finding tutorials and documentation that was up to date.
People think that a good language would make a good game, that's error #1. The ecosystem matters more than the language itself, basically using Rust is starting from scratch so you can't use all the good things that C++ / C# had for the last 15 years.
Edit: I want to clarify that I know that Rust is a good language, but as of now in 2021 it's just not ready for games, and there is no sign of change. It's fine to say "I can make games in Rust, it's going to be hard and painful but I can get something, but saying it's better than C# is definitly wrong.
That's trivially false.
> Last week, I released A Snake’s Tale on iOS, Android, Windows, Mac, and Linux.
> A Snake’s Tale was programmed entirely in Rust, and to the best of my knowledge, it is the first commercial game made in Rust to be released.
Dated 09 May 2017.
Time will tell.
https://unity3d.com/showcase/case-stories/squad-kerbal-space...
Secondly, there is the ongoing rewrite from C++ into HPC#.
Third, I still remember the days when Pascal, Basic and C compilers were deemed worthless for professional game engines, followed by similar remarks to C++, back when Abrash books were still hot of the press.
Finally, languages don't dictate how fun games are and how much they sell.
Yes, Unity uses C++ in the core engine, just like in the old days the first wave of games written in C were full of inline Assembly, while the first wave of Objective-C and C++ games were plain old C.
Yet the Switch has outsold the DS, and Unity powers more than 50% of the games sold on the platform.
C# 9 is at the same level as D and Nim, minus a couple of little things that could still be added. To the point that with .NET 5, Microsoft has started to rewrite the runtime in C#, whereas Unity is slowly porting the rendering pipeline into the HPC# subset.
So if they would decide to have Unity on D or Nim, compiled with the LLVM compilers, which kind of discussion would we be having, which compiler makes clever use of LLVM IR?
What do you mean? How does one reach D/Nim levels of performance (or did you mean expressivity) in C#? I'm experimenting with Nim for gamedev these days, I might be persuaded to take another look at C# depending on your answer.
Also, what is the HPC# subset? Any resources to read about that?
- use structs like in C
- do safe stack allocations for arrays
- use GC free heap allocations and map them to memory slices
- GC free code regions
- static lambdas
- machine numeric types
- static lambdas
- native function pointers
- native sized numeric types
- more control over structs layout and usage
- using available in any type that implements Dispose pattern even if the interface isn't adopted
- you can make use of Roslyn to ensure using is not forgotten
- unsafe and native pointers
- vector types for SIMD, NEON and AVX
- you can generate MSIL on the fly similarly to what C++/CLI compiler would have done. Naturally this trick requires unsafe Assemblies.
HPC# is a C# subset created by Unity with the long term roadmap goal to replace C++ on Unity. Although it looks like a C# subset and plain .NET types, there is a new compiler, Burst, that is aware of those special types.
There is also an ECS framework that goes alongside it, DOTS.
The founding members of the projects are ex Psygnosis employees well known in the C++ community.
https://docs.unity3d.com/Packages/com.unity.burst@1.5/manual...
https://youtube.com/playlist?list=PLX2vGYjWbI0QRLkvupULwSZCP...
The language is still pretty new but there is a lot of people investing in this. Embark studios and Ready at Dawn come to mind.
> People think that a good language would make a good game, that's error #1. The ecosystem matters more than the language itself, basically using Rust is starting from scratch so you can't use all the good things that C++ / C# had for the last 15 years.
It's not an error. Ecosystem matters but to a point. Like game engines are written with a particular type of game in mind. If your game doesn't fit the particular use case, it might make more sense to roll your own. Also, if you have been building your own game engines in C++, doing it in Rust should not be much of a problem.
The advantage vs some C# library is essentially the advantages of Rust over C#: precise control over memory layout and usage, no GC, higher performance, an ecosystem that was designed to be x-plat from the beginning instead of bolting that on after the fact.
C# also has all the C++ like mechanisms to do GC free allocation.
There is more "ceremony" involved with unsafe C# code, but things like Span<T> and Memory<T> have made high-perf code so much easier in many cases.
Still, so for something that's basically all highly performance sensitive, something like Rust would be a good choice (I don't actually use Rust yet, but am planning to learn).
The most likely reason they chose to do it in Rust, though, is because they wanted to and no one else had.
Rust doesn't have the mature libraries that C# offers, but it isn't barren anymore either. It does offer nice assurances like entirely avoiding race conditions by default (when using safe Rust). Rust often leads to performant code, but it's hard to say if that's really a feature of the language or just a bias due to the kinds of people using it and the projects they work on.
If you're just looking to get into game development without any other goals in mind, then C# is a safer choice
It does make memory management much more explicit, which makes it at least easier to write performant code.
The question however is what your program is doing. If it's limited by network requests or something similar with high latency you won't be able to optimize much on the language side of performance.
If however you're processing a lot of strings, the safe borrowing mechanism can help you avoid most copying.
For example on my previous job we had a part of our CI build that would parse a huge text file and combine it with some information from an ELF's debug info in Perl. It took 45 mins for one execution. It was also impossible to read.
I rewrote it in F# which after some heavy optimization work worked through it in 2 mins.
I had just heard of Rust and rewrote it in Rust, basically transforming F# to Rust syntax and trying to eliminate as many copies as possible. Now the whole execution took 8s.
So at that point I was sold on Rust, however the library ecosystem was still lacking. Nowadays it's much better.
For what it is worth, I've had a very similar experience with the re-write of an internal tool in Rust.
I was in pure disbelief, running the next command in the toolchain this tool runs in, expecting it to fail on some empty input files but it worked. 20x speed-ups almost feel like some essential work must have been missed or skipped but when you realize that's not the case, it is a different kind of pleasure.
Doesn't it "just" prevent data races? I don't think it prevents all race conditions.
I use C# (.NET) daily and I think it’s great for game development, but Rust certainly has its own advantages.
Remember that all of the 'hot' code is internal to Unity and is not written in C#. C# basically just takes on the role of a particularly powerful scripting language and isn't dealing with cleaning up huge amounts of data as would be the case for anything dealing with assets directly.
There are a couple of talks related to it.
a) Module system lowers the complexity overhead of using third-party libraries, which means you aren't tempted/required to reinvent as many wheels
b) Easy, reliable, monolithic build system, particularly for cross-platform builds
c) Ease of writing bug-resistant concurrent logic (my understanding is that concurrency doesn't get used much in games because it's so hard to get right)
Of course the above can mostly be said for C# too. But Rust could maybe be seen as the best of both (C++/C#) worlds
I would say its biggest disadvantage is simply that neither major engine uses it (officially). Unity and Unreal are so powerful at this point (and free for smaller projects!) that you're better off using them for nearly any game project, unless: a) you just feel like writing your engine from scratch for fun, b) you're doing something wildly novel, or c) you're a AAA studio that can afford to hand-roll an engine in order to save on licensing fees down the road. Maybe Rust will see adoption in category c one day, but there's a huge amount of institutional momentum to contend with.
The magical part about Rust really is how accurately (compared to other languages) you know which little gear in the big machine is failing. Often you even know precisely why and how it is failing.
Precondition for this is of course that you really grok Rusts ownership and type system.
Of course you could still ignore it then, but the language made make this choice at every point consciously so it is totally your fault if it bites you later.
I e.g. tend to comment on unwraps why they cannot panic, and if they could (because I wanted to follow another strain of thought first, I use except and a message or writw a TODO comment.
> this is only a partial list of changes made to improve the GC itself, but that last bullet brings me to a topic of particular fascination for me, as it speaks to a lot of the work we’ve done in .NET in recent years. In this release, we’ve continued, and even accelerated, the process of porting native implementations in the coreclr runtime from C/C++ to instead be normal C# managed code in System.Private.Corelib. Such a move has a plethora of benefits, including making it much easier for us to share a single implementation across multiple runtimes (like coreclr and mono), and even making it easier for us to evolve API surface area, such as by reusing the same logic to handle both arrays and spans. But one thing that takes some folks by surprise is that such benefits also include performance, in multiple ways.
https://devblogs.microsoft.com/dotnet/performance-improvemen...
> In a community run benchmark of different gRPC server implementations, .NET gets the highest requests per second after Rust, and is just ahead of C++ and Go.
https://devblogs.microsoft.com/aspnet/grpc-performance-impro...
Veloren is the spiritual successor to CubeWorld, made by disappointed fans wanting something better.
They never abandoned the game. It was a two person team (husband and wife), and both devs worked full time jobs while making CW. After the initial alpha release, CW got a ton of attention and became a DDoS target, which triggered some mental issues in the lead dev.[1] They went dark after that for a long time (probably because everything new was usually posted by this lead dev).
The silent mystery with the game just built up even more hype over six years until the full game finally released, and the massive attention and disaster seemed to happen all over again. Every post about the game complained about the new design decisions with leveling. The lead dev seemed to think this was the best version of the game (based on his comments in his blog) and he seems to not have taken the criticism well, leading to him going dark again.
I wish he would have taken the hits and continued with the game, but if it's affecting his mental health in this way, he is probably better off abandoning it. I hope he gets better and I am still looking forward to anything he and his wife make in the future.
[1] https://web.archive.org/web/20190910123212/http://wollay.blo...
in open source, talking about the work is really as important as doing the work. a key catalyst in turning "free as in beer" to the kind of communal shared understanding anarcho-syndicalist working practicing healthy community. i want a "free as in ourselves" mantra or some such to trot out here. anyhow Veloren keeping their story of development alive is such a respectable powerful act, keeping users & developers & everyone in between engaged & interested & learning.
* I'd assume peformance was great, but is there metrics to show?
* Is the client and server written in Rust, or just the server?
Those things could be a huge deal for any game developer, especially, when you already know Rust.
Consumer software is better without crashes. It's sad how rife software is these days with segfaults that can be prevented by design.
Open-source + built in a slightly interesting language are the only reasons we'd be discussing an MMORPG.
Good luck to the team. MMORPG that anyone wants to play is probably the hardest challenge in gamedev and game design.
Did not know that
What does that have to do with the parent comment? The usual argument I've seen is that game developers "move too fast", "don't have everything designed ahead of time", "have to iterate quickly" and Rust's insistence on writing correct code gets in the way of that during the prototype phase.
Java doesn't really have that issue as it is quite a bit more forgiving than C++ and will happily let you hammer a square peg into a round hole at the expense of performance, as evidenced by Minecraft.
And everyone who plays large modpacks, goes around large buildings, or just sets off a ton of TNT has seen how it has suffered for it.
On the other side, anyone who has seen the selection of mods available for Java edition vs bedrock edition (the C++ rewrite) despite a modding API for bedrock being officially supported has seen how it has benefitted from this.
We chose Rust because it's performant, memory-safe, and comes with a host of modern features that make writing code with the language very enjoyable.
We could have chosen C++, but I'm very glad that we didn't. Memory safety is great: I've not needed to break out gdb even once throughout the history of this project, despite the size of the project. This safety means that code is easier to review because it 'does what it says on the tin' and is much less prone to UB and non-local behaviours. It also reduces the prevalence of bugs. I've been shocked by just how much easier it is to write reliable and bug-free code with Rust than it is with languages that I've used in the past (C, C++, Python, Vala, amongst others).
The type system is also very powerful and it lets us encode a lot of useful invariants that can be checked by the compiler. Knowing that what you're doing is correct-by-nature is a great help and it frees your mind up to focus on the logic of what you're writing rather than getting distracted by irrelevant details like representation.
Rust plays very well with data-oriented design. This works great for us. At its heart, Veloren uses a high-performance ECS that is extremely cache-coherent. There's still lots of optimisation work to do, but we're already seeing that servers that can handle hundreds of players and millions of entities without issue, despite the fact that terrain generation is done server-side (and, as such, we have similar performance constraints to games like Minecraft).
The client, server and client/server frontends (frontends are logically independent and alternative frontends can be written for the game) are all written in Rust. In addition, the in-development plugin API will allow for plugins written in Rust and compiled to WASM.
In addition, Rust is also very portable. Compiling the game on (and for) many platforms is incredibly easy. The game runs well on Windows, Mac OS, Linux, BSD, and community members have even gotten it running on the Raspberry Pi and a hacked Nintendo Switch!
I hope this doesn't come across as being overly evangelical, but I think I speak for all of the developers when I say that we have no regrets in the slightest about choosing Rust! That doesn't mean it's the right choice for all projects, of course. The Rust gamedev ecosystem is still relatively immature. Although this is changing fast, don't expect to find any nuts-and-bolts game engines ready to go. However, if you're not afraid of diving down into low-level APIs here and there, Rust might be a great choice.
Edit: At a second glance, I see you're asking more about why mentioning the language is important. As a community-driven project, we rely on encouraging new contributors to work on the game and the choice of language is something that developers usually care about a lot. Extensibility and open development is really important for us and so 'showing the innards' is a big part of what we do when interacting with the community. Unless it's security-sensitive, we'll always discuss development issues and ideas in a public forum where anybody can add their input.
https://rustgamedev.com/episodes/interview-with-team-veloren
Not at all, I'm worried now my post seemed mean! This was exactly what I was looking for. I wanted to know if this was chosen just as a PoC for Rust, or whether it actively made development better (which it sounds like it does :D). There's a big difference between "Here is X written in Rust" and "X is so much easier because we wrote it in Rust!".
The fact you then go on to use ECS within Rust must have amazing returns on metrics. Good luck on your progress!
I think you meant cache-efficient, ie: it uses the cache efficiently. Cache coherence is something completely different.
And in general is should be much easier to create a performance sensitive game in Rust then in Java. Besides that Rust is much more ergonomic to use.
I can see an argument that Rust could also help prevent those as it is a higher-level language and has a few language features to prevent some of the logic problems, but not that many?
(that said, I have personally found bugs in text-based MUDs that could have been prevented by Rust. They were all "just" DoS bugs though, instantly crash the server type things)
Why? Just good language design. Things like "enums" (algebraic data types, not C-enums) making for type checked state machines, really strict typing, immutability by default, simple language semantics, good linters that people actually use, the borrow checker actually does usually lend itself to good design too, and so on.
void inner (const T& t1, T& t2);
void outer (T* t, int i, int j) {
inner(t[i], t[j]);
}
There are three memory safety bugs in that code: - the pointer `t` is not checked for null
- the indices `i` and `j` are not checked to see if they are outside the bounds of `i` and `j`
- the indices `i` and `j` are not checked to see if they are the same.
The first bug will cause a segfault and crash. The second is a potential buffer exploit. The third is a logical bug that can be exploited depending on what inner() is supposed to do. Most people know to check the first two, the third one is subtle and isn't necessarily a bug. But it may become a bug that can be exploited inside `inner`, especially over the lifetime of the code.Rust will prevent all three, or force you to perform the checks before using an `unsafe` block.
But more than that, this kind of issue crops up due to an inherent weakness of code review - it catches errors in blocks of logic, but not in logic below it and logic above it. Since C/C++ don't have idiomatic error handling worth a damn (the only "idiomatic" errors in C++ are debug assertions, ime) you can't defend against silent logic bugs due to violating invariants of callers or callees that are expressed through Option/Result types in Rust (I mentioned this in a comment above). That's the real benefit of writing code in Rust, in addition to the absence of footguns.
Or, you know, nasal demons
That a stronger type system "eliminates a whole class of bugs" is nice and all, but users should be wary of the false sense of security it gives (in the same way that the weak type system of C gives a false sense of security when you come from assembler programming). You can have proven and certified bug-free crypto routines, and fail pathetically because their a giant hole in your crypto system. Just a friendly warning.
In particular if you do the engine as a collaborative piece, then running a game starts to look like any other volunteer group: a bimodal distribution where few old hands keep it on the rails, a lot of new people whose raw enthusiasm overpowers their lack of experience, who need to be given tasks they can not fuck up so badly.
In between it’s a race between burnout and life balance for the people who have shown up for three years. They provide a lot of the leadership and competence, but they also tend to disappear. So you need to groom the newbs to replace them regularly. The old hands are the scribes who provide historical data when those transitions don’t go smoothly. They are continuity and influence, not productivity.
Any system that provides some safety for people still working out how to contribute is going to fare much better than one that is alienating. Rust to me is a mix of both, therefore plausible but not a slam dunk.
All of this is a work in progress (hence the pre-alpha versioning), but we already have a few hours of gameplay with dungeons and caves to explore, lots of items to craft and find, and several skill trees to upgrade. In the long-term, we're aiming for more procedural interaction with elements of the world.
I encourage you to bring up a screenshot of Cube World side by side and see if you can tell the difference between this game. Looks nothing like Minecraft, except for it being blocky.
Jokes aside thanks for sharing. It’s always interesting to read game source code and Rust beginners can learn a lot reading this code.
* It has the performance profile of C
* A really good package manager
* I don't have to worry about segfaults/runtime issues from manual memory management
* I love the type system (yay expressive static types with pattern matching)
* Also prevents data races and other things like iterator invalidation
* Also, null safety, among other things leads to a lot fewer runtime issues I need to figure out
It does this well, since at the same time I was able to write 10k lines of JS game code into 10k lines of Rust game code: https://www.reddit.com/r/rust/comments/k3jy5g/i_rewrote_10k_...
Have since rewritten server from nodejs to Rust. There the line count grew. But async/await was splendid there, & serde made implementing the json server/client protocol straight forward
* It has algebraic data types, pattern matching, etc. - language features that just don't exist in most languages I've used. (I did play with F# for a bit and really loved its capabilities, but I've never had the occasion to get into F#, unfortunately.) Once I start using these features, I suddenly find that all these other languages are sorely lacking.
* Its safety guarantees mean that I spend more time in the IDE fixing compiler errors and less time in the running exe finding my problem. I often find that when my program compiles, it is generally correct. This has given me a lot of confidence in the quality of my releases (borne out in actual production code, not just toy projects)
* Speed of execution is (in my experience), better than an order of magnitude faster than in other languages for a similar implementation.
YMMV, and there may be some of that New Relationship Energy here, but I can absolutely see why it's been on SO's most loved languages for five years in a row[0].
[0] https://insights.stackoverflow.com/survey/2020#technology-mo...
A huge chunk of software we have today is built upon other software that is built upon other software that ... but that whole foundation is rather shaky and probably incorrect. Basically, if you want to express it that way: Everything is broken and we have played the wrapping game for far too long as a professional group. There will probably forever remain bugs in that gigantic mountain of code, that we rely on.
People get excited about rewriting things in Rust to avoid a good chunk of the legacy code written in languages that are not memory save and that do have a lot of undefined behavior or allow for race conditions easily once you even as little as touch concurrency. People want to finally have a solid basis, which is proven to be correct in implementation. Rust goes a long way towards this goal, so people like it.
I subscribe to some great projects' repositories and read the issues. These projects sometimes bring me great value and I am not saying they aren't useful. Usually however, non-trivial C++ or C (and other languages) projects have all the same kind of issues. People thinking every noun has to be a class and the standard paradigm of mutating everything everywhere, be it through setter or directly, then forgetting to update state at some point, where it was necessary. People sharing state across multiple threads and forgetting to acquire a lock or releasing it. Or in some other way building race conditions. People thinking they will be able to do manual memory management correctly and then having segfaults, which require long debugging sessions or a lot of experience to fix. Use after free bugs. Security issues resulting from such causes. This and all that kind of stuff, that a good type system should prevent you from doing. And that is where Rust delivers.
Rust has many zero cost abstractions that make writing things easier.
It’s super high level at the speed class of C - sometimes even faster given that libraries for common tasks are well programmed. With the high level abstractions the compiler may probably reason and optimize better?
Rust is a great language, not my preference (Julia is better imo, and I still absolutely love C), but the community and tools being built in Rust are fantastic.
Can we please stop saying X language is "better" than Y? It really does not make any sense. Both languages were designed with very different goals in mind. Each of them is a good fit for their respective use cases, but saying Julia is "better" than Rust makes no sense.
Of course, saying something is better than something else is always prefixed with an implicit "I believe that...", so it's fine to argue with it. But that doesn't mean it's an illegitimate thing to say.
Some languages are better: more conducive to popularity; safer; more conducive to not wasting resources; nicer to work with; more expressive. We don't have reliable methods of objectively measuring these metrics, but they do exist.
Rust, I believe, has a pretty high aggregate score.