2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-19 04:45:23 +00:00

RE COutput/InputStream and friends and migrate over

This branch is probably still horribly broken, but it's a good first step to migrating away from having hecl embedded in the runtime
This commit is contained in:
2022-02-17 23:37:54 -08:00
parent c679c2e0f8
commit dad7249927
172 changed files with 3629 additions and 2780 deletions

View File

@@ -23,12 +23,12 @@ union BitsToDouble {
double doub;
};
CScriptLayerManager::CScriptLayerManager(CBitStreamReader& reader, const CWorldSaveGameInfo& saveWorld) {
const u32 bitCount = reader.ReadEncoded(10);
CScriptLayerManager::CScriptLayerManager(CInputStream& reader, const CWorldSaveGameInfo& saveWorld) {
const u32 bitCount = reader.ReadBits(10);
x10_saveLayers.reserve(bitCount);
for (u32 i = 0; i < bitCount; ++i) {
const bool bit = reader.ReadEncoded(1) != 0;
const bool bit = reader.ReadBits(1) != 0;
if (bit) {
x10_saveLayers.setBit(i);
} else {
@@ -37,18 +37,18 @@ CScriptLayerManager::CScriptLayerManager(CBitStreamReader& reader, const CWorldS
}
}
void CScriptLayerManager::PutTo(CBitStreamWriter& writer) const {
void CScriptLayerManager::PutTo(COutputStream& writer) const {
u32 totalLayerCount = 0;
for (size_t i = 0; i < x0_areaLayers.size(); ++i) {
totalLayerCount += GetAreaLayerCount(s32(i)) - 1;
}
writer.WriteEncoded(totalLayerCount, 10);
writer.WriteBits(totalLayerCount, 10);
for (size_t i = 0; i < x0_areaLayers.size(); ++i) {
const u32 count = GetAreaLayerCount(s32(i));
for (u32 l = 1; l < count; ++l) {
writer.WriteEncoded(IsLayerActive(s32(i), s32(l)), 1);
writer.WriteBits(IsLayerActive(s32(i), s32(l)), 1);
}
}
}
@@ -81,40 +81,40 @@ CWorldState::CWorldState(CAssetId id) : x0_mlvlId(id), x4_areaId(0) {
x14_layerState = std::make_shared<CScriptLayerManager>();
}
CWorldState::CWorldState(CBitStreamReader& reader, CAssetId mlvlId, const CWorldSaveGameInfo& saveWorld)
CWorldState::CWorldState(CInputStream& reader, CAssetId mlvlId, const CWorldSaveGameInfo& saveWorld)
: x0_mlvlId(mlvlId) {
x4_areaId = TAreaId(reader.ReadEncoded(32));
x10_desiredAreaAssetId = u32(reader.ReadEncoded(32));
x4_areaId = TAreaId(reader.ReadBits(32));
x10_desiredAreaAssetId = u32(reader.ReadBits(32));
x8_mailbox = std::make_shared<CScriptMailbox>(reader, saveWorld);
xc_mapWorldInfo = std::make_shared<CMapWorldInfo>(reader, saveWorld, mlvlId);
x14_layerState = std::make_shared<CScriptLayerManager>(reader, saveWorld);
}
void CWorldState::PutTo(CBitStreamWriter& writer, const CWorldSaveGameInfo& savw) const {
writer.WriteEncoded(x4_areaId, 32);
writer.WriteEncoded(u32(x10_desiredAreaAssetId.Value()), 32);
void CWorldState::PutTo(COutputStream& writer, const CWorldSaveGameInfo& savw) const {
writer.WriteBits(x4_areaId, 32);
writer.WriteBits(u32(x10_desiredAreaAssetId.Value()), 32);
x8_mailbox->PutTo(writer, savw);
xc_mapWorldInfo->PutTo(writer, savw, x0_mlvlId);
x14_layerState->PutTo(writer);
}
CGameState::GameFileStateInfo CGameState::LoadGameFileState(const u8* data) {
CBitStreamReader stream(data, 4096);
CMemoryInStream stream(data, 4096, CMemoryInStream::EOwnerShip::NotOwned);
GameFileStateInfo ret;
for (u32 i = 0; i < 128; i++) {
stream.ReadEncoded(8);
stream.ReadBits(8);
}
ret.x14_timestamp = stream.ReadEncoded(32);
ret.x14_timestamp = stream.ReadBits(32);
ret.x20_hardMode = stream.ReadEncoded(1) != 0;
stream.ReadEncoded(1);
const CAssetId origMLVL = u32(stream.ReadEncoded(32));
ret.x20_hardMode = stream.ReadBits(1) != 0;
stream.ReadBits(1);
const CAssetId origMLVL = u32(stream.ReadBits(32));
ret.x8_mlvlId = origMLVL;
BitsToDouble conv;
conv.low = stream.ReadEncoded(32);
conv.high = stream.ReadEncoded(32);
conv.low = stream.ReadBits(32);
conv.high = stream.ReadBits(32);
ret.x0_playTime = conv.doub;
CPlayerState playerState(stream);
@@ -148,24 +148,24 @@ CGameState::CGameState() {
}
}
CGameState::CGameState(CBitStreamReader& stream, u32 saveIdx) : x20c_saveFileIdx(saveIdx) {
CGameState::CGameState(CInputStream& stream, u32 saveIdx) : x20c_saveFileIdx(saveIdx) {
x9c_transManager = std::make_shared<CWorldTransManager>();
x228_24_hardMode = false;
x228_25_initPowerupsAtFirstSpawn = true;
for (bool& value : x0_) {
value = stream.ReadEncoded(8) != 0;
value = stream.ReadBits(8) != 0;
}
stream.ReadEncoded(32);
stream.ReadBits(32);
x228_24_hardMode = stream.ReadEncoded(1) != 0;
x228_25_initPowerupsAtFirstSpawn = stream.ReadEncoded(1) != 0;
x84_mlvlId = u32(stream.ReadEncoded(32));
x228_24_hardMode = stream.ReadBits(1) != 0;
x228_25_initPowerupsAtFirstSpawn = stream.ReadBits(1) != 0;
x84_mlvlId = u32(stream.ReadBits(32));
MP1::CMain::EnsureWorldPakReady(x84_mlvlId);
BitsToDouble conv;
conv.low = stream.ReadEncoded(32);
conv.high = stream.ReadEncoded(32);
conv.low = stream.ReadBits(32);
conv.high = stream.ReadBits(32);
xa0_playTime = conv.doub;
x98_playerState = std::make_shared<CPlayerState>(stream);
@@ -185,7 +185,7 @@ CGameState::CGameState(CBitStreamReader& stream, u32 saveIdx) : x20c_saveFileIdx
WriteBackupBuf();
}
void CGameState::ReadPersistentOptions(CBitStreamReader& r) { xa8_systemOptions = CPersistentOptions(r); }
void CGameState::ReadPersistentOptions(CInputStream& r) { xa8_systemOptions = r.Get<CPersistentOptions>(); }
void CGameState::ImportPersistentOptions(const CPersistentOptions& opts) {
if (opts.xd0_24_fusionLinked)
@@ -212,24 +212,24 @@ void CGameState::ExportPersistentOptions(CPersistentOptions& opts) const {
void CGameState::WriteBackupBuf() {
x218_backupBuf.resize(940);
CBitStreamWriter w(x218_backupBuf.data(), 940);
CMemoryStreamOut w(x218_backupBuf.data(), 940);
PutTo(w);
}
void CGameState::PutTo(CBitStreamWriter& writer) {
void CGameState::PutTo(COutputStream& writer) {
for (const bool value : x0_) {
writer.WriteEncoded(u32(value), 8);
writer.WriteBits(u32(value), 8);
}
writer.WriteEncoded(CBasics::GetTime() / CBasics::TICKS_PER_SECOND, 32);
writer.WriteEncoded(x228_24_hardMode, 1);
writer.WriteEncoded(x228_25_initPowerupsAtFirstSpawn, 1);
writer.WriteEncoded(u32(x84_mlvlId.Value()), 32);
writer.WriteBits(CBasics::GetTime() / CBasics::TICKS_PER_SECOND, 32);
writer.WriteBits(x228_24_hardMode, 1);
writer.WriteBits(x228_25_initPowerupsAtFirstSpawn, 1);
writer.WriteBits(u32(x84_mlvlId.Value()), 32);
BitsToDouble conv;
conv.doub = xa0_playTime;
writer.WriteEncoded(conv.low, 32);
writer.WriteEncoded(conv.high, 32);
writer.WriteBits(conv.low, 32);
writer.WriteBits(conv.high, 32);
x98_playerState->PutTo(writer);
x17c_gameOptions.PutTo(writer);