Skip to content

Commit

Permalink
feat: base id assignment for parsed records
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed Jan 19, 2022
1 parent e90c6df commit dee225a
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 47 deletions.
3 changes: 2 additions & 1 deletion Code/components/es_loader/ESLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ void ESLoader::LoadFiles()

const Map<uint32_t, CLMT>& pluginClimates = pluginFile.GetClimates();
climates.insert(pluginClimates.begin(), pluginClimates.end());
spdlog::info("Climate count in {}: {}", plugin.m_filename, pluginClimates.size());
}

spdlog::info("All climates:");
for (auto& [formId, climate] : climates)
{
spdlog::info("\t{} ({:X})", climate.m_editorId);
spdlog::info("\t{} ({:X})", climate.m_editorId, formId);
}
}

Expand Down
17 changes: 11 additions & 6 deletions Code/components/es_loader/Records/CLMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@

#include <ESLoader.h>

void CLMT::ParseChunks() noexcept
CLMT CLMT::ParseChunks() noexcept
{
CLMT clmt;
clmt.CopyRecordData(*this);

IterateChunks([&](ChunkId aChunkId, Buffer::Reader& aReader) {
switch (aChunkId)
{
case ChunkId::EDID_ID:
m_editorId = ESLoader::LoadZString(aReader);
clmt.m_editorId = ESLoader::LoadZString(aReader);
break;
case ChunkId::WLST_ID:
m_weatherList = Chunks::WLST(aReader);
clmt.m_weatherList = Chunks::WLST(aReader);
break;
case ChunkId::FNAM_ID:
m_sunTexture = ESLoader::LoadZString(aReader);
clmt.m_sunTexture = ESLoader::LoadZString(aReader);
break;
case ChunkId::GNAM_ID:
m_glareTexture = ESLoader::LoadZString(aReader);
clmt.m_glareTexture = ESLoader::LoadZString(aReader);
break;
case ChunkId::TNAM_ID:
m_timing = Chunks::TNAM(aReader);
clmt.m_timing = Chunks::TNAM(aReader);
break;
}
});

return clmt;
}
2 changes: 1 addition & 1 deletion Code/components/es_loader/Records/CLMT.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ class CLMT : public Record
//TNAM
Chunks::TNAM m_timing{};

void ParseChunks() noexcept;
CLMT ParseChunks() noexcept;
};
13 changes: 7 additions & 6 deletions Code/components/es_loader/Records/CONT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@

#include <ESLoader.h>

CONT::Data CONT::ParseChunks() noexcept
CONT CONT::ParseChunks() noexcept
{
Data data;
CONT cont;
cont.CopyRecordData(*this);

IterateChunks([&](ChunkId aChunkId, Buffer::Reader& aReader) {
switch (aChunkId)
{
case ChunkId::EDID_ID:
data.m_editorId = ESLoader::LoadZString(aReader);
cont.m_editorId = ESLoader::LoadZString(aReader);
break;
case ChunkId::FULL_ID:
data.m_name = ESLoader::LoadZString(aReader);
cont.m_name = ESLoader::LoadZString(aReader);
break;
case ChunkId::CNTO_ID:
Chunks::CNTO cnto(aReader);
data.m_objects.push_back(cnto);
cont.m_objects.push_back(cnto);
break;
}
});

return data;
return cont;
}
19 changes: 8 additions & 11 deletions Code/components/es_loader/Records/CONT.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
#include "Chunks.h"

// https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/CONT
class CONT : Record
class CONT : public Record
{
public:
static constexpr FormEnum kType = FormEnum::CONT;

struct Data
{
// EDID
String m_editorId = "";
// FULL
String m_name = "";
// Objects
Vector<Chunks::CNTO> m_objects{};
};
// EDID
String m_editorId = "";
// FULL
String m_name = "";
// Objects
Vector<Chunks::CNTO> m_objects{};

Data ParseChunks() noexcept;
CONT ParseChunks() noexcept;
};
11 changes: 8 additions & 3 deletions Code/components/es_loader/Records/NPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

#include <ESLoader.h>

