From 4f04fe66de0c6ba6e5992e3bb5ca6fdfbd4e08ec Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 10 Dec 2019 00:31:55 +0100 Subject: [PATCH] - transitioned RR to the new mapinfo --- source/common/textures/buildtiles.cpp | 5 +- source/duke3d/src/savegame.cpp | 42 ++-- source/rr/src/cheats.cpp | 3 +- source/rr/src/game.cpp | 11 +- source/rr/src/gamedef.cpp | 26 +- source/rr/src/net.cpp | 336 +------------------------- source/rr/src/osdcmds.cpp | 3 +- source/rr/src/premap.cpp | 78 +++--- source/rr/src/savegame.cpp | 21 +- source/rr/src/screens.cpp | 58 ++--- source/rr/src/sector.h | 3 - source/rr/src/sounds.cpp | 7 +- 12 files changed, 115 insertions(+), 478 deletions(-) diff --git a/source/common/textures/buildtiles.cpp b/source/common/textures/buildtiles.cpp index bd21fafe7..1238ea97a 100644 --- a/source/common/textures/buildtiles.cpp +++ b/source/common/textures/buildtiles.cpp @@ -556,12 +556,15 @@ void artClearMapArt(void) //========================================================================== // -// Load map specfici ART +// Load map specficied ART // //========================================================================== +static FString currentMapArt; void artSetupMapArt(const char* filename) { + if (currentMapArt.CompareNoCase(filename)) return; + currentMapArt = filename; artClearMapArt(); FStringf firstname("%s_00.art", filename); diff --git a/source/duke3d/src/savegame.cpp b/source/duke3d/src/savegame.cpp index 6a7c1489b..1e2e30a17 100644 --- a/source/duke3d/src/savegame.cpp +++ b/source/duke3d/src/savegame.cpp @@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_DUKE_NS static OutputFileCounter savecounter; -char previousboardfilename[BMAX_PATH]; // For storing pointers in files. // back_p==0: ptr -> "small int" @@ -221,6 +220,8 @@ static int different_user_map; // XXX: keyboard input 'blocked' after load fail? (at least ESC?) int32_t G_LoadPlayer(FSaveGameNode *sv) { + char workbuffer[BMAX_PATH]; + if (sv->bIsExt) { int volume = -1; @@ -318,19 +319,17 @@ int32_t G_LoadPlayer(FSaveGameNode *sv) int const mapIdx = volume*MAXLEVELS + level; if (boardfilename[0]) - strcpy(currentboardfilename, boardfilename); + strcpy(workbuffer, boardfilename); else if (mapList[mapIdx].fileName.IsNotEmpty()) - strcpy(currentboardfilename, mapList[mapIdx].fileName); + strcpy(workbuffer, mapList[mapIdx].fileName); - if (currentboardfilename[0]) + if (workbuffer[0]) { // only setup art if map differs from previous - if (!previousboardfilename[0] || Bstrcmp(previousboardfilename, currentboardfilename)) - artSetupMapArt(currentboardfilename); - Bstrcpy(previousboardfilename, currentboardfilename); - append_ext_UNSAFE(currentboardfilename, ".mhk"); - engineLoadMHK(currentboardfilename); + artSetupMapArt(workbuffer); + append_ext_UNSAFE(workbuffer, ".mhk"); + engineLoadMHK(workbuffer); } currentboardfilename[0] = '\0'; @@ -519,20 +518,19 @@ int32_t G_LoadPlayer(FSaveGameNode *sv) int const mapIdx = h.volnum*MAXLEVELS + h.levnum; - if (boardfilename[0]) - strcpy(currentboardfilename, boardfilename); - else if (mapList[mapIdx].fileName.IsNotEmpty()) - strcpy(currentboardfilename, mapList[mapIdx].fileName); + if (boardfilename[0]) + strcpy(workbuffer, boardfilename); + else if (mapList[mapIdx].fileName.IsNotEmpty()) + strcpy(workbuffer, mapList[mapIdx].fileName); - if (currentboardfilename[0]) - { - // only setup art if map differs from previous - if (!previousboardfilename[0] || Bstrcmp(previousboardfilename, currentboardfilename)) - artSetupMapArt(currentboardfilename); - Bstrcpy(previousboardfilename, currentboardfilename); - append_ext_UNSAFE(currentboardfilename, ".mhk"); - engineLoadMHK(currentboardfilename); - } + + if (workbuffer[0]) + { + // only setup art if map differs from previous + artSetupMapArt(workbuffer); + append_ext_UNSAFE(workbuffer, ".mhk"); + engineLoadMHK(workbuffer); + } Bmemcpy(currentboardfilename, boardfilename, BMAX_PATH); diff --git a/source/rr/src/cheats.cpp b/source/rr/src/cheats.cpp index bfdda7e15..3c01dea68 100644 --- a/source/rr/src/cheats.cpp +++ b/source/rr/src/cheats.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "duke3d.h" #include "osdcmds.h" #include "cheats.h" +#inclide "mapinfo.h" BEGIN_RR_NS @@ -554,7 +555,7 @@ void G_DoCheats(void) int32_t const volnume = ud.m_volume_number, levnume = m_level_number; 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.level_number = levnume; diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index 0dff6a3d7..72afda81e 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------- +//------------------------------------------------------------------------- /* Copyright (C) 2016 EDuke32 developers and contributors @@ -47,6 +47,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "filesystem/filesystem.h" #include "statistics.h" #include "c_dispatch.h" +#include "mapinfo.h" // Uncomment to prevent anything except mirrors from drawing. It is sensible to // also uncomment ENGINE_CLEAR_SCREEN in build/src/engine_priv.h. @@ -6366,8 +6367,8 @@ static int32_t S_DefineMusic(const char *ID, const char *name) if (sel < 0) return -1; } - - return S_DefineAudioIfSupported(&g_mapInfo[sel].musicfn, name); + mapList[sel].music = name; + return 0; } static int parsedefinitions_game(scriptfile *, int); @@ -6798,10 +6799,6 @@ static void G_Cleanup(void) for (i=(MAXLEVELS*(MAXVOLUMES+1))-1; i>=0; i--) // +1 volume for "intro", "briefing" music { - Bfree(g_mapInfo[i].name); - Bfree(g_mapInfo[i].filename); - Bfree(g_mapInfo[i].musicfn); - G_FreeMapState(i); } diff --git a/source/rr/src/gamedef.cpp b/source/rr/src/gamedef.cpp index 6941e90a9..582bdc011 100644 --- a/source/rr/src/gamedef.cpp +++ b/source/rr/src/gamedef.cpp @@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "printf.h" #include "menu/menu.h" #include "stringtable.h" +#include "mapinfo.h" BEGIN_RR_NS @@ -886,10 +887,7 @@ void C_DefineMusic(int volumeNum, int levelNum, const char *fileName) Bassert((unsigned)volumeNum < MAXVOLUMES+1); Bassert((unsigned)levelNum < MAXLEVELS); - map_t *const pMapInfo = &g_mapInfo[(MAXLEVELS*volumeNum)+levelNum]; - - Bfree(pMapInfo->musicfn); - pMapInfo->musicfn = dup_filename(fileName); + mapList[(MAXLEVELS*volumeNum)+levelNum].music = fileName; } void C_DefineVolumeFlags(int32_t vol, int32_t flags) @@ -1873,16 +1871,11 @@ static int32_t C_ParseCommand(int32_t loop) Bcorrectfilename(tempbuf,0); - if (g_mapInfo[j *MAXLEVELS+k].filename == NULL) - 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); + mapList[j *MAXLEVELS+k].fileName = tempbuf; C_SkipComments(); - g_mapInfo[j *MAXLEVELS+k].partime = + mapList[j *MAXLEVELS+k].parTime = (((*(textptr+0)-'0')*10+(*(textptr+1)-'0'))*REALGAMETICSPERSEC*60)+ (((*(textptr+3)-'0')*10+(*(textptr+4)-'0'))*REALGAMETICSPERSEC); @@ -1892,7 +1885,7 @@ static int32_t C_ParseCommand(int32_t loop) // cheap hack, 0.99 doesn't have the 3D Realms time if (*(textptr+2) == ':') { - g_mapInfo[j *MAXLEVELS+k].designertime = + mapList[j *MAXLEVELS+k].designerTime = (((*(textptr+0)-'0')*10+(*(textptr+1)-'0'))*REALGAMETICSPERSEC*60)+ (((*(textptr+3)-'0')*10+(*(textptr+4)-'0'))*REALGAMETICSPERSEC); @@ -1919,14 +1912,7 @@ static int32_t C_ParseCommand(int32_t loop) tempbuf[i] = '\0'; - if (g_mapInfo[j*MAXLEVELS+k].name == NULL) - 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); + mapList[j *MAXLEVELS+k].name = tempbuf; continue; diff --git a/source/rr/src/net.cpp b/source/rr/src/net.cpp index edeb400a5..993283e75 100644 --- a/source/rr/src/net.cpp +++ b/source/rr/src/net.cpp @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "savegame.h" #include "input.h" #include "m_crc32.h" +#include "mapinfo.h" #include "enet.h" @@ -2359,340 +2360,7 @@ void Net_ParsePacket(uint8_t *packbuf, int packbufleng) //case PACKET_TYPE_QUIT: // G_GameExit(" "); // break; -#if 0 - default: - switch (packbuf[0]) - { - case PACKET_TYPE_MESSAGE: - //slaves in M/S mode only send to master - if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - { - if (packbuf[1] == 255) - { - //Master re-transmits message to all others - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) - Net_SendPacket(i,packbuf,packbufleng); - } - else if (((int)packbuf[1]) != myconnectindex) - { - //Master re-transmits message not intended for master - Net_SendPacket((int)packbuf[1],packbuf,packbufleng); - break; - } - } - Bstrcpy(recbuf,(char*)packbuf+2); - recbuf[packbufleng-2] = 0; - - G_AddUserQuote(recbuf); - S_PlaySound(EXITMENUSOUND); - - pus = NUMPAGES; - pub = NUMPAGES; - - break; - - case PACKET_TYPE_NEW_GAME: - //Slaves in M/S mode only send to master - //Master re-transmits message to all others - if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) Net_SendPacket(i,packbuf,packbufleng); - - if (vote_map != -1 || vote_episode != -1 || voting != -1) - G_AddUserQuote("VOTE SUCCEEDED"); - - m_level_number = ud.level_number = packbuf[1]; - ud.m_volume_number = ud.volume_number = packbuf[2]; - ud.m_player_skill = ud.player_skill = packbuf[3]; - - // Non-menu variables handled by G_EnterLevel - ud.m_monsters_off = packbuf[4]; - ud.m_respawn_monsters = packbuf[5]; - ud.m_respawn_items = packbuf[6]; - ud.m_respawn_inventory = packbuf[7]; - m_coop = packbuf[8]; - m_marker = packbuf[9]; - m_ffire = packbuf[10]; - m_noexits = packbuf[11]; - //ud.m_weaponstay = packbuf[12]; - - for (int TRAVERSE_CONNECT(i)) - { - P_ResetWeapons(i); - P_ResetInventory(i); - } - - G_NewGame(ud.volume_number,ud.level_number,ud.player_skill); - - if (G_EnterLevel(MODE_GAME)) G_BackToMenu(); - - break; - - case PACKET_TYPE_INIT_SETTINGS: - //Slaves in M/S mode only send to master - //Master re-transmits message to all others - if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - for (i = connectpoint2[connecthead]; i >= 0; i = connectpoint2[i]) - if (i != other) Net_SendPacket(i, packbuf, packbufleng); - - m_level_number = ud.level_number = packbuf[1]; - ud.m_volume_number = ud.volume_number = packbuf[2]; - ud.m_player_skill = ud.player_skill = packbuf[3]; - - // Non-menu variables handled by G_EnterLevel - ud.m_monsters_off = packbuf[4]; - ud.m_respawn_monsters = packbuf[5]; - ud.m_respawn_items = packbuf[6]; - ud.m_respawn_inventory = packbuf[7]; - m_coop = packbuf[8]; - m_marker = packbuf[9]; - m_ffire = packbuf[10]; - m_noexits = packbuf[11]; - //ud.m_weaponstay = packbuf[12]; - break; - - case PACKET_TYPE_VERSION: - //slaves in M/S mode only send to master - //Master re-transmits message to all others - if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) Net_SendPacket(i,packbuf,packbufleng); - - if (packbuf[2] != (char)atoi(s_buildDate)) - { - initprintf("Player has version %d, expecting %d\n",packbuf[2],(char)atoi(s_buildDate)); - G_GameExit("You cannot play with different versions of EDuke32!"); - } - if (packbuf[3] != (char)BYTEVERSION) - { - initprintf("Player has version %d, expecting %d (%d, %d, %d)\n",packbuf[3],BYTEVERSION, NETVERSION, PLUTOPAK, VOLUMEONE); - G_GameExit("You cannot play Duke with different versions!"); - } - if (packbuf[4] > g_numSyncBytes) - { - initprintf("Sync debugging enabled\n"); - g_numSyncBytes = packbuf[4]; - } - - break; - - case PACKET_TYPE_PLAYER_OPTIONS: - //slaves in M/S mode only send to master - //Master re-transmits message to all others - if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) Net_SendPacket(i,packbuf,packbufleng); - - other = packbuf[1]; - i = 2; - - g_player[other].ps->aim_mode = packbuf[i++]; - g_player[other].ps->auto_aim = packbuf[i++]; - g_player[other].ps->weaponswitch = packbuf[i++]; - g_player[other].ps->palookup = g_player[other].pcolor = packbuf[i++]; - g_player[other].pteam = packbuf[i++]; - - break; - - //case PACKET_TYPE_FRAGLIMIT_CHANGED: - // //slaves in M/S mode only send to master - // //Master re-transmits message to all others - // if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - // for (i = connectpoint2[connecthead];i >= 0;i = connectpoint2[i]) - // if (i != other) Net_SendPacket(i, packbuf, packbufleng); - // - // ud.fraglimit = packbuf[2]; - // - // Bsprintf(tempbuf, "FRAGLIMIT CHANGED TO %d", ud.fraglimit); - // G_AddUserQuote(tempbuf); - // break; - - case PACKET_TYPE_EOL: - if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) Net_SendPacket(i,packbuf,packbufleng); - - for (TRAVERSE_CONNECT(i)) - g_player[i].ps->gm = MODE_EOL; - - ud.level_number = packbuf[1]; - m_level_number = ud.level_number; - ud.from_bonus = packbuf[2]; - break; - - case PACKET_TYPE_PLAYER_NAME: - //slaves in M/S mode only send to master - //Master re-transmits message to all others - if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) Net_SendPacket(i,packbuf,packbufleng); - - other = packbuf[1]; - - for (i=2;packbuf[i];i++) - g_player[other].user_name[i-2] = packbuf[i]; - g_player[other].user_name[i-2] = 0; - i++; - - initprintf("Player %d's name is now %s\n", other, g_player[other].user_name); - - break; - - case PACKET_TYPE_WEAPON_CHOICE: - //slaves in M/S mode only send to master - //Master re-transmits message to all others - if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) Net_SendPacket(i,packbuf,packbufleng); - - other = packbuf[1]; - - i = 2; - - j = i; //This used to be Duke packet #9... now concatenated with Duke packet #6 - for (;i-j<10;i++) g_player[other].wchoice[i-j] = packbuf[i]; - - break; - case PACKET_TYPE_RTS: - //slaves in M/S mode only send to master - //Master re-transmits message to all others - if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) Net_SendPacket(i,packbuf,packbufleng); - - G_StartRTS(packbuf[1], other); - break; - - case PACKET_TYPE_MENU_LEVEL_QUIT: - //slaves in M/S mode only send to master - if (myconnectindex == connecthead) - { - //Master re-transmits message to all others - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) - Net_SendPacket(i,packbuf,packbufleng); - } - - G_GameExit("Game aborted from menu; disconnected."); - - break; - - case PACKET_TYPE_USER_MAP: - //slaves in M/S mode only send to master - if (myconnectindex == connecthead) - { - //Master re-transmits message to all others - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) - Net_SendPacket(i,packbuf,packbufleng); - } - - Bstrcpy(boardfilename,(char*)packbuf+1); - boardfilename[packbufleng-1] = 0; - Bcorrectfilename(boardfilename,0); - if (boardfilename[0] != 0) - { - if (fileSystem.FileExists(boardfilename,0)) - { - Bmemset(boardfilename,0,sizeof(boardfilename)); - Net_SendUserMapName(); - } - } - - if (m_level_number == 7 && ud.m_volume_number == 0 && boardfilename[0] == 0) - m_level_number = 0; - - break; - - case PACKET_TYPE_MAP_VOTE: - case PACKET_TYPE_MAP_VOTE_INITIATE: - case PACKET_TYPE_MAP_VOTE_CANCEL: - - if (myconnectindex == connecthead) - { - //Master re-transmits message to all others - for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - if (i != other) - Net_SendPacket(i,packbuf,packbufleng); - } - - switch (packbuf[0]) - { - case PACKET_TYPE_MAP_VOTE: - if (voting == myconnectindex && g_player[packbuf[1]].gotvote == 0) - { - g_player[packbuf[1]].gotvote = 1; - g_player[packbuf[1]].vote = packbuf[2]; - Bsprintf(tempbuf,"Confirmed vote from %s",g_player[packbuf[1]].user_name); - G_AddUserQuote(tempbuf); - } - break; - - case PACKET_TYPE_MAP_VOTE_INITIATE: // call map vote - /* if (g_networkBroadcastMode == 0 && packbuf[1] == connecthead) - break; // ignore this from master */ - voting = packbuf[1]; - vote_episode = packbuf[2]; - vote_map = packbuf[3]; - - Bsprintf(tempbuf,"%s^00 HAS CALLED A VOTE TO CHANGE MAP TO %s (E%dL%d)", - g_player[packbuf[1]].user_name, - g_mapInfo[(unsigned char)(packbuf[2]*MAXLEVELS + packbuf[3])].name, - packbuf[2]+1,packbuf[3]+1); - G_AddUserQuote(tempbuf); - - Bsprintf(tempbuf,"Press F1 to Accept, F2 to Decline"); - G_AddUserQuote(tempbuf); - - for (i=MAXPLAYERS-1;i>=0;i--) - { - g_player[i].vote = 0; - g_player[i].gotvote = 0; - } - g_player[voting].gotvote = g_player[voting].vote = 1; - break; - - case PACKET_TYPE_MAP_VOTE_CANCEL: // cancel map vote - if (voting == packbuf[1]) - { - voting = -1; - i = 0; - for (j=MAXPLAYERS-1;j>=0;j--) - i += g_player[j].gotvote; - - if (i != numplayers) - Bsprintf(tempbuf,"%s^00 has canceled the vote",g_player[(unsigned char)packbuf[1]].user_name); - else Bsprintf(tempbuf,"Vote failed"); - for (i=MAXPLAYERS-1;i>=0;i--) - { - g_player[i].vote = 0; - g_player[i].gotvote = 0; - } - G_AddUserQuote(tempbuf); - } - break; - } - break; - - //case PACKET_TYPE_LOAD_GAME: - // //Slaves in M/S mode only send to master - // //Master re-transmits message to all others - // if ((!g_networkBroadcastMode) && (myconnectindex == connecthead)) - // for (i=connectpoint2[connecthead];i>=0;i=connectpoint2[i]) - // if (i != other) Net_SendPacket(i,packbuf,packbufleng); - // - // multiflag = 2; - // multiwhat = 0; - // multiwho = packbuf[2]; //other: need to send in m/s mode because of possible re-transmit - // multipos = packbuf[1]; - // G_LoadPlayer(multipos); - // multiflag = 0; - // break; - } - break; -#endif } } @@ -3849,7 +3517,7 @@ void Net_ReceiveMapVoteInitiate(uint8_t *pbuf) Bsprintf(tempbuf,"%s^00 has called a vote to change map to %s (E%dL%d)", g_player[voting].user_name, - g_mapInfo[(uint8_t)(vote_episode*MAXLEVELS + vote_map)].name, + mapList[(uint8_t)(vote_episode*MAXLEVELS + vote_map)].DisplayName(), vote_episode+1,vote_map+1); G_AddUserQuote(tempbuf); diff --git a/source/rr/src/osdcmds.cpp b/source/rr/src/osdcmds.cpp index c30c5cd63..1c57d4316 100644 --- a/source/rr/src/osdcmds.cpp +++ b/source/rr/src/osdcmds.cpp @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "osdcmds.h" #include "savegame.h" #include "sbar.h" +#include "mapinfo.h" BEGIN_RR_NS @@ -68,7 +69,7 @@ static int osdcmd_changelevel(osdcmdptr_t parm) } } - if (level > MAXLEVELS || g_mapInfo[volume *MAXLEVELS+level].filename == NULL) + if (level > MAXLEVELS || mapList *MAXLEVELS+level].fileName.IsEmpty) { OSD_Printf("changelevel: invalid level number\n"); return OSDCMD_SHOWHELP; diff --git a/source/rr/src/premap.cpp b/source/rr/src/premap.cpp index f06317f25..2edc60e0c 100644 --- a/source/rr/src/premap.cpp +++ b/source/rr/src/premap.cpp @@ -29,6 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "cmdline.h" #include "statistics.h" #include "menu/menu.h" +#include "mapinfo.h" +#include "cmdlib.h" BEGIN_RR_NS @@ -504,14 +506,13 @@ static void G_DoLoadScreen(const char *statustext, int32_t percent) } else if (RR && g_lastLevel) { - menutext_center(textY,GStrings("ENTERIN")); + menutext_center(textY,GStrings("TXT_ENTERIN")); menutext_center(textY+16+8,GStrings("TXT_CLOSEENCOUNTERS")); } else { menutext_center(textY, RR ? GStrings("TXT_ENTERIN") : GStrings("TXT_LOADING")); - if (g_mapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name != NULL) - menutext_center(textY+16+8,g_mapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name); + menutext_center(textY+16+8,mapList[(ud.volume_number*MAXLEVELS) + ud.level_number].DisplayName()); } #ifndef EDUKE32_TOUCH_DEVICES @@ -2179,10 +2180,7 @@ int G_FindLevelByFile(const char *fileName) for (bssize_t levelNum = 0; levelNum < MAXLEVELS; levelNum++) { - if (g_mapInfo[volOffset + levelNum].filename == NULL) - continue; - - if (!Bstrcasecmp(fileName, g_mapInfo[volOffset + levelNum].filename)) + if (!mapList[volOffset + levelNum].fileName.CompareNoCase(fileName)) return volOffset + levelNum; } } @@ -2249,20 +2247,18 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName, int levelNum { char *p; char const *exts[] = { -#ifdef HAVE_FLAC "flac", -#endif -#ifdef HAVE_VORBIS "ogg", -#endif -#ifdef HAVE_XMP + "mp3", "xm", "mod", "it", "s3m", "mtm", -#endif - "mid" + "mid", + "hmp", + "hmi", + "xmi" }; Bstrncpy(nameBuf, fileName, BMAX_PATH); @@ -2279,14 +2275,14 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName, int levelNum { Bmemcpy(p+1, ext, Bstrlen(ext) + 1); - if (fileSystem.FileExists(nameBuf)) - { - realloc_copy(&g_mapInfo[levelNum].musicfn, nameBuf); + if (FileExists(nameBuf)) + { + mapList[levelNum].music = nameBuf; return; } } - realloc_copy(&g_mapInfo[levelNum].musicfn, "dethtoll.mid"); + mapList[levelNum].music = "dethtoll.mid"; } int G_EnterLevel(int gameMode) @@ -2342,22 +2338,19 @@ int G_EnterLevel(int gameMode) } mii = (ud.volume_number*MAXLEVELS)+ud.level_number; + auto &mi = mapList[mii]; - if (g_mapInfo[mii].name == NULL || g_mapInfo[mii].filename == NULL) + if ( mi.name.IsEmpty() || mi.fileName.IsEmpty()) { if (RR && g_lastLevel) { - if (g_mapInfo[mii].filename == NULL) - g_mapInfo[mii].filename = (char *)Xcalloc(BMAX_PATH, sizeof(uint8_t)); - if (g_mapInfo[mii].name == NULL) - g_mapInfo[mii].name = Xstrdup("CLOSE ENCOUNTERS"); + // FIXME: Initialize this properly in the data structures! + mi.fileName = "endgame.map"; + mi.name = "$TXT_CLOSEENCOUNTERS"; } else if (Menu_HaveUserMap()) { - if (g_mapInfo[mii].filename == NULL) - g_mapInfo[mii].filename = (char *)Xcalloc(BMAX_PATH, sizeof(uint8_t)); - if (g_mapInfo[mii].name == NULL) - g_mapInfo[mii].name = Xstrdup("User Map"); + mi.name = "$TXT_USERMAP"; } else { @@ -2378,18 +2371,7 @@ int G_EnterLevel(int gameMode) DukePlayer_t *const pPlayer = g_player[0].ps; int16_t lbang; - if (RR && g_lastLevel) - { - if (engineLoadBoard("endgame.map", 0, &pPlayer->pos, &lbang, &pPlayer->cursectnum) < 0) - { - OSD_Printf(OSD_ERROR "Map \"endgame.map\" not found or invalid map version!\n"); - return 1; - } - - G_LoadMapHack(levelName, "endgame.map"); - G_SetupFilenameBasedMusic(levelName, "endgame.map", m_level_number); - } - else if (!VOLUMEONE && Menu_HaveUserMap()) + if (!VOLUMEONE && Menu_HaveUserMap()) { if (engineLoadBoard(boardfilename, 0, &pPlayer->pos, &lbang, &pPlayer->cursectnum) < 0) { @@ -2401,15 +2383,15 @@ int G_EnterLevel(int gameMode) G_LoadMapHack(levelName, boardfilename); G_SetupFilenameBasedMusic(levelName, boardfilename, m_level_number); } - else if (engineLoadBoard(g_mapInfo[mii].filename, VOLUMEONE, &pPlayer->pos, &lbang, &pPlayer->cursectnum) < 0) + else if (engineLoadBoard(mi.fileName, VOLUMEONE, &pPlayer->pos, &lbang, &pPlayer->cursectnum) < 0) { - OSD_Printf(OSD_ERROR "Map \"%s\" not found or invalid map version!\n", g_mapInfo[mii].filename); + OSD_Printf(OSD_ERROR "Map \"%s\" not found or invalid map version!\n", mi.fileName.GetChars()); return 1; } else { - STAT_NewLevel(g_mapInfo[mii].filename); - G_LoadMapHack(levelName, g_mapInfo[mii].filename); + STAT_NewLevel(mi.fileName); + G_LoadMapHack(levelName, mi.fileName); } if (RR && !RRRA && ud.volume_number == 1 && ud.level_number == 1) @@ -2444,7 +2426,7 @@ int G_EnterLevel(int gameMode) G_AlignWarpElevators(); resetpspritevars(gameMode); - ud.playerbest = CONFIG_GetMapBestTime(Menu_HaveUserMap() ? boardfilename : g_mapInfo[mii].filename, g_loadedMapHack.md4); + ud.playerbest = CONFIG_GetMapBestTime(Menu_HaveUserMap() ? boardfilename : mi.fileName.GetChars(), g_loadedMapHack.md4); // G_FadeLoad(0,0,0, 252,0, -28, 4, -1); G_CacheMapData(); @@ -2452,9 +2434,9 @@ int G_EnterLevel(int gameMode) if (ud.recstat != 2) { - if (g_mapInfo[g_musicIndex].musicfn == NULL || - g_mapInfo[mii].musicfn == NULL || // intentional, to pass control further while avoiding the strcmp on null - strcmp(g_mapInfo[g_musicIndex].musicfn, g_mapInfo[mii].musicfn) || + if (mapList[g_musicIndex].music.IsEmpty() || + mi.music.IsEmpty() || + mi.music.CompareNoCase(mapList[g_musicIndex].music) || g_musicSize == 0 || ud.last_level == -1) { @@ -2545,7 +2527,7 @@ int G_EnterLevel(int gameMode) else { OSD_Printf(OSDTEXT_YELLOW "E%dL%d: %s\n", ud.volume_number+1, ud.level_number+1, - g_mapInfo[mii].name); + mapList[mii].DisplayName()); } g_restorePalette = -1; diff --git a/source/rr/src/savegame.cpp b/source/rr/src/savegame.cpp index 5ee8113ad..7838c98c5 100644 --- a/source/rr/src/savegame.cpp +++ b/source/rr/src/savegame.cpp @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "gamecontrol.h" #include "version.h" #include "z_music.h" +#include "mapinfo.h" #include "savegamehelp.h" BEGIN_RR_NS @@ -273,17 +274,17 @@ int32_t G_LoadPlayer(const char *path) Bmemcpy(boardfilename, h.boardfn, sizeof(boardfilename)); int const mapIdx = h.volnum*MAXLEVELS + h.levnum; - + char workbuffer[BMAX_PATH]; if (boardfilename[0]) - Bstrcpy(currentboardfilename, boardfilename); - else if (g_mapInfo[mapIdx].filename) - Bstrcpy(currentboardfilename, g_mapInfo[mapIdx].filename); + Bstrcpy(workbuffer, boardfilename); + else + Bstrcpy(workbuffer, mapList[mapIdx].fileName); - if (currentboardfilename[0]) + if (workbuffer[0]) { - artSetupMapArt(currentboardfilename); - append_ext_UNSAFE(currentboardfilename, ".mhk"); - engineLoadMHK(currentboardfilename); + artSetupMapArt(workbuffer); + append_ext_UNSAFE(workbuffer, ".mhk"); + engineLoadMHK(workbuffer); } Bmemcpy(currentboardfilename, boardfilename, BMAX_PATH); @@ -1169,8 +1170,8 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i auto fw = WriteSavegameChunk("header.dat"); fw->Write(&h, sizeof(savehead_t)); - auto& mi = g_mapInfo[(MAXLEVELS * ud.volume_number) + ud.level_number]; - G_WriteSaveHeader(name, mi.filename, mi.name); + auto& mi = mapList[(MAXLEVELS * ud.volume_number) + ud.level_number]; + G_WriteSaveHeader(name, mi.fileName, mi.DisplayName()); } else { diff --git a/source/rr/src/screens.cpp b/source/rr/src/screens.cpp index 409da64aa..1d1d95ba1 100644 --- a/source/rr/src/screens.cpp +++ b/source/rr/src/screens.cpp @@ -33,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "mdsprite.h" #include "gamecvars.h" #include "menu/menu.h" +#include "mapinfo.h" BEGIN_RR_NS @@ -175,7 +176,7 @@ static void G_ShowScores(void) if (g_mostConcurrentPlayers > 1 && (g_gametypeFlags[ud.coop]&GAMETYPE_SCORESHEET)) { 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; minitext(70, SCORESHEETOFFSET+80, GStrings("Name"), 8, 2+8+16+ROTATESPRITE_MAX); @@ -994,7 +995,7 @@ void G_DisplayRest(int32_t smoothratio) { if (!G_HaveUserMap()) minitext(5, a+6, GStrings.localize(gVolumeNames[ud.volume_number]), 0, 2+8+16+256); - minitext(5, a+6+6, g_mapInfo[ud.volume_number*MAXLEVELS + ud.level_number].name, 0, 2+8+16+256); + minitext(5, a+6+6, mapList[ud.volume_number*MAXLEVELS + ud.level_number].DisplayName(), 0, 2+8+16+256); } } } @@ -1024,12 +1025,12 @@ void G_DisplayRest(int32_t smoothratio) else if (g_levelTextTime < 5) o |= 1; - if (g_mapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name != NULL) + if (mapList[(ud.volume_number*MAXLEVELS) + ud.level_number].name.IsNotEmpty()) { char const * const fn = currentboardfilename[0] != 0 && ud.volume_number == 0 && ud.level_number == 7 ? currentboardfilename - : g_mapInfo[(ud.volume_number*MAXLEVELS) + ud.level_number].name; + : mapList[(ud.volume_number*MAXLEVELS) + ud.level_number].DisplayName(); menutext_(160<<16, (90+16+8)<<16, -g_levelTextTime+22/*quotepulseshade*/, fn, o, TEXT_XCENTER); } @@ -1118,7 +1119,7 @@ void G_DisplayRest(int32_t smoothratio) { Bsprintf(tempbuf, "%s^00 has called a vote for map", g_player[voting].user_name); 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(70, "Press F1 to Accept, F2 to Decline"); } @@ -1911,7 +1912,7 @@ static void G_DisplayMPResultsScreen(void) if (!RR && PLUTOPAK) // JBF 20030804 rotatesprite_fs((260)<<16, 36<<16, 65536L, 0, PLUTOPAKSPRITE+2, 0, 0, 2+8); gametext_center(58+(RR ? 0 : 2), GStrings("Multiplayer Totals")); - gametext_center(58+10, g_mapInfo[G_LastMapInfoIndex()].name); + gametext_center(58+10, mapList[G_LastMapInfoIndex()].DisplayName()); gametext_center_shade(RR ? 175 : 165, GStrings("Presskey"), quotepulseshade); @@ -1979,11 +1980,11 @@ static int32_t G_PrintTime_ClockPad(void) clockpad = max(clockpad, ij); 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); - if (g_mapInfo[G_LastMapInfoIndex()].designertime) + if (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); } } @@ -2012,13 +2013,13 @@ const char* G_PrintParTime(void) { if (ud.last_level < 1) return ""; - return G_PrintTime2(g_mapInfo[G_LastMapInfoIndex()].partime); + return G_PrintTime2(mapList[G_LastMapInfoIndex()].parTime); } const char* G_PrintDesignerTime(void) { if (ud.last_level < 1) return ""; - return G_PrintTime2(g_mapInfo[G_LastMapInfoIndex()].designertime); + return G_PrintTime2(mapList[G_LastMapInfoIndex()].designerTime); } const char* G_PrintBestTime(void) { @@ -2043,17 +2044,17 @@ void G_BonusScreen(int32_t bonusonly) } else { - lastmapname = g_mapInfo[G_LastMapInfoIndex()].name; - if (!lastmapname) // this isn't right but it's better than no name at all - lastmapname = g_mapInfo[G_LastMapInfoIndex()].name; + lastmapname = mapList[G_LastMapInfoIndex()].DisplayName(); + if (!lastmapname || !*lastmapname) // this isn't right but it's better than no name at all + lastmapname = mapList[G_LastMapInfoIndex()].fileName; } if (RR) { if ((g_lastLevel && ud.volume_number == 2) || g_vixenLevel) - lastmapname = "CLOSE ENCOUNTERS"; - else if (g_turdLevel) - lastmapname = "SMELTING PLANT"; + lastmapname = GStrings("TXT_CLOSEENCOUNTERS"); + else if (g_turdLevel) + lastmapname = GStrings("SMELTIN' PLANT"); } @@ -2256,7 +2257,7 @@ void G_BonusScreen(int32_t bonusonly) yy+= yystep; if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0])) { - if (g_mapInfo[G_LastMapInfoIndex()].partime) + if (mapList[G_LastMapInfoIndex()].parTime) { if (!RR) gametext(10, yy+9, GStrings("TXT_ParTime")); @@ -2264,7 +2265,7 @@ void G_BonusScreen(int32_t bonusonly) menutext(30, yy, GStrings("TXT_ParTime")); yy+=yystep; } - if (g_mapInfo[G_LastMapInfoIndex()].designertime) + if (mapList[G_LastMapInfoIndex()].designerTime) { // EDuke 2.0 / NAM source suggests "Green Beret's Time:" if (DUKE) @@ -2320,7 +2321,7 @@ void G_BonusScreen(int32_t bonusonly) 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(); if (!RR) @@ -2329,7 +2330,7 @@ void G_BonusScreen(int32_t bonusonly) menutext(191, yy, tempbuf); yy+=yystep; } - if (g_mapInfo[G_LastMapInfoIndex()].designertime) + if (mapList[G_LastMapInfoIndex()].designerTime) { G_PrintDesignerTime(); if (DUKE) @@ -2623,9 +2624,9 @@ void G_BonusScreenRRRA(int32_t bonusonly) } else { - lastmapname = g_mapInfo[G_LastMapInfoIndex()].name; - if (!lastmapname) // this isn't right but it's better than no name at all - lastmapname = g_mapInfo[G_LastMapInfoIndex()].name; + lastmapname = mapList[G_LastMapInfoIndex()].DisplayName(); + if (!lastmapname || !*lastmapname) // this isn't right but it's better than no name at all + lastmapname = mapList[G_LastMapInfoIndex()].fileName; } if ((g_lastLevel && ud.volume_number == 2) || g_vixenLevel) @@ -2826,12 +2827,12 @@ void G_BonusScreenRRRA(int32_t bonusonly) yy+= yystep; if (!(ud.volume_number == 0 && ud.last_level-1 == 7 && boardfilename[0])) { - if (g_mapInfo[G_LastMapInfoIndex()].partime) + if (mapList[G_LastMapInfoIndex()].parTime) { menutext(30, yy, GStrings("TXT_PARTIME")); yy+=yystep; } - if (g_mapInfo[G_LastMapInfoIndex()].designertime) + if (mapList[G_LastMapInfoIndex()].designerTime) { menutext(30, yy, GStrings("TXT_XTRTIME")); yy+=yystep; @@ -2869,13 +2870,14 @@ void G_BonusScreenRRRA(int32_t bonusonly) 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(); menutext(191, yy, tempbuf); yy+=yystep; } - if (g_mapInfo[G_LastMapInfoIndex()].designertime) + if (mapList[G_LastMapInfoIndex()].designerT + ime) { G_PrintDesignerTime(); menutext(191, yy, tempbuf); diff --git a/source/rr/src/sector.h b/source/rr/src/sector.h index 8647cae3f..f167be4a2 100644 --- a/source/rr/src/sector.h +++ b/source/rr/src/sector.h @@ -98,12 +98,9 @@ typedef struct { } mapstate_t; typedef struct { - int32_t partime, designertime; - char *name, *filename, *musicfn; mapstate_t *savedstate; } map_t; -//extern map_t g_mapInfo[(MAXVOLUMES+1)*MAXLEVELS]; // +1 volume for "intro", "briefing" music void G_ActivateBySector(int sect,int spriteNum); int S_FindMusicSFX(int sectNum, int *sndptr); diff --git a/source/rr/src/sounds.cpp b/source/rr/src/sounds.cpp index cb5097f3d..fa516ac71 100644 --- a/source/rr/src/sounds.cpp +++ b/source/rr/src/sounds.cpp @@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "openaudio.h" #include "z_music.h" #include +#include "mapinfo.h" BEGIN_RR_NS @@ -131,7 +132,7 @@ static void S_SetMusicIndex(unsigned int m) void S_PlayLevelMusicOrNothing(unsigned int m) { - Mus_Play(g_mapInfo[m].filename, RR ? nullptr : g_mapInfo[m].musicfn, true); + Mus_Play(mapList[m].fileName, RR ? nullptr : mapList[m].music, true); S_SetMusicIndex(m); } @@ -139,8 +140,8 @@ int S_TryPlaySpecialMusic(unsigned int m) { if (RR) return 1; - char const * musicfn = g_mapInfo[m].musicfn; - if (musicfn != NULL) + auto &musicfn = mapList[m].music; + if (musicfn.IsNotEmpty()) { if (!Mus_Play(nullptr, musicfn, 1)) {