#include "dynos.cpp.h" ///////////// // Parsing // ///////////// static TexData* ParseTexListSymbol(GfxData* aGfxData, DataNode* aNode, String& aToken) { // Textures for (auto& _Node : aGfxData->mTextures) { if (aToken == _Node->mName) { return DynOS_Tex_Parse(aGfxData, _Node)->mData; } } // Unknown PrintError(" ERROR: Unknown texlist arg: %s", aToken.begin()); return NULL; } DataNode* DynOS_TexList_Parse(GfxData* aGfxData, DataNode* aNode) { if (aNode->mData) return aNode; // TexList data aNode->mSize = (u32) (aNode->mTokens.Count()); aNode->mData = New(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 // ///////////// void DynOS_TexList_Write(FILE* aFile, GfxData* aGfxData, DataNode *aNode) { if (!aNode->mData) return; // Name WriteBytes(aFile, DATA_TYPE_TEXTURE_LIST); aNode->mName.Write(aFile); // Data WriteBytes(aFile, aNode->mSize); 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) { PrintError("Could not write texture in texlist"); } } } ///////////// // Reading // ///////////// DataNode* DynOS_TexList_Load(FILE *aFile, GfxData *aGfxData) { DataNode *_Node = New>(); // Name _Node->mName.Read(aFile); // Data _Node->mSize = ReadBytes(aFile); _Node->mData = New(_Node->mSize); for (u32 i = 0; i != _Node->mSize; ++i) { u32 _Value = ReadBytes(aFile); void *_Ptr = DynOS_Pointer_Load(aFile, aGfxData, _Value, false); if (_Ptr == NULL) { PrintError("Could not read texture in texlist"); } else { _Node->mData[i] = ((DataNode*)_Ptr)->mData; } } // Add it if (aGfxData != NULL) { aGfxData->mTextureLists.Add(_Node); } return _Node; }