diff --git a/data/dynos_bin_col.cpp b/data/dynos_bin_col.cpp index 42717256..e4537694 100644 --- a/data/dynos_bin_col.cpp +++ b/data/dynos_bin_col.cpp @@ -400,3 +400,70 @@ DataNode* DynOS_Col_Parse(GfxData* aGfxData, DataNode* aNo aNode->mLoadIndex = aGfxData->mLoadIndex++; return aNode; } + + ///////////// + // Writing // +///////////// + +static void WriteCollisionData(FILE* aFile, GfxData* aGfxData, DataNode *aNode) { + if (!aNode->mData) return; + + // Name + WriteBytes(aFile, DATA_TYPE_COLLISION); + aNode->mName.Write(aFile); + + // Data + WriteBytes(aFile, aNode->mSize); + for (u32 i = 0; i != aNode->mSize; ++i) { + WriteBytes(aFile, aNode->mData[i]); + } +} + +bool DynOS_Col_WriteBinary(const SysPath &aOutputFilename, GfxData *aGfxData, DataNode* _Node) { + FILE *_File = fopen(aOutputFilename.c_str(), "wb"); + if (!_File) { + PrintError(" ERROR: Unable to create file \"%s\"", aOutputFilename.c_str()); + return false; + } + + WriteCollisionData(_File, aGfxData, _Node); + + fclose(_File); + return true; +} + + ///////////// + // Loading // +///////////// + +static DataNode* LoadCollisionData(FILE *aFile) { + 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) { + _Node->mData[i] = ReadBytes(aFile); + } + + return _Node; +} + +DataNode* DynOS_Col_LoadFromBinary(const SysPath &aPackFolder, const char *aCollisionName) { + // Load data from binary file + DataNode* collisionNode = NULL; + SysPath _Filename = fstring("%s/%s.col", aPackFolder.begin(), aCollisionName); + FILE *_File = fopen(_Filename.c_str(), "rb"); + if (_File) { + u8 type = ReadBytes(_File); + if (type == DATA_TYPE_COLLISION) { + collisionNode = LoadCollisionData(_File); + } + fclose(_File); + } + + return collisionNode; +} diff --git a/data/dynos_col_load.cpp b/data/dynos_col_load.cpp deleted file mode 100644 index 62b83e2d..00000000 --- a/data/dynos_col_load.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "dynos.cpp.h" - -// -// Load collision from binary -// - -static DataNode* LoadCollisionData(FILE *aFile) { - 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) { - _Node->mData[i] = ReadBytes(aFile); - } - - return _Node; -} - -DataNode* DynOS_Col_LoadFromBinary(const SysPath &aPackFolder, const char *aCollisionName) { - // Load data from binary file - DataNode* collisionNode = NULL; - SysPath _Filename = fstring("%s/%s.col", aPackFolder.begin(), aCollisionName); - FILE *_File = fopen(_Filename.c_str(), "rb"); - if (_File) { - collisionNode = LoadCollisionData(_File); - fclose(_File); - } - - return collisionNode; -} diff --git a/data/dynos_col_write.cpp b/data/dynos_col_write.cpp deleted file mode 100644 index 66041143..00000000 --- a/data/dynos_col_write.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "dynos.cpp.h" - -// -// Collisions -// - -static void WriteCollisionData(FILE* aFile, GfxData* aGfxData, DataNode *aNode) { - if (!aNode->mData) return; - - // Name - aNode->mName.Write(aFile); - - // Data - WriteBytes(aFile, aNode->mSize); - for (u32 i = 0; i != aNode->mSize; ++i) { - WriteBytes(aFile, aNode->mData[i]); - } -} - -bool DynOS_Col_WriteBinary(const SysPath &aOutputFilename, GfxData *aGfxData, DataNode* _Node) { - FILE *_File = fopen(aOutputFilename.c_str(), "wb"); - if (!_File) { - PrintError(" ERROR: Unable to create file \"%s\"", aOutputFilename.c_str()); - return false; - } - - WriteCollisionData(_File, aGfxData, _Node); - - fclose(_File); - return true; -} diff --git a/data/dynos_gfx_write.cpp b/data/dynos_gfx_write.cpp index 07ddc253..1697470a 100644 --- a/data/dynos_gfx_write.cpp +++ b/data/dynos_gfx_write.cpp @@ -313,6 +313,18 @@ void DynOS_Gfx_Free(GfxData* aGfxData) { Delete(_Node->mData); Delete(_Node); } + for (auto& _Node : aGfxData->mCollisions) { + Delete(_Node->mData); + Delete(_Node); + } + for (auto& _Node : aGfxData->mLevelScripts) { + Delete(_Node->mData); + Delete(_Node); + } + for (auto& _Node : aGfxData->mMacroObjects) { + Delete(_Node->mData); + Delete(_Node); + } Delete(aGfxData); } }