mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-05 16:27:27 +00:00
chore: implement obj loading skeleton with localize asset
This commit is contained in:
35
src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.cpp
Normal file
35
src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "AssetLoaderRawFileIW3.h"
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
AssetLoaderRawFile::AssetLoaderRawFile(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult AssetLoaderRawFile::CreateAsset(const std::string& assetName, AssetCreationContext& context)
|
||||
{
|
||||
const auto file = m_search_path.Open(assetName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
auto* rawFile = m_memory.Alloc<RawFile>();
|
||||
rawFile->name = m_memory.Dup(assetName.c_str());
|
||||
rawFile->len = static_cast<int>(file.m_length);
|
||||
|
||||
auto* fileBuffer = m_memory.Alloc<char>(static_cast<size_t>(file.m_length + 1));
|
||||
file.m_stream->read(fileBuffer, file.m_length);
|
||||
if (file.m_stream->gcount() != file.m_length)
|
||||
return AssetCreationResult::Failure();
|
||||
fileBuffer[rawFile->len] = '\0';
|
||||
|
||||
rawFile->buffer = fileBuffer;
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, rawFile));
|
||||
}
|
21
src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.h
Normal file
21
src/ObjLoading/Game/IW3/RawFile/AssetLoaderRawFileIW3.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class AssetLoaderRawFile final : public AssetCreator<AssetRawFile>
|
||||
{
|
||||
public:
|
||||
AssetLoaderRawFile(MemoryManager& memory, ISearchPath& searchPath);
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override;
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
||||
} // namespace IW3
|
16
src/ObjLoading/Game/IW3/RawFile/DefaultCreatorRawFileIW3.cpp
Normal file
16
src/ObjLoading/Game/IW3/RawFile/DefaultCreatorRawFileIW3.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "DefaultCreatorRawFileIW3.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
DefaultCreatorRawFile::DefaultCreatorRawFile(MemoryManager& memory)
|
||||
: m_memory(memory)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult DefaultCreatorRawFile::CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const
|
||||
{
|
||||
auto* asset = m_memory.Alloc<RawFile>();
|
||||
asset->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, asset));
|
||||
}
|
18
src/ObjLoading/Game/IW3/RawFile/DefaultCreatorRawFileIW3.h
Normal file
18
src/ObjLoading/Game/IW3/RawFile/DefaultCreatorRawFileIW3.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IDefaultAssetCreator.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class DefaultCreatorRawFile : public DefaultAssetCreator<AssetRawFile>
|
||||
{
|
||||
public:
|
||||
explicit DefaultCreatorRawFile(MemoryManager& memory);
|
||||
AssetCreationResult CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const override;
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
};
|
||||
} // namespace IW3
|
Reference in New Issue
Block a user