News for hackers. Stuff that matters.
Re:Unreal Rust by steveklabnik on Sunday September 04, 2022 @07:21PM (#32718748)
Memory safety does matter for games. Especially in places like networked games, or anti cheat software.

Even in single player games, a game crashing and losing your progress sucks.

Rust’s non-borrow checker features help with other kinds of things. Rust isn’t only an ownership system.

Re:Unreal Rust by moldavi on Sunday September 04, 2022 @07:54PM (#32718937)
For a single player turn-based game, I'm not so sure the tradeoff is as obvious as everyone says, after coding one in C++ and another in Rust.

It's turn based, so I don't need AAA game multi-threaded performance. It's single-player, so cheating doesn't really hurt anyone.

I use sanitizers to catch memory problems, but there have only been a few of those over the years. Maybe ECS just isn't that vulnerable to memory-safety problems?

The borrow checker prevents iterator invalidation problems, but most of my functions are read-only so there's not really a chance for those anyway, or many other single-threaded race conditions for that matter.

After this long using Rust, I'm noticing more and more that the borrow checker is imposing a lot of artificial complexity, when I compare it to my C++ version. We're often told that Rust is hard because the underlying problem is hard, but I've encountered many cases where that's not true, it really is just the borrow checker. And unfortunately, most of them are problems that Polonius won't fix.

Rust has a lot of great features (enums and cargo!) but I think one should think carefully about their domain and architecture before choosing a language, lest they pay too much cost for too little benefit.

Just my two cents!

Re:Unreal Rust by Morgawr on Monday September 05, 2022 @12:01AM (#32720372)
> It's turn based, so I don't need AAA game multi-threaded performance. It's single-player, so cheating doesn't really hurt anyone.

I don't understand this, just because it's turn based it doesn't mean you can't squeeze more juice out of your CPU if you want to have all kinds of good graphics, fancy animations, fancy complex environments (lots of moving pieces, etc), physics simulation, etc.

Turn based is just one style of play but there's plenty of turn (or pseudo-turn) based games (like JRPGs) which struggle with platform limitations. One could even argue that games like Final Fantasy XIV are turn based.

Re:Unreal Rust by zarzavat on Sunday September 04, 2022 @10:50PM (#32719965)
> I use sanitizers to catch memory problems, but there have only been a few of those over the years. Maybe ECS just isn't that vulnerable to memory-safety problems?

To expand on this a bit. In games, objects generally fit into two categories:

1. Short-lived temporary objects, usually stack-allocated or arena-allocated, etc. e.g. a point vector, or matrix.

2. Long-lived objects with indeterminate lifetime. e.g. a character or item.

In the case of long-lived objects, there are various strategies you could use to make it safe e.g. using object IDs or custom smart pointers to refer to other objects that potentially might go missing instead of pointers which are bound to be corrupted.

Generally you want to register all of your long-lived objects in one central location that will handle memory management. Manual, reference counting or GC are all viable strategies depending on requirements.

I like Rust and would use it for games but mainly because of the package management.

Re:Unreal Rust by pcwalton on Sunday September 04, 2022 @10:55PM (#32720010)
> It's turn based, so I don't need AAA game multi-threaded performance.

Then you could just use a GC'd language. For example, you could use C# in Unity.

Re:Unreal Rust by cwzwarich on Sunday September 04, 2022 @10:07PM (#32719747)
> We're often told that Rust is hard because the underlying problem is hard, but I've encountered many cases where that's not true, it really is just the borrow checker. And unfortunately, most of them are problems that Polonius won't fix.

Out of curiosity, what are your favorite examples?

Re:Unreal Rust by spoiler on Monday September 05, 2022 @05:28AM (#32722230)
I would be curious to know more about this case too, fwiw!

Personally, I've only struggled a bit with the borrow checker in a couples of cases: trying to have self/circular references when trying to model OOP, and when fiddling/interacting with some low level async code. Both were unnecessary in my case, and each situation was caused by a lack of understanding.

Re:Unreal Rust by Veliladon on Monday September 05, 2022 @07:29AM (#32723140)
You can put recurring references in a type, you just need to Box it up first.

So you'd have something like:

   enum List<T> {
       Cons(T, Box<List<T>>),
       Nil,
   }
Since the list is now boxed up the borrow checker has a fixed sized object to put on the stack at compile time.
Re:Unreal Rust by pornel on Monday September 05, 2022 @01:46PM (#32727019)
Previous post mentioned self/circular references. You can't do that with a `Box`. You can with `Rc<RefCell<List` or `*mut List`, but those options either have a runtime cost, or aren't borrow-checked.

Lack of self-referential types that are both safe and zero-cost is a legit limitation of Rust.

Re:Unreal Rust by spoiler on Monday September 05, 2022 @11:25AM (#32725331)
Hi! Thanks for taking the time to explain the concept! I'm familiar with these (and others) now, but I was curious to know what others issues the commenter alludes to
Re:Unreal Rust by jokethrowaway on Monday September 05, 2022 @03:34AM (#32721534)
Fascinating!

Do you use async closures? That's the only case where I felt the borrow checker is a bit behind. Also I haven't checked in a few months and I know there was some work ongoing.

That forced me to start organising the code in a different way which is less functional but easier to understand, so it's not crystal clear what's happening.

Re:Unreal Rust by pjmlp on Monday September 05, 2022 @02:11AM (#32721090)
In which cases they are already mostly using Erlang, Java, .NET languages, or Go on their server stacks.

Rust is a great C and C++ replacement for low level stuff, I am still not convinced it is worthy versus those languages for distributed computing in terms of the productivity automatic memory management brings to the table.

Re:Unreal Rust by MiguelX413 on Sunday September 04, 2022 @07:54PM (#32718933)
As mentioned, the type system helps reduce invalid states among many other things too!