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
|
|
|
|
|
2018-10-05 09:20:30 +00:00
|
|
|
#include <base/system.h>
|
2018-06-05 19:22:40 +00:00
|
|
|
#include <base/hash.h>
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// raw datafile access
|
|
|
|
class CDataFileReader
|
|
|
|
{
|
2011-04-19 09:54:44 +00:00
|
|
|
struct CDatafile *m_pDataFile;
|
2010-05-29 07:25:38 +00:00
|
|
|
void *GetDataImpl(int Index, int Swap);
|
2017-08-30 06:36:17 +00:00
|
|
|
int GetFileDataSize(int Index);
|
2018-10-05 09:20:30 +00:00
|
|
|
|
|
|
|
int GetExternalItemType(int InternalType);
|
|
|
|
int GetInternalItemType(int ExternalType);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
|
|
|
CDataFileReader() : m_pDataFile(0) {}
|
|
|
|
~CDataFileReader() { Close(); }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
bool IsOpen() const { return m_pDataFile != 0; }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
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();
|
2011-03-31 13:13:49 +00:00
|
|
|
|
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);
|
2011-02-12 10:40:36 +00:00
|
|
|
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);
|
2018-10-05 09:20:30 +00:00
|
|
|
int FindItemIndex(int Type, int ID);
|
2011-02-12 10:40:36 +00:00
|
|
|
void *FindItem(int Type, int ID);
|
2010-05-29 07:25:38 +00:00
|
|
|
int NumItems();
|
|
|
|
int NumData();
|
|
|
|
void Unload();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2018-06-05 19:22:40 +00:00
|
|
|
SHA256_DIGEST Sha256();
|
2010-05-29 07:25:38 +00:00
|
|
|
unsigned Crc();
|
2017-07-08 11:38:27 +00:00
|
|
|
int MapSize();
|
2017-07-08 20:09:03 +00:00
|
|
|
IOHANDLE File();
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// write access
|
|
|
|
class CDataFileWriter
|
|
|
|
{
|
|
|
|
struct CDataInfo
|
|
|
|
{
|
|
|
|
int m_UncompressedSize;
|
|
|
|
int m_CompressedSize;
|
|
|
|
void *m_pCompressedData;
|
2010-09-27 20:35:57 +00:00
|
|
|
};
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
struct CItemInfo
|
|
|
|
{
|
|
|
|
int m_Type;
|
2011-02-12 10:40:36 +00:00
|
|
|
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;
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-07-30 23:40:28 +00:00
|
|
|
enum
|
|
|
|
{
|
2018-10-05 09:20:30 +00:00
|
|
|
MAX_ITEM_TYPES=0x10000,
|
2011-07-30 23:40:28 +00:00
|
|
|
MAX_ITEMS=1024,
|
|
|
|
MAX_DATAS=1024,
|
2018-10-05 09:20:30 +00:00
|
|
|
MAX_EXTENDED_ITEM_TYPES=64,
|
2011-07-30 23:40:28 +00:00
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
IOHANDLE m_File;
|
|
|
|
int m_NumItems;
|
|
|
|
int m_NumDatas;
|
|
|
|
int m_NumItemTypes;
|
2018-10-05 09:20:30 +00:00
|
|
|
int m_NumExtendedItemTypes;
|
2011-07-30 23:40:28 +00:00
|
|
|
CItemTypeInfo *m_pItemTypes;
|
|
|
|
CItemInfo *m_pItems;
|
|
|
|
CDataInfo *m_pDatas;
|
2018-10-05 09:20:30 +00:00
|
|
|
int m_aExtendedItemTypes[MAX_EXTENDED_ITEM_TYPES];
|
|
|
|
|
|
|
|
int GetExtendedItemTypeIndex(int Type);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
2011-07-30 23:40:28 +00:00
|
|
|
CDataFileWriter();
|
|
|
|
~CDataFileWriter();
|
2015-08-21 21:02:50 +00:00
|
|
|
void Init();
|
|
|
|
bool OpenFile(class IStorage *pStorage, const char *pFilename);
|
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);
|
2011-02-12 10:40:36 +00:00
|
|
|
int AddItem(int Type, int ID, int Size, void *pData);
|
2010-05-29 07:25:38 +00:00
|
|
|
int Finish();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|