ObjLoading: Be able to load and index IWD files

This commit is contained in:
Jan
2020-01-01 18:46:33 +01:00
parent a4d55ffae7
commit 0abdb64832
27 changed files with 667 additions and 252 deletions

View File

@ -1,13 +1,18 @@
#include "ObjLoading.h"
#include "IObjLoader.h"
#include "Game/T6/ObjLoaderT6.h"
#include "ObjContainer/ObjContainerRegistry.h"
#include "ObjContainer/IWD/IWD.h"
#include "SearchPath/SearchPaths.h"
ObjLoading::Configuration_t ObjLoading::Configuration;
IObjLoader* objLoaders[]
{
new ObjLoaderT6()
};
SearchPaths iwdSearchPaths;
void ObjLoading::LoadReferencedContainersForZone(ISearchPath* searchPath, Zone* zone)
{
for (auto* loader : objLoaders)
@ -34,5 +39,49 @@ void ObjLoading::LoadObjDataForZone(ISearchPath* searchPath, Zone* zone)
void ObjLoading::UnloadContainersOfZone(Zone* zone)
{
g_ObjContainerRegistry.RemoveContainerReferences(zone);
for (auto* loader : objLoaders)
{
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())
{
const 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);
}
ISearchPath* ObjLoading::GetIWDSearchPaths()
{
return &iwdSearchPaths;
}