sm64coopdx/data/dynos_bin_movtexqc.cpp

98 lines
2.6 KiB
C++
Raw Normal View History

#include "dynos.cpp.h"
extern "C" {
#include "include/level_misc_macros.h"
#include "src/game/moving_texture.h"
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnarrowing"
/////////////
// Parsing //
/////////////
2022-04-12 05:56:44 +00:00
#define movtexqc_constant(x) if (_Arg == #x) { return (Movtex*) (x); }
static Movtex* ParseMovtexQCSymbolArg(GfxData* aGfxData, DataNode<MovtexQC>* aNode, u64 aTokenIndex) {
const String& _Arg = aNode->mTokens[aTokenIndex];
2022-04-12 05:54:36 +00:00
// Other constants
2022-04-12 05:56:44 +00:00
movtexqc_constant(NULL);
2022-04-12 05:54:36 +00:00
// Movtexs
for (auto& _Node : aGfxData->mMovtexs) {
if (_Arg == _Node->mName) {
return DynOS_Movtex_Parse(aGfxData, _Node, false)->mData;
}
}
// Unknown
PrintError(" ERROR: Unknown movtexqc arg: %s", _Arg.begin());
return NULL;
}
DataNode<MovtexQC>* DynOS_MovtexQC_Parse(GfxData* aGfxData, DataNode<MovtexQC>* aNode) {
if (aNode->mData) return aNode;
// MovtexQC data
aNode->mSize = (u32) (aNode->mTokens.Count() / 2);
aNode->mData = New<MovtexQC>(aNode->mSize);
for (u32 i = 0; i != aNode->mSize; ++i) {
s16 id = (s16) aNode->mTokens[2 * i + 0].ParseInt();
Movtex* quadArraySegmented = ParseMovtexQCSymbolArg(aGfxData, aNode, 2 * i + 1);
aNode->mData[i] = { id, quadArraySegmented };
aGfxData->mPointerList.Add(aNode->mData[i].quadArraySegmented);
}
aNode->mLoadIndex = aGfxData->mLoadIndex++;
return aNode;
}
#pragma GCC diagnostic pop
/////////////
// Writing //
/////////////
2022-06-25 07:52:53 +00:00
void DynOS_MovtexQC_Write(BinFile* aFile, GfxData* aGfxData, DataNode<MovtexQC> *aNode) {
if (!aNode->mData) return;
// Name
2022-06-25 07:52:53 +00:00
aFile->Write<u8>(DATA_TYPE_MOVTEXQC);
aNode->mName.Write(aFile);
// Data
2022-06-25 07:52:53 +00:00
aFile->Write<u32>(aNode->mSize);
for (u32 i = 0; i != aNode->mSize; ++i) {
2022-06-25 07:52:53 +00:00
aFile->Write<s16>(aNode->mData[i].id);
DynOS_Pointer_Write(aFile, (const void *) (aNode->mData[i].quadArraySegmented), aGfxData);
}
}
/////////////
// Reading //
/////////////
2022-06-25 07:52:53 +00:00
DataNode<MovtexQC>* DynOS_MovtexQC_Load(BinFile *aFile, GfxData *aGfxData) {
DataNode<MovtexQC> *_Node = New<DataNode<MovtexQC>>();
// Name
_Node->mName.Read(aFile);
// Data
2022-06-25 07:52:53 +00:00
_Node->mSize = aFile->Read<u32>();
_Node->mData = New<MovtexQC>(_Node->mSize);
for (u32 i = 0; i != _Node->mSize; ++i) {
2022-06-25 07:52:53 +00:00
_Node->mData[i].id = aFile->Read<s16>();
u32 _Value = aFile->Read<u32>();
void *_Ptr = DynOS_Pointer_Load(aFile, aGfxData, _Value, &_Node->mFlags);
_Node->mData[i].quadArraySegmented = (Movtex*)_Ptr;
}
// Add it
if (aGfxData != NULL) {
aGfxData->mMovtexQCs.Add(_Node);
}
return _Node;
}