mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 11:10:47 +00:00
Mapster32/Lunatic: ask when a <V10 map would be overwritten with a map-text one.
Also, clean up the saving/loading logic a bit: - On load failure, display message with purple color. - Take over the current file name ('boardfilename') only on success. - Check SaveBoard() return values in various places. git-svn-id: https://svn.eduke32.com/eduke32@3911 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
5ea2eee072
commit
b2c5e2d807
4 changed files with 70 additions and 28 deletions
|
@ -220,6 +220,7 @@ int32_t _getnumber16(const char *namestart, int32_t num, int32_t maxnumber, char
|
||||||
#define getnumber16(namestart, num, maxnumber, sign) _getnumber16(namestart, num, maxnumber, sign, NULL)
|
#define getnumber16(namestart, num, maxnumber, sign) _getnumber16(namestart, num, maxnumber, sign, NULL)
|
||||||
void printmessage256(int32_t x, int32_t y, const char *name);
|
void printmessage256(int32_t x, int32_t y, const char *name);
|
||||||
void message(const char *fmt, ...) ATTRIBUTE((format(printf,1,2)));
|
void message(const char *fmt, ...) ATTRIBUTE((format(printf,1,2)));
|
||||||
|
extern int32_t AskIfSure(const char *text);
|
||||||
|
|
||||||
const char* getstring_simple(const char *querystr, const char *defaultstr, int32_t maxlen, int32_t completion);
|
const char* getstring_simple(const char *querystr, const char *defaultstr, int32_t maxlen, int32_t completion);
|
||||||
|
|
||||||
|
@ -317,6 +318,13 @@ extern int32_t scripthistend;
|
||||||
#define AIMING_AT_WALL_OR_MASK (AIMING_AT_WALL || AIMING_AT_MASKWALL)
|
#define AIMING_AT_WALL_OR_MASK (AIMING_AT_WALL || AIMING_AT_MASKWALL)
|
||||||
#define AIMING_AT_CEILING_OR_FLOOR (AIMING_AT_CEILING || AIMING_AT_FLOOR)
|
#define AIMING_AT_CEILING_OR_FLOOR (AIMING_AT_CEILING || AIMING_AT_FLOOR)
|
||||||
|
|
||||||
|
// SaveBoard flags.
|
||||||
|
enum SaveBoardFlags
|
||||||
|
{
|
||||||
|
M32_SB_NOEXT = 1, // no ExtSaveMap (backup.map) and no taglabels saving
|
||||||
|
M32_SB_ASKOV = 2, // for NEW_MAP_FORMAT build, ask whether write map if going from V7/8 to VX
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef EXTERNC
|
#ifdef EXTERNC
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -100,6 +100,7 @@ int32_t zoom = 768, gettilezoom = 1;
|
||||||
int32_t lastpm16time = 0;
|
int32_t lastpm16time = 0;
|
||||||
|
|
||||||
extern int32_t mapversion;
|
extern int32_t mapversion;
|
||||||
|
extern int32_t g_loadedMapVersion;
|
||||||
|
|
||||||
int16_t highlight[MAXWALLS+MAXSPRITES];
|
int16_t highlight[MAXWALLS+MAXSPRITES];
|
||||||
int16_t highlightsector[MAXSECTORS], highlightsectorcnt = -1;
|
int16_t highlightsector[MAXSECTORS], highlightsectorcnt = -1;
|
||||||
|
@ -187,6 +188,7 @@ char lastpm16buf[156];
|
||||||
|
|
||||||
//static int32_t checksectorpointer_warn = 0;
|
//static int32_t checksectorpointer_warn = 0;
|
||||||
static int32_t saveboard_savedtags, saveboard_fixedsprites;
|
static int32_t saveboard_savedtags, saveboard_fixedsprites;
|
||||||
|
static int32_t saveboard_canceled;
|
||||||
|
|
||||||
static int32_t backup_highlighted_map(mapinfofull_t *mapinfo);
|
static int32_t backup_highlighted_map(mapinfofull_t *mapinfo);
|
||||||
static int32_t restore_highlighted_map(mapinfofull_t *mapinfo, int32_t forreal);
|
static int32_t restore_highlighted_map(mapinfofull_t *mapinfo, int32_t forreal);
|
||||||
|
@ -431,6 +433,7 @@ static void reset_default_mapstate(void)
|
||||||
#ifdef YAX_ENABLE
|
#ifdef YAX_ENABLE
|
||||||
yax_resetbunchnums();
|
yax_resetbunchnums();
|
||||||
#endif
|
#endif
|
||||||
|
g_loadedMapVersion = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void m32_keypresscallback(int32_t code, int32_t downp)
|
static void m32_keypresscallback(int32_t code, int32_t downp)
|
||||||
|
@ -804,7 +807,7 @@ CANCEL:
|
||||||
{
|
{
|
||||||
keystatus[0x15] = keystatus[0x1c] = 0;
|
keystatus[0x15] = keystatus[0x1c] = 0;
|
||||||
|
|
||||||
SaveBoard(NULL, 0);
|
SaveBoard(NULL, M32_SB_ASKOV);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -7693,7 +7696,7 @@ CANCEL:
|
||||||
ret = LoadBoard(NULL, 4);
|
ret = LoadBoard(NULL, 4);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
message("Invalid map format, nothing loaded (code %d).", ret);
|
message("^13Invalid map format, nothing loaded (code %d).", ret);
|
||||||
if (bakstat==0)
|
if (bakstat==0)
|
||||||
mapinfofull_free(&bakmap);
|
mapinfofull_free(&bakmap);
|
||||||
}
|
}
|
||||||
|
@ -7838,7 +7841,7 @@ CANCEL:
|
||||||
int32_t corrupt = CheckMapCorruption(4, 0);
|
int32_t corrupt = CheckMapCorruption(4, 0);
|
||||||
|
|
||||||
if (ask_if_sure(corrupt<4?"Save changes?":"Map corrupt. Save changes?", 2+(corrupt>=4)))
|
if (ask_if_sure(corrupt<4?"Save changes?":"Map corrupt. Save changes?", 2+(corrupt>=4)))
|
||||||
SaveBoard(NULL, 0);
|
SaveBoard(NULL, M32_SB_ASKOV);
|
||||||
|
|
||||||
while (keystatus[1] || keystatus[0x2e])
|
while (keystatus[1] || keystatus[0x2e])
|
||||||
{
|
{
|
||||||
|
@ -7992,7 +7995,7 @@ static void SaveBoardAndPrintMessage(const char *fn)
|
||||||
_printmessage16("Saving board...");
|
_printmessage16("Saving board...");
|
||||||
showframe(1);
|
showframe(1);
|
||||||
|
|
||||||
f = SaveBoard(fn, 0);
|
f = SaveBoard(fn, M32_SB_ASKOV);
|
||||||
|
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
|
@ -8003,6 +8006,8 @@ static void SaveBoardAndPrintMessage(const char *fn)
|
||||||
message("Saved board %sto %s.", saveboard_savedtags?"and tags ":"", f);
|
message("Saved board %sto %s.", saveboard_savedtags?"and tags ":"", f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (!saveboard_canceled)
|
||||||
{
|
{
|
||||||
if (saveboard_fixedsprites)
|
if (saveboard_fixedsprites)
|
||||||
message("^13SAVING BOARD FAILED (changed sectnums of %d sprites).",
|
message("^13SAVING BOARD FAILED (changed sectnums of %d sprites).",
|
||||||
|
@ -8011,6 +8016,7 @@ static void SaveBoardAndPrintMessage(const char *fn)
|
||||||
message("^13SAVING BOARD FAILED.");
|
message("^13SAVING BOARD FAILED.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get the file name of the file that would be written if SaveBoard(fn, 0) was called
|
// get the file name of the file that would be written if SaveBoard(fn, 0) was called
|
||||||
const char *GetSaveBoardFilename(const char *fn)
|
const char *GetSaveBoardFilename(const char *fn)
|
||||||
|
@ -8026,17 +8032,36 @@ const char *GetSaveBoardFilename(const char *fn)
|
||||||
return getbasefn(fn);
|
return getbasefn(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// flags: 1:no ExtSaveMap (backup.map) and no taglabels saving
|
// flags: see enum SaveBoardFlags.
|
||||||
|
// returns: NULL on failure, file name on success.
|
||||||
const char *SaveBoard(const char *fn, uint32_t flags)
|
const char *SaveBoard(const char *fn, uint32_t flags)
|
||||||
{
|
{
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
const char *f = GetSaveBoardFilename(fn);
|
const char *f = GetSaveBoardFilename(fn);
|
||||||
|
|
||||||
saveboard_savedtags = 0;
|
saveboard_canceled = 0;
|
||||||
|
#ifdef NEW_MAP_FORMAT
|
||||||
|
if ((flags&M32_SB_ASKOV) && mapversion>=10 &&
|
||||||
|
g_loadedMapVersion != -1 && g_loadedMapVersion < mapversion)
|
||||||
|
{
|
||||||
|
char question[128];
|
||||||
|
Bsnprintf(question, sizeof(question), "Are you sure to overwrite a version "
|
||||||
|
"V%d map with a V%d map-text one?", g_loadedMapVersion, mapversion);
|
||||||
|
|
||||||
|
if (AskIfSure(question))
|
||||||
|
{
|
||||||
|
message("Cancelled saving board");
|
||||||
|
saveboard_canceled = 1;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
saveboard_savedtags = 0;
|
||||||
saveboard_fixedsprites = ExtPreSaveMap();
|
saveboard_fixedsprites = ExtPreSaveMap();
|
||||||
|
|
||||||
ret = saveboard(f, &startpos, startang, startsectnum);
|
ret = saveboard(f, &startpos, startang, startsectnum);
|
||||||
if ((flags&1)==0)
|
if ((flags&M32_SB_NOEXT)==0)
|
||||||
{
|
{
|
||||||
ExtSaveMap(f);
|
ExtSaveMap(f);
|
||||||
saveboard_savedtags = !taglab_save(f);
|
saveboard_savedtags = !taglab_save(f);
|
||||||
|
@ -8047,6 +8072,9 @@ const char *SaveBoard(const char *fn, uint32_t flags)
|
||||||
|
|
||||||
// flags: 1: for running on Mapster32 init
|
// flags: 1: for running on Mapster32 init
|
||||||
// 4: passed to loadboard flags (no polymer_loadboard); implies no maphack loading
|
// 4: passed to loadboard flags (no polymer_loadboard); implies no maphack loading
|
||||||
|
// returns:
|
||||||
|
// 0 on success,
|
||||||
|
// <0 on failure.
|
||||||
int32_t LoadBoard(const char *filename, uint32_t flags)
|
int32_t LoadBoard(const char *filename, uint32_t flags)
|
||||||
{
|
{
|
||||||
int32_t i, tagstat;
|
int32_t i, tagstat;
|
||||||
|
@ -8055,9 +8083,6 @@ int32_t LoadBoard(const char *filename, uint32_t flags)
|
||||||
if (!filename)
|
if (!filename)
|
||||||
filename = selectedboardfilename;
|
filename = selectedboardfilename;
|
||||||
|
|
||||||
if (filename != boardfilename)
|
|
||||||
Bstrcpy(boardfilename, filename);
|
|
||||||
|
|
||||||
editorzrange[0] = INT32_MIN;
|
editorzrange[0] = INT32_MIN;
|
||||||
editorzrange[1] = INT32_MAX;
|
editorzrange[1] = INT32_MAX;
|
||||||
|
|
||||||
|
@ -8072,6 +8097,10 @@ int32_t LoadBoard(const char *filename, uint32_t flags)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Success, so copy the file name.
|
||||||
|
if (filename != boardfilename)
|
||||||
|
Bstrcpy(boardfilename, filename);
|
||||||
|
|
||||||
mkonwinvalid();
|
mkonwinvalid();
|
||||||
|
|
||||||
highlightcnt = -1;
|
highlightcnt = -1;
|
||||||
|
@ -8099,7 +8128,8 @@ int32_t LoadBoard(const char *filename, uint32_t flags)
|
||||||
else
|
else
|
||||||
Bstrcpy(msgtail, "successfully");
|
Bstrcpy(msgtail, "successfully");
|
||||||
|
|
||||||
message("Loaded V%d map %s%s %s", mapversion, boardfilename, tagstat==0?" w/tags":"", msgtail);
|
message("Loaded V%d map %s%s %s", g_loadedMapVersion,
|
||||||
|
boardfilename, tagstat==0?" w/tags":"", msgtail);
|
||||||
}
|
}
|
||||||
|
|
||||||
startpos = pos; //this is same
|
startpos = pos; //this is same
|
||||||
|
|
|
@ -80,6 +80,7 @@ float debug1, debug2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t mapversion=7; // JBF 20040211: default mapversion to 7
|
int32_t mapversion=7; // JBF 20040211: default mapversion to 7
|
||||||
|
int32_t g_loadedMapVersion = -1; // -1: none (e.g. started new)
|
||||||
|
|
||||||
static int32_t get_mapversion(void);
|
static int32_t get_mapversion(void);
|
||||||
|
|
||||||
|
@ -10037,6 +10038,8 @@ skip_reading_mapbin:
|
||||||
check_sprite(i);
|
check_sprite(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Back up the map version of the *loaded* map. Must be before yax_update().
|
||||||
|
g_loadedMapVersion = mapversion;
|
||||||
#ifdef YAX_ENABLE
|
#ifdef YAX_ENABLE
|
||||||
yax_update(mapversion<9);
|
yax_update(mapversion<9);
|
||||||
if (editstatus)
|
if (editstatus)
|
||||||
|
|
|
@ -2987,7 +2987,7 @@ static void m32_showmouse(void)
|
||||||
pop_nofog();
|
pop_nofog();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t AskIfSure(const char *text)
|
int32_t AskIfSure(const char *text)
|
||||||
{
|
{
|
||||||
int32_t retval=1;
|
int32_t retval=1;
|
||||||
|
|
||||||
|
@ -3027,7 +3027,7 @@ static int32_t AskIfSure(const char *text)
|
||||||
if (PRESSED_KEYSC(ESC))
|
if (PRESSED_KEYSC(ESC))
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
|
||||||
return(retval);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t IsValidTile(int32_t idTile)
|
static int32_t IsValidTile(int32_t idTile)
|
||||||
|
@ -10513,7 +10513,7 @@ void app_crashhandler(void)
|
||||||
if (levelname[0])
|
if (levelname[0])
|
||||||
{
|
{
|
||||||
append_ext_UNSAFE(levelname, "_crash.map");
|
append_ext_UNSAFE(levelname, "_crash.map");
|
||||||
SaveBoard(levelname, 1);
|
SaveBoard(levelname, M32_SB_NOEXT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11099,13 +11099,14 @@ static void Keys2d3d(void)
|
||||||
Bsprintf(tempbuf, "Save to %s?", levelname);
|
Bsprintf(tempbuf, "Save to %s?", levelname);
|
||||||
if (!AskIfSure(tempbuf))
|
if (!AskIfSure(tempbuf))
|
||||||
{
|
{
|
||||||
SaveBoard(levelname, 0);
|
if (SaveBoard(levelname, M32_SB_ASKOV) != NULL)
|
||||||
|
{
|
||||||
message("Board saved to %s", levelname);
|
message("Board saved to %s", levelname);
|
||||||
asksave = 0;
|
asksave = 0;
|
||||||
lastsave=totalclock;
|
lastsave=totalclock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
message("Map is heavily corrupted, not saving. See OSD for details.");
|
message("Map is heavily corrupted, not saving. See OSD for details.");
|
||||||
}
|
}
|
||||||
|
@ -11284,12 +11285,12 @@ void ExtCheckKeys(void)
|
||||||
{
|
{
|
||||||
if (CheckMapCorruption(5, 0)>=4)
|
if (CheckMapCorruption(5, 0)>=4)
|
||||||
{
|
{
|
||||||
SaveBoard("autosave_corrupt.map", 1);
|
if (SaveBoard("autosave_corrupt.map", M32_SB_NOEXT) != NULL)
|
||||||
message("Board autosaved to AUTOSAVE_CORRUPT.MAP");
|
message("Board autosaved to AUTOSAVE_CORRUPT.MAP");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SaveBoard("autosave.map", 0);
|
if (SaveBoard("autosave.map", 0) != NULL)
|
||||||
message("Board autosaved to AUTOSAVE.MAP");
|
message("Board autosaved to AUTOSAVE.MAP");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue