Skip to content

Commit

Permalink
feat: Build a reference map of navmesh chunks for each worldspace/cell
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamashi committed Feb 3, 2022
1 parent 80c70b5 commit b16ec88
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Code/components/es_loader/ESLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ UniquePtr<RecordCollection> ESLoader::BuildRecordCollection() noexcept
return UniquePtr<RecordCollection>();
}

return LoadFiles();
auto recordCollection = LoadFiles();

recordCollection->BuildReferences();

return std::move(recordCollection);
}


Expand Down
1 change: 1 addition & 0 deletions Code/components/es_loader/ESLoaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ TEST_F(ESLoaderTest, GetWorldTamriel)
const WRLD& tamrielWorld = pCollection->GetWorldById(60);

EXPECT_EQ(tamrielWorld.m_editorId, "Tamriel");
EXPECT_EQ(tamrielWorld.m_navMeshRefs.size(), 0x3315);
}

} // namespace
11 changes: 11 additions & 0 deletions Code/components/es_loader/RecordCollection.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
#include "RecordCollection.h"

void RecordCollection::BuildReferences()
{
for (auto& [_, navmesh] : m_navMeshes)
{
if(navmesh.m_navMesh.m_worldSpaceId)
{
auto& world = GetWorldById(navmesh.m_navMesh.m_worldSpaceId);
world.m_navMeshRefs.push_back(&navmesh);
}
}
}
2 changes: 2 additions & 0 deletions Code/components/es_loader/RecordCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class RecordCollection
return m_navMeshes[aFormId];
}

void BuildReferences();

private:
Map<uint32_t, Record> m_allRecords{};
Map<uint32_t, REFR> m_objectReferences{};
Expand Down
4 changes: 4 additions & 0 deletions Code/components/es_loader/Records/WRLD.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "Record.h"
#include "Chunks.h"

class NAVM;

// https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/WRLD
class WRLD : public Record
{
Expand All @@ -17,6 +19,8 @@ class WRLD : public Record
uint32_t m_musicId;
float m_lodMultiplier;

Vector<NAVM const*> m_navMeshRefs;

void ParseChunks(WRLD& aSourceRecord, Map<uint8_t, uint32_t>& aParentToFormIdPrefix) noexcept;
void ParseGRUP() noexcept;
};

0 comments on commit b16ec88

Please sign in to comment.