mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-21 00:25:44 +00:00
95 lines
2.4 KiB
C++
95 lines
2.4 KiB
C++
#include "ObjLoading.h"
|
|
#include "IObjLoader.h"
|
|
#include "Game/IW4/ObjLoaderIW4.h"
|
|
#include "Game/T6/ObjLoaderT6.h"
|
|
#include "ObjContainer/IWD/IWD.h"
|
|
#include "SearchPath/SearchPaths.h"
|
|
|
|
ObjLoading::Configuration_t ObjLoading::Configuration;
|
|
|
|
const IObjLoader* const OBJ_LOADERS[]
|
|
{
|
|
new IW4::ObjLoader(),
|
|
new T6::ObjLoader()
|
|
};
|
|
|
|
void ObjLoading::LoadReferencedContainersForZone(ISearchPath* searchPath, Zone* zone)
|
|
{
|
|
for (const auto* loader : OBJ_LOADERS)
|
|
{
|
|
if (loader->SupportsZone(zone))
|
|
{
|
|
loader->LoadReferencedContainersForZone(searchPath, zone);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ObjLoading::LoadObjDataForZone(ISearchPath* searchPath, Zone* zone)
|
|
{
|
|
for (const auto* loader : OBJ_LOADERS)
|
|
{
|
|
if (loader->SupportsZone(zone))
|
|
{
|
|
loader->LoadObjDataForZone(searchPath, zone);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ObjLoading::UnloadContainersOfZone(Zone* zone)
|
|
{
|
|
for (const auto* loader : OBJ_LOADERS)
|
|
{
|
|
if (loader->SupportsZone(zone))
|
|
{
|
|
loader->UnloadContainersOfZone(zone);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ObjLoading::LoadIWDsInSearchPath(ISearchPath* searchPath)
|
|
{
|
|
searchPath->Find(SearchPathSearchOptions().IncludeSubdirectories(false).FilterExtensions("iwd"),
|
|
[searchPath](const std::string& path) -> void
|
|
{
|
|
auto file = FileAPI::Open(path, FileAPI::Mode::MODE_READ);
|
|
|
|
if (file.IsOpen())
|
|
{
|
|
auto* fileP = new FileAPI::File(std::move(file));
|
|
IWD* iwd = new IWD(path, fileP);
|
|
|
|
if (iwd->Initialize())
|
|
{
|
|
IWD::Repository.AddContainer(iwd, searchPath);
|
|
}
|
|
else
|
|
{
|
|
delete iwd;
|
|
|
|
fileP->Close();
|
|
delete fileP;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
void ObjLoading::UnloadIWDsInSearchPath(ISearchPath* searchPath)
|
|
{
|
|
IWD::Repository.RemoveContainerReferences(searchPath);
|
|
}
|
|
|
|
SearchPaths ObjLoading::GetIWDSearchPaths()
|
|
{
|
|
SearchPaths iwdPaths;
|
|
|
|
for (auto* iwd : IWD::Repository)
|
|
{
|
|
iwdPaths.IncludeSearchPath(iwd);
|
|
}
|
|
|
|
return iwdPaths;
|
|
}
|