mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
Add AssetLoader basis
This commit is contained in:
@ -1,49 +1,33 @@
|
||||
#include "ZoneCreatorT6.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "ObjLoading.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Game/T6/GameT6.h"
|
||||
#include "Game/T6/GameAssetPoolT6.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
namespace T6
|
||||
ZoneCreator::ZoneCreator()
|
||||
{
|
||||
class SpecifiedAsset
|
||||
for(auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
|
||||
{
|
||||
public:
|
||||
XAssetType m_type;
|
||||
std::string m_name;
|
||||
bool m_reference;
|
||||
};
|
||||
AddAssetTypeName(assetType, GameAssetPoolT6::AssetTypeNameByType(assetType));
|
||||
}
|
||||
}
|
||||
|
||||
class AssetLoaderImpl
|
||||
{
|
||||
ZoneCreationContext& m_context;
|
||||
void ZoneCreator::AddAssetTypeName(asset_type_t assetType, std::string name)
|
||||
{
|
||||
m_asset_types_by_name.emplace(std::make_pair(std::move(name), assetType));
|
||||
}
|
||||
|
||||
void CreateZoneAssetPools(Zone* zone) const
|
||||
{
|
||||
zone->m_pools = std::make_unique<GameAssetPoolT6>(zone, zone->m_priority);
|
||||
void ZoneCreator::CreateZoneAssetPools(Zone* zone) const
|
||||
{
|
||||
zone->m_pools = std::make_unique<GameAssetPoolT6>(zone, zone->m_priority);
|
||||
|
||||
for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
|
||||
zone->m_pools->InitPoolDynamic(assetType);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit AssetLoaderImpl(ZoneCreationContext& context)
|
||||
: m_context(context)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<Zone> CreateZoneForDefinition()
|
||||
{
|
||||
auto zone = std::make_unique<Zone>(m_context.m_zone_name, 0, &g_GameT6);
|
||||
CreateZoneAssetPools(zone.get());
|
||||
|
||||
std::vector<SpecifiedAsset> specifiedAssets;
|
||||
|
||||
return zone;
|
||||
}
|
||||
};
|
||||
for (auto assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
|
||||
zone->m_pools->InitPoolDynamic(assetType);
|
||||
}
|
||||
|
||||
bool ZoneCreator::SupportsGame(const std::string& gameName) const
|
||||
@ -53,6 +37,30 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const
|
||||
|
||||
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
|
||||
{
|
||||
AssetLoaderImpl impl(context);
|
||||
return impl.CreateZoneForDefinition();
|
||||
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameT6);
|
||||
CreateZoneAssetPools(zone.get());
|
||||
|
||||
std::vector<Gdt*> gdtList;
|
||||
gdtList.reserve(context.m_gdt_files.size());
|
||||
for (const auto& gdt : context.m_gdt_files)
|
||||
gdtList.push_back(gdt.get());
|
||||
const auto assetLoadingContext = std::make_unique<AssetLoadingContext>(zone.get(), context.m_asset_search_path, std::move(gdtList));
|
||||
|
||||
for(const auto& assetEntry : context.m_definition->m_assets)
|
||||
{
|
||||
if (assetEntry.m_is_reference)
|
||||
continue;
|
||||
|
||||
const auto foundAssetTypeEntry = m_asset_types_by_name.find(assetEntry.m_asset_type);
|
||||
if(foundAssetTypeEntry == m_asset_types_by_name.end())
|
||||
{
|
||||
std::cout << "Unknown asset type \"" << assetEntry.m_asset_type << "\"" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!ObjLoading::LoadAssetForZone(assetLoadingContext.get(), foundAssetTypeEntry->second, assetEntry.m_asset_name))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return zone;
|
||||
}
|
||||
|
Reference in New Issue
Block a user