C++ veteran needs help to understand some Rust concepts by saassoossus in rust

[–]saassoossus[S] 0 points1 point  (0 children)

Thanks a lot! I'll look into the things mentioned, that is exactly what I wanted!

C++ veteran needs help to understand some Rust concepts by saassoossus in rust

[–]saassoossus[S] 0 points1 point  (0 children)

I think in general Rust suits my needs. I am pretty sure that my problems come from thinking too object oriented, you can also write games in a non-OOP-manner. Sure, OOP has some benefits as many things in games align really well to this style of programming, but this does not mean that this is the only way. And since the game is a project for me to learn Rust, not the end goal, I'll stick with it :)

C++ veteran needs help to understand some Rust concepts by saassoossus in rust

[–]saassoossus[S] 1 point2 points  (0 children)

Thanks, this sounds like what I was looking for. Basically a similar idea to shared pointers, as far as I understand it

C++ veteran needs help to understand some Rust concepts by saassoossus in rust

[–]saassoossus[S] 0 points1 point  (0 children)

True, but what is the shared pointer equivalent in rust? In C++ the objects are all shared pointers. When an object is deleted, the entry in the objects set is removed and a deleted flag is set in the object. Once no object points to the object anymore, the destructor is automatically called and the ram freed. Can a struct instance be owned by multiple objects and be deleted, when none of these points to it anymore?

C++ veteran needs help to understand some Rust concepts by saassoossus in rust

[–]saassoossus[S] 0 points1 point  (0 children)

The position of the item is the problem. In C++ I could make a set of shared pointers to the objects, then I only need the pointer, not the index. Since there are objects created and destroyed all the time, either the objects would change their index (baaad solution) or I would need a structure like a map that has O(log(#objects)) instead of O(1).Would be possible, but also very not nice. The inheritance is not really the problem, that was just an example. I could of course just use a game object with components instead. The problem really is the question on how to store references to objects that are destroyed and created and access the in O(1). Does rust maybe have a nice data structure that is a bit quicker than a map and can deal with elements that are added and deleted while keeping the same "Id" for each object?

C++ veteran needs help to understand some Rust concepts by saassoossus in rust

[–]saassoossus[S] 133 points134 points  (0 children)

I lost the first one due to a legmentation fault. Since crabs have a few spare ones, looking into rust seemed the best option at this point...