Reorder map and datafile functions

This commit is contained in:
Robert Müller 2023-05-15 18:04:58 +02:00
parent 52e1494347
commit 6b37c3dbf4
5 changed files with 51 additions and 47 deletions

View file

@ -19,6 +19,7 @@ public:
virtual int GetDataSize(int Index) = 0;
virtual void *GetDataSwapped(int Index) = 0;
virtual void UnloadData(int Index) = 0;
virtual void *GetItem(int Index, int *pType = nullptr, int *pID = nullptr) = 0;
virtual int GetItemSize(int Index) = 0;
virtual void GetType(int Type, int *pStart, int *pNum) = 0;
@ -31,12 +32,13 @@ class IEngineMap : public IMap
MACRO_INTERFACE("enginemap", 0)
public:
virtual bool Load(const char *pMapName) = 0;
virtual bool IsLoaded() = 0;
virtual void Unload() = 0;
virtual bool IsLoaded() = 0;
virtual IOHANDLE File() = 0;
virtual SHA256_DIGEST Sha256() = 0;
virtual unsigned Crc() = 0;
virtual int MapSize() = 0;
virtual IOHANDLE File() = 0;
};
extern IEngineMap *CreateEngineMap();

View file

@ -217,6 +217,28 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
return true;
}
bool CDataFileReader::Close()
{
if(!m_pDataFile)
return true;
// free the data that is loaded
for(int i = 0; i < m_pDataFile->m_Header.m_NumRawData; i++)
free(m_pDataFile->m_ppDataPtrs[i]);
io_close(m_pDataFile->m_File);
free(m_pDataFile);
m_pDataFile = nullptr;
return true;
}
IOHANDLE CDataFileReader::File()
{
if(!m_pDataFile)
return 0;
return m_pDataFile->m_File;
}
int CDataFileReader::NumData() const
{
if(!m_pDataFile)
@ -465,22 +487,6 @@ int CDataFileReader::NumItems() const
return m_pDataFile->m_Header.m_NumItems;
}
bool CDataFileReader::Close()
{
if(!m_pDataFile)
return true;
// free the data that is loaded
int i;
for(i = 0; i < m_pDataFile->m_Header.m_NumRawData; i++)
free(m_pDataFile->m_ppDataPtrs[i]);
io_close(m_pDataFile->m_File);
free(m_pDataFile);
m_pDataFile = 0;
return true;
}
SHA256_DIGEST CDataFileReader::Sha256() const
{
if(!m_pDataFile)
@ -509,13 +515,6 @@ int CDataFileReader::MapSize() const
return m_pDataFile->m_Header.m_Size + 16;
}
IOHANDLE CDataFileReader::File()
{
if(!m_pDataFile)
return 0;
return m_pDataFile->m_File;
}
CDataFileWriter::CDataFileWriter()
{
m_File = 0;

View file

@ -30,27 +30,27 @@ public:
m_pDataFile(nullptr) {}
~CDataFileReader() { Close(); }
bool IsOpen() const { return m_pDataFile != nullptr; }
bool Open(class IStorage *pStorage, const char *pFilename, int StorageType);
bool Close();
bool IsOpen() const { return m_pDataFile != nullptr; }
IOHANDLE File();
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);
int NumData() const;
void *GetItem(int Index, int *pType = nullptr, int *pID = nullptr);
int GetItemSize(int Index) const;
void GetType(int Type, int *pStart, int *pNum);
int FindItemIndex(int Type, int ID);
void *FindItem(int Type, int ID);
int NumItems() const;
int NumData() const;
SHA256_DIGEST Sha256() const;
unsigned Crc() const;
int MapSize() const;
IOHANDLE File();
};
// write access
@ -98,8 +98,8 @@ class CDataFileWriter
CDataInfo *m_pDatas;
int m_aExtendedItemTypes[MAX_EXTENDED_ITEM_TYPES];
int GetExtendedItemTypeIndex(int Type);
int GetTypeFromIndex(int Index);
int GetExtendedItemTypeIndex(int Type);
public:
CDataFileWriter();

View file

@ -9,44 +9,47 @@ void *CMap::GetData(int Index)
{
return m_DataFile.GetData(Index);
}
int CMap::GetDataSize(int Index)
{
return m_DataFile.GetDataSize(Index);
}
void *CMap::GetDataSwapped(int Index)
{
return m_DataFile.GetDataSwapped(Index);
}
void CMap::UnloadData(int Index)
{
m_DataFile.UnloadData(Index);
}
void *CMap::GetItem(int Index, int *pType, int *pID)
{
return m_DataFile.GetItem(Index, pType, pID);
}
int CMap::GetItemSize(int Index)
{
return m_DataFile.GetItemSize(Index);
}
void CMap::GetType(int Type, int *pStart, int *pNum)
{
m_DataFile.GetType(Type, pStart, pNum);
}
void *CMap::FindItem(int Type, int ID)
{
return m_DataFile.FindItem(Type, ID);
}
int CMap::NumItems()
{
return m_DataFile.NumItems();
}
void CMap::Unload()
{
m_DataFile.Close();
}
bool CMap::Load(const char *pMapName)
{
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
@ -55,11 +58,21 @@ bool CMap::Load(const char *pMapName)
return m_DataFile.Open(pStorage, pMapName, IStorage::TYPE_ALL);
}
void CMap::Unload()
{
m_DataFile.Close();
}
bool CMap::IsLoaded()
{
return m_DataFile.IsOpen();
}
IOHANDLE CMap::File()
{
return m_DataFile.File();
}
SHA256_DIGEST CMap::Sha256()
{
return m_DataFile.Sha256();
@ -75,9 +88,4 @@ int CMap::MapSize()
return m_DataFile.MapSize();
}
IOHANDLE CMap::File()
{
return m_DataFile.File();
}
extern IEngineMap *CreateEngineMap() { return new CMap; }

View file

@ -25,19 +25,14 @@ public:
void *FindItem(int Type, int ID) override;
int NumItems() override;
void Unload() override;
bool Load(const char *pMapName) override;
void Unload() override;
bool IsLoaded() override;
IOHANDLE File() override;
SHA256_DIGEST Sha256() override;
unsigned Crc() override;
int MapSize() override;
IOHANDLE File() override;
};
#endif