- Add Shader tests (8 test cases) - Add Material tests (13 test cases) - Add FileArchive tests (7 test cases) - Add Loader tests for Texture, Mesh, Audio, Shader, Material (4 tests each) - Implement IResourceLoader.cpp with ReadFileData and GetExtension - Update CMakeLists.txt to include new test files and source
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#include "XCEngine/Resources/IResourceLoader.h"
|
|
#include <fstream>
|
|
|
|
namespace XCEngine {
|
|
namespace Resources {
|
|
|
|
Containers::Array<Core::uint8> IResourceLoader::ReadFileData(const Containers::String& path) {
|
|
Containers::Array<Core::uint8> data;
|
|
|
|
std::ifstream file(path.CStr(), std::ios::binary | std::ios::ate);
|
|
if (!file.is_open()) {
|
|
return data;
|
|
}
|
|
|
|
std::streamsize size = file.tellg();
|
|
file.seekg(0, std::ios::beg);
|
|
|
|
data.Resize(static_cast<size_t>(size));
|
|
if (!file.read(reinterpret_cast<char*>(data.Data()), size)) {
|
|
data.Clear();
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
Containers::String IResourceLoader::GetExtension(const Containers::String& path) {
|
|
Containers::String ext;
|
|
size_t dotPos = Containers::String::npos;
|
|
for (size_t i = path.Length(); i > 0; --i) {
|
|
if (path[i - 1] == '.') {
|
|
dotPos = i - 1;
|
|
break;
|
|
}
|
|
}
|
|
if (dotPos != Containers::String::npos) {
|
|
ext = path.Substring(dotPos + 1);
|
|
}
|
|
return ext;
|
|
}
|
|
|
|
} // namespace Resources
|
|
} // namespace XCEngine
|