- TEST_SPEC.md: Updated test directory structure to reflect Core/Asset, Core/IO, and Resources/<Type> subdirectories - TEST_SPEC.md: Updated module names and test counts (852 total) - TEST_SPEC.md: Updated build commands for new Resources subdirectories - README.md: Updated engine structure with Core/Asset/ and Core/IO/ - README.md: Updated Resources section with layered architecture - README.md: Updated test coverage table with accurate counts
57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include "ResourceTypes.h"
|
|
#include <XCEngine/Core/Containers/HashMap.h>
|
|
#include <XCEngine/Core/Containers/Array.h>
|
|
#include <XCEngine/Core/Types.h>
|
|
|
|
namespace XCEngine {
|
|
namespace Resources {
|
|
|
|
struct DependencyNode {
|
|
ResourceGUID guid;
|
|
ResourceType type;
|
|
Containers::Array<ResourceGUID> dependencies;
|
|
Containers::Array<ResourceGUID> dependents;
|
|
Core::uint32 refCount = 0;
|
|
};
|
|
|
|
class ResourceDependencyGraph {
|
|
public:
|
|
ResourceDependencyGraph();
|
|
~ResourceDependencyGraph();
|
|
|
|
void AddNode(ResourceGUID guid, ResourceType type);
|
|
void RemoveNode(ResourceGUID guid);
|
|
|
|
void AddDependency(ResourceGUID owner, ResourceGUID dependency);
|
|
void RemoveDependency(ResourceGUID owner, ResourceGUID dependency);
|
|
|
|
Containers::Array<ResourceGUID> GetDependencies(ResourceGUID guid) const;
|
|
Containers::Array<ResourceGUID> GetDependents(ResourceGUID guid) const;
|
|
Containers::Array<ResourceGUID> GetAllDependencies(ResourceGUID guid) const;
|
|
|
|
void IncrementRefCount(ResourceGUID guid);
|
|
void DecrementRefCount(ResourceGUID guid);
|
|
Core::uint32 GetRefCount(ResourceGUID guid) const;
|
|
|
|
bool HasCircularDependency(ResourceGUID guid, Containers::Array<ResourceGUID>& outCycle) const;
|
|
|
|
Containers::Array<ResourceGUID> TopologicalSort() const;
|
|
|
|
bool Unload(ResourceGUID guid);
|
|
|
|
void Clear();
|
|
|
|
bool HasNode(ResourceGUID guid) const;
|
|
|
|
private:
|
|
bool HasCircularDependencyInternal(ResourceGUID guid, Containers::HashMap<ResourceGUID, bool>& visited,
|
|
Containers::Array<ResourceGUID>& path, Containers::Array<ResourceGUID>& outCycle) const;
|
|
|
|
Containers::HashMap<ResourceGUID, DependencyNode> m_nodes;
|
|
};
|
|
|
|
} // namespace Resources
|
|
} // namespace XCEngine
|