From 11f3b3c5752dce90862175ae3bc0c55feec9ee6d Mon Sep 17 00:00:00 2001 From: janwas Date: Wed, 15 Dec 2004 14:26:21 +0000 Subject: [PATCH] CFilePacker now takes version+magic string in the ctor (allows writing data in one go, so vfs_store can be used). This was SVN commit r1505. --- source/graphics/MapWriter.cpp | 4 ++-- source/graphics/ModelDef.cpp | 5 ++--- source/graphics/SkeletonAnimDef.cpp | 4 ++-- source/ps/FilePacker.h | 18 ++++++++++++------ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index 0daf31a931..bee1d9fde5 100755 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -20,13 +20,13 @@ CMapWriter::CMapWriter() // SaveMap: try to save the current map to the given file void CMapWriter::SaveMap(const char* filename, CTerrain *pTerrain, CLightEnv *pLightEnv, CUnitManager *pUnitMan) { - CFilePacker packer; + CFilePacker packer(FILE_VERSION, "PSMP"); // build necessary data PackMap(packer, pTerrain, pLightEnv, pUnitMan); // write it out - packer.Write(filename,FILE_VERSION,"PSMP"); + packer.Write(filename); } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/graphics/ModelDef.cpp b/source/graphics/ModelDef.cpp index c0176405a9..5e57d78a6f 100755 --- a/source/graphics/ModelDef.cpp +++ b/source/graphics/ModelDef.cpp @@ -104,7 +104,7 @@ CModelDef* CModelDef::Load(const char* filename) // Save: write the given CModelDef to the given file void CModelDef::Save(const char* filename,const CModelDef* mdef) { - CFilePacker packer; + CFilePacker packer(FILE_VERSION, "PSMD"); // pack everything up u32 numVertices=mdef->GetNumVertices(); @@ -128,8 +128,7 @@ void CModelDef::Save(const char* filename,const CModelDef* mdef) packer.PackRaw(&mdef->m_PropPoints[i].m_BoneIndex,sizeof(mdef->m_PropPoints[i].m_BoneIndex)); } - // flush everything out to file - packer.Write(filename,FILE_VERSION,"PSMD"); + packer.Write(filename); } diff --git a/source/graphics/SkeletonAnimDef.cpp b/source/graphics/SkeletonAnimDef.cpp index af06a5b449..f4da92a155 100755 --- a/source/graphics/SkeletonAnimDef.cpp +++ b/source/graphics/SkeletonAnimDef.cpp @@ -88,7 +88,7 @@ CSkeletonAnimDef* CSkeletonAnimDef::Load(const char* filename) // Save: try to save anim to file void CSkeletonAnimDef::Save(const char* filename,const CSkeletonAnimDef* anim) { - CFilePacker packer; + CFilePacker packer(FILE_VERSION, "PSSA"); // pack up all the data packer.PackString(CStr(anim->m_Name)); @@ -98,6 +98,6 @@ void CSkeletonAnimDef::Save(const char* filename,const CSkeletonAnimDef* anim) packer.PackRaw(anim->m_Keys,anim->m_NumKeys*anim->m_NumFrames*sizeof(Key)); // now write it - packer.Write(filename,FILE_VERSION,"PSSA"); + packer.Write(filename); } diff --git a/source/ps/FilePacker.h b/source/ps/FilePacker.h index f8566dfb1f..13fe0ef7b3 100755 --- a/source/ps/FilePacker.h +++ b/source/ps/FilePacker.h @@ -10,11 +10,13 @@ #define _FILEPACKER_H #include -#include "lib/types.h" +#include "lib/types.h" // u32 #include "CStr.h" //////////////////////////////////////////////////////////////////////////////////////// -// CFilePacker: class to assist in writing of binary files +// CFilePacker: class to assist in writing of binary files. +// basically a resizeable buffer that allows adding raw data and strings; +// upon calling Write(), everything is written out to disk. class CFilePacker { public: @@ -25,10 +27,13 @@ public: public: // constructor - CFilePacker(); + // adds version and signature (i.e. the header) to the buffer. + // this means Write() can write the entire buffer to file in one go, + // which is simpler and more efficient than writing in pieces. + CFilePacker(u32 version,const char magicstr[4]); - // Write: write out any packed data to file, using given version and magic bits - void Write(const char* filename,u32 version,const char magicstr[4]); + // Write: write out to file all packed data added so far + void Write(const char* filename); // PackRaw: pack given number of bytes onto the end of the data stream void PackRaw(const void* rawdata,u32 rawdatalen); @@ -36,7 +41,8 @@ public: void PackString(const CStr& str); private: - // the output data stream built during pack operations + // the output data stream built during pack operations. + // contains the header, so we can write this out in one go. std::vector m_Data; };