3 ms·
I try to avoid circular references in C++ as well, at all cost, in my physics engines and game engines. For example, there is a unidirectional access from World
by erwincoumans 5y ago
I try to avoid circular references in C++ as well, at all cost, in my physics engines and game engines. For example, there is a unidirectional access from World -> Object -> Contact Point -> Vector3 and never the other way around (Vector3 doesn't know about Point, Object or World).
Would Rust allow to have all data in 'structs' (no private data), and make all logic pure functional (functions without side effects, data in, data out)? That way, you won't need circular references or stateful objects and it simplifies memory management.
- Animats 5y agoSome parts of the system map well to a purely functional model, and some don't. The part that decodes incoming messages is almost entirely functional. The part that maintains the scene graph isn't. There's a continual stream of update messages coming in, requests for assets go out, and assets come back. One asset reply may update many objects that use the same mesh or texture, so there's not the one-to-one relationship that an "async" model wants. Admittedly this is a somewhat unusual application. It's somewhere between writing an MMO client and a web browser. I once wrote a RSS feed reader in Rust, and that didn't have any of these hard problems.