4 ms·
I wrote something similar for a resource system for a game engine. If you had a ResourceHandle<T> you knew that the T inside it would never change, and it was s
by a_t48 7y ago
I wrote something similar for a resource system for a game engine. If you had a ResourceHandle<T> you knew that the T inside it would never change, and it was safe to pass to any other system. You could always make a mutable copy of the RH<T> to get a T out (and as an optimization if you held the last handle, skip the copy). Once you were done writing to the T, you could tell the resource system to harden it into a handle to give to other systems again (which included serializing it to give it a static hash for the T). There was other cleverness to make it ergonomic that I've since forgotten. Across a large codebase it _was_ nice to ensure that immutable data wasn't going to change, and that you could load up data with the same hash again later and get the same results. It _is_ possible to do via mutable data structures, but you can't always ensure that every person on your team will be careful in the right way.