metaforce/Runtime/RetroTypes.cpp

49 lines
1.5 KiB
C++
Raw Permalink Normal View History

#include "Runtime/RetroTypes.hpp"
#include "Runtime/Streams/IOStreams.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/IMain.hpp"
#include <logvisor/logvisor.hpp>
2017-08-12 22:26:14 -07:00
2021-04-10 01:42:06 -07:00
namespace metaforce {
logvisor::Module Log("metaforce::RetroTypes::CAssetId");
2017-08-12 22:26:14 -07:00
SObjectTag::SObjectTag(CInputStream& in) {
in.ReadBytes(reinterpret_cast<u8*>(&type), 4);
id = in.Get<CAssetId>();
}
void SObjectTag::ReadMLVL(CInputStream& in) {
id = in.Get<CAssetId>();
in.ReadBytes(reinterpret_cast<u8*>(&type), 4);
}
2018-12-07 21:30:43 -08:00
CAssetId::CAssetId(CInputStream& in) {
if (g_Main != nullptr) {
if (g_Main->GetExpectedIdSize() == sizeof(u32)) {
Assign(u32(in.ReadLong()));
} else if (g_Main->GetExpectedIdSize() == sizeof(u64)) {
Assign(in.ReadLongLong());
} else {
2020-04-11 15:51:39 -07:00
Log.report(logvisor::Fatal, FMT_STRING("Unsupported id length {}"), g_Main->GetExpectedIdSize());
}
} else {
2020-04-11 15:51:39 -07:00
Log.report(logvisor::Fatal, FMT_STRING("Input constructor called before runtime Main entered!"));
}
2017-08-12 22:26:14 -07:00
}
void CAssetId::PutTo(COutputStream& out) const {
if (g_Main != nullptr) {
if (g_Main->GetExpectedIdSize() == sizeof(u32)) {
out.Put(u32(id));
} else if (g_Main->GetExpectedIdSize() == sizeof(u64)) {
out.Put(id);
} else {
2020-04-11 15:51:39 -07:00
Log.report(logvisor::Fatal, FMT_STRING("Unsupported id length {}"), g_Main->GetExpectedIdSize());
}
} else {
2020-04-11 15:51:39 -07:00
Log.report(logvisor::Fatal, FMT_STRING("PutTo called before runtime Main entered!"));
}
2017-08-12 22:26:14 -07:00
}
2021-04-10 01:42:06 -07:00
} // namespace metaforce