// Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #pragma once #include #include #include #include #include #include #include namespace anki { // Forward class GrManager; class PhysicsWorld; class ResourceManager; class AsyncLoader; class ResourceManagerModel; class ShaderCompilerCache; class ShaderProgramResourceSystem; class AccelerationStructureScratchAllocator; ANKI_CVAR(NumericCVar, Rsrc, TransferScratchMemorySize, 256_MB, 1_MB, 4_GB, "Memory that is used fot texture and buffer uploads") ANKI_CVAR(BoolCVar, Rsrc, TrackFileUpdates, false, "If true the resource manager is able to track file update times") // Resource manager. It holds a few global variables class ResourceManager : public MakeSingleton { template friend class ResourcePtrDeleter; friend class ResourceObject; template friend class MakeSingleton; public: Error init(AllocAlignedCallback allocCallback, void* allocCallbackData); // Load a resource. // Note: Thread-safe against itself, freeResource() and refreshFileUpdateTimes() template Error loadResource(CString filename, ResourcePtr& out, Bool async = true); // Iterate all loaded resource and check if the files have been updated since they were loaded. // Note: Thread-safe against itself, loadResource() and freeResource() void refreshFileUpdateTimes(); // Internals: // Note: Thread-safe against itself, loadResource() and refreshFileUpdateTimes() template ANKI_INTERNAL void freeResource(T* ptr); private: template class TypeData { public: class Entry { public: DynamicArray m_resources; // Hosts multiple versions of a resource. The last element is the newest SpinLock m_mtx; U64 m_fileUpdateTime = 0; }; ResourceHashMap m_map; ResourceBlockArray m_entries; RWMutex m_mtx; TypeData() { for([[maybe_unused]] const Entry& e : m_entries) { ANKI_ASSERT(e.m_resources.getSize() > 0 && "Forgot to release some resource"); } } }; class AllTypeData: #define ANKI_INSTANTIATE_RESOURCE(className) \ public \ TypeData #define ANKI_INSTANSIATE_RESOURCE_DELIMITER() , #include { }; AllTypeData m_allTypes; Atomic m_uuid = {1}; Bool m_trackFileUpdateTimes = false; ResourceManager(); ~ResourceManager(); template void refreshFileUpdateTimesInternal(); }; } // end namespace anki