mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 14:08:19 +00:00
Remove separate CDataFileWriter::Init/OpenFile
functions
Simplify usage of datafile writer by removing duplicate functions for opening file.
This commit is contained in:
parent
03400f6ff3
commit
f7722eb016
|
@ -596,9 +596,24 @@ int CDataFileReader::MapSize() const
|
|||
CDataFileWriter::CDataFileWriter()
|
||||
{
|
||||
m_File = 0;
|
||||
|
||||
m_pItemTypes = static_cast<CItemTypeInfo *>(calloc(MAX_ITEM_TYPES, sizeof(CItemTypeInfo)));
|
||||
m_NumItemTypes = 0;
|
||||
mem_zero(m_pItemTypes, sizeof(CItemTypeInfo) * MAX_ITEM_TYPES);
|
||||
for(int i = 0; i < MAX_ITEM_TYPES; i++)
|
||||
{
|
||||
m_pItemTypes[i].m_First = -1;
|
||||
m_pItemTypes[i].m_Last = -1;
|
||||
}
|
||||
|
||||
m_pItems = static_cast<CItemInfo *>(calloc(MAX_ITEMS, sizeof(CItemInfo)));
|
||||
m_NumItems = 0;
|
||||
|
||||
m_pDatas = static_cast<CDataInfo *>(calloc(MAX_DATAS, sizeof(CDataInfo)));
|
||||
m_NumDatas = 0;
|
||||
|
||||
mem_zero(m_aExtendedItemTypes, sizeof(m_aExtendedItemTypes));
|
||||
m_NumExtendedItemTypes = 0;
|
||||
}
|
||||
|
||||
CDataFileWriter::~CDataFileWriter()
|
||||
|
@ -634,34 +649,11 @@ CDataFileWriter::~CDataFileWriter()
|
|||
}
|
||||
}
|
||||
|
||||
bool CDataFileWriter::OpenFile(class IStorage *pStorage, const char *pFilename, int StorageType)
|
||||
{
|
||||
dbg_assert(!m_File, "a file already exists");
|
||||
m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE, StorageType);
|
||||
return m_File != 0;
|
||||
}
|
||||
|
||||
void CDataFileWriter::Init()
|
||||
{
|
||||
dbg_assert(!m_File, "a file already exists");
|
||||
m_NumItems = 0;
|
||||
m_NumDatas = 0;
|
||||
m_NumItemTypes = 0;
|
||||
m_NumExtendedItemTypes = 0;
|
||||
mem_zero(m_pItemTypes, sizeof(CItemTypeInfo) * MAX_ITEM_TYPES);
|
||||
mem_zero(m_aExtendedItemTypes, sizeof(m_aExtendedItemTypes));
|
||||
|
||||
for(int i = 0; i < MAX_ITEM_TYPES; i++)
|
||||
{
|
||||
m_pItemTypes[i].m_First = -1;
|
||||
m_pItemTypes[i].m_Last = -1;
|
||||
}
|
||||
}
|
||||
|
||||
bool CDataFileWriter::Open(class IStorage *pStorage, const char *pFilename, int StorageType)
|
||||
{
|
||||
Init();
|
||||
return OpenFile(pStorage, pFilename, StorageType);
|
||||
dbg_assert(!m_File, "File already open");
|
||||
m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE, StorageType);
|
||||
return m_File != 0;
|
||||
}
|
||||
|
||||
int CDataFileWriter::GetTypeFromIndex(int Index) const
|
||||
|
|
|
@ -132,13 +132,11 @@ public:
|
|||
}
|
||||
~CDataFileWriter();
|
||||
|
||||
void Init();
|
||||
bool OpenFile(class IStorage *pStorage, const char *pFilename, int StorageType = IStorage::TYPE_SAVE);
|
||||
bool Open(class IStorage *pStorage, const char *pFilename, int StorageType = IStorage::TYPE_SAVE);
|
||||
int AddItem(int Type, int ID, int Size, const void *pData);
|
||||
int AddData(int Size, const void *pData, int CompressionLevel = Z_DEFAULT_COMPRESSION);
|
||||
int AddDataSwapped(int Size, const void *pData);
|
||||
int AddDataString(const char *pStr);
|
||||
int AddItem(int Type, int ID, int Size, const void *pData);
|
||||
void Finish();
|
||||
};
|
||||
|
||||
|
|
|
@ -3866,7 +3866,6 @@ void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
|
|||
Reader.Open(Storage(), pNewMapName, IStorage::TYPE_ALL);
|
||||
|
||||
CDataFileWriter Writer;
|
||||
Writer.Init();
|
||||
|
||||
int SettingsIndex = Reader.NumData();
|
||||
bool FoundInfo = false;
|
||||
|
@ -3944,7 +3943,7 @@ void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
|
|||
free(pSettings);
|
||||
Reader.Close();
|
||||
char aTemp[IO_MAX_PATH_LENGTH];
|
||||
Writer.OpenFile(Storage(), IStorage::FormatTmpPath(aTemp, sizeof(aTemp), pNewMapName));
|
||||
Writer.Open(Storage(), IStorage::FormatTmpPath(aTemp, sizeof(aTemp), pNewMapName));
|
||||
Writer.Finish();
|
||||
|
||||
str_copy(pNewMapName, aTemp, MapNameSize);
|
||||
|
|
|
@ -45,7 +45,6 @@ void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
|
|||
Reader.Open(pStorage, pMapName, IStorage::TYPE_ABSOLUTE);
|
||||
|
||||
CDataFileWriter Writer;
|
||||
Writer.Init();
|
||||
|
||||
int SettingsIndex = Reader.NumData();
|
||||
bool FoundInfo = false;
|
||||
|
@ -123,7 +122,7 @@ void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
|
|||
|
||||
free(pSettings);
|
||||
Reader.Close();
|
||||
if(!Writer.OpenFile(pStorage, pMapName))
|
||||
if(!Writer.Open(pStorage, pMapName))
|
||||
{
|
||||
dbg_msg("config_store", "couldn't open map file '%s' for writing", pMapName);
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue