sm64coopdx/data/dynos_bin_rooms.cpp

65 lines
1.3 KiB
C++
Raw Normal View History

2022-04-04 08:42:25 +02:00
#include "dynos.cpp.h"
extern "C" {
}
/////////////
// Parsing //
/////////////
DataNode<u8>* DynOS_Rooms_Parse(GfxData* aGfxData, DataNode<u8>* aNode) {
if (aNode->mData) return aNode;
// U8 data
aNode->mSize = (u32) (aNode->mTokens.Count());
aNode->mData = New<u8>(aNode->mSize);
for (u32 i = 0; i != aNode->mSize; ++i) {
aNode->mData[i] = (u8) aNode->mTokens[i].ParseInt();
}
aNode->mLoadIndex = aGfxData->mLoadIndex++;
return aNode;
}
/////////////
// Writing //
/////////////
2022-06-25 09:52:53 +02:00
void DynOS_Rooms_Write(BinFile* aFile, GfxData* aGfxData, DataNode<u8> *aNode) {
2022-04-04 08:42:25 +02:00
if (!aNode->mData) return;
// Name
2022-06-25 09:52:53 +02:00
aFile->Write<u8>(DATA_TYPE_ROOMS);
2022-04-04 08:42:25 +02:00
aNode->mName.Write(aFile);
// Data
2022-06-25 09:52:53 +02:00
aFile->Write<u32>(aNode->mSize);
2022-04-04 08:42:25 +02:00
for (u32 i = 0; i != aNode->mSize; ++i) {
2022-06-25 09:52:53 +02:00
aFile->Write<u8>(aNode->mData[i]);
2022-04-04 08:42:25 +02:00
}
}
/////////////
// Reading //
/////////////
2022-06-25 09:52:53 +02:00
DataNode<u8>* DynOS_Rooms_Load(BinFile *aFile, GfxData *aGfxData) {
2022-04-04 08:42:25 +02:00
DataNode<u8> *_Node = New<DataNode<u8>>();
// Name
_Node->mName.Read(aFile);
// Data
2022-06-25 09:52:53 +02:00
_Node->mSize = aFile->Read<u32>();
2022-04-04 08:42:25 +02:00
_Node->mData = New<u8>(_Node->mSize);
for (u32 i = 0; i != _Node->mSize; ++i) {
2022-06-25 09:52:53 +02:00
_Node->mData[i] = aFile->Read<u8>();
2022-04-04 08:42:25 +02:00
}
// Add it
if (aGfxData != NULL) {
aGfxData->mRooms.Add(_Node);
}
return _Node;
}