sm64coopdx/data/dynos_bin_rooms.cpp

65 lines
1.4 KiB
C++
Raw Normal View History

2022-04-04 06:42:25 +00: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 //
/////////////
void DynOS_Rooms_Write(FILE* aFile, GfxData* aGfxData, DataNode<u8> *aNode) {
if (!aNode->mData) return;
// Name
WriteBytes<u8>(aFile, DATA_TYPE_ROOMS);
aNode->mName.Write(aFile);
// Data
WriteBytes<u32>(aFile, aNode->mSize);
for (u32 i = 0; i != aNode->mSize; ++i) {
WriteBytes<u8>(aFile, aNode->mData[i]);
}
}
/////////////
// Reading //
/////////////
DataNode<u8>* DynOS_Rooms_Load(FILE *aFile, GfxData *aGfxData) {
DataNode<u8> *_Node = New<DataNode<u8>>();
// Name
_Node->mName.Read(aFile);
// Data
_Node->mSize = ReadBytes<u32>(aFile);
_Node->mData = New<u8>(_Node->mSize);
for (u32 i = 0; i != _Node->mSize; ++i) {
_Node->mData[i] = ReadBytes<u8>(aFile);
}
// Add it
if (aGfxData != NULL) {
aGfxData->mRooms.Add(_Node);
}
return _Node;
}