clean up leveload a bit
This commit is contained in:
1 parent
8dfa841a7b
commit
c14af4a136
1 file changed
+154
-152
+154
-152
@@ -578,6 +578,7 @@ FUNCINLINE static ATTRINLINE void P_LoadRawSubsectors(void *data)
|
||||
|
||||
size_t numlevelflats;
|
||||
levelflat_t *levelflats;
|
||||
levelflat_t *foundflats;
|
||||
|
||||
//SoM: Other files want this info.
|
||||
size_t P_PrecacheLevelFlats(void)
|
||||
@@ -703,18 +704,9 @@ static void P_LoadRawSectors(UINT8 *data)
|
||||
{
|
||||
mapsector_t *ms = (mapsector_t *)data;
|
||||
sector_t *ss = sectors;
|
||||
levelflat_t *foundflats;
|
||||
|
||||
size_t i;
|
||||
|
||||
// Allocate a big chunk of memory as big as our MAXLEVELFLATS limit.
|
||||
//Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty
|
||||
foundflats = calloc(MAXLEVELFLATS, sizeof (*foundflats));
|
||||
if (foundflats == NULL)
|
||||
I_Error("Ran out of memory while loading sectors\n");
|
||||
|
||||
numlevelflats = 0;
|
||||
|
||||
// For each counted sector, copy the sector raw data from our cache pointer ms, to the global table pointer ss.
|
||||
for (i = 0; i < numsectors; i++, ss++, ms++)
|
||||
{
|
||||
@@ -775,16 +767,6 @@ static void P_LoadRawSectors(UINT8 *data)
|
||||
ss->floorspeed = 0;
|
||||
ss->ceilspeed = 0;
|
||||
}
|
||||
|
||||
// set the sky flat num
|
||||
skyflatnum = P_AddLevelFlat(SKYFLATNAME, foundflats);
|
||||
|
||||
// copy table for global usage
|
||||
levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t));
|
||||
free(foundflats);
|
||||
|
||||
// search for animated flats and set up
|
||||
P_SetupLevelFlatAnims();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1469,7 +1451,6 @@ static void P_LoadRawSideDefs2(void *data)
|
||||
break;
|
||||
}
|
||||
}
|
||||
R_ClearTextureNumCache(true);
|
||||
}
|
||||
|
||||
static boolean LineInBlock(fixed_t cx1, fixed_t cy1, fixed_t cx2, fixed_t cy2, fixed_t bx1, fixed_t by1)
|
||||
@@ -1986,12 +1967,32 @@ static void P_LoadMapData(const virtres_t* virt)
|
||||
lines = Z_Calloc(numlines * sizeof (*lines), PU_LEVEL, NULL);
|
||||
mapthings = Z_Calloc(nummapthings * sizeof (*mapthings), PU_LEVEL, NULL);
|
||||
|
||||
// Allocate a big chunk of memory as big as our MAXLEVELFLATS limit.
|
||||
//Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty
|
||||
foundflats = calloc(MAXLEVELFLATS, sizeof (*foundflats));
|
||||
if (foundflats == NULL)
|
||||
I_Error("Ran out of memory while loading sectors\n");
|
||||
numlevelflats = 0;
|
||||
|
||||
// Strict map data
|
||||
P_LoadRawVertexes(virtvertexes->data);
|
||||
P_LoadRawSectors(virtsectors->data);
|
||||
P_LoadRawLineDefs(virtlinedefs->data);
|
||||
P_SetupLines();
|
||||
P_LoadRawSideDefs2(virtsidedefs->data);
|
||||
P_PrepareRawThings(virtthings->data);
|
||||
|
||||
R_ClearTextureNumCache(true);
|
||||
|
||||
// set the sky flat num
|
||||
skyflatnum = P_AddLevelFlat(SKYFLATNAME, foundflats);
|
||||
|
||||
// copy table for global usage
|
||||
levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t));
|
||||
free(foundflats);
|
||||
|
||||
// search for animated flats and set up
|
||||
P_SetupLevelFlatAnims();
|
||||
}
|
||||
|
||||
/** Sets up a sky texture to use for the level.
|
||||
@@ -2242,16 +2243,6 @@ static void P_LoadMapFromFile(void)
|
||||
P_PrepareRawThings(vres_Find(curmapvirt, "THINGS")->data);
|
||||
|
||||
P_MakeMapMD5(curmapvirt, &mapmd5);
|
||||
|
||||
// We do the following silly
|
||||
// construction because vres_Free
|
||||
// no-sells deletions of pointers
|
||||
// that are == curmapvirt.
|
||||
{
|
||||
virtres_t *temp = curmapvirt;
|
||||
curmapvirt = NULL;
|
||||
vres_Free(temp);
|
||||
}
|
||||
}
|
||||
|
||||
static void P_RunLevelScript(const char *scriptname)
|
||||
@@ -2487,6 +2478,129 @@ static boolean P_CanSave(void)
|
||||
return false; // SRB2Kart: no SP, no saving.
|
||||
}
|
||||
|
||||
static void P_InitGametype(void)
|
||||
{
|
||||
INT32 i;
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
if (playeringame[i])
|
||||
{
|
||||
players[i].pflags &= ~PF_NIGHTSMODE;
|
||||
|
||||
// Start players with pity shields if possible
|
||||
players[i].pity = -1;
|
||||
|
||||
if (!G_RaceGametype())
|
||||
{
|
||||
players[i].mo = NULL;
|
||||
G_DoReborn(i);
|
||||
}
|
||||
else // gametype is GT_COOP or GT_RACE
|
||||
{
|
||||
players[i].mo = NULL;
|
||||
|
||||
if (players[i].starposttime)
|
||||
{
|
||||
G_SpawnPlayer(i, true);
|
||||
}
|
||||
else
|
||||
G_SpawnPlayer(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (modeattacking == ATTACKING_RECORD && !demo.playback)
|
||||
P_LoadRecordGhosts();
|
||||
|
||||
if (G_TagGametype())
|
||||
{
|
||||
INT32 realnumplayers = 0;
|
||||
INT32 playersactive[MAXPLAYERS];
|
||||
|
||||
//I just realized how problematic this code can be.
|
||||
//D_NumPlayers() will not always cover the scope of the netgame.
|
||||
//What if one player is node 0 and the other node 31?
|
||||
//The solution? Make a temp array of all players that are currently playing and pick from them.
|
||||
//Future todo? When a player leaves, shift all nodes down so D_NumPlayers() can be used as intended?
|
||||
//Also, you'd never have to loop through all 32 players slots to find anything ever again.
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (playeringame[i] && !players[i].spectator)
|
||||
{
|
||||
playersactive[realnumplayers] = i; //stores the player's node in the array.
|
||||
realnumplayers++;
|
||||
}
|
||||
}
|
||||
|
||||
if (realnumplayers) //this should also fix the dedicated crash bug. You only pick a player if one exists to be picked.
|
||||
{
|
||||
i = P_RandomKey(realnumplayers);
|
||||
players[playersactive[i]].pflags |= PF_TAGIT; //choose our initial tagger before map starts.
|
||||
|
||||
// Taken and modified from G_DoReborn()
|
||||
// Remove the player so he can respawn elsewhere.
|
||||
// first dissasociate the corpse
|
||||
if (players[playersactive[i]].mo)
|
||||
P_RemoveMobj(players[playersactive[i]].mo);
|
||||
|
||||
G_SpawnPlayer(playersactive[i], false); //respawn the lucky player in his dedicated spawn location.
|
||||
}
|
||||
else
|
||||
CONS_Printf(M_GetText("No player currently available to become IT. Awaiting available players.\n"));
|
||||
|
||||
}
|
||||
else if (G_RaceGametype() && server)
|
||||
CV_StealthSetValue(&cv_numlaps,
|
||||
((netgame || multiplayer) && cv_basenumlaps.value
|
||||
&& (!(mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE)
|
||||
|| (mapheaderinfo[gamemap - 1]->numlaps > cv_basenumlaps.value)))
|
||||
? cv_basenumlaps.value
|
||||
: mapheaderinfo[gamemap - 1]->numlaps);
|
||||
|
||||
// Start recording replay in multiplayer with a temp filename
|
||||
//Ensure dedis only record a replay if there is a player at the start of the map, otherwise we get invalid replays!
|
||||
if (!demo.playback && multiplayer && D_NumPlayers()) {
|
||||
static char buf[256];
|
||||
sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap));
|
||||
|
||||
I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755);
|
||||
I_mkdir(va("%s"PATHSEP"replay"PATHSEP"online", srb2home), 0755);
|
||||
G_RecordDemo(buf);
|
||||
if (dedicated)
|
||||
G_BeginRecording(); //this has to move here, since dedicated servers dont run got_mapcmd
|
||||
}
|
||||
|
||||
wantedcalcdelay = wantedfrequency*2;
|
||||
indirectitemcooldown = 0;
|
||||
hyubgone = 0;
|
||||
mapreset = 0;
|
||||
nospectategrief = 0;
|
||||
thwompsactive = false;
|
||||
spbplace = -1;
|
||||
|
||||
startedInFreePlay = false;
|
||||
{
|
||||
UINT8 nump = 0;
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (!playeringame[i] || players[i].spectator)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
nump++;
|
||||
if (nump == 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nump <= 1)
|
||||
{
|
||||
startedInFreePlay = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct minimapinfo minimapinfo;
|
||||
static void P_InitMinimapInfo(void)
|
||||
{
|
||||
@@ -2822,131 +2936,19 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate)
|
||||
// none of this needs to be done because it's not the beginning of the map when
|
||||
// a netgame save is being loaded, and could actively be harmful by messing with
|
||||
// the client's view of the data.)
|
||||
if (fromnetsave)
|
||||
goto netgameskip;
|
||||
// ==========
|
||||
if (!fromnetsave)
|
||||
P_InitGametype();
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
if (playeringame[i])
|
||||
{
|
||||
players[i].pflags &= ~PF_NIGHTSMODE;
|
||||
|
||||
// Start players with pity shields if possible
|
||||
players[i].pity = -1;
|
||||
|
||||
if (!G_RaceGametype())
|
||||
{
|
||||
players[i].mo = NULL;
|
||||
G_DoReborn(i);
|
||||
}
|
||||
else // gametype is GT_COOP or GT_RACE
|
||||
{
|
||||
players[i].mo = NULL;
|
||||
|
||||
if (players[i].starposttime)
|
||||
{
|
||||
G_SpawnPlayer(i, true);
|
||||
}
|
||||
else
|
||||
G_SpawnPlayer(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (modeattacking == ATTACKING_RECORD && !demo.playback)
|
||||
P_LoadRecordGhosts();
|
||||
|
||||
if (G_TagGametype())
|
||||
// Now safe to free.
|
||||
// We do the following silly
|
||||
// construction because vres_Free
|
||||
// no-sells deletions of pointers
|
||||
// that are == curmapvirt.
|
||||
{
|
||||
INT32 realnumplayers = 0;
|
||||
INT32 playersactive[MAXPLAYERS];
|
||||
|
||||
//I just realized how problematic this code can be.
|
||||
//D_NumPlayers() will not always cover the scope of the netgame.
|
||||
//What if one player is node 0 and the other node 31?
|
||||
//The solution? Make a temp array of all players that are currently playing and pick from them.
|
||||
//Future todo? When a player leaves, shift all nodes down so D_NumPlayers() can be used as intended?
|
||||
//Also, you'd never have to loop through all 32 players slots to find anything ever again.
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (playeringame[i] && !players[i].spectator)
|
||||
{
|
||||
playersactive[realnumplayers] = i; //stores the player's node in the array.
|
||||
realnumplayers++;
|
||||
}
|
||||
}
|
||||
|
||||
if (realnumplayers) //this should also fix the dedicated crash bug. You only pick a player if one exists to be picked.
|
||||
{
|
||||
i = P_RandomKey(realnumplayers);
|
||||
players[playersactive[i]].pflags |= PF_TAGIT; //choose our initial tagger before map starts.
|
||||
|
||||
// Taken and modified from G_DoReborn()
|
||||
// Remove the player so he can respawn elsewhere.
|
||||
// first dissasociate the corpse
|
||||
if (players[playersactive[i]].mo)
|
||||
P_RemoveMobj(players[playersactive[i]].mo);
|
||||
|
||||
G_SpawnPlayer(playersactive[i], false); //respawn the lucky player in his dedicated spawn location.
|
||||
}
|
||||
else
|
||||
CONS_Printf(M_GetText("No player currently available to become IT. Awaiting available players.\n"));
|
||||
|
||||
virtres_t *temp = curmapvirt;
|
||||
curmapvirt = NULL;
|
||||
vres_Free(temp);
|
||||
}
|
||||
else if (G_RaceGametype() && server)
|
||||
CV_StealthSetValue(&cv_numlaps,
|
||||
((netgame || multiplayer) && cv_basenumlaps.value
|
||||
&& (!(mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE)
|
||||
|| (mapheaderinfo[gamemap - 1]->numlaps > cv_basenumlaps.value)))
|
||||
? cv_basenumlaps.value
|
||||
: mapheaderinfo[gamemap - 1]->numlaps);
|
||||
|
||||
// Start recording replay in multiplayer with a temp filename
|
||||
//Ensure dedis only record a replay if there is a player at the start of the map, otherwise we get invalid replays!
|
||||
if (!demo.playback && multiplayer && D_NumPlayers()) {
|
||||
static char buf[256];
|
||||
sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap));
|
||||
|
||||
I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755);
|
||||
I_mkdir(va("%s"PATHSEP"replay"PATHSEP"online", srb2home), 0755);
|
||||
G_RecordDemo(buf);
|
||||
if (dedicated)
|
||||
G_BeginRecording(); //this has to move here, since dedicated servers dont run got_mapcmd
|
||||
}
|
||||
|
||||
wantedcalcdelay = wantedfrequency*2;
|
||||
indirectitemcooldown = 0;
|
||||
hyubgone = 0;
|
||||
mapreset = 0;
|
||||
nospectategrief = 0;
|
||||
thwompsactive = false;
|
||||
spbplace = -1;
|
||||
|
||||
startedInFreePlay = false;
|
||||
{
|
||||
UINT8 nump = 0;
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (!playeringame[i] || players[i].spectator)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
nump++;
|
||||
if (nump == 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nump <= 1)
|
||||
{
|
||||
startedInFreePlay = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ===========
|
||||
// landing point for netgames.
|
||||
netgameskip:
|
||||
|
||||
if (!reloadinggamestate)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user