ddnet/src/engine/shared/datafile.h

83 lines
1.8 KiB
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#ifndef ENGINE_SHARED_DATAFILE_H
#define ENGINE_SHARED_DATAFILE_H
// raw datafile access
class CDataFileReader
{
struct CDatafile *m_pDataFile;
2010-05-29 07:25:38 +00:00
void *GetDataImpl(int Index, int Swap);
public:
CDataFileReader() : m_pDataFile(0) {}
~CDataFileReader() { Close(); }
2010-05-29 07:25:38 +00:00
bool IsOpen() const { return m_pDataFile != 0; }
2010-10-06 21:07:35 +00:00
bool Open(class IStorage *pStorage, const char *pFilename, int StorageType);
2010-05-29 07:25:38 +00:00
bool Close();
static bool GetCrcSize(class IStorage *pStorage, const char *pFilename, int StorageType, unsigned *pCrc, unsigned *pSize);
2010-05-29 07:25:38 +00:00
void *GetData(int Index);
void *GetDataSwapped(int Index); // makes sure that the data is 32bit LE ints when saved
int GetDataSize(int Index);
void UnloadData(int Index);
void *GetItem(int Index, int *pType, int *pID);
2010-05-29 07:25:38 +00:00
int GetItemSize(int Index);
void GetType(int Type, int *pStart, int *pNum);
void *FindItem(int Type, int ID);
2010-05-29 07:25:38 +00:00
int NumItems();
int NumData();
void Unload();
2010-05-29 07:25:38 +00:00
unsigned Crc();
};
// write access
class CDataFileWriter
{
struct CDataInfo
{
int m_UncompressedSize;
int m_CompressedSize;
void *m_pCompressedData;
};
2010-05-29 07:25:38 +00:00
struct CItemInfo
{
int m_Type;
int m_ID;
2010-05-29 07:25:38 +00:00
int m_Size;
int m_Next;
int m_Prev;
void *m_pData;
};
struct CItemTypeInfo
{
int m_Num;
int m_First;
int m_Last;
};
2010-05-29 07:25:38 +00:00
IOHANDLE m_File;
int m_NumItems;
int m_NumDatas;
int m_NumItemTypes;
CItemTypeInfo m_aItemTypes[0xffff];
CItemInfo m_aItems[1024];
CDataInfo m_aDatas[1024];
2010-05-29 07:25:38 +00:00
public:
CDataFileWriter() : m_File(0) {}
2010-05-29 07:25:38 +00:00
bool Open(class IStorage *pStorage, const char *Filename);
int AddData(int Size, void *pData);
int AddDataSwapped(int Size, void *pData);
int AddItem(int Type, int ID, int Size, void *pData);
2010-05-29 07:25:38 +00:00
int Finish();
};
#endif