Skip to content

Commit 47d3cd7

Browse files
committed
Update (CND): Implement parsing & writing section PVS
1 parent 813f50d commit 47d3cd7

File tree

2 files changed

+68
-0
lines changed
  • libraries/libim/content/asset/world/impl/serialization/cnd

2 files changed

+68
-0
lines changed

libraries/libim/content/asset/world/impl/serialization/cnd/cnd.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,64 @@ void CND::writeSection_Cogs(OutputStream& ostream, const std::vector<SharedRef<C
447447
);
448448
}
449449
}
450+
451+
452+
std::size_t CND::getOffset_PVS(const InputStream& istream, const CndHeader& header)
453+
{
454+
AT_SCOPE_EXIT([ &istream, off = istream.tell() ](){
455+
istream.seek(off);
456+
});
457+
458+
// PVS section is at the end of thing section
459+
istream.seek(getOffset_Things(istream, header));
460+
istream.advance(sizeof(CndThingHeader) * header.numThings);
461+
462+
auto sizes = istream.read<CndThingSectorListSizes>();
463+
istream.advance(
464+
sizeof(CndPhysicsInfo) * sizes.sizePhysicsInfoList +
465+
sizeof(uint32_t) * sizes.sizeNumPathFramesList +
466+
sizeof(PathFrame) * sizes.sizePathFrameList +
467+
sizeof(CndActorInfo) * sizes.sizeActorInfoList +
468+
sizeof(CndWeaponInfo) * sizes.sizeWeaponInfoList +
469+
sizeof(CndExplosionInfo) * sizes.sizeExplosionInfoList +
470+
sizeof(CndItemInfo) * sizes.sizeItemInfoList +
471+
sizeof(CndHintUserVal) * sizes.sizeHintUserValueList +
472+
sizeof(CndParticleInfo) * sizes.sizeParticleInfoList +
473+
sizeof(CndAiControlInfoHeader) * sizes.sizeAiControlInfoList +
474+
sizeof(Vector3f) * sizes.sizeAiPathFrameList
475+
);
476+
477+
return istream.tell();
478+
}
479+
480+
ByteArray CND::parseSection_PVS(const InputStream& istream)
481+
{
482+
try {
483+
return istream.read<ByteArray>(istream.read<uint32_t>());
484+
}
485+
catch(const std::exception& e) {
486+
throw CNDError("parseSection_PVS",
487+
"An exception was encountered while parsing section 'PVS': "s + e.what()
488+
);
489+
}
490+
}
491+
492+
ByteArray CND::readPVS(const InputStream& istream)
493+
{
494+
auto header = readHeader(istream);
495+
istream.seek(getOffset_PVS(istream, header));
496+
return parseSection_PVS(istream);
497+
}
498+
499+
void CND::writeSection_PVS(OutputStream& ostream, const ByteArray& pvs)
500+
{
501+
try {
502+
ostream.write<int32_t>(safe_cast<int32_t>(pvs.size()));
503+
ostream.write(pvs);
504+
}
505+
catch(const std::exception& e) {
506+
throw CNDError("writeSection_PVS",
507+
"An exception was encountered while writing section 'PVS': "s + e.what()
508+
);
509+
}
510+
}

libraries/libim/content/asset/world/impl/serialization/cnd/cnd.h

+7
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ namespace libim::content::asset {
207207
static std::vector<CndThing> parseSection_Things(const InputStream& istream, const CndHeader& header);
208208
static std::vector<CndThing> readThings(const InputStream& istream);
209209
static void writeSection_Things(OutputStream& ostream, const std::vector<CndThing>& things);
210+
211+
// Note: Section PVS is optional and it doesn't need to be written but performance will be degraded.
212+
// Also if this section is not written, the sectors in sector section should have pvsIdx member set to -1
213+
static std::size_t getOffset_PVS(const InputStream& istream, const CndHeader& header);
214+
static ByteArray parseSection_PVS(const InputStream& istream);
215+
static ByteArray readPVS(const InputStream& istream);
216+
static void writeSection_PVS(OutputStream& ostream, const ByteArray& pvs);
210217
};
211218
}
212219
#endif // LIBIM_CND_H

0 commit comments

Comments
 (0)