A couple of Mapster changes related to saving.

- new mapster32.cfg and OSD variable 'fixmaponsave_sprites', telling the
  editor whether to 'fix' the sprite sectnums on saving and entering 3D
  mode. Note that a) sprite sectnums are never fixed when 'script_expertmode'
  is enabled, as before, and b) sprites that have out-of-bounds sectnums
  are still fixed if a proper sector is found
- if saving and some sprite sectnums have thus been tweaked, inform the
  mapper on the status line and print the changes in the OSD
- fix update issue similar to an earlier one: when 'saving as', the astub.c-
  based file name is now updated too, so saving with Ctrl-S now saves into
  the one save with 'save as' (and not the old one)
- don't attempt to recheck wall pointers from scratch (when saving and running
  with -check) if it's a TROR map

git-svn-id: https://svn.eduke32.com/eduke32@2110 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2011-11-11 20:05:29 +00:00
parent e18ef2ccc8
commit b2d789731a
4 changed files with 101 additions and 44 deletions

View file

@ -151,7 +151,7 @@ extern void AlignWallPoint2(int32_t w0);
extern int32_t AutoAlignWalls(int32_t w0, uint32_t flags, int32_t nrecurs); extern int32_t AutoAlignWalls(int32_t w0, uint32_t flags, int32_t nrecurs);
extern void SetFirstWall(int32_t sectnum, int32_t wallnum); extern void SetFirstWall(int32_t sectnum, int32_t wallnum);
extern void fixspritesectors(void); extern int32_t fixspritesectors(void);
extern void clearkeys(void); extern void clearkeys(void);
extern int32_t ExtInit(void); extern int32_t ExtInit(void);
@ -161,8 +161,9 @@ extern void ExtPreCheckKeys(void);
extern void ExtAnalyzeSprites(void); extern void ExtAnalyzeSprites(void);
extern void ExtCheckKeys(void); extern void ExtCheckKeys(void);
extern void ExtPreLoadMap(void); extern void ExtPreLoadMap(void);
extern void ExtSetupMapFilename(const char *mapname);
extern void ExtLoadMap(const char *mapname); extern void ExtLoadMap(const char *mapname);
extern void ExtPreSaveMap(void); extern int32_t ExtPreSaveMap(void);
extern void ExtSaveMap(const char *mapname); extern void ExtSaveMap(const char *mapname);
extern const char *ExtGetSectorCaption(int16_t sectnum); extern const char *ExtGetSectorCaption(int16_t sectnum);
extern const char *ExtGetWallCaption(int16_t wallnum); extern const char *ExtGetWallCaption(int16_t wallnum);
@ -188,6 +189,7 @@ extern int32_t autocorruptcheck;
extern int32_t corruptcheck_noalreadyrefd; extern int32_t corruptcheck_noalreadyrefd;
extern int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing); extern int32_t CheckMapCorruption(int32_t printfromlev, uint64_t tryfixing);
extern int32_t fixmaponsave_sprites;
extern int32_t m32_script_expertmode; // if true, make read-only vars writable extern int32_t m32_script_expertmode; // if true, make read-only vars writable
extern void showsectordata(int16_t sectnum, int16_t small); extern void showsectordata(int16_t sectnum, int16_t small);

View file

@ -143,6 +143,7 @@ typedef struct
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); static int32_t restore_highlighted_map(mapinfofull_t *mapinfo);
static void SaveBoardAndPrintMessage(const char *fn);
static const char *GetSaveBoardFilename(void); static const char *GetSaveBoardFilename(void);
/* /*
@ -185,7 +186,7 @@ int8_t sideview_reversehrot = 0;
char lastpm16buf[156]; char lastpm16buf[156];
//static int32_t checksectorpointer_warn = 0; //static int32_t checksectorpointer_warn = 0;
static int32_t saveboard_savedtags=0; static int32_t saveboard_savedtags, saveboard_fixedsprites;
char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck); char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck);
static int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls); static int32_t adjustmark(int32_t *xplc, int32_t *yplc, int16_t danumwalls);
@ -206,7 +207,7 @@ static void copysector(int16_t soursector, int16_t destsector, int16_t deststart
int32_t drawtilescreen(int32_t pictopleft, int32_t picbox); int32_t drawtilescreen(int32_t pictopleft, int32_t picbox);
void overheadeditor(void); void overheadeditor(void);
static int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line); static int32_t getlinehighlight(int32_t xplc, int32_t yplc, int32_t line);
void fixspritesectors(void); int32_t fixspritesectors(void);
static int32_t movewalls(int32_t start, int32_t offs); static int32_t movewalls(int32_t start, int32_t offs);
int32_t loadnames(const char *namesfile, int8_t root); int32_t loadnames(const char *namesfile, int8_t root);
void updatenumsprites(void); void updatenumsprites(void);
@ -6829,7 +6830,6 @@ CANCEL:
} }
else if (bad == 2) else if (bad == 2)
{ {
const char *f;
char *slash; char *slash;
keystatus[0x1c] = 0; keystatus[0x1c] = 0;
@ -6839,25 +6839,15 @@ CANCEL:
slash = Bstrrchr(selectedboardfilename,'/'); slash = Bstrrchr(selectedboardfilename,'/');
Bstrcpy(slash ? slash+1 : selectedboardfilename, boardfilename); Bstrcpy(slash ? slash+1 : selectedboardfilename, boardfilename);
_printmessage16("Saving board..."); SaveBoardAndPrintMessage(selectedboardfilename);
showframe(1);
f = SaveBoard(selectedboardfilename, 0);
if (f)
printmessage16("Saved board %sto %s.",
saveboard_savedtags?"and tags ":"", f);
else
printmessage16("Saving board failed.");
Bstrcpy(boardfilename, selectedboardfilename); Bstrcpy(boardfilename, selectedboardfilename);
ExtSetupMapFilename(boardfilename);
} }
bad = 0; bad = 0;
} }
else if (ch == 's' || ch == 'S') //S else if (ch == 's' || ch == 'S') //S
{ {
const char *f;
bad = 0; bad = 0;
if (CheckMapCorruption(4, 0)>=4) if (CheckMapCorruption(4, 0)>=4)
@ -6867,16 +6857,7 @@ CANCEL:
break; break;
} }
_printmessage16("Saving board..."); SaveBoardAndPrintMessage(NULL);
showframe(1);
f = SaveBoard(NULL, 0);
if (f)
printmessage16("Saved board %sto %s.",
saveboard_savedtags?"and tags ":"", f);
else
printmessage16("Saving board failed.");
showframe(1); showframe(1);
} }
@ -7059,6 +7040,33 @@ static int32_t ask_above_or_below(void)
} }
#endif #endif
static void SaveBoardAndPrintMessage(const char *fn)
{
const char *f;
_printmessage16("Saving board...");
showframe(1);
f = SaveBoard(fn, 0);
if (f)
{
if (saveboard_fixedsprites)
printmessage16("Saved board %sto %s (changed sectnums of %d sprites).",
saveboard_savedtags?"and tags ":"", f, saveboard_fixedsprites);
else
printmessage16("Saved board %sto %s.", saveboard_savedtags?"and tags ":"", f);
}
else
{
if (saveboard_fixedsprites)
printmessage16("Saving board failed (changed sectnums of %d sprites).",
saveboard_fixedsprites);
else
printmessage16("Saving board failed.");
}
}
// get the file name of the file that would be written if SaveBoard(NULL, 0) was called // get the file name of the file that would be written if SaveBoard(NULL, 0) was called
static const char *GetSaveBoardFilename(void) static const char *GetSaveBoardFilename(void)
{ {
@ -7080,7 +7088,7 @@ static const char *GetSaveBoardFilename(void)
return f; return f;
} }
// flags: 1:no ExSaveMap (backup.map) and no taglabels saving // flags: 1:no ExtSaveMap (backup.map) and no taglabels saving
const char *SaveBoard(const char *fn, uint32_t flags) const char *SaveBoard(const char *fn, uint32_t flags)
{ {
const char *f; const char *f;
@ -7104,7 +7112,7 @@ const char *SaveBoard(const char *fn, uint32_t flags)
f++; f++;
} }
ExtPreSaveMap(); saveboard_fixedsprites = ExtPreSaveMap();
ret = saveboard(f,&startposx,&startposy,&startposz,&startang,&startsectnum); ret = saveboard(f,&startposx,&startposy,&startposz,&startang,&startsectnum);
if ((flags&1)==0) if ((flags&1)==0)
{ {
@ -7635,16 +7643,20 @@ static int32_t deletesector(int16_t sucksect)
return(0); return(0);
} }
void fixspritesectors(void) int32_t fixspritesectors(void)
{ {
int32_t i, j, dax, day, cz, fz; int32_t i, j, dax, day, cz, fz;
int32_t numfixedsprites = 0, printfirsttime = 0;
for (i=numsectors-1; i>=0; i--) for (i=numsectors-1; i>=0; i--)
if (sector[i].wallnum <= 0 || sector[i].wallptr >= numwalls) if (sector[i].wallnum <= 0 || sector[i].wallptr >= numwalls)
{
deletesector(i); deletesector(i);
initprintf("Deleted sector %d which had corrupt .wallnum or .wallptr\n", i);
}
if (m32_script_expertmode) if (m32_script_expertmode)
return; return 0;
for (i=0; i<MAXSPRITES; i++) for (i=0; i<MAXSPRITES; i++)
if (sprite[i].statnum < MAXSTATUS) if (sprite[i].statnum < MAXSTATUS)
@ -7663,12 +7675,25 @@ void fixspritesectors(void)
if (cz <= sprite[i].z && sprite[i].z <= fz) if (cz <= sprite[i].z && sprite[i].z <= fz)
{ {
if (fixmaponsave_sprites || (sprite[i].sectnum < 0 || sprite[i].sectnum >= numsectors))
{
numfixedsprites++;
if (printfirsttime == 0)
{
initprintf("--------------------\n");
printfirsttime = 1;
}
initprintf("Changed sectnum of sprite %d from %d to %d\n", i, sprite[i].sectnum, j);
changespritesect(i, j); changespritesect(i, j);
}
break; break;
} }
} }
} }
} }
return numfixedsprites;
} }
static int32_t movewalls(int32_t start, int32_t offs) static int32_t movewalls(int32_t start, int32_t offs)

View file

@ -266,6 +266,8 @@ int32_t loadsetup(const char *fn)
if (readconfig(fp, "autocorruptchecksec", val, VL) > 0) autocorruptcheck = max(0, atoi_safe(val)); if (readconfig(fp, "autocorruptchecksec", val, VL) > 0) autocorruptcheck = max(0, atoi_safe(val));
if (readconfig(fp, "corruptcheck_noalreadyrefd", val, VL) > 0) if (readconfig(fp, "corruptcheck_noalreadyrefd", val, VL) > 0)
corruptcheck_noalreadyrefd = !!atoi_safe(val); corruptcheck_noalreadyrefd = !!atoi_safe(val);
if (readconfig(fp, "fixmaponsave_sprites", val, VL) > 0)
fixmaponsave_sprites = !!atoi_safe(val);
if (readconfig(fp, "showheightindicators", val, VL) > 0) if (readconfig(fp, "showheightindicators", val, VL) > 0)
showheightindicators = clamp(atoi_safe(val), 0, 2); showheightindicators = clamp(atoi_safe(val), 0, 2);
@ -474,6 +476,9 @@ int32_t writesetup(const char *fn)
"; (toggled with 'corruptcheck noalreadyrefd')\n" "; (toggled with 'corruptcheck noalreadyrefd')\n"
"corruptcheck_noalreadyrefd = %d\n" "corruptcheck_noalreadyrefd = %d\n"
"\n" "\n"
"; Fix sprite sectnums when saving a map or entering 3D mode\n"
"fixmaponsave_sprites = %d\n"
"\n"
"; Height indicators (0:none, 1:only 2-sided&different, 2:all)\n" "; Height indicators (0:none, 1:only 2-sided&different, 2:all)\n"
"showheightindicators = %d\n" "showheightindicators = %d\n"
"\n" "\n"
@ -573,7 +578,7 @@ int32_t writesetup(const char *fn)
msens, unrealedlook, pk_uedaccel, quickmapcycling, msens, unrealedlook, pk_uedaccel, quickmapcycling,
sideview_reversehrot, sideview_reversehrot,
revertCTRL,scrollamount,pk_turnaccel,pk_turndecel,autosave,autocorruptcheck, revertCTRL,scrollamount,pk_turnaccel,pk_turndecel,autosave,autocorruptcheck,
corruptcheck_noalreadyrefd, showheightindicators,showambiencesounds, corruptcheck_noalreadyrefd, fixmaponsave_sprites, showheightindicators,showambiencesounds,
autogray,showinnergray, autogray,showinnergray,
graphicsmode, graphicsmode,
MixRate,AmbienceToggle,ParentalLock, !!m32_osd_tryscript, MixRate,AmbienceToggle,ParentalLock, !!m32_osd_tryscript,

View file

@ -69,7 +69,8 @@ static char *setupfilename = "mapster32.cfg";
static char defaultduke3dgrp[BMAX_PATH] = "duke3d.grp"; static char defaultduke3dgrp[BMAX_PATH] = "duke3d.grp";
static char *g_grpNamePtr = defaultduke3dgrp; static char *g_grpNamePtr = defaultduke3dgrp;
char *g_defNamePtr = defsfilename; char *g_defNamePtr = defsfilename;
static int32_t fixmapbeforesaving = 0; int32_t fixmaponsave_sprites = 1;
static int32_t fixmaponsave_walls = 0;
static int32_t lastsave = -180*60; static int32_t lastsave = -180*60;
static int32_t NoAutoLoad = 0; static int32_t NoAutoLoad = 0;
static int32_t spnoclip=1; static int32_t spnoclip=1;
@ -803,6 +804,15 @@ static void MultiPskyInit(void)
parallaxyscale = 32768; parallaxyscale = 32768;
} }
void ExtSetupMapFilename(const char *mapname)
{
Bstrcpy(levelname, mapname);
Bsprintf(tempbuf, "Mapster32 - %s", mapname);
wm_setapptitle(tempbuf);
}
void ExtLoadMap(const char *mapname) void ExtLoadMap(const char *mapname)
{ {
int32_t i; int32_t i;
@ -811,7 +821,7 @@ void ExtLoadMap(const char *mapname)
getmessageleng = 0; getmessageleng = 0;
getmessagetimeoff = 0; getmessagetimeoff = 0;
Bstrcpy(levelname,mapname); ExtSetupMapFilename(mapname);
// old-fashioned multi-psky handling // old-fashioned multi-psky handling
@ -851,11 +861,9 @@ void ExtLoadMap(const char *mapname)
parallaxtype=0; parallaxtype=0;
////////// //////////
Bsprintf(tempbuf, "Mapster32 - %s",mapname);
#if M32_UNDO #if M32_UNDO
map_undoredo_free(); map_undoredo_free();
#endif #endif
wm_setapptitle(tempbuf);
} }
void ExtSaveMap(const char *mapname) void ExtSaveMap(const char *mapname)
@ -8331,14 +8339,16 @@ static void InitCustomColors(void)
} }
} }
void ExtPreSaveMap(void) int32_t ExtPreSaveMap(void)
{ {
fixspritesectors(); //Do this before saving! int32_t numfixedsprites;
numfixedsprites = fixspritesectors(); //Do this before saving!
updatesectorz(startposx,startposy,startposz,&startsectnum); updatesectorz(startposx,startposy,startposz,&startsectnum);
if (startsectnum < 0) if (startsectnum < 0)
updatesector(startposx,startposy,&startsectnum); updatesector(startposx,startposy,&startsectnum);
if (fixmapbeforesaving) if (fixmaponsave_walls)
{ {
int32_t i, startwall, j, endwall; int32_t i, startwall, j, endwall;
@ -8348,6 +8358,9 @@ void ExtPreSaveMap(void)
for (j=startwall; j<numwalls; j++) for (j=startwall; j<numwalls; j++)
if (wall[j].point2 < startwall) if (wall[j].point2 < startwall)
startwall = wall[j].point2; startwall = wall[j].point2;
if (sector[i].wallptr != startwall)
initprintf("Warning: set sector %d's wallptr to %d (was %d)\n", i,
sector[i].wallptr, startwall);
sector[i].wallptr = startwall; sector[i].wallptr = startwall;
} }
@ -8355,6 +8368,11 @@ void ExtPreSaveMap(void)
sector[i].wallnum = sector[i+1].wallptr-sector[i].wallptr; sector[i].wallnum = sector[i+1].wallptr-sector[i].wallptr;
sector[numsectors-1].wallnum = numwalls - sector[numsectors-1].wallptr; sector[numsectors-1].wallnum = numwalls - sector[numsectors-1].wallptr;
#ifdef YAX_ENABLE
// setting redwalls from scratch would very likely wreak havoc with TROR maps
if (numyaxbunches > 0)
return numfixedsprites;
#endif
for (i=0; i<numwalls; i++) for (i=0; i<numwalls; i++)
{ {
wall[i].nextsector = -1; wall[i].nextsector = -1;
@ -8368,6 +8386,8 @@ void ExtPreSaveMap(void)
checksectorpointer(j, i); checksectorpointer(j, i);
} }
} }
return numfixedsprites;
} }
static void G_ShowParameterHelp(void) static void G_ShowParameterHelp(void)
@ -8614,15 +8634,15 @@ static void G_CheckCommandLine(int32_t argc, const char **argv)
} }
if (!Bstrcasecmp(c+1,"check")) if (!Bstrcasecmp(c+1,"check"))
{ {
initprintf("Map pointer checking on saving enabled\n"); initprintf("Map wall checking on save enabled\n");
fixmapbeforesaving = 1; fixmaponsave_walls = 1;
i++; i++;
continue; continue;
} }
if (!Bstrcasecmp(c+1,"nocheck")) if (!Bstrcasecmp(c+1,"nocheck"))
{ {
initprintf("Map pointer checking disabled\n"); initprintf("Map wall checking on save disabled\n");
fixmapbeforesaving = 0; fixmaponsave_walls = 0;
i++; i++;
continue; continue;
} }
@ -8954,6 +8974,11 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm)
else else
OSD_Printf("M32 Script expert mode DISABLED.\n"); OSD_Printf("M32 Script expert mode DISABLED.\n");
} }
else if (!Bstrcasecmp(parm->name, "fixmaponsave_sprites"))
{
OSD_Printf("Fix sprite sectnums on map saving: %s\n",
(fixmaponsave_sprites = !fixmaponsave_sprites) ? "enabled":"disabled");
}
else if (!Bstrcasecmp(parm->name, "show_heightindicators")) else if (!Bstrcasecmp(parm->name, "show_heightindicators"))
{ {
static const char *how[3] = {"none", "two-sided walls only", "all"}; static const char *how[3] = {"none", "two-sided walls only", "all"};