1
0
forked from 0ad/0ad

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.
This commit is contained in:
janwas 2004-12-15 14:26:21 +00:00
parent 6539cfc935
commit 11f3b3c575
4 changed files with 18 additions and 13 deletions

View File

@ -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);
}
///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -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);
}

View File

@ -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);
}

View File

@ -10,11 +10,13 @@
#define _FILEPACKER_H
#include <vector>
#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<u8> m_Data;
};