8#include <Common/logging.h>
12#include <unordered_map>
32 template<
typename CookedType>
35 template<
typename DerivedType,
typename BaseType,
typename... DeducedArgs>
39 DeducedArgs&&... args)
42 auto newResource = std::make_unique<DerivedType>(std::forward<DeducedArgs>(args)...);
44 DerivedType* resourcePtr =
nullptr;
45 syncedResources.locked(
46 [&resourcePtr, &newResource](
auto& resources)
48 resourcePtr = resources.add(std::move(newResource));
54 template<
typename CookedType,
typename... DeducedArgs>
58 DeducedArgs&&... args)
61 auto newResource = std::make_unique<CookedType>(std::forward<DeducedArgs>(args)...);
63 CookedType* resourcePtr =
nullptr;
64 syncedIdToResource.locked(
65 [
id, &resourcePtr, &newResource](
auto& idToResource)
67 auto findResult = idToResource.find(
id);
68 if(findResult == idToResource.end())
70 resourcePtr = newResource.get();
71 idToResource[id] = std::move(newResource);
75 PH_LOG(CookedResourceCollectionBase, Note,
76 "overwriting existing cooked resource (id: {})", id);
79 resourcePtr = findResult->second.get();
80 *resourcePtr = std::move(*newResource);
87 template<
typename CookedType,
typename... DeducedArgs>
92 const CookedType* resourcePtr =
nullptr;
93 syncedIdToResource.constLocked(
94 [
id, &resourcePtr](
const auto& idToResource)
96 auto findResult = idToResource.find(
id);
97 if(findResult != idToResource.end())
99 resourcePtr = findResult->second.get();
Provides thread-safe cooked data creation and storage. All methods are thread-safe to call,...
Definition CookedResourceCollectionBase.h:25
virtual ~CookedResourceCollectionBase()=default
virtual std::string getStats() const =0
static const CookedType * getCookedResourceByID(const TSynchronized< TSdlResourceIdMap< CookedType > > &syncedIdToResource, const SdlResourceId id)
Definition CookedResourceCollectionBase.h:88
static CookedType * makeCookedResourceWithID(TSynchronized< TSdlResourceIdMap< CookedType > > &syncedIdToResource, const SdlResourceId id, DeducedArgs &&... args)
Definition CookedResourceCollectionBase.h:55
static DerivedType * makeCookedResource(TSynchronized< TUniquePtrVector< BaseType > > &syncedResources, DeducedArgs &&... args)
Definition CookedResourceCollectionBase.h:37
std::unordered_map< SdlResourceId, std::unique_ptr< CookedType > > TSdlResourceIdMap
Definition CookedResourceCollectionBase.h:33
Marks the derived class as non-copyable and non-movable.
Definition INoCopyAndMove.h:17
Definition TUniquePtrVector.h:20
The root for all renderer implementations.
Definition EEngineProject.h:6
std::uint64_t SdlResourceId
Definition SdlResourceId.h:8
PH_DEFINE_EXTERNAL_LOG_GROUP(ApiDatabase, Core)