void NPC::ParseChunks() noexcept
NPC NPC::ParseChunks() noexcept
{
NPC npc;
npc.CopyRecordData(*this);

IterateChunks([&](ChunkId aChunkId, Buffer::Reader& aReader) {
switch (aChunkId)
{
case ChunkId::ACBS_ID:
m_baseStats = Chunks::ACBS(aReader);
npc.m_baseStats = Chunks::ACBS(aReader);
break;
case ChunkId::DOFT_ID:
m_defaultOutfit = Chunks::DOFT(aReader);
npc.m_defaultOutfit = Chunks::DOFT(aReader);
break;
}
});

return npc;
}
2 changes: 1 addition & 1 deletion Code/components/es_loader/Records/NPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ class NPC : public Record
Chunks::ACBS m_baseStats{};
Chunks::DOFT m_defaultOutfit{};

void ParseChunks() noexcept;
NPC ParseChunks() noexcept;
};
9 changes: 7 additions & 2 deletions Code/components/es_loader/Records/REFR.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#include "REFR.h"

void REFR::ParseChunks() noexcept
REFR REFR::ParseChunks() noexcept
{
REFR refr;
refr.CopyRecordData(*this);

IterateChunks([&](ChunkId aChunkId, Buffer::Reader& aReader) {
switch (aChunkId)
{
case ChunkId::NAME_ID:
m_basicObject = Chunks::NAME(aReader);
refr.m_basicObject = Chunks::NAME(aReader);
break;
}
});

return refr;
}
2 changes: 1 addition & 1 deletion Code/components/es_loader/Records/REFR.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class REFR : public Record

Chunks::NAME m_basicObject{};

void ParseChunks() noexcept;
REFR ParseChunks() noexcept;
};

29 changes: 14 additions & 15 deletions Code/components/es_loader/TESFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,20 @@ bool TESFile::ReadGroupOrRecord(Buffer::Reader& aReader) noexcept
{
//case FormEnum::ACHR:
case FormEnum::REFR: {
REFR recordREFR;
recordREFR.CopyRecordData(*pRecord);
recordREFR.SetBaseId(GetFormIdPrefix());
recordREFR.ParseChunks();
m_objectReferences[recordREFR.GetFormId()] = recordREFR;
REFR parsedRecord = CopyAndParseRecord<REFR>(pRecord);
m_objectReferences[parsedRecord.GetFormId()] = parsedRecord;
break;
}
case FormEnum::CELL:
break;
case FormEnum::CLMT: {
CLMT recordCLMT;
recordCLMT.CopyRecordData(*pRecord);
recordCLMT.SetBaseId(GetFormIdPrefix());
recordCLMT.ParseChunks();
m_climates[pRecord->GetFormId()] = recordCLMT;
CLMT parsedRecord = CopyAndParseRecord<CLMT>(pRecord);
m_climates[parsedRecord.GetFormId()] = parsedRecord;
break;
}
case FormEnum::NPC_: {
NPC recordNPC;
recordNPC.CopyRecordData(*pRecord);
recordNPC.SetBaseId(GetFormIdPrefix());
recordNPC.ParseChunks();
m_npcs[pRecord->GetFormId()] = recordNPC;
NPC parsedRecord = CopyAndParseRecord<NPC>(pRecord);
m_npcs[parsedRecord.GetFormId()] = parsedRecord;
break;
}
}
Expand All @@ -118,3 +109,11 @@ bool TESFile::ReadGroupOrRecord(Buffer::Reader& aReader) noexcept
return true;
}

template <class T>
T TESFile::CopyAndParseRecord(Record* pRecordHeader)
{
T* pRecord = reinterpret_cast<T*>(pRecordHeader);
T parsedRecord = pRecord->ParseChunks();
parsedRecord.SetBaseId(GetFormIdPrefix());
return parsedRecord;
}
3 changes: 3 additions & 0 deletions Code/components/es_loader/TESFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class TESFile
private:
bool ReadGroupOrRecord(Buffer::Reader& aReader) noexcept;

template <class T>
T CopyAndParseRecord(Record* pRecordHeader);

String m_filename = "";
Buffer m_buffer{};

Expand Down

0 comments on commit dee225a

Please sign in to comment.