about summary refs log tree commit diff
path: root/src/engine/shared/datafile.h
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2010-05-29 07:25:38 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2010-05-29 07:25:38 +0000
commit72c06a258940696093f255fb1061beb58e1cdd0b (patch)
tree36b9a7712eec2d4f07837eab9c38ef1c5af85319 /src/engine/shared/datafile.h
parente56feb597bc743677633432f77513b02907fd169 (diff)
downloadzcatch-72c06a258940696093f255fb1061beb58e1cdd0b.tar.gz
zcatch-72c06a258940696093f255fb1061beb58e1cdd0b.zip
copied refactor to trunk
Diffstat (limited to 'src/engine/shared/datafile.h')
-rw-r--r--src/engine/shared/datafile.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/engine/shared/datafile.h b/src/engine/shared/datafile.h
new file mode 100644
index 00000000..eddce611
--- /dev/null
+++ b/src/engine/shared/datafile.h
@@ -0,0 +1,77 @@
+#ifndef ENGINE_SHARED_DATAFILE_H
+#define ENGINE_SHARED_DATAFILE_H
+
+// raw datafile access
+class CDataFileReader
+{
+	class CDatafile *m_pDataFile;
+	void *GetDataImpl(int Index, int Swap);
+public:
+	CDataFileReader() : m_pDataFile(0) {}
+	~CDataFileReader() { Close(); }
+	
+	bool IsOpen() const { return m_pDataFile != 0; }
+	
+	bool Open(class IStorage *pStorage, const char *pFilename);
+	bool Close();
+	
+	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);
+	int GetItemSize(int Index);
+	void GetType(int Type, int *pStart, int *pNum);
+	void *FindItem(int Type, int Id);
+	int NumItems();
+	int NumData();
+	void Unload();
+	
+	unsigned Crc();
+};
+
+// write access
+class CDataFileWriter
+{
+	struct CDataInfo
+	{
+		int m_UncompressedSize;
+		int m_CompressedSize;
+		void *m_pCompressedData;
+	} ;
+
+	struct CItemInfo
+	{
+		int m_Type;
+		int m_Id;
+		int m_Size;
+		int m_Next;
+		int m_Prev;
+		void *m_pData;
+	};
+
+	struct CItemTypeInfo
+	{
+		int m_Num;
+		int m_First;
+		int m_Last;
+	};
+	
+	IOHANDLE m_File;
+	int m_NumItems;
+	int m_NumDatas;
+	int m_NumItemTypes;
+	CItemTypeInfo m_aItemTypes[0xffff];
+	CItemInfo m_aItems[1024];
+	CDataInfo m_aDatas[1024];	
+	
+public:
+	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);
+	int Finish();
+};
+
+
+#endif