2022-04-06 05:56:03 +00:00
|
|
|
#include "dynos.cpp.h"
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
// Parsing //
|
|
|
|
/////////////
|
|
|
|
|
|
|
|
static TexData* ParseTexListSymbol(GfxData* aGfxData, DataNode<TexData*>* aNode, String& aToken) {
|
|
|
|
// Textures
|
|
|
|
for (auto& _Node : aGfxData->mTextures) {
|
|
|
|
if (aToken == _Node->mName) {
|
|
|
|
return DynOS_Tex_Parse(aGfxData, _Node)->mData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown
|
2023-05-19 11:20:08 +00:00
|
|
|
PrintDataError(" ERROR: Unknown texlist arg: %s", aToken.begin());
|
2022-04-06 05:56:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataNode<TexData*>* DynOS_TexList_Parse(GfxData* aGfxData, DataNode<TexData*>* aNode) {
|
|
|
|
if (aNode->mData) return aNode;
|
|
|
|
|
|
|
|
// TexList data
|
|
|
|
aNode->mSize = (u32) (aNode->mTokens.Count());
|
|
|
|
|
|
|
|
aNode->mData = New<TexData*>(aNode->mSize);
|
|
|
|
for (u32 i = 0; i != aNode->mSize; ++i) {
|
|
|
|
aNode->mData[i] = ParseTexListSymbol(aGfxData, aNode, aNode->mTokens[i]);
|
|
|
|
aGfxData->mPointerList.Add(&aNode->mData[i]);
|
|
|
|
}
|
|
|
|
aNode->mLoadIndex = aGfxData->mLoadIndex++;
|
|
|
|
return aNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
// Writing //
|
|
|
|
/////////////
|
|
|
|
|
2022-06-25 07:52:53 +00:00
|
|
|
void DynOS_TexList_Write(BinFile* aFile, GfxData* aGfxData, DataNode<TexData*> *aNode) {
|
2022-04-06 05:56:03 +00:00
|
|
|
if (!aNode->mData) return;
|
|
|
|
|
|
|
|
// Name
|
2022-06-25 07:52:53 +00:00
|
|
|
aFile->Write<u8>(DATA_TYPE_TEXTURE_LIST);
|
2022-04-06 05:56:03 +00:00
|
|
|
aNode->mName.Write(aFile);
|
|
|
|
|
|
|
|
// Data
|
2022-06-25 07:52:53 +00:00
|
|
|
aFile->Write<u32>(aNode->mSize);
|
2022-04-06 05:56:03 +00:00
|
|
|
for (u32 i = 0; i != aNode->mSize; ++i) {
|
|
|
|
// find node
|
|
|
|
bool found = false;
|
|
|
|
for (auto& _Node : aGfxData->mTextures) {
|
|
|
|
if (_Node->mData == aNode->mData[i]) {
|
|
|
|
DynOS_Pointer_Write(aFile, (const void *) (_Node), aGfxData);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2023-05-19 11:20:08 +00:00
|
|
|
PrintDataError("Could not write texture in texlist");
|
2022-04-06 05:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
// Reading //
|
|
|
|
/////////////
|
|
|
|
|
2022-06-25 07:52:53 +00:00
|
|
|
DataNode<TexData*>* DynOS_TexList_Load(BinFile *aFile, GfxData *aGfxData) {
|
2022-04-06 05:56:03 +00:00
|
|
|
DataNode<TexData*> *_Node = New<DataNode<TexData*>>();
|
|
|
|
|
|
|
|
// Name
|
|
|
|
_Node->mName.Read(aFile);
|
|
|
|
|
|
|
|
// Data
|
2022-06-25 07:52:53 +00:00
|
|
|
_Node->mSize = aFile->Read<u32>();
|
2022-04-06 05:56:03 +00:00
|
|
|
_Node->mData = New<TexData*>(_Node->mSize);
|
|
|
|
for (u32 i = 0; i != _Node->mSize; ++i) {
|
2022-06-25 07:52:53 +00:00
|
|
|
u32 _Value = aFile->Read<u32>();
|
2022-05-04 07:14:33 +00:00
|
|
|
void *_Ptr = DynOS_Pointer_Load(aFile, aGfxData, _Value, &_Node->mFlags);
|
2022-04-06 05:56:03 +00:00
|
|
|
if (_Ptr == NULL) {
|
2023-05-19 11:20:08 +00:00
|
|
|
PrintDataError("Could not read texture in texlist");
|
2022-04-06 05:56:03 +00:00
|
|
|
} else {
|
|
|
|
_Node->mData[i] = ((DataNode<TexData>*)_Ptr)->mData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add it
|
|
|
|
if (aGfxData != NULL) {
|
|
|
|
aGfxData->mTextureLists.Add(_Node);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _Node;
|
|
|
|
}
|