From 5c67e22c2203a617455ec0d075db0e80f102e5d3 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Tue, 20 Nov 2018 00:13:08 -0500 Subject: [PATCH 1/7] Random map buffer only gets added to when Needs another temporary buffer for the vote screen so that it doesn't roll dupes --- src/d_netcmd.c | 7 ++++--- src/f_finale.c | 2 +- src/g_game.c | 28 ++++++++++++++-------------- src/g_game.h | 3 ++- src/m_menu.c | 2 +- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 2dc94a45..47f47451 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2066,6 +2066,7 @@ void D_MapChange(INT32 mapnum, INT32 newgametype, boolean pencoremode, boolean r chmappending++; if (netgame) WRITEUINT32(buf_p, M_RandomizedSeed()); // random seed + G_AddMapToBuffer(mapnum-1); SendNetXCmd(XD_MAP, buf, buf_p - buf); } } @@ -2087,11 +2088,11 @@ void D_SetupVote(void) for (i = 0; i < 5; i++) { if (i == 2) // sometimes a different gametype - WRITEUINT16(p, G_RandMap(G_TOLFlag(secondgt), prevmap, false, false, 0, true)); + WRITEUINT16(p, G_RandMap(G_TOLFlag(secondgt), prevmap, false, 0, true)); else if (i >= 3) // unknown-random and force-unknown MAP HELL - WRITEUINT16(p, G_RandMap(G_TOLFlag(gametype), prevmap, true, false, (i-2), (i < 4))); + WRITEUINT16(p, G_RandMap(G_TOLFlag(gametype), prevmap, false, (i-2), (i < 4))); else - WRITEUINT16(p, G_RandMap(G_TOLFlag(gametype), prevmap, false, false, 0, true)); + WRITEUINT16(p, G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, true)); } SendNetXCmd(XD_SETUPVOTE, buf, p - buf); diff --git a/src/f_finale.c b/src/f_finale.c index ea89b2b7..b84289be 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1068,7 +1068,7 @@ void F_TitleScreenTicker(boolean run) return; }*/ - mapname = G_BuildMapName(G_RandMap(TOL_RACE, -2, false, false, 0, false)+1); + mapname = G_BuildMapName(G_RandMap(TOL_RACE, -2, false, 0, false)+1); numstaff = 1; while (numstaff < 99 && (l = W_CheckNumForName(va("%sS%02u",mapname,numstaff+1))) != LUMPERROR) diff --git a/src/g_game.c b/src/g_game.c index 517e5bcb..ba6bf5a3 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -779,7 +779,7 @@ const char *G_BuildMapName(INT32 map) map = gamemap-1; else map = prevmap; - map = G_RandMap(G_TOLFlag(cv_newgametype.value), map, false, false, 0, false)+1; + map = G_RandMap(G_TOLFlag(cv_newgametype.value), map, false, 0, false)+1; } if (map < 100) @@ -3268,7 +3268,7 @@ static INT32 TOLMaps(INT16 tolflags) * \author Graue */ static INT16 *okmaps = NULL; -INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean dontadd, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon) +INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon) { INT32 numokmaps = 0; INT16 ix, bufx; @@ -3329,20 +3329,20 @@ tryagain: if (randmapbuffer[3] == -1) // Is the buffer basically empty? { ignorebuffer = true; // This will probably only help in situations where there's very few maps, but it's folly not to at least try it - goto tryagain; //return G_RandMap(tolflags, pprevmap, dontadd, true, maphell, callagainsoon); + goto tryagain; //return G_RandMap(tolflags, pprevmap, true, maphell, callagainsoon); } for (bufx = 3; bufx < NUMMAPS; bufx++) // Let's clear all but the three most recent maps... randmapbuffer[bufx] = -1; if (cv_kartvoterulechanges.value == 1) // sometimes randmapbuffer[NUMMAPS] = 0; - goto tryagain; //return G_RandMap(tolflags, pprevmap, dontadd, ignorebuffer, maphell, callagainsoon); + goto tryagain; //return G_RandMap(tolflags, pprevmap, ignorebuffer, maphell, callagainsoon); } if (maphell) // Any wiggle room to loosen our restrictions here? { maphell--; - goto tryagain; //return G_RandMap(tolflags, pprevmap, dontadd, true, maphell-1, callagainsoon); + goto tryagain; //return G_RandMap(tolflags, pprevmap, true, maphell-1, callagainsoon); } ix = 0; // Sorry, none match. You get MAP01. @@ -3350,15 +3350,7 @@ tryagain: randmapbuffer[bufx] = -1; // if we're having trouble finding a map we should probably clear it } else - { ix = okmaps[M_RandomKey(numokmaps)]; - if (!dontadd) - { - for (bufx = NUMMAPS-1; bufx > 0; bufx--) - randmapbuffer[bufx] = randmapbuffer[bufx-1]; - randmapbuffer[0] = ix; - } - } if (!callagainsoon) { @@ -3369,6 +3361,14 @@ tryagain: return ix; } +void G_AddMapToBuffer(INT16 map) +{ + INT16 bufx; + for (bufx = NUMMAPS-1; bufx > 0; bufx--) + randmapbuffer[bufx] = randmapbuffer[bufx-1]; + randmapbuffer[0] = map; +} + // // G_DoCompleted // @@ -3519,7 +3519,7 @@ static void G_DoCompleted(void) if (cv_advancemap.value == 0) // Stay on same map. nextmap = prevmap; else if (cv_advancemap.value == 2) // Go to random map. - nextmap = G_RandMap(G_TOLFlag(gametype), prevmap, false, false, 0, false); + nextmap = G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, false); } // We are committed to this map now. diff --git a/src/g_game.h b/src/g_game.h index 621da3f8..27f961d3 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -255,6 +255,7 @@ FUNCMATH INT32 G_TicsToMilliseconds(tic_t tics); // Don't split up TOL handling INT16 G_TOLFlag(INT32 pgametype); -INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean dontadd, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon); +INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon); +void G_AddMapToBuffer(INT16 map); #endif diff --git a/src/m_menu.c b/src/m_menu.c index 7d7c1fbf..9b1eb62c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7454,7 +7454,7 @@ static void M_StartServer(INT32 choice) G_StopMetalDemo(); if (!cv_nextmap.value) - CV_SetValue(&cv_nextmap, G_RandMap(G_TOLFlag(cv_newgametype.value), -1, false, false, 0, false)+1); + CV_SetValue(&cv_nextmap, G_RandMap(G_TOLFlag(cv_newgametype.value), -1, false, 0, false)+1); if (cv_maxplayers.value < ssplayers+1) CV_SetValue(&cv_maxplayers, ssplayers+1); From c6268253eb8d414cbadad8a7a2992ebbc42c3566 Mon Sep 17 00:00:00 2001 From: toaster Date: Thu, 22 Nov 2018 17:10:36 +0000 Subject: [PATCH 2/7] The oft-promised buffer fixes. Also, making it so the gametype switch for "Sometimes" is every 10 maps, not a full buffer round (now that it doesn't add to the buffer when you first see it). Unfortunately, the code didn't turn out nearly as nice as I'd desired, but things don't always work out. In addition: For some reason, I rolled Tinkerer's Arena twice within three hits of the Dice voting option, so something's wrong and this branch needs proper, rigorous investigative testing but I don't know what and I'm way too tired (both physically and metaphysically) to investigate any further. --- src/d_netcmd.c | 1 - src/g_game.c | 49 +++++++++++++++++++++++++++++++++++++++---------- src/p_setup.c | 2 ++ 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 47f47451..4a08a1af 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2066,7 +2066,6 @@ void D_MapChange(INT32 mapnum, INT32 newgametype, boolean pencoremode, boolean r chmappending++; if (netgame) WRITEUINT32(buf_p, M_RandomizedSeed()); // random seed - G_AddMapToBuffer(mapnum-1); SendNetXCmd(XD_MAP, buf, buf_p - buf); } } diff --git a/src/g_game.c b/src/g_game.c index ba6bf5a3..f9f156a8 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3137,8 +3137,7 @@ INT16 G_SometimesGetDifferentGametype(void) if (randmapbuffer[NUMMAPS] > 0 && (encorepossible || cv_kartvoterulechanges.value != 3)) { - if (cv_kartvoterulechanges.value != 1) - randmapbuffer[NUMMAPS]--; + randmapbuffer[NUMMAPS]--; if (encorepossible) { switch (cv_kartvoterulechanges.value) @@ -3166,6 +3165,8 @@ INT16 G_SometimesGetDifferentGametype(void) randmapbuffer[NUMMAPS] = 1; // every other vote (or always if !encorepossible) break; case 1: // sometimes + randmapbuffer[NUMMAPS] = 10; // ...every two cups? + break; default: // fallthrough - happens when clearing buffer, but needs a reasonable countdown if cvar is modified case 2: // frequent @@ -3268,6 +3269,7 @@ static INT32 TOLMaps(INT16 tolflags) * \author Graue */ static INT16 *okmaps = NULL; +static INT16 votebuffer[3] = {-1, -1, -1}; INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon) { INT32 numokmaps = 0; @@ -3297,6 +3299,26 @@ tryagain: if (!ignorebuffer) { + if (votebuffer[0] != -1) + { + if (ix == votebuffer[0]) + continue; + + for (bufx = 1; bufx < 3; bufx++) + { + if (votebuffer[bufx] == -1) // Rest of buffer SHOULD be empty + break; + if (ix == votebuffer[bufx]) + { + isokmap = false; + break; + } + } + + if (!isokmap) + continue; + } + for (bufx = 0; bufx < (maphell ? 3 : NUMMAPS); bufx++) { if (randmapbuffer[bufx] == -1) // Rest of buffer SHOULD be empty @@ -3307,12 +3329,12 @@ tryagain: break; } } + + if (!isokmap) + continue; } - if (!isokmap) - continue; - - if (pprevmap == -2) // title demos + if (pprevmap == -2) // title demo hack { lumpnum_t l; if ((l = W_CheckNumForName(va("%sS01",G_BuildMapName(ix+1)))) == LUMPERROR) @@ -3334,8 +3356,6 @@ tryagain: for (bufx = 3; bufx < NUMMAPS; bufx++) // Let's clear all but the three most recent maps... randmapbuffer[bufx] = -1; - if (cv_kartvoterulechanges.value == 1) // sometimes - randmapbuffer[NUMMAPS] = 0; goto tryagain; //return G_RandMap(tolflags, pprevmap, ignorebuffer, maphell, callagainsoon); } @@ -3356,6 +3376,17 @@ tryagain: { Z_Free(okmaps); okmaps = NULL; + for (bufx = 0; bufx < 3; bufx++) + votebuffer[bufx] = -1; + } + else if (votebuffer[2] == -1) + { + for (bufx = 0; bufx < 3; bufx++) + if (votebuffer[bufx] == -1) + { + votebuffer[bufx] = ix; + break; + } } return ix; @@ -3509,8 +3540,6 @@ static void G_DoCompleted(void) { for (i = 3; i < NUMMAPS; i++) // Let's clear all but the three most recent maps... randmapbuffer[i] = -1; - if (cv_kartvoterulechanges.value == 1) // sometimes - randmapbuffer[NUMMAPS] = 0; } #endif diff --git a/src/p_setup.c b/src/p_setup.c index 68cdc797..533bba14 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3113,6 +3113,8 @@ boolean P_SetupLevel(boolean skipprecip) #endif } + G_AddMapToBuffer(gamemap-1); + return true; } From 478f895ea0aab1120cc260809613f26c32253ee7 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Mon, 26 Nov 2018 04:27:31 -0500 Subject: [PATCH 3/7] Remove previous commit's votebuffer, allow an external optional buffer to be passed into G_RandMap I meant to fix the previous method, but I didn't even understand how it knew it was in a vote or not... so I just did it my own way :V (Shouldn't FLUSHMAPBUFFEREARLY be on now...?) --- src/d_netcmd.c | 11 ++++++++--- src/doomstat.h | 1 + src/f_finale.c | 2 +- src/g_game.c | 38 ++++++++++---------------------------- src/g_game.h | 2 +- src/m_menu.c | 2 +- 6 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 4a08a1af..fc545763 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2076,6 +2076,7 @@ void D_SetupVote(void) UINT8 *p = buf; INT32 i; UINT8 secondgt = G_SometimesGetDifferentGametype(); + INT16 votebuffer[3] = {-1,-1,-1}; if (cv_kartencore.value && G_RaceGametype()) WRITEUINT8(p, (gametype|0x80)); @@ -2086,12 +2087,16 @@ void D_SetupVote(void) for (i = 0; i < 5; i++) { + UINT16 m; if (i == 2) // sometimes a different gametype - WRITEUINT16(p, G_RandMap(G_TOLFlag(secondgt), prevmap, false, 0, true)); + m = G_RandMap(G_TOLFlag(secondgt), prevmap, false, 0, true, votebuffer); else if (i >= 3) // unknown-random and force-unknown MAP HELL - WRITEUINT16(p, G_RandMap(G_TOLFlag(gametype), prevmap, false, (i-2), (i < 4))); + m = G_RandMap(G_TOLFlag(gametype), prevmap, false, (i-2), (i < 4), votebuffer); else - WRITEUINT16(p, G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, true)); + m = G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, true, votebuffer); + if (i < 3) + votebuffer[i] = m; + WRITEUINT16(p, m); } SendNetXCmd(XD_SETUPVOTE, buf, p - buf); diff --git a/src/doomstat.h b/src/doomstat.h index 34456b32..3784145f 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -467,6 +467,7 @@ extern boolean comebackshowninfo; extern tic_t curlap, bestlap; extern INT16 votelevels[5][2]; +extern INT16 votebuffer[5]; extern SINT8 votes[MAXPLAYERS]; extern SINT8 pickedvote; diff --git a/src/f_finale.c b/src/f_finale.c index b84289be..eb6adae1 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1068,7 +1068,7 @@ void F_TitleScreenTicker(boolean run) return; }*/ - mapname = G_BuildMapName(G_RandMap(TOL_RACE, -2, false, 0, false)+1); + mapname = G_BuildMapName(G_RandMap(TOL_RACE, -2, false, 0, false, NULL)+1); numstaff = 1; while (numstaff < 99 && (l = W_CheckNumForName(va("%sS%02u",mapname,numstaff+1))) != LUMPERROR) diff --git a/src/g_game.c b/src/g_game.c index f9f156a8..04a540b8 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -779,7 +779,7 @@ const char *G_BuildMapName(INT32 map) map = gamemap-1; else map = prevmap; - map = G_RandMap(G_TOLFlag(cv_newgametype.value), map, false, 0, false)+1; + map = G_RandMap(G_TOLFlag(cv_newgametype.value), map, false, 0, false, NULL)+1; } if (map < 100) @@ -3269,8 +3269,7 @@ static INT32 TOLMaps(INT16 tolflags) * \author Graue */ static INT16 *okmaps = NULL; -static INT16 votebuffer[3] = {-1, -1, -1}; -INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon) +INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon, INT16 *extbuffer) { INT32 numokmaps = 0; INT16 ix, bufx; @@ -3299,24 +3298,18 @@ tryagain: if (!ignorebuffer) { - if (votebuffer[0] != -1) + if (extbuffer != NULL) { - if (ix == votebuffer[0]) - continue; - - for (bufx = 1; bufx < 3; bufx++) + for (bufx = 0; bufx < (INT16)(sizeof extbuffer); bufx++) { - if (votebuffer[bufx] == -1) // Rest of buffer SHOULD be empty + if (extbuffer[bufx] == -1) // Rest of buffer SHOULD be empty break; - if (ix == votebuffer[bufx]) + if (ix == extbuffer[bufx]) { isokmap = false; break; } } - - if (!isokmap) - continue; } for (bufx = 0; bufx < (maphell ? 3 : NUMMAPS); bufx++) @@ -3351,18 +3344,18 @@ tryagain: if (randmapbuffer[3] == -1) // Is the buffer basically empty? { ignorebuffer = true; // This will probably only help in situations where there's very few maps, but it's folly not to at least try it - goto tryagain; //return G_RandMap(tolflags, pprevmap, true, maphell, callagainsoon); + goto tryagain; } for (bufx = 3; bufx < NUMMAPS; bufx++) // Let's clear all but the three most recent maps... randmapbuffer[bufx] = -1; - goto tryagain; //return G_RandMap(tolflags, pprevmap, ignorebuffer, maphell, callagainsoon); + goto tryagain; } if (maphell) // Any wiggle room to loosen our restrictions here? { maphell--; - goto tryagain; //return G_RandMap(tolflags, pprevmap, true, maphell-1, callagainsoon); + goto tryagain; } ix = 0; // Sorry, none match. You get MAP01. @@ -3376,17 +3369,6 @@ tryagain: { Z_Free(okmaps); okmaps = NULL; - for (bufx = 0; bufx < 3; bufx++) - votebuffer[bufx] = -1; - } - else if (votebuffer[2] == -1) - { - for (bufx = 0; bufx < 3; bufx++) - if (votebuffer[bufx] == -1) - { - votebuffer[bufx] = ix; - break; - } } return ix; @@ -3548,7 +3530,7 @@ static void G_DoCompleted(void) if (cv_advancemap.value == 0) // Stay on same map. nextmap = prevmap; else if (cv_advancemap.value == 2) // Go to random map. - nextmap = G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, false); + nextmap = G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, false, NULL); } // We are committed to this map now. diff --git a/src/g_game.h b/src/g_game.h index 27f961d3..e29d4bbe 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -255,7 +255,7 @@ FUNCMATH INT32 G_TicsToMilliseconds(tic_t tics); // Don't split up TOL handling INT16 G_TOLFlag(INT32 pgametype); -INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon); +INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon, INT16 votebuffer[5]); void G_AddMapToBuffer(INT16 map); #endif diff --git a/src/m_menu.c b/src/m_menu.c index 9b1eb62c..c9792948 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7454,7 +7454,7 @@ static void M_StartServer(INT32 choice) G_StopMetalDemo(); if (!cv_nextmap.value) - CV_SetValue(&cv_nextmap, G_RandMap(G_TOLFlag(cv_newgametype.value), -1, false, 0, false)+1); + CV_SetValue(&cv_nextmap, G_RandMap(G_TOLFlag(cv_newgametype.value), -1, false, 0, false, NULL)+1); if (cv_maxplayers.value < ssplayers+1) CV_SetValue(&cv_maxplayers, ssplayers+1); From e59a675eb38e1e51f4ab4cf9bb9cc9456797dcb2 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Mon, 26 Nov 2018 04:28:39 -0500 Subject: [PATCH 4/7] Mistakes --- src/doomstat.h | 1 - src/g_game.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/doomstat.h b/src/doomstat.h index 3784145f..34456b32 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -467,7 +467,6 @@ extern boolean comebackshowninfo; extern tic_t curlap, bestlap; extern INT16 votelevels[5][2]; -extern INT16 votebuffer[5]; extern SINT8 votes[MAXPLAYERS]; extern SINT8 pickedvote; diff --git a/src/g_game.h b/src/g_game.h index e29d4bbe..6a9014ea 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -255,7 +255,7 @@ FUNCMATH INT32 G_TicsToMilliseconds(tic_t tics); // Don't split up TOL handling INT16 G_TOLFlag(INT32 pgametype); -INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon, INT16 votebuffer[5]); +INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maphell, boolean callagainsoon, INT16 *extbuffer); void G_AddMapToBuffer(INT16 map); #endif From 494fa55390ee46897ed930940730e58cafd0abff Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Mon, 26 Nov 2018 04:42:14 -0500 Subject: [PATCH 5/7] Accidental removal --- src/g_game.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/g_game.c b/src/g_game.c index 04a540b8..c6acb394 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3310,6 +3310,9 @@ tryagain: break; } } + + if (!isokmap) + continue; } for (bufx = 0; bufx < (maphell ? 3 : NUMMAPS); bufx++) From 4bd6ae3f04b8f2159d51e795e9040eb59cefc9b5 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Mon, 26 Nov 2018 05:09:56 -0500 Subject: [PATCH 6/7] Calculate buffer size manually (Yes, I checked; this always outputs "3" for its current usage.) --- src/g_game.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index c6acb394..9d7ebbb4 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3273,11 +3273,20 @@ INT16 G_RandMap(INT16 tolflags, INT16 pprevmap, boolean ignorebuffer, UINT8 maph { INT32 numokmaps = 0; INT16 ix, bufx; + UINT16 extbufsize = 0; boolean usehellmaps; // Only consider Hell maps in this pick if (!okmaps) okmaps = Z_Malloc(NUMMAPS * sizeof(INT16), PU_STATIC, NULL); + if (extbuffer != NULL) + { + bufx = 0; + while (extbuffer[bufx]) { + extbufsize++; bufx++; + } + } + tryagain: usehellmaps = (maphell == 0 ? false : (maphell == 2 || M_RandomChance(FRACUNIT/100))); // 1% chance of Hell @@ -3298,9 +3307,9 @@ tryagain: if (!ignorebuffer) { - if (extbuffer != NULL) + if (extbufsize > 0) { - for (bufx = 0; bufx < (INT16)(sizeof extbuffer); bufx++) + for (bufx = 0; bufx < extbufsize; bufx++) { if (extbuffer[bufx] == -1) // Rest of buffer SHOULD be empty break; From 5dbd7472370c916ed63cdbcf03e7cf8c96dd2a9c Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Mon, 26 Nov 2018 06:09:26 -0500 Subject: [PATCH 7/7] Flush map buffer early, again Now it's directly in G_AddMapToBuffer --- src/g_game.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 9d7ebbb4..ac34c74d 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3240,7 +3240,6 @@ INT16 G_TOLFlag(INT32 pgametype) return INT16_MAX; } -#ifdef FLUSHMAPBUFFEREARLY static INT32 TOLMaps(INT16 tolflags) { INT32 num = 0; @@ -3251,14 +3250,14 @@ static INT32 TOLMaps(INT16 tolflags) { if (!mapheaderinfo[i]) continue; - + if (mapheaderinfo[i]->menuflags & LF2_HIDEINMENU) // Don't include Map Hell + continue; if ((mapheaderinfo[i]->typeoflevel & tolflags) == tolflags) num++; } return num; } -#endif /** Select a random map with the given typeoflevel flags. * If no map has those flags, this arbitrarily gives you map 1. @@ -3388,10 +3387,21 @@ tryagain: void G_AddMapToBuffer(INT16 map) { - INT16 bufx; + INT16 bufx, refreshnum = (TOLMaps(G_TOLFlag(gametype)) / 2) + 1; + + // Add the map to the buffer. for (bufx = NUMMAPS-1; bufx > 0; bufx--) randmapbuffer[bufx] = randmapbuffer[bufx-1]; randmapbuffer[0] = map; + + // We're getting pretty full, so lets flush this for future usage. + if (randmapbuffer[refreshnum] != -1) + { + // Clear all but the five most recent maps. + for (bufx = 5; bufx < NUMMAPS; bufx++) // bufx < refreshnum? Might not handle everything for gametype switches, though. + randmapbuffer[bufx] = -1; + //CONS_Printf("Random map buffer has been flushed.\n"); + } } // @@ -3529,14 +3539,6 @@ static void G_DoCompleted(void) automapactive = false; -#ifdef FLUSHMAPBUFFEREARLY - if (randmapbuffer[TOLMaps(G_TOLFlag(gametype))-5] != -1) // We're getting pretty full, so! -- no need for this, handled in G_RandMap - { - for (i = 3; i < NUMMAPS; i++) // Let's clear all but the three most recent maps... - randmapbuffer[i] = -1; - } -#endif - if (gametype != GT_COOP) { if (cv_advancemap.value == 0) // Stay on same map.