From f6f55c579005a9adcda109b6450fb05c55ae8d93 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 5 Mar 2024 10:25:51 +0100 Subject: [PATCH] more pain --- src/command.c | 6 +- src/command.h | 2 +- src/console.c | 3 +- src/console.h | 3 - src/d_clisrv.c | 172 +++++++++++++++++++++++++++++-------------------- src/g_game.c | 4 +- src/i_time.c | 2 +- src/i_time.h | 1 + src/p_saveg.c | 62 +++++++----------- 9 files changed, 133 insertions(+), 122 deletions(-) diff --git a/src/command.c b/src/command.c index 2347b34b3..af5d936ca 100644 --- a/src/command.c +++ b/src/command.c @@ -1478,7 +1478,6 @@ badinput: // static boolean serverloading = false; -static boolean serverloadingstealth = false; static void Got_NetVar(UINT8 **p, INT32 playernum) { @@ -1506,7 +1505,7 @@ static void Got_NetVar(UINT8 **p, INT32 playernum) cvar = CV_FindNetVar(netid); svalue = (char *)*p; SKIPSTRING(*p); - stealth = READUINT8(*p) || (serverloading && serverloadingstealth); + stealth = READUINT8(*p); if (!cvar) { @@ -1560,14 +1559,13 @@ void CV_SaveNetVars(UINT8 **p, boolean isdemorecording) WRITEUINT16(count_p, count); } -void CV_LoadNetVars(UINT8 **p, boolean onlyIfChanged) +void CV_LoadNetVars(UINT8 **p) { consvar_t *cvar; UINT16 count; // prevent "invalid command received" serverloading = true; - serverloadingstealth = onlyIfChanged; for (cvar = consvar_vars; cvar; cvar = cvar->next) if (cvar->flags & CV_NETVAR) diff --git a/src/command.h b/src/command.h index 83d30352c..2276a0ae2 100644 --- a/src/command.h +++ b/src/command.h @@ -178,7 +178,7 @@ void CV_SaveVariables(FILE *f); // load/save gamesate (load and save option and for network join in game) void CV_SaveNetVars(UINT8 **p, boolean isdemorecording); -void CV_LoadNetVars(UINT8 **p, boolean onlyIfChanged); +void CV_LoadNetVars(UINT8 **p); // reset cheat netvars after cheats is deactivated void CV_ResetCheatNetVars(void); diff --git a/src/console.c b/src/console.c index fc33216ee..1327e561f 100644 --- a/src/console.c +++ b/src/console.c @@ -54,7 +54,6 @@ static boolean con_started = false; // console has been initialised boolean con_startup = false; // true at game startup, screen need refreshing static boolean con_forcepic = true; // at startup toggle console translucency when first off boolean con_recalc; // set true when screen size has changed - boolean con_muted = false; static tic_t con_tick; // console ticker for anim or blinking prompt cursor // con_scrollup should use time (currenttime - lasttime).. @@ -1261,7 +1260,7 @@ static void CON_Print(char *msg) INT32 controlchars = 0; // for color changing char color = '\x80'; // keep color across lines - if (msg == NULL || con_muted) + if (msg == NULL) return; if (*msg == '\3') // chat text, makes ding sound diff --git a/src/console.h b/src/console.h index 63f937529..377306b9f 100644 --- a/src/console.h +++ b/src/console.h @@ -27,9 +27,6 @@ extern boolean con_recalc; extern boolean con_startup; -// no messages will be printed while the console is muted -extern boolean con_muted; - // top clip value for view render: do not draw part of view hidden by console extern INT32 con_clipviewtop; diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5b1d1874b..9b48949e2 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -81,7 +81,7 @@ boolean nodownload = false; boolean serverrunning = false; INT32 serverplayer = 0; char motd[254], server_context[8]; // Message of the Day, Unique Context (even without Mumble support) -//char netDebugText[10000]; +//char netDebugText[10000]; //TODO move debug text out of d_clisrv, this is ass // Server specific vars UINT8 playernode[MAXPLAYERS]; @@ -4936,7 +4936,7 @@ static void HandlePacketFromAwayNode(SINT8 node) scp = netbuffer->u.servercfg.varlengthinputs; CV_LoadPlayerNames(&scp); - CV_LoadNetVars(&scp, false); + CV_LoadNetVars(&scp); #ifdef JOININGAME /// \note Wait. What if a Lua script uses some global custom variables synched with the NetVars hook? /// Shouldn't them be downloaded even at intermission time? @@ -6219,49 +6219,64 @@ boolean TryRunTics(tic_t realtics) ticking = neededtic > gametic; - // record the actual local controls + // detect if we can do simulation boolean canSimulate = (gamestate == GS_LEVEL) - && leveltime >= TICRATE*4 - && gametic >= TICRATE - //&& !countdown2 //SRB2Kart: No simulating after everyone has finished ... it breaks stuff + && leveltime >= NEWTICRATE && gametic >= NEWTICRATE && (cv_simulate.value && !server) && !exitcountdown //SRB2Kart: No simulating after everyone has finished ... it breaks stuff //countdown 2? the sequel? idk - && (cv_simulate.value && !server) //SRB2Kart: make it impossible to sim before the start of the race - && !resynch_local_inprogress && gametic >= lastSavestateClearedTic + TICRATE; - boolean recordingStates = canSimulate; + && !resynch_local_inprogress && gametic >= lastSavestateClearedTic + NEWTICRATE; //do not simulate for one second after clearing if (simtic > gametic && !canSimulate) { - // if we can't simulate anymore, we ought to reload and invalidate the savestates + // if we can't simulate anymore, we ought to reload a valid "server's" + // (in fact, our own) gamestate and then invalidate all of them. + // TODO 2.2.9 sends/receives savestates, we have to rewrite this later. + // maybe we should __specifically__ request the savestate from the server. + // we'll be requesting it anyway because if we desynched, we can't simulate. if (gameStateBufferIsValid[gametic % BACKUPTICS]) - P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); + { + if (!(gamestate == GS_INTERMISSION)) + P_LoadGameState(&gameStateBuffer[gametic % MAXSIMULATIONS]); + // Most of the time the RandSeed is correct (e.g. lua map voting) + // because we always load "real state" before making sims + // so setting it up explicitly for the intermission isn't needed. + // If RandSeed is not in synch with the server for whateva reason, it's + // an issue with vanilla SRB2(?) or we saved a bad gamestate + // TODO improve intermission handling later + // because we can get into intermission during sim with lua. + // it happened once with "battleroyale" lua mod + } else - CONS_Printf("Problem: game state buffer inaccessible! (simtic %d gametic %d)\n", simtic, gametic); + // CONS_Printf("Game state buffer is invalid! (simtic %d gametic %d)\n", simtic, gametic); + DEBFILE(va("NETPLUS: Game state buffer is invalid! (simtic %d gametic %d)\n", simtic, gametic)); simtic = gametic; - CONS_Printf("Clearing savestates due to !canSim\n"); + // CONS_Printf("Not simulating, clearing savestates...\n"); + DEBFILE("NETPLUS: Not simulating, clearing savestates...\n"); InvalidateSavestates(); } PerformDebugRewinds(); - liveTic = I_GetTime(); + liveTic = entertic; //we get entertic from SRB2Loop() // record the actual local controls for this frame for (tic_t i = 0; i < realtics; i++) localTicBuffer[(liveTic - i) % BACKUPTICS] = localcmds; - if (ticking && !resynch_local_inprogress) + if (ticking) { - // Load the real state if it exists - if (simtic != gametic && gameStateBufferIsValid[gametic % BACKUPTICS]) + // Load the real state if it exists before doing anything + // The server will resynch us anyway if things would go wrong + if (simtic > gametic && gameStateBufferIsValid[gametic % BACKUPTICS]) { P_LoadGameState(&gameStateBuffer[gametic % BACKUPTICS]); - - if (Consistancy() != consistancy[gametic%BACKUPTICS]) - CONS_Printf("oops, consistency error, even I got that one!\n"); + if (Consistancy() != consistancy[gametic % TICQUEUE]) + // CONS_Alert(CONS_WARNING, "Saved state at %d isn't consistent with recorded checksum\n", gametic); + DEBFILE(va("NETPLUS: Saved state at %d isn't consistent with recorded checksum\n", gametic)); } else if (simtic != gametic && !gameStateBufferIsValid[gametic % BACKUPTICS]) - CONS_Printf("Problem: game state buffer inaccessible but a simulation happened!!\n"); + // CONS_Alert(CONS_WARNING, "Game state buffer is inaccessible but a simulation happened\n"); + DEBFILE("NETPLUS: Game state buffer is inaccessible but a simulation happened\n"); // run the count * tics while (neededtic > gametic) @@ -6282,27 +6297,29 @@ boolean TryRunTics(tic_t realtics) consistancy[gametic%TICQUEUE] = Consistancy(); - if (recordingStates) + if (canSimulate) { - // store this real state - P_SaveGameState(&gameStateBuffer[gametic % BACKUPTICS]); - - gameStateBufferIsValid[gametic % BACKUPTICS] = true; - - // store the ticcmds used during this game tic + if (neededtic == gametic) + { + // store this real state (hopefully accurate to the one from server) + P_SaveGameState(&gameStateBuffer[gametic % BACKUPTICS]); + gameStateBufferIsValid[gametic % BACKUPTICS] = true; + } + // store the ticcmds used during this game tic for simulations + // TODO optimize it in a way that they won't be saved when we finished chasing to server's gamestate for (int i = 0; i < MAXPLAYERS; i++) - gameTicBuffer[gametic % BACKUPTICS][i] = netcmds[(gametic - 1) % BACKUPTICS][i]; + gameTicBuffer[gametic % MAXSIMULATIONS][i] = netcmds[(gametic - 1) % BACKUPTICS][i]; } + // Leave a certain amount of tics present in the net buffer as long as we've ran at least one tic this frame. + if (!canSimulate) //do not use the vanilla netbuffer or simulations will be doubled/tripled/so on + if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value) + break; if (update_stats) { PS_STOP_TIMING(ps_tictime); PS_UpdateTickStats(); } - - // Leave a certain amount of tics present in the net buffer as long as we've ran at least one tic this frame. - if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value) - break; } } @@ -6339,7 +6356,11 @@ UINT64 simEndTime; static void RunSimulations() { if (!gameStateBufferIsValid[gametic % BACKUPTICS]) + { + // CONS_Alert(CONS_WARNING, "Can't simulate, save on %d is invalid!\n", gametic); + DEBFILE(va("NETPLUS: Can't simulate, save on %d is invalid!\n", gametic)); return; // do not simulate if we cannot guarantee a recovery + } static int lastsimtic = 0; @@ -6422,25 +6443,33 @@ static void RunSimulations() // simulate the rest o da future issimulation = true; - con_muted = true; simStartTime = I_GetPrecisePrecision(); + // localangle_sim[liveTic % MAXSIMULATIONS] = localangle; for (int i = 0; i < numToSimulate; i++) { - // control other players (just use their previous control for now) + // // control other players (just use their previous control for now) + // here you can do all sorts of player predictions. for (int j = 0; j < MAXPLAYERS; j++) { if (playeringame[j] && j != consoleplayer) - netcmds[gametic % BACKUPTICS][j] = gameTicBuffer[(min(simtic + 1, gametic) + BACKUPTICS) % BACKUPTICS][j]; + //simtic+1 это для херни со smoothedTic + //use Memcpy or G_CopyTiccmd for that + netcmds[gametic % BACKUPTICS][j] = gameTicBuffer[(min(simtic + 1, gametic) + MAXSIMULATIONS) % MAXSIMULATIONS][j]; } // control the local player if (simtic + i < gametic) // game is smoothed, take tics from the _actual_ received state - netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(simtic + 1) % BACKUPTICS][consoleplayer]; + { + netcmds[gametic % BACKUPTICS][consoleplayer] = gameTicBuffer[(simtic + 1) % MAXSIMULATIONS][consoleplayer]; + } else - netcmds[gametic % BACKUPTICS][consoleplayer] = localTicBuffer[(liveTic - estimatedRTT + i + 1 + BACKUPTICS) % BACKUPTICS]; + { + netcmds[gametic % BACKUPTICS][consoleplayer] = localTicBuffer[(liveTic - estimatedRTT + i + 1 + MAXSIMULATIONS) % MAXSIMULATIONS]; + } + DEBFILE(va("============ Running SIM tic %d (local %d) (sim %d)\n", gametic, localgametic, simtic)); G_Ticker(true); // tic a bunch of times lol see what happens lolol simtic++; @@ -6458,12 +6487,11 @@ static void RunSimulations() } issimulation = false; - con_muted = false; // Finalise steadyplayers if (numToSimulate > 0) { - int histIndex = max((int)(simtic - smoothedTic) - cv_netsteadyplayers.value, 0); // up to cv_netsteadyplayers.value behind the simulation + int histIndex = max((int)(simtic - gametic) - cv_netsteadyplayers.value, 0); // up to cv_netsteadyplayers.value behind the simulation for (int i = 0; i < MAXPLAYERS; i++) { if (playeringame[i] && players[i].mo && i != consoleplayer && !players[i].spectator) @@ -6477,11 +6505,11 @@ static void RunSimulations() P_SetThingPosition(players[i].mo); // fill any holes in the simulation history (due to frame skips) - for (int j = (int)max(lastsimtic + 1, (int)simtic - 5); j <= (int)simtic; j++) + for (int j = (int)max(lastsimtic + 2, (int)simtic - 5); j <= (int)simtic; j++) { - steadyplayers[i].simx[j % BACKUPTICS] = steadyplayers[i].histx[histIndex]; - steadyplayers[i].simy[j % BACKUPTICS] = steadyplayers[i].histy[histIndex]; - steadyplayers[i].simz[j % BACKUPTICS] = steadyplayers[i].histz[histIndex]; + steadyplayers[i].simx[j % MAXSIMULATIONS] = steadyplayers[i].histx[histIndex]; + steadyplayers[i].simy[j % MAXSIMULATIONS] = steadyplayers[i].histy[histIndex]; + steadyplayers[i].simz[j % MAXSIMULATIONS] = steadyplayers[i].histz[histIndex]; } // Generate trails @@ -6492,12 +6520,12 @@ static void RunSimulations() for (int s = 0; s < trailLifetime; s++) { // If there is a big discrepency between the player's current position and their last one, spawn a trail showing their movements - fixed_t prevx = steadyplayers[i].simx[(simtic - s - 1) % BACKUPTICS], prevy = steadyplayers[i].simy[(simtic - s - 1) % BACKUPTICS], - prevz = steadyplayers[i].simz[(simtic - s - 1) % BACKUPTICS]; - fixed_t curx = steadyplayers[i].simx[(simtic - s) % BACKUPTICS], cury = steadyplayers[i].simy[(simtic - s) % BACKUPTICS], - curz = steadyplayers[i].simz[(simtic - s) % BACKUPTICS]; + fixed_t prevx = steadyplayers[i].simx[(simtic - s - 1) % MAXSIMULATIONS], prevy = steadyplayers[i].simy[(simtic - s - 1) % MAXSIMULATIONS], + prevz = steadyplayers[i].simz[(simtic - s - 1) % MAXSIMULATIONS]; + fixed_t curx = steadyplayers[i].simx[(simtic - s) % MAXSIMULATIONS], cury = steadyplayers[i].simy[(simtic - s) % MAXSIMULATIONS], + curz = steadyplayers[i].simz[(simtic - s) % MAXSIMULATIONS]; fixed_t distance = max(abs(curx - prevx), max(abs(cury - prevy), abs(curz - prevz))); - fixed_t stepDistance = 60 << FRACBITS; // distance between trail steps + fixed_t stepDistance = 60 << FRACBITS; // distance between trail steps fixed_t activationDistance = 60 << FRACBITS; // distance between trail steps // If player is changing direction quickly in a net simulation, create a ghost trail @@ -6509,7 +6537,7 @@ static void RunSimulations() for (currentStep = step; currentStep < (1 << FRACBITS); currentStep += step) { - mobj_t* ghost = P_SpawnGhostMobj(players[i].mo); + mobj_t *ghost = P_SpawnGhostMobj(players[i].mo); ghost->x = prevx + FixedMul(curx - prevx, currentStep); ghost->y = prevy + FixedMul(cury - prevy, currentStep); @@ -6526,17 +6554,19 @@ static void RunSimulations() // move steadyplayer shields and signs if (cv_netsteadyplayers.value) { - mobj_t* mobj; - player_t* redflagplayer = NULL; - player_t* blueflagplayer = NULL; + mobj_t *mobj; + player_t *redflagplayer = NULL; + player_t *blueflagplayer = NULL; -#define ADJUSTPOSITION(obj, player) do { \ - P_UnsetThingPosition(obj); \ - obj->x += steadyplayers[player].histx[histIndex] - steadyplayers[player].histx[simtic - gametic]; \ - obj->y += steadyplayers[player].histy[histIndex] - steadyplayers[player].histy[simtic - gametic]; \ - obj->z += steadyplayers[player].histz[histIndex] - steadyplayers[player].histz[simtic - gametic]; \ - P_SetThingPosition(obj); \ -} while(0) +#define ADJUSTPOSITION(obj, player) \ + do \ + { \ + P_UnsetThingPosition(obj); \ + obj->x += steadyplayers[player].histx[histIndex] - steadyplayers[player].histx[simtic - gametic]; \ + obj->y += steadyplayers[player].histy[histIndex] - steadyplayers[player].histy[simtic - gametic]; \ + obj->z += steadyplayers[player].histz[histIndex] - steadyplayers[player].histz[simtic - gametic]; \ + P_SetThingPosition(obj); \ + } while (0) for (int i = 0; i < MAXPLAYERS; i++) { @@ -6548,19 +6578,19 @@ static void RunSimulations() blueflagplayer = &players[i]; } -// if (players[i].followmobj) -// ADJUSTPOSITION(players[i].followmobj, i); + //if (players[i].followmobj) + //ADJUSTPOSITION(players[i].followmobj, i); } - //for (mobj = (mobj_t*)thlist[THINK_MOBJ].next; mobj != (mobj_t*)&thlist[THINK_MOBJ]; mobj = (mobj_t*)mobj->thinker.next) - //{ -// if (mobj->flags2 & MF2_SHIELD && mobj->target != NULL && mobj->target->player != NULL && mobj->target != players[consoleplayer].mo) -// ADJUSTPOSITION(mobj, mobj->target->player - players); -// else if (mobj->type == MT_BLUEFLAG && blueflagplayer) -// ADJUSTPOSITION(mobj, blueflagplayer - players); -// else if (mobj->type == MT_REDFLAG && redflagplayer) -// ADJUSTPOSITION(mobj, redflagplayer - players); - //} + /*for (mobj = (mobj_t *)thlist[THINK_MOBJ].next; mobj != (mobj_t *)&thlist[THINK_MOBJ]; mobj = (mobj_t *)mobj->thinker.next) + { + if (mobj->flags2 & MF2_SHIELD && mobj->target != NULL && mobj->target->player != NULL && mobj->target != players[consoleplayer].mo) + ADJUSTPOSITION(mobj, mobj->target->player - players); + else if (mobj->type == MT_BLUEFLAG && blueflagplayer) + ADJUSTPOSITION(mobj, blueflagplayer - players); + else if (mobj->type == MT_REDFLAG && redflagplayer) + ADJUSTPOSITION(mobj, redflagplayer - players); + }*/ } } diff --git a/src/g_game.c b/src/g_game.c index 4bdbf2265..0dccc4653 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -7784,7 +7784,7 @@ void G_DoPlayDemo(char *defdemoname) } // net var data - CV_LoadNetVars(&demo_p, false); + CV_LoadNetVars(&demo_p); // Sigh ... it's an empty demo. if (*demo_p == DEMOMARKER) @@ -7828,7 +7828,7 @@ void G_DoPlayDemo(char *defdemoname) #endif // net var data - CV_LoadNetVars(&demo_p, false); + CV_LoadNetVars(&demo_p); // Sigh ... it's an empty demo. if (*demo_p == DEMOMARKER) diff --git a/src/i_time.c b/src/i_time.c index a1ef580bd..863ed784c 100644 --- a/src/i_time.c +++ b/src/i_time.c @@ -27,7 +27,7 @@ static CV_PossibleValue_t timescale_cons_t[] = {{FRACUNIT/20, "MIN"}, {20*FRACUN consvar_t cv_timescale = {"timescale", "1.0", CV_NETVAR|CV_CHEAT|CV_FLOAT, timescale_cons_t, NULL, FRACUNIT, NULL, NULL, 0, 0, NULL}; static precise_t enterprecise, oldenterprecise; -static fixed_t entertic, oldentertics; +fixed_t entertic, oldentertics; static double tictimer; tic_t I_GetTime(void) diff --git a/src/i_time.h b/src/i_time.h index cab36133b..43531b91a 100644 --- a/src/i_time.h +++ b/src/i_time.h @@ -29,6 +29,7 @@ typedef struct timestate_s { extern timestate_t g_time; extern consvar_t cv_timescale; +extern fixed_t entertic, oldentertics; /** \brief Called by D_SRB2Loop, returns current time in game tics. */ diff --git a/src/p_saveg.c b/src/p_saveg.c index e225902f2..36eee2f77 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -500,14 +500,6 @@ static void P_LocalUnArchivePlayers(void) } } -/// -/// Colormaps -/// - -static extracolormap_t *net_colormaps = NULL; -static UINT32 num_net_colormaps = 0; -static UINT32 num_ffloors = 0; // for loading - #define SD_FLOORHT 0x01 #define SD_CEILHT 0x02 #define SD_FLOORPIC 0x04 @@ -3104,14 +3096,15 @@ static void P_LocalUnArchiveThinkers() { thinker_t *thinker; mobj_t* mobj; + //mobj_t* currentmobj; UINT8 tclass; UINT8 restoreExecutors = false; - INT32 i, j, list; - int skyviewid = 0; - int skycenterid = 0; + int32_t i, j, list; + //int skyviewid = 0; + i//nt skycenterid = 0; thinker_t newthinkers[NUM_THINKERLISTS] = { 0 }; static thinker_t* thinkersbytype[tc_end][16384]; - static int numthinkersbytype[tc_end]; + static uint32_t numthinkersbytype[tc_end]; static mobjloclink_t mobjByLoc[32768][MAXNUMMOBJSBYLOC]; static int numMobjsByLoc[32768]; static mobj_t* mobjByNum[16384]; @@ -3149,7 +3142,7 @@ static void P_LocalUnArchiveThinkers() for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next) { - if (thinker->function.acp1 == P_RemoveThinkerDelayed) + if (thinker->function.acp1 == P_RemoveThinkerDelayed || thinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) continue; for (j = 0; j < tc_end; j++) { @@ -3177,13 +3170,12 @@ static void P_LocalUnArchiveThinkers() // remove from item respawn queues iquetail = iquehead = 0; - waypointcap = NULL; // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity for (i = 0; i < (int)numsectors; i++) { mobj_t* thing = sectors[i].thinglist, *next; - sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata; + sectors[i].floordata = sectors[i].ceilingdata = sectors[i].lightingdata = NULL; // clear nothinkers too while (thing) @@ -3208,7 +3200,7 @@ static void P_LocalUnArchiveThinkers() sector_t* preserveSubsector = NULL; tclass = READUINT8(save_p); - + if (tclass == 0xFF) break; // next list @@ -3245,7 +3237,7 @@ static void P_LocalUnArchiveThinkers() { for (j = numthinkersbytype[tclass] - 1; j >= 0; j--) { - if (thinkersbytype[tclass][j] == NULL) + if (!thinkersbytype[tclass][j]) { numthinkersbytype[tclass]--; continue; @@ -3273,7 +3265,7 @@ static void P_LocalUnArchiveThinkers() } // detach any playing sounds from this object if we can (still need to work on doing this properly!) - //S_DetachChannelsFromOrigin((mobj_t*)newthinker); + // S_DetachChannelsFromOrigin((mobj_t*)newthinker); // unlink it from the old list (if it's not a nothinker) if (!(tclass == tc_mobj && (((mobj_t*)newthinker)->flags & MF_NOTHINK))) @@ -3292,7 +3284,7 @@ static void P_LocalUnArchiveThinkers() } // preserve vital positioning stuff (cleanup...) - mobj_t preservedMobj; + static mobj_t preservedMobj; if (tclass == tc_mobj) preservedMobj = *(mobj_t*)newthinker; @@ -3419,17 +3411,21 @@ static void P_LocalUnArchiveThinkers() for (i = 0; i < NUM_THINKERLISTS; i++) { thinker_t* next; + int ind = 0; for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = next) { next = thinker->next; + ind++; thinker->references = 0; if (thinker->function.acp1 == (actionf_p1)P_MobjThinker) P_RemoveSavegameMobj((mobj_t *)thinker, true); else if (thinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) - P_RemovePrecipMobj((precipmobj_t*)thinker); // i bet this is gonna break :D + // P_RemovePrecipMobj((precipmobj_t*)thinker); // i bet this is gonna break :D + // the problem was in using NetUnarchiving, we have to use our function to fix the weather + continue; else { // we can remove this thinker manually, bye! @@ -3438,7 +3434,7 @@ static void P_LocalUnArchiveThinkers() Z_Free(thinker); } } - + // connect the new linker list to the old linker list newthinkers[i].prev->next = thlist[i].next; thlist[i].next->prev = newthinkers[i].prev; @@ -3464,10 +3460,8 @@ static void P_LocalUnArchiveThinkers() } // restore pointers + #define RELINK(var) if (var) { UINT32 index = (UINT32)var; var = NULL; P_SetTarget(&var, mobjByNum[index]); } - - //RELINK(waypointcap); - for (thinker = thlist[THINK_MOBJ].next; thinker != &thlist[THINK_MOBJ]; thinker = thinker->next) { if (thinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) @@ -3509,15 +3503,9 @@ static void P_LocalUnArchiveThinkers() RELINK(players[i].axis1); RELINK(players[i].axis2); RELINK(players[i].awayviewmobj); - //RELINK(players[i].followmobj); - //RELINK(players[i].drone); } } #undef RELINK - - // restore skyboxes - //skyboxmo[0] = skyboxviewpnts[(skyviewid >= 0) ? skyviewid : 0]; - //skyboxmo[1] = skyboxcenterpnts[(skycenterid >= 0) ? skycenterid : 0]; } // @@ -3527,13 +3515,13 @@ static void P_NetUnArchiveThinkers(boolean preserveLevel) { thinker_t *currentthinker; thinker_t *next; - mobj_t* currentmobj; + //mobj_t* currentmobj; UINT8 tclass; UINT8 restoreNum = false; UINT32 i; UINT32 numloaded = 0; - int skyviewid = -1; - int skycenterid = -1; + //int skyviewid = -1; + //int skycenterid = -1; if (READUINT32(save_p) != ARCHIVEBLOCK_THINKERS) I_Error("Bad $$$.sav at archive block Thinkers"); @@ -4482,7 +4470,7 @@ boolean P_LoadGame(INT16 mapoverride) boolean P_LoadNetGame(boolean preserveLevel) { - CV_LoadNetVars(&save_p, false); + CV_LoadNetVars(&save_p); if (!P_NetUnArchiveMisc(preserveLevel)) return false; P_NetUnArchivePlayers(); @@ -4571,11 +4559,9 @@ void P_SaveGameState(savestate_t* savestate) // It uses a mixture of existing NetUnArchive functions and faster LocalUnArchive functions to do the job boolean P_LoadGameState(const savestate_t* savestate) { - angle_t preserveAngle = localangle; - INT32 preserveAiming = localaiming; INT16 savedGameMap; - save_p = ((unsigned char*)savestate->buffer); + save_p = (unsigned char *)(uintptr_t)savestate->buffer; savedGameMap = READINT16(save_p); globalmobjnum = READUINT32(save_p); @@ -4586,7 +4572,7 @@ boolean P_LoadGameState(const savestate_t* savestate) return false; } - CV_LoadNetVars(&save_p, true); + CV_LoadNetVars(&save_p); P_NetUnArchiveMisc(true); P_LocalUnArchivePlayers();