mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-04 21:33:51 +00:00
(svn r18771) -Codechange: minor cleanups in saveload code
This commit is contained in:
parent
f5053cee7e
commit
188c8ebd5c
@ -1613,23 +1613,23 @@ static const SaveLoadFormat _saveload_formats[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the savegameformat of the game. Whether it was create with ZLIB compression
|
* Return the savegameformat of the game. Whether it was created with ZLIB compression
|
||||||
* uncompressed, or another type
|
* uncompressed, or another type
|
||||||
* @param s Name of the savegame format. If NULL it picks the first available one
|
* @param s Name of the savegame format. If NULL it picks the first available one
|
||||||
* @return Pointer to SaveLoadFormat struct giving all characteristics of this type of savegame
|
* @return Pointer to SaveLoadFormat struct giving all characteristics of this type of savegame
|
||||||
*/
|
*/
|
||||||
static const SaveLoadFormat *GetSavegameFormat(const char *s)
|
static const SaveLoadFormat *GetSavegameFormat(const char *s)
|
||||||
{
|
{
|
||||||
const SaveLoadFormat *def = endof(_saveload_formats) - 1;
|
const SaveLoadFormat *def = lastof(_saveload_formats);
|
||||||
|
|
||||||
/* find default savegame format, the highest one with which files can be written */
|
/* find default savegame format, the highest one with which files can be written */
|
||||||
while (!def->init_write) def--;
|
while (!def->init_write) def--;
|
||||||
|
|
||||||
if (s != NULL && s[0] != '\0') {
|
if (!StrEmpty(s)) {
|
||||||
const SaveLoadFormat *slf;
|
for (const SaveLoadFormat *slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) {
|
||||||
for (slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) {
|
if (slf->init_write != NULL && strcmp(s, slf->name) == 0) {
|
||||||
if (slf->init_write != NULL && strcmp(s, slf->name) == 0)
|
|
||||||
return slf;
|
return slf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowInfoF("Savegame format '%s' is not available. Reverting to '%s'.", s, def->name);
|
ShowInfoF("Savegame format '%s' is not available. Reverting to '%s'.", s, def->name);
|
||||||
@ -1705,16 +1705,12 @@ static void SaveFileError()
|
|||||||
*/
|
*/
|
||||||
static SaveOrLoadResult SaveFileToDisk(bool threaded)
|
static SaveOrLoadResult SaveFileToDisk(bool threaded)
|
||||||
{
|
{
|
||||||
const SaveLoadFormat *fmt;
|
|
||||||
uint32 hdr[2];
|
|
||||||
|
|
||||||
_sl.excpt_uninit = NULL;
|
_sl.excpt_uninit = NULL;
|
||||||
try {
|
try {
|
||||||
fmt = GetSavegameFormat(_savegame_format);
|
const SaveLoadFormat *fmt = GetSavegameFormat(_savegame_format);
|
||||||
|
|
||||||
/* We have written our stuff to memory, now write it to file! */
|
/* We have written our stuff to memory, now write it to file! */
|
||||||
hdr[0] = fmt->tag;
|
uint32 hdr[2] = { fmt->tag, TO_BE32(SAVEGAME_VERSION << 16) };
|
||||||
hdr[1] = TO_BE32(SAVEGAME_VERSION << 16);
|
|
||||||
if (fwrite(hdr, sizeof(hdr), 1, _sl.fh) != 1) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
|
if (fwrite(hdr, sizeof(hdr), 1, _sl.fh) != 1) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
|
||||||
|
|
||||||
if (!fmt->init_write()) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor");
|
if (!fmt->init_write()) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor");
|
||||||
|
Loading…
Reference in New Issue
Block a user