- started transitioning to a global mapinfo list.

This will make it a lot easier for cross-game parts of the engine to query game state.
So far the EDuke frontend has been ported over.
This commit is contained in:
Christoph Oelckers 2019-12-10 00:01:45 +01:00
parent 16818d2d71
commit 3b57f38e55
14 changed files with 137 additions and 104 deletions

View file

@ -26,10 +26,14 @@
#include "menu.h" #include "menu.h"
#include "gstrings.h" #include "gstrings.h"
#include "quotemgr.h" #include "quotemgr.h"
#include "mapinfo.h"
#ifndef NETCODE_DISABLE #ifndef NETCODE_DISABLE
#include "enet.h" #include "enet.h"
#endif #endif
MapRecord mapList[512]; // Due to how this gets used it needs to be static. EDuke defines 7 episode plus one spare episode with 64 potential levels each and relies on the static array which is freely accessible by scripts.
MapRecord *currentLevel;
void C_CON_SetAliases(); void C_CON_SetAliases();
InputState inputState; InputState inputState;
void SetClipshapes(); void SetClipshapes();

41
source/common/mapinfo.h Normal file
View file

@ -0,0 +1,41 @@
#pragma once
#include "gstrings.h"
// Localization capable replacement of the game specific solutions.
inline void MakeStringLocalizable(FString &quote)
{
// Only prepend a quote if the string is localizable.
if (quote.Len() > 0 && quote[0] != '$' && GStrings[quote]) quote.Insert(0, "$");
}
struct MapRecord
{
int parTime;
int designerTime;
FString fileName;
FString name;
FString music;
int cdSongId;
// The rest is only used by Blood
int nextLevel;
int nextSecret;
int messageStart; // messages are stored in the quote array to reduce clutter.
FString author;
// bool fog, weather; // Blood defines these but they aren't used.
const char *DisplayName()
{
return GStrings.localize(name);
}
void SetName(const char *n)
{
name = n;
MakeStringLocalizable(name);
}
};
extern MapRecord mapList[512];
extern MapRecord *currentLevel;

View file

@ -42,7 +42,8 @@
void Quotes::MakeStringLabel(FString &quote) void Quotes::MakeStringLabel(FString &quote)
{ {
quote.Insert(0, "$"); // Only prepend a quote if the string is localizable.
if (quote.Len() > 0 && quote[0] != '$' && GStrings[quote]) quote.Insert(0, "$");
} }
void Quotes::InitializeQuote(int num, const char *text, bool fromscript) void Quotes::InitializeQuote(int num, const char *text, bool fromscript)

View file

@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "duke3d.h" #include "duke3d.h"
#include "osdcmds.h" #include "osdcmds.h"
#include "mapinfo.h"
BEGIN_DUKE_NS BEGIN_DUKE_NS
@ -555,7 +556,7 @@ void G_DoCheats(void)
int32_t const volnume = ud.m_volume_number, levnume = m_level_number; int32_t const volnume = ud.m_volume_number, levnume = m_level_number;
if ((!VOLUMEONE || volnume == 0) && (unsigned)volnume < (unsigned)g_volumeCnt && if ((!VOLUMEONE || volnume == 0) && (unsigned)volnume < (unsigned)g_volumeCnt &&
(unsigned)levnume < MAXLEVELS && g_mapInfo[volnume*MAXLEVELS + levnume].filename != NULL) (unsigned)levnume < MAXLEVELS && mapList[volnume*MAXLEVELS + levnume].fileName.IsNotEmpty())
{ {
ud.volume_number = volnume; ud.volume_number = volnume;
ud.level_number = levnume; ud.level_number = levnume;

View file

@ -48,6 +48,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "filesystem/filesystem.h" #include "filesystem/filesystem.h"
#include "statistics.h" #include "statistics.h"
#include "menu/menu.h" #include "menu/menu.h"
#include "mapinfo.h"
// Uncomment to prevent anything except mirrors from drawing. It is sensible to // Uncomment to prevent anything except mirrors from drawing. It is sensible to
// also uncomment ENGINE_CLEAR_SCREEN in build/src/engine_priv.h. // also uncomment ENGINE_CLEAR_SCREEN in build/src/engine_priv.h.
@ -4814,7 +4815,8 @@ static int32_t S_DefineMusic(const char *ID, const char *name)
return -1; return -1;
} }
return S_DefineAudioIfSupported(&g_mapInfo[sel].musicfn, name); mapList[sel].music = name;
return 0;
} }
static int parsedefinitions_game(scriptfile *, int); static int parsedefinitions_game(scriptfile *, int);
@ -5389,10 +5391,6 @@ static void G_Cleanup(void)
for (i=(MAXLEVELS*(MAXVOLUMES+1))-1; i>=0; i--) // +1 volume for "intro", "briefing" music for (i=(MAXLEVELS*(MAXVOLUMES+1))-1; i>=0; i--) // +1 volume for "intro", "briefing" music
{ {
Xfree(g_mapInfo[i].name);
Xfree(g_mapInfo[i].filename);
Xfree(g_mapInfo[i].musicfn);
G_FreeMapState(i); G_FreeMapState(i);
} }

View file

@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "m_argv.h" #include "m_argv.h"
#include "menu/menu.h" #include "menu/menu.h"
#include "stringtable.h" #include "stringtable.h"
#include "mapinfo.h"
void C_CON_SetButtonAlias(int num, const char* text); void C_CON_SetButtonAlias(int num, const char* text);
void C_CON_ClearButtonAlias(int num); void C_CON_ClearButtonAlias(int num);
@ -2029,10 +2030,7 @@ void C_DefineMusic(int volumeNum, int levelNum, const char *fileName)
if (strcmp(fileName, "/.") == 0) if (strcmp(fileName, "/.") == 0)
return; return;
map_t *const pMapInfo = &g_mapInfo[(MAXLEVELS*volumeNum)+levelNum]; mapList[(MAXLEVELS * volumeNum) + levelNum].music = fileName;
Xfree(pMapInfo->musicfn);
pMapInfo->musicfn = dup_filename(fileName);
} }
void C_DefineVolumeFlags(int32_t vol, int32_t flags) void C_DefineVolumeFlags(int32_t vol, int32_t flags)
@ -2084,12 +2082,12 @@ void C_UndefineLevel(int32_t vol, int32_t lev)
Bassert((unsigned)vol < MAXVOLUMES); Bassert((unsigned)vol < MAXVOLUMES);
Bassert((unsigned)lev < MAXLEVELS); Bassert((unsigned)lev < MAXLEVELS);
map_t *const map = &g_mapInfo[(MAXLEVELS*vol)+lev]; auto& gmap = mapList[(MAXLEVELS * vol) + lev];
DO_FREE_AND_NULL(map->filename); gmap.fileName = "";
DO_FREE_AND_NULL(map->name); gmap.name = "";
map->partime = 0; gmap.parTime = 0;
map->designertime = 0; gmap.designerTime = 0;
} }
LUNATIC_EXTERN int32_t C_SetDefName(const char *name) LUNATIC_EXTERN int32_t C_SetDefName(const char *name)
@ -5174,16 +5172,11 @@ repeatcase:
Bcorrectfilename(tempbuf,0); Bcorrectfilename(tempbuf,0);
if (g_mapInfo[j *MAXLEVELS+k].filename == NULL) mapList[j * MAXLEVELS + k].fileName = tempbuf;
g_mapInfo[j *MAXLEVELS+k].filename = (char *)Xcalloc(Bstrlen(tempbuf)+1,sizeof(uint8_t));
else if ((Bstrlen(tempbuf)+1) > sizeof(g_mapInfo[j*MAXLEVELS+k].filename))
g_mapInfo[j *MAXLEVELS+k].filename = (char *)Xrealloc(g_mapInfo[j*MAXLEVELS+k].filename,(Bstrlen(tempbuf)+1));
Bstrcpy(g_mapInfo[j*MAXLEVELS+k].filename,tempbuf);
C_SkipComments(); C_SkipComments();
g_mapInfo[j *MAXLEVELS+k].partime = mapList[j *MAXLEVELS+k].parTime =
(((*(textptr+0)-'0')*10+(*(textptr+1)-'0'))*REALGAMETICSPERSEC*60)+ (((*(textptr+0)-'0')*10+(*(textptr+1)-'0'))*REALGAMETICSPERSEC*60)+
(((*(textptr+3)-'0')*10+(*(textptr+4)-'0'))*REALGAMETICSPERSEC); (((*(textptr+3)-'0')*10+(*(textptr+4)-'0'))*REALGAMETICSPERSEC);
@ -5193,7 +5186,7 @@ repeatcase:
// cheap hack, 0.99 doesn't have the 3D Realms time // cheap hack, 0.99 doesn't have the 3D Realms time
if (*(textptr+2) == ':') if (*(textptr+2) == ':')
{ {
g_mapInfo[j *MAXLEVELS+k].designertime = mapList[j *MAXLEVELS+k].designerTime =
(((*(textptr+0)-'0')*10+(*(textptr+1)-'0'))*REALGAMETICSPERSEC*60)+ (((*(textptr+0)-'0')*10+(*(textptr+1)-'0'))*REALGAMETICSPERSEC*60)+
(((*(textptr+3)-'0')*10+(*(textptr+4)-'0'))*REALGAMETICSPERSEC); (((*(textptr+3)-'0')*10+(*(textptr+4)-'0'))*REALGAMETICSPERSEC);
@ -5220,14 +5213,7 @@ repeatcase:
tempbuf[i] = '\0'; tempbuf[i] = '\0';
if (g_mapInfo[j*MAXLEVELS+k].name == NULL) mapList[j * MAXLEVELS + k].SetName(tempbuf);
g_mapInfo[j*MAXLEVELS+k].name = (char *)Xcalloc(Bstrlen(tempbuf)+1,sizeof(uint8_t));
else if ((Bstrlen(tempbuf)+1) > sizeof(g_mapInfo[j*MAXLEVELS+k].name))
g_mapInfo[j *MAXLEVELS+k].name = (char *)Xrealloc(g_mapInfo[j*MAXLEVELS+k].name,(Bstrlen(tempbuf)+1));
/* initprintf("level name string len: %d\n",Bstrlen(tempbuf)); */
Bstrcpy(g_mapInfo[j*MAXLEVELS+k].name,tempbuf);
continue; continue;

View file

@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "menu/menu.h" #include "menu/menu.h"
#include "c_dispatch.h" #include "c_dispatch.h"
#include "quotemgr.h" #include "quotemgr.h"
#include "mapinfo.h"
#include "debugbreak.h" #include "debugbreak.h"
extern bool rotatesprite_2doverride; extern bool rotatesprite_2doverride;
@ -3752,13 +3753,13 @@ badindex:
int const levelNum = ud.volume_number * MAXLEVELS + ud.level_number; int const levelNum = ud.volume_number * MAXLEVELS + ud.level_number;
const char *pName; const char *pName;
if (EDUKE32_PREDICT_FALSE((unsigned)levelNum >= ARRAY_SIZE(g_mapInfo))) if (EDUKE32_PREDICT_FALSE((unsigned)levelNum >= ARRAY_SIZE(mapList)))
{ {
CON_ERRPRINTF("out of bounds map number (vol=%d, lev=%d)\n", ud.volume_number, ud.level_number); CON_ERRPRINTF("out of bounds map number (vol=%d, lev=%d)\n", ud.volume_number, ud.level_number);
abort_after_error(); abort_after_error();
} }
pName = j == STR_MAPNAME ? g_mapInfo[levelNum].name : g_mapInfo[levelNum].filename; pName = j == STR_MAPNAME ? mapList[levelNum].DisplayName() : mapList[levelNum].fileName.GetChars();
if (EDUKE32_PREDICT_FALSE(pName == NULL)) if (EDUKE32_PREDICT_FALSE(pName == NULL))
{ {
@ -3767,7 +3768,7 @@ badindex:
abort_after_error(); abort_after_error();
} }
quoteMgr.InitializeQuote(q, j == STR_MAPNAME ? g_mapInfo[levelNum].name : g_mapInfo[levelNum].filename); quoteMgr.InitializeQuote(q, j == STR_MAPNAME ? mapList[levelNum].DisplayName() : mapList[levelNum].fileName.GetChars());
break; break;
} }
case STR_PLAYERNAME: case STR_PLAYERNAME:

View file

@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "savegame.h" #include "savegame.h"
#include "input.h" #include "input.h"
#include "gamecvars.h" #include "gamecvars.h"
#include "mapinfo.h"
#include "enet.h" #include "enet.h"
#include "m_crc32.h" #include "m_crc32.h"
@ -2037,7 +2038,7 @@ static void Net_ReceiveMapVoteInitiate(uint8_t *pbuf)
vote_map = pendingnewgame.level_number; vote_map = pendingnewgame.level_number;
Bsprintf(tempbuf, GStrings("votemap"), g_player[voting].user_name, Bsprintf(tempbuf, GStrings("votemap"), g_player[voting].user_name,
g_mapInfo[(uint8_t)(vote_episode * MAXLEVELS + vote_map)].name, vote_episode + 1, vote_map + 1); mapList[(uint8_t)(vote_episode * MAXLEVELS + vote_map)].DisplayName(), vote_episode + 1, vote_map + 1);
G_AddUserQuote(tempbuf); G_AddUserQuote(tempbuf);
strcpy(tempbuf, GStrings("TXT_PRESSF1_F2")); strcpy(tempbuf, GStrings("TXT_PRESSF1_F2"));

View file

@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "menus.h" #include "menus.h"
#include "savegame.h" #include "savegame.h"
#include "sbar.h" #include "sbar.h"
#include "mapinfo.h"
BEGIN_DUKE_NS BEGIN_DUKE_NS
@ -59,7 +60,7 @@ static int osdcmd_changelevel(osdcmdptr_t parm)
if (volume < 0 || level < 0) if (volume < 0 || level < 0)
return OSDCMD_SHOWHELP; return OSDCMD_SHOWHELP;
if (level > MAXLEVELS || g_mapInfo[volume * MAXLEVELS + level].filename == NULL) if (level > MAXLEVELS || mapList[volume * MAXLEVELS + level].fileName.IsEmpty())
{ {
OSD_Printf("changelevel: no map defined for episode %d level %d\n", volume + 1, level + 1); OSD_Printf("changelevel: no map defined for episode %d level %d\n", volume + 1, level + 1);
return OSDCMD_SHOWHELP; return OSDCMD_SHOWHELP;

View file

@ -30,6 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "savegame.h" #include "savegame.h"
#include "statistics.h" #include "statistics.h"
#include "menu/menu.h" #include "menu/menu.h"
#include "mapinfo.h"
#include "cmdlib.h"
BEGIN_DUKE_NS BEGIN_DUKE_NS
static uint8_t precachehightile[2][(MAXTILES+7)>>3]; static uint8_t precachehightile[2][(MAXTILES+7)>>3];
@ -379,9 +381,7 @@ static void G_DoLoadScreen(const char *statustext, int percent)
else else
{ {
menutext_center(90, GStrings("TXT_LOADING")); menutext_center(90, GStrings("TXT_LOADING"));
menutext_center(90+16+8, mapList[(ud.volume_number*MAXLEVELS) + ud.level_number].DisplayName());
if (g_mapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name != NULL)
menutext_center(90+16+8, g_mapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name);
} }
#ifndef EDUKE32_TOUCH_DEVICES #ifndef EDUKE32_TOUCH_DEVICES
@ -1621,13 +1621,11 @@ int G_FindLevelByFile(const char *fileName)
{ {
int i = 0; int i = 0;
for (auto &levelNum : g_mapInfo) for (auto &levelNum : mapList)
{ {
i++; i++;
if (levelNum.filename == NULL) if (levelNum.fileName.CompareNoCase(fileName) == 0)
continue;
else if (!Bstrcasecmp(fileName, levelNum.filename))
return i-1; return i-1;
} }
@ -1691,20 +1689,18 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName)
{ {
char *p; char *p;
char const *exts[] = { char const *exts[] = {
#ifdef HAVE_FLAC
"flac", "flac",
#endif
#ifdef HAVE_VORBIS
"ogg", "ogg",
#endif "mp3",
#ifdef HAVE_XMP
"xm", "xm",
"mod", "mod",
"it", "it",
"s3m", "s3m",
"mtm", "mtm",
#endif "mid",
"mid" "hmp",
"hmi",
"xmi"
}; };
Bstrncpy(nameBuf, fileName, BMAX_PATH); Bstrncpy(nameBuf, fileName, BMAX_PATH);
@ -1717,31 +1713,32 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName)
p[0] = '.'; p[0] = '.';
} }
// Test if a real file with this name exists with all known extensions for music.
for (auto & ext : exts) for (auto & ext : exts)
{ {
Bmemcpy(p+1, ext, Bstrlen(ext) + 1); Bmemcpy(p+1, ext, Bstrlen(ext) + 1);
if (fileSystem.FileExists(nameBuf)) if (FileExists(nameBuf))
{ {
realloc_copy(&g_mapInfo[USERMAPMUSICFAKESLOT].musicfn, nameBuf); mapList[USERMAPMUSICFAKESLOT].music = nameBuf;
return; return;
} }
} }
char const * usermapMusic = g_mapInfo[MUS_USERMAP].musicfn; auto &usermapMusic = mapList[MUS_USERMAP].music;
if (usermapMusic != nullptr) if (usermapMusic.IsNotEmpty())
{ {
realloc_copy(&g_mapInfo[USERMAPMUSICFAKESLOT].musicfn, usermapMusic); mapList[USERMAPMUSICFAKESLOT].music = usermapMusic;
return; return;
} }
#ifndef EDUKE32_STANDALONE #ifndef EDUKE32_STANDALONE
if (!FURY) if (!FURY)
{ {
char const * e1l8 = g_mapInfo[7].musicfn; auto &e1l8 = mapList[7].music;
if (e1l8 != nullptr) if (e1l8.IsNotEmpty())
{ {
realloc_copy(&g_mapInfo[USERMAPMUSICFAKESLOT].musicfn, e1l8); mapList[USERMAPMUSICFAKESLOT].music = e1l8;
return; return;
} }
} }
@ -1816,13 +1813,13 @@ int G_EnterLevel(int gameMode)
int const mapidx = (ud.volume_number * MAXLEVELS) + ud.level_number; int const mapidx = (ud.volume_number * MAXLEVELS) + ud.level_number;
Bassert((unsigned)mapidx < ARRAY_SIZE(g_mapInfo)); Bassert((unsigned)mapidx < ARRAY_SIZE(mapList));
auto &m = g_mapInfo[mapidx]; auto& mm = mapList[mapidx];
if (VOLUMEONE || !Menu_HaveUserMap()) if (VOLUMEONE || !Menu_HaveUserMap())
{ {
if (m.name == NULL || m.filename == NULL) if (mm.name.IsEmpty() || mm.fileName.IsEmpty())
{ {
OSD_Printf(OSDTEXT_RED "Map E%dL%d not defined!\n", ud.volume_number+1, ud.level_number+1); OSD_Printf(OSDTEXT_RED "Map E%dL%d not defined!\n", ud.volume_number+1, ud.level_number+1);
return 1; return 1;
@ -1856,15 +1853,15 @@ int G_EnterLevel(int gameMode)
G_LoadMapHack(levelName, boardfilename); G_LoadMapHack(levelName, boardfilename);
G_SetupFilenameBasedMusic(levelName, boardfilename); G_SetupFilenameBasedMusic(levelName, boardfilename);
} }
else if (engineLoadBoard(m.filename, VOLUMEONE, &p0.pos, &playerAngle, &p0.cursectnum) < 0) else if (engineLoadBoard(mm.fileName, VOLUMEONE, &p0.pos, &playerAngle, &p0.cursectnum) < 0)
{ {
OSD_Printf(OSD_ERROR "Map \"%s\" not found or invalid map version!\n", m.filename); OSD_Printf(OSD_ERROR "Map \"%s\" not found or invalid map version!\n", mm.fileName.GetChars());
return 1; return 1;
} }
else else
{ {
STAT_NewLevel(m.filename); STAT_NewLevel(mm.fileName);
G_LoadMapHack(levelName, m.filename); G_LoadMapHack(levelName, mm.fileName);
} }
p0.q16ang = fix16_from_int(playerAngle); p0.q16ang = fix16_from_int(playerAngle);
@ -1885,7 +1882,7 @@ int G_EnterLevel(int gameMode)
G_ResetAllPlayers(); G_ResetAllPlayers();
G_CollectSpawnPoints(gameMode); G_CollectSpawnPoints(gameMode);
ud.playerbest = CONFIG_GetMapBestTime(Menu_HaveUserMap() ? boardfilename : m.filename, g_loadedMapHack.md4); ud.playerbest = CONFIG_GetMapBestTime(Menu_HaveUserMap() ? boardfilename : mm.fileName.GetChars(), g_loadedMapHack.md4);
// G_FadeLoad(0,0,0, 252,0, -28, 4, -1); // G_FadeLoad(0,0,0, 252,0, -28, 4, -1);
G_CacheMapData(); G_CacheMapData();
@ -1897,8 +1894,8 @@ int G_EnterLevel(int gameMode)
{ {
S_PlayLevelMusicOrNothing(USERMAPMUSICFAKESLOT); S_PlayLevelMusicOrNothing(USERMAPMUSICFAKESLOT);
} }
else if (g_mapInfo[g_musicIndex].musicfn == NULL || m.musicfn == NULL || else if (mapList[g_musicIndex].music.IsEmpty() || mm.music.IsEmpty() || mapList[g_musicIndex].music.CompareNoCase(mm.music) == 0 ||
strcmp(g_mapInfo[g_musicIndex].musicfn, m.musicfn) || g_musicSize == 0 || ud.last_level == -1) g_musicSize == 0 || ud.last_level == -1)
{ {
S_PlayLevelMusicOrNothing(mapidx); S_PlayLevelMusicOrNothing(mapidx);
} }
@ -1960,9 +1957,9 @@ int G_EnterLevel(int gameMode)
if (G_HaveUserMap()) if (G_HaveUserMap())
OSD_Printf(OSDTEXT_YELLOW "%s: %s\n", GStrings("TXT_USERMAP"), boardfilename); OSD_Printf(OSDTEXT_YELLOW "%s: %s\n", GStrings("TXT_USERMAP"), boardfilename);
else if (FURY) else if (FURY)
OSD_Printf(OSDTEXT_YELLOW "%s: %s\n", GStrings("TXT_ENTERING"), m.name); OSD_Printf(OSDTEXT_YELLOW "%s: %s\n", GStrings("TXT_ENTERING"), mm.DisplayName());
else else
OSD_Printf(OSDTEXT_YELLOW "E%dL%d: %s\n", ud.volume_number + 1, ud.level_number + 1, m.name); OSD_Printf(OSDTEXT_YELLOW "E%dL%d: %s\n", ud.volume_number + 1, ud.level_number + 1, mm.DisplayName());
g_restorePalette = -1; g_restorePalette = -1;

View file

@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "version.h" #include "version.h"
#include "savegamehelp.h" #include "savegamehelp.h"
#include "menu/menu.h" #include "menu/menu.h"
#include "mapinfo.h"
#include "z_music.h" #include "z_music.h"
BEGIN_DUKE_NS BEGIN_DUKE_NS
@ -317,9 +318,9 @@ int32_t G_LoadPlayer(FSaveGameNode *sv)
int const mapIdx = volume*MAXLEVELS + level; int const mapIdx = volume*MAXLEVELS + level;
if (boardfilename[0]) if (boardfilename[0])
Bstrcpy(currentboardfilename, boardfilename); strcpy(currentboardfilename, boardfilename);
else if (g_mapInfo[mapIdx].filename) else if (mapList[mapIdx].fileName.IsNotEmpty())
Bstrcpy(currentboardfilename, g_mapInfo[mapIdx].filename); strcpy(currentboardfilename, mapList[mapIdx].fileName);
if (currentboardfilename[0]) if (currentboardfilename[0])
@ -519,9 +520,9 @@ int32_t G_LoadPlayer(FSaveGameNode *sv)
int const mapIdx = h.volnum*MAXLEVELS + h.levnum; int const mapIdx = h.volnum*MAXLEVELS + h.levnum;
if (boardfilename[0]) if (boardfilename[0])
Bstrcpy(currentboardfilename, boardfilename); strcpy(currentboardfilename, boardfilename);
else if (g_mapInfo[mapIdx].filename) else if (mapList[mapIdx].fileName.IsNotEmpty())
Bstrcpy(currentboardfilename, g_mapInfo[mapIdx].filename); strcpy(currentboardfilename, mapList[mapIdx].fileName);
if (currentboardfilename[0]) if (currentboardfilename[0])
{ {
@ -1469,8 +1470,8 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
auto fw = WriteSavegameChunk("header.dat"); auto fw = WriteSavegameChunk("header.dat");
fw->Write(&h, sizeof(savehead_t)); fw->Write(&h, sizeof(savehead_t));
auto& mi = g_mapInfo[(MAXLEVELS * ud.volume_number) + ud.level_number]; auto& mii = mapList[(MAXLEVELS * ud.volume_number) + ud.level_number];
G_WriteSaveHeader(name, mi.filename, mi.name); G_WriteSaveHeader(name, mii.fileName, mii.DisplayName());
} }
else else
{ {

View file

@ -33,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "screens.h" #include "screens.h"
#include "gamecvars.h" #include "gamecvars.h"
#include "menu/menu.h" #include "menu/menu.h"
#include "mapinfo.h"
BEGIN_DUKE_NS BEGIN_DUKE_NS
@ -183,7 +184,7 @@ static void G_ShowScores(void)
if (g_mostConcurrentPlayers > 1 && (g_gametypeFlags[ud.coop]&GAMETYPE_SCORESHEET)) if (g_mostConcurrentPlayers > 1 && (g_gametypeFlags[ud.coop]&GAMETYPE_SCORESHEET))
{ {
gametext_center(SCORESHEETOFFSET+58+2, GStrings("Multiplayer Totals")); gametext_center(SCORESHEETOFFSET+58+2, GStrings("Multiplayer Totals"));
gametext_center(SCORESHEETOFFSET+58+10, g_mapInfo[G_LastMapInfoIndex()].name); gametext_center(SCORESHEETOFFSET+58+10, mapList[G_LastMapInfoIndex()].DisplayName());
t = 0; t = 0;
minitext(70, SCORESHEETOFFSET+80, GStrings("Name"), 8, 2+8+16+ROTATESPRITE_MAX); minitext(70, SCORESHEETOFFSET+80, GStrings("Name"), 8, 2+8+16+ROTATESPRITE_MAX);
@ -958,7 +959,7 @@ void G_DisplayRest(int32_t smoothratio)
if (textret == 0 && ud.overhead_on == 2) if (textret == 0 && ud.overhead_on == 2)
{ {
const int32_t a = (ud.screen_size > 0) ? 147 : 179; const int32_t a = (ud.screen_size > 0) ? 147 : 179;
char const * levelname = g_mapInfo[ud.volume_number*MAXLEVELS + ud.level_number].name; char const * levelname = mapList[ud.volume_number*MAXLEVELS + ud.level_number].DisplayName();
if (G_HaveUserMap()) if (G_HaveUserMap())
levelname = boardfilename; levelname = boardfilename;
else if (!(G_GetLogoFlags() & LOGO_HIDEEPISODE)) else if (!(G_GetLogoFlags() & LOGO_HIDEEPISODE))
@ -993,12 +994,13 @@ void G_DisplayRest(int32_t smoothratio)
else if (g_levelTextTime < 5) else if (g_levelTextTime < 5)
o |= 1; o |= 1;
if (g_mapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name != NULL) auto dname = mapList[(ud.volume_number * MAXLEVELS) + ud.level_number].DisplayName();
if (dname != NULL && *dname != 0)
{ {
char const * const fn = currentboardfilename[0] != 0 && char const * const fn = currentboardfilename[0] != 0 &&
ud.volume_number == 0 && ud.level_number == 7 ud.volume_number == 0 && ud.level_number == 7
? currentboardfilename ? currentboardfilename
: g_mapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name; : dname;
menutext_(160<<16, (90+16+8)<<16, -g_levelTextTime+22/*quotepulseshade*/, fn, o, TEXT_XCENTER); menutext_(160<<16, (90+16+8)<<16, -g_levelTextTime+22/*quotepulseshade*/, fn, o, TEXT_XCENTER);
} }
@ -1102,7 +1104,7 @@ void G_DisplayRest(int32_t smoothratio)
{ {
Bsprintf(tempbuf, "%s^00 has called a vote for map", g_player[voting].user_name); Bsprintf(tempbuf, "%s^00 has called a vote for map", g_player[voting].user_name);
gametext_center(40, tempbuf); gametext_center(40, tempbuf);
Bsprintf(tempbuf, "%s (E%dL%d)", g_mapInfo[vote_episode*MAXLEVELS + vote_map].name, vote_episode+1, vote_map+1); Bsprintf(tempbuf, "%s (E%dL%d)", mapList[vote_episode*MAXLEVELS + vote_map].DisplayName(), vote_episode+1, vote_map+1);
gametext_center(48, tempbuf); gametext_center(48, tempbuf);
gametext_center(70, "Press F1 to Accept, F2 to Decline"); gametext_center(70, "Press F1 to Accept, F2 to Decline");
} }
@ -1883,7 +1885,7 @@ static void G_DisplayMPResultsScreen(void)
if (PLUTOPAK) // JBF 20030804 if (PLUTOPAK) // JBF 20030804
rotatesprite_fs((260)<<16, 36<<16, 65536L, 0, PLUTOPAKSPRITE+2, 0, 0, 2+8); rotatesprite_fs((260)<<16, 36<<16, 65536L, 0, PLUTOPAKSPRITE+2, 0, 0, 2+8);
gametext_center(58+2, GStrings("Multiplayer Totals")); gametext_center(58+2, GStrings("Multiplayer Totals"));
gametext_center(58+10, g_mapInfo[G_LastMapInfoIndex()].name); gametext_center(58+10, mapList[G_LastMapInfoIndex()].DisplayName());
gametext_center_shade(165, GStrings("Presskey"), quotepulseshade); gametext_center_shade(165, GStrings("Presskey"), quotepulseshade);
@ -1951,11 +1953,11 @@ static int32_t G_PrintTime_ClockPad(void)
clockpad = max(clockpad, ij); clockpad = max(clockpad, ij);
if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0])) if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0]))
{ {
for (ii=g_mapInfo[G_LastMapInfoIndex()].partime/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) { } for (ii=mapList[G_LastMapInfoIndex()].parTime/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) { }
clockpad = max(clockpad, ij); clockpad = max(clockpad, ij);
if (!NAM_WW2GI && g_mapInfo[G_LastMapInfoIndex()].designertime) if (!NAM_WW2GI && mapList[G_LastMapInfoIndex()].designerTime)
{ {
for (ii=g_mapInfo[G_LastMapInfoIndex()].designertime/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) { } for (ii= mapList[G_LastMapInfoIndex()].designerTime/(REALGAMETICSPERSEC*60), ij=1; ii>9; ii/=10, ij++) { }
clockpad = max(clockpad, ij); clockpad = max(clockpad, ij);
} }
} }
@ -1984,13 +1986,13 @@ const char* G_PrintParTime(void)
{ {
if (ud.last_level < 1) if (ud.last_level < 1)
return "<invalid>"; return "<invalid>";
return G_PrintTime2(g_mapInfo[G_LastMapInfoIndex()].partime); return G_PrintTime2(mapList[G_LastMapInfoIndex()].parTime);
} }
const char* G_PrintDesignerTime(void) const char* G_PrintDesignerTime(void)
{ {
if (ud.last_level < 1) if (ud.last_level < 1)
return "<invalid>"; return "<invalid>";
return G_PrintTime2(g_mapInfo[G_LastMapInfoIndex()].designertime); return G_PrintTime2(mapList[G_LastMapInfoIndex()].designerTime);
} }
const char* G_PrintBestTime(void) const char* G_PrintBestTime(void)
{ {
@ -2002,7 +2004,7 @@ void G_BonusScreen(int32_t bonusonly)
int32_t gfx_offset; int32_t gfx_offset;
int32_t bonuscnt; int32_t bonuscnt;
int32_t clockpad = 2; int32_t clockpad = 2;
char *lastmapname; const char *lastmapname;
if (g_networkMode == NET_DEDICATED_SERVER) if (g_networkMode == NET_DEDICATED_SERVER)
return; return;
@ -2015,9 +2017,9 @@ void G_BonusScreen(int32_t bonusonly)
} }
else else
{ {
lastmapname = g_mapInfo[G_LastMapInfoIndex()].name; lastmapname = mapList[G_LastMapInfoIndex()].name;
if (!lastmapname) // this isn't right but it's better than no name at all if (!lastmapname || !*lastmapname) // this isn't right but it's better than no name at all
lastmapname = g_mapInfo[G_LastMapInfoIndex()].name; lastmapname = mapList[G_LastMapInfoIndex()].fileName;
} }
@ -2183,12 +2185,12 @@ void G_BonusScreen(int32_t bonusonly)
yy+=10; yy+=10;
if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0])) if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0]))
{ {
if (g_mapInfo[G_LastMapInfoIndex()].partime) if (mapList[G_LastMapInfoIndex()].parTime)
{ {
gametext(10, yy+9, GStrings("TXT_ParTime")); gametext(10, yy+9, GStrings("TXT_ParTime"));
yy+=10; yy+=10;
} }
if (!NAM_WW2GI && !DUKEBETA && g_mapInfo[G_LastMapInfoIndex()].designertime) if (!NAM_WW2GI && !DUKEBETA && mapList[G_LastMapInfoIndex()].designerTime)
{ {
// EDuke 2.0 / NAM source suggests "Green Beret's Time:" // EDuke 2.0 / NAM source suggests "Green Beret's Time:"
gametext(10, yy+9, GStrings("TXT_3DRTIME")); gametext(10, yy+9, GStrings("TXT_3DRTIME"));
@ -2227,13 +2229,13 @@ void G_BonusScreen(int32_t bonusonly)
if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0])) if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0]))
{ {
if (g_mapInfo[G_LastMapInfoIndex()].partime) if (mapList[G_LastMapInfoIndex()].parTime)
{ {
G_PrintParTime(); G_PrintParTime();
gametext_number((320>>2)+71, yy+9, tempbuf); gametext_number((320>>2)+71, yy+9, tempbuf);
yy+=10; yy+=10;
} }
if (!NAM_WW2GI && !DUKEBETA && g_mapInfo[G_LastMapInfoIndex()].designertime) if (!NAM_WW2GI && !DUKEBETA && mapList[G_LastMapInfoIndex()].designerTime)
{ {
G_PrintDesignerTime(); G_PrintDesignerTime();
gametext_number((320>>2)+71, yy+9, tempbuf); gametext_number((320>>2)+71, yy+9, tempbuf);

View file

@ -106,12 +106,10 @@ extern void G_SaveMapState();
extern void G_RestoreMapState(); extern void G_RestoreMapState();
typedef struct { typedef struct {
int32_t partime, designertime;
char *name, *filename, *musicfn;
mapstate_t *savedstate; mapstate_t *savedstate;
} map_t; } map_t;
//extern map_t g_mapInfo[(MAXVOLUMES+1)*MAXLEVELS]; // +1 volume for "intro", "briefing" music
void G_ActivateBySector(int sect,int spriteNum); void G_ActivateBySector(int sect,int spriteNum);
int S_FindMusicSFX(int sectNum, int *sndptr); int S_FindMusicSFX(int sectNum, int *sndptr);

View file

@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "al_midi.h" #include "al_midi.h"
#include "openaudio.h" #include "openaudio.h"
#include "z_music.h" #include "z_music.h"
#include "mapinfo.h"
#include <atomic> #include <atomic>
BEGIN_DUKE_NS BEGIN_DUKE_NS
@ -147,15 +148,15 @@ void S_PlayLevelMusicOrNothing(unsigned int m)
if (retval >= 0) if (retval >= 0)
{ {
Mus_Play(g_mapInfo[m].filename, g_mapInfo[m].musicfn, true); Mus_Play(mapList[m].fileName, mapList[m].music, true);
S_SetMusicIndex(m); S_SetMusicIndex(m);
} }
} }
int S_TryPlaySpecialMusic(unsigned int m) int S_TryPlaySpecialMusic(unsigned int m)
{ {
char const * musicfn = g_mapInfo[m].musicfn; auto &musicfn = mapList[m].music;
if (musicfn != NULL) if (musicfn.IsNotEmpty())
{ {
if (!Mus_Play(nullptr, musicfn, true)) if (!Mus_Play(nullptr, musicfn, true))
{ {