diff --git a/src/d_clisrv.c b/src/d_clisrv.c index dca3f1e19..a79f1e711 100755 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1540,7 +1540,7 @@ static boolean SV_SendServerConfig(INT32 node) } #ifndef NONET -#define SAVEGAMESIZE (2048*1024) //(768*1024) +#define SAVEGAMESIZE (8192*1024) // was (768*1024) static boolean SV_ResendingSavegameToAnyone(void) { diff --git a/src/p_saveg.c b/src/p_saveg.c index 11185d309..53076ade5 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -134,7 +134,6 @@ static void P_NetArchivePlayers(void) { INT32 i, j; UINT16 flags; -// size_t q; WRITEUINT32(save_p, ARCHIVEBLOCK_PLAYERS); @@ -3061,7 +3060,7 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker) mobj->mobjnum = READUINT32(save_p); - // Lactozilla: Unarchive world number + // Unarchive world number mobj->worldnum = READUINT32(save_p); if (mobj->worldnum == 0xFFFFFFFF) I_Error("Unknown world"); @@ -3723,7 +3722,10 @@ static void P_NetUnArchiveThinkers(void) // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity for (i = 0; i < numsectors; i++) { - sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = sectors[i].fadecolormapdata = NULL; + unarchiveworld->sectors[i].floordata = NULL; + unarchiveworld->sectors[i].ceilingdata = NULL; + unarchiveworld->sectors[i].lightingdata = NULL; + unarchiveworld->sectors[i].fadecolormapdata = NULL; } // read in saved thinkers @@ -4374,6 +4376,9 @@ static inline boolean P_NetUnArchiveMisc(boolean reloading) if(!mapheaderinfo[gamemap-1]) P_AllocMapHeader(gamemap-1); + curmapheader = nextmapheader = mapheaderinfo[gamemap-1]; + worldmapheader = curmapheader; + // tell the sound code to reset the music since we're skipping what // normally sets this flag mapmusflags |= MUSIC_RELOADRESET; @@ -4758,8 +4763,6 @@ static void P_NetArchiveWorlds(void) void P_SaveNetGame(boolean resending) { - thinker_t *th; - mobj_t *mobj; INT32 i; CV_SaveNetVars(&save_p); @@ -4772,12 +4775,12 @@ void P_SaveNetGame(boolean resending) world_t *w = worldlist[i]; INT32 mobjnum = 1; // don't start from 0, it'd be confused with a blank pointer otherwise - for (th = w->thlist[THINK_MOBJ].next; th != &w->thlist[THINK_MOBJ]; th = th->next) + for (thinker_t *th = w->thlist[THINK_MOBJ].next; th != &w->thlist[THINK_MOBJ]; th = th->next) { if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) continue; - mobj = (mobj_t *)th; + mobj_t *mobj = (mobj_t *)th; if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) continue; mobj->mobjnum = mobjnum++; @@ -4785,19 +4788,16 @@ void P_SaveNetGame(boolean resending) } } - // Lactozilla: Assign world numbers to players + // Assign world numbers to players for (i = 0; i < MAXPLAYERS; i++) { - player_t *player; - INT32 w; - if (!playeringame[i]) continue; - player = &players[i]; + player_t *player = &players[i]; player->worldnum = -1; - for (w = 0; w < numworlds; w++) + for (INT32 w = 0; w < numworlds; w++) { if (P_GetPlayerWorld(player) == worldlist[w]) { @@ -4902,39 +4902,42 @@ static void RelinkWorldsToEntities(void) static void SetUnArchiveWorld(world_t *w) { - unarchiveworld = world = baseworld = localworld = w; + P_SetWorld(w); + + unarchiveworld = baseworld = localworld = world; } static void P_NetUnArchiveWorlds(boolean reloading) { player_t *player = &players[consoleplayer]; - INT32 worldcount, i; if (READUINT32(save_p) != ARCHIVEBLOCK_WORLD) I_Error("Bad $$$.sav at archive block World"); - worldcount = READINT32(save_p); + INT32 worldcount = READINT32(save_p); // initialize colormap vars because paranoia ClearNetColormaps(); - // Unarchive the first world - gamemap = READINT16(save_p); - SetUnArchiveWorld(worldlist[0]); - UnArchiveWorld(); - - for (i = 1; i < worldcount; i++) + // Unarchive each world + for (INT32 i = 0; i < worldcount; i++) { gamemap = READINT16(save_p); - if (!P_LoadLevel(player, true, true, reloading)) - I_Error("P_NetUnArchiveWorlds: failed loading world"); + + // Don't load the first world (because it already is loaded at this point) + if (i != 0) + { + if (!P_LoadLevel(player, true, true, reloading)) + I_Error("P_NetUnArchiveWorlds: failed loading world"); + } + SetUnArchiveWorld(worldlist[i]); UnArchiveWorld(); } - gamemap = worldlist[0]->gamemap; - curmapheader = nextmapheader = mapheaderinfo[gamemap-1]; - worldmapheader = curmapheader; + P_SetWorld(worldlist[0]); + baseworld = localworld = worldlist[0]; + curmapheader = nextmapheader = worldmapheader; P_NetUnArchiveColormaps(); RelinkWorldsToEntities(); diff --git a/src/p_setup.c b/src/p_setup.c index 6dbb53c73..81ac86be0 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -6879,7 +6879,7 @@ static boolean P_LoadMapFromFile(void) // LEVEL INITIALIZATION FUNCTIONS // -static void P_InitLevelSky(INT32 skynum, player_t *player) +static void P_InitLevelSky(INT32 skynum) { P_SetupSkyTexture(skynum); P_SetupWorldSky(skynum, world); @@ -7012,20 +7012,12 @@ static void P_InitLevelSettings(mapheader_t *mapheader, player_t *player, boolea if (!addworld) countdown = countdown2 = exitfadestarted = 0; - if (!addworld || fromnetsave) + if (!addworld) { for (i = 0; i < MAXPLAYERS; i++) - { - if (fromnetsave) - { - players[i].followmobj = NULL; - players[i].mo = NULL; - } - else - P_InitPlayerSettings(i, canresetlives); - } + P_InitPlayerSettings(i, canresetlives); } - else if (player) + else if (player && !fromnetsave) { P_DetachPlayerWorld(player); P_InitPlayerSettings((INT32)(player - players), canresetlives); @@ -7739,7 +7731,7 @@ boolean P_LoadLevel(player_t *player, boolean addworld, boolean fromnetsave, boo S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); } - if (player && (!titlemapinaction)) + if (player && !titlemapinaction && !fromnetsave) P_UnloadWorldPlayer(player); // Initialize the world @@ -7804,7 +7796,7 @@ boolean P_LoadLevel(player_t *player, boolean addworld, boolean fromnetsave, boo CON_SetupBackColormap(); // SRB2 determines the sky texture to be used depending on the map header. - P_InitLevelSky(worldmapheader->skynum, player); + P_InitLevelSky(worldmapheader->skynum); P_ResetSpawnpoints(); diff --git a/src/p_tick.c b/src/p_tick.c index ae52eb9d1..e9236cd60 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -209,13 +209,13 @@ static void P_AddThinkerIntoWorld(world_t *w, const thinklistnum_t n, thinker_t thinker->next = &w->thlist[n]; thinker->prev = w->thlist[n].prev; w->thlist[n].prev = thinker; - - thinker->references = 0; // killough 11/98: init reference counter to 0 } void P_AddThinker(const thinklistnum_t n, thinker_t *thinker) { P_AddThinkerIntoWorld(world, n, thinker); + + thinker->references = 0; // killough 11/98: init reference counter to 0 } // @@ -293,6 +293,7 @@ void P_MoveThinkerToWorld(world_t *w, const thinklistnum_t n, thinker_t *thinker I_Assert(n < NUM_THINKERLISTS); #endif + // Remove this thinker from its thinkerlist next = thinker->next; (next->prev = currentthinker = thinker->prev)->next = next; @@ -315,7 +316,7 @@ mobj_t *P_SetTarget(mobj_t **mop, mobj_t *targ) { if (*mop) // If there was a target already, decrease its refcount (*mop)->thinker.references--; -if ((*mop = targ) != NULL) // Set new target and if non-NULL, increase its counter + if ((*mop = targ) != NULL) // Set new target and if non-NULL, increase its counter targ->thinker.references++; return targ; } diff --git a/src/p_world.c b/src/p_world.c index f6bc074ce..dd9fa553c 100644 --- a/src/p_world.c +++ b/src/p_world.c @@ -71,11 +71,10 @@ world_t *P_InitWorld(void) // world_t *P_InitNewWorld(void) { - world_t *w; - worldlist = Z_Realloc(worldlist, (numworlds + 1) * sizeof(void *), PU_STATIC, NULL); worldlist[numworlds] = P_InitWorld(); - w = worldlist[numworlds]; + + world_t *w = worldlist[numworlds]; if (!numworlds) baseworld = w; @@ -380,14 +379,19 @@ void P_UnloadWorld(world_t *w) LUA_InvalidateLevel(w); P_UnloadSectorAttachments(w->sectors, w->numsectors); - if (world->extrasubsectors) + if (w->extrasubsectors) { - HWR_FreeExtraSubsectors(world->extrasubsectors); - world->extrasubsectors = NULL; + HWR_FreeExtraSubsectors(w->extrasubsectors); + w->extrasubsectors = NULL; } - if (world->sky_dome) - HWR_FreeSkyDome(world->sky_dome); + if (w->sky_dome) + HWR_FreeSkyDome(w->sky_dome); + + Z_Free(w->thlist); + Z_Free(w); + + // TODO: Actually free world data here! } // @@ -397,17 +401,6 @@ void P_UnloadWorldList(void) { INT32 i; - if (numworlds > 1) - P_UnloadSectorAttachments(sectors, numsectors); - else - { - for (i = 0; i < numworlds; i++) - { - if (worldlist[i]) - P_UnloadWorld(worldlist[i]); - } - } - for (i = 0; i < MAXPLAYERS; i++) { if (playeringame[i]) @@ -421,22 +414,17 @@ void P_UnloadWorldList(void) } } - if (numworlds > 1) + for (i = 0; i < numworlds; i++) { - for (i = 0; i < numworlds; i++) - { - world_t *w = worldlist[i]; + world_t *w = worldlist[i]; + if (w == NULL) + continue; - if (w == NULL) - continue; - - Z_Free(w->thlist); - Z_Free(w); - } - - Z_Free(worldlist); + P_UnloadWorld(w); } + Z_Free(worldlist); + worldlist = NULL; numworlds = 0;