- 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
63 lines
2.1 KiB
C++
63 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <XCEngine/Core/Asset/IResource.h>
|
|
#include <XCEngine/Core/Asset/ResourceTypes.h>
|
|
#include <XCEngine/Core/Asset/ImportSettings.h>
|
|
#include <XCEngine/Core/Containers/String.h>
|
|
#include <XCEngine/Core/Containers/Array.h>
|
|
#include <functional>
|
|
|
|
namespace XCEngine {
|
|
namespace Resources {
|
|
|
|
struct LoadResult {
|
|
IResource* resource = nullptr;
|
|
bool success = false;
|
|
Containers::String errorMessage;
|
|
|
|
LoadResult() = default;
|
|
explicit LoadResult(IResource* res) : resource(res), success(res != nullptr) {}
|
|
explicit LoadResult(const Containers::String& error) : success(false), errorMessage(error) {}
|
|
explicit LoadResult(bool inSuccess, const Containers::String& error = "")
|
|
: success(inSuccess), errorMessage(error) {}
|
|
|
|
operator bool() const { return success && resource != nullptr; }
|
|
};
|
|
|
|
class IResourceLoader {
|
|
public:
|
|
virtual ~IResourceLoader() = default;
|
|
|
|
virtual ResourceType GetResourceType() const = 0;
|
|
virtual Containers::Array<Containers::String> GetSupportedExtensions() const = 0;
|
|
virtual bool CanLoad(const Containers::String& path) const = 0;
|
|
virtual LoadResult Load(const Containers::String& path, const ImportSettings* settings = nullptr) = 0;
|
|
|
|
virtual void LoadAsync(const Containers::String& path,
|
|
const ImportSettings* settings,
|
|
std::function<void(LoadResult)> callback) {
|
|
LoadResult result = Load(path, settings);
|
|
if (callback) {
|
|
callback(result);
|
|
}
|
|
}
|
|
|
|
virtual ImportSettings* GetDefaultSettings() const = 0;
|
|
|
|
protected:
|
|
static Containers::Array<Core::uint8> ReadFileData(const Containers::String& path);
|
|
static Containers::String GetExtension(const Containers::String& path);
|
|
};
|
|
|
|
#define REGISTER_RESOURCE_LOADER(loaderType) \
|
|
namespace { \
|
|
struct loaderType##Registrar { \
|
|
loaderType##Registrar() { \
|
|
ResourceManager::Get().RegisterLoader(new loaderType()); \
|
|
} \
|
|
} g_##loaderType##Registrar; \
|
|
}
|
|
|
|
} // namespace Resources
|
|
} // namespace XCEngine
|