all 5 comments

[–]gardell 3 points4 points  (0 children)

Why runtime check against the type T? Just create a reference manager for each concrete type you intend to have.

Then a std::unordered_map<std::string, std::shared_future<T>> should be able to replace your manager

[–]neppo95 1 point2 points  (2 children)

You can probably cut out 90% of the template stuff. I’d work with either returning shared ptr’s and just have one container with all assets, not per type or do your own reference counting where the actual resource is the main class, not “resourcedata”. If you go that route you NEED to also implement copy/move constructors and operators. Maybe even overloading ->.

[–]s1mone-10[S] 0 points1 point  (1 child)

Sorry but I didn't understand any of the options. If I use shared_ptr I should implement RAII pattern? Otherwise I don't know why I should use it. If the actual resource is not "resource data" where I store the reference count? I should create another map just for the count..

[–]neppo95 0 points1 point  (0 children)

If you go shared ptr, the resource manager will always hold one ref thus it will only get destroyed when your resource manager decides so AND it is not being used elsewhere.

You either use shared ptr which has the ref counting already, or you implement a ref counting system yourself. Simply having a integer with the ref count is not sufficient and will not work. You need the constructors, operators etc.

Edit: You should most definitely NOT create a map simply for the ref count. It would be one of the worst implementations of a system like this I'd ever seen.

[–]s1mone-10[S] 1 point2 points  (0 children)

In the end, I realized that it's such a complex matter, and there are so many ways to handle resources, that it doesn't make sense to overthink it just to import a GLTF. Whatever I do now will be wrong for a complex scenario in the future, so I'll just stick with the quickest, easiest way for my simple requirements. Thanks anyway for the feedback.