diff --git a/src/console.c b/src/console.c index 90212469e..8bd8518f9 100644 --- a/src/console.c +++ b/src/console.c @@ -43,8 +43,12 @@ #ifdef HAVE_THREADS I_mutex con_mutex; -# define Lock_state() I_lock_mutex(&con_mutex) -# define Unlock_state() I_unlock_mutex(con_mutex) +// g_in_exiting_signal_handler is an evil hack +// to avoid infinite SIGABRT recursion in the signal handler +// due to poisoned locks or mach-o kernel not supporting locks in signals +// or something like that. idk +# define Lock_state() if (!g_in_exiting_signal_handler) { I_lock_mutex(&con_mutex); } +# define Unlock_state() if (!g_in_exiting_signal_handler) { I_unlock_mutex(con_mutex); } #else/*HAVE_THREADS*/ # define Lock_state() # define Unlock_state() diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 9e20b5474..8b24616b6 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -50,6 +50,7 @@ #include "s_sound.h" // sfx_syfail #include "m_perfstats.h" #include "d_main.h" +#include "r_fps.h" #ifdef CLIENT_LOADINGSCREEN // cl loading screen @@ -5780,6 +5781,11 @@ static INT16 Consistancy(void) ret += P_GetRandSeed(); #ifdef MOBJCONSISTANCY + if (!thinkercap.next) + { + DEBFILE(va("Consistancy = %u\n", ret)); + return ret; + } if (gamestate == GS_LEVEL) { for (th = thinkercap.next; th != &thinkercap; th = th->next) @@ -5787,9 +5793,6 @@ static INT16 Consistancy(void) if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - mo = (mobj_t *)th; if (mo->flags & (MF_SPECIAL | MF_SOLID | MF_PUSHABLE | MF_BOSS | MF_MISSILE | MF_SPRING | MF_MONITOR | MF_FIRE | MF_ENEMY | MF_PAIN | MF_STICKY)) @@ -6292,6 +6295,8 @@ boolean TryRunTics(tic_t realtics) if (ticking) { + boolean tickInterp = true; + // run the count * tics while (neededtic > gametic) { @@ -6302,7 +6307,18 @@ boolean TryRunTics(tic_t realtics) if (update_stats) PS_START_TIMING(ps_tictime); - G_Ticker((gametic % NEWTICRATERATIO) == 0); + boolean run = (gametic % NEWTICRATERATIO) == 0; + + if (run && tickInterp) + { + // Update old view state BEFORE ticking so resetting + // the old interpolation state from game logic works. + R_UpdateViewInterpolation(); + tickInterp = false; // do not update again in sped-up tics + } + + G_Ticker(run); + ExtraDataTicker(); gametic++; consistancy[gametic%TICQUEUE] = Consistancy(); diff --git a/src/d_main.c b/src/d_main.c index 1c1f2060e..a9d1428a9 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -37,6 +37,7 @@ #include "d_net.h" #include "f_finale.h" #include "g_game.h" +#include "g_input.h" #include "hu_stuff.h" #include "i_sound.h" #include "i_system.h" @@ -150,6 +151,8 @@ INT32 eventhead, eventtail; boolean dedicated = false; +boolean loaded_config = false; + // // D_PostEvent // Called by the I/O functions when input is detected @@ -839,6 +842,8 @@ void D_SRB2Loop(void) // Fully completed frame made. finishprecise = I_GetPreciseTime(); + // Use the time before sleep for frameskip calculations: + // post-sleep time is literally being intentionally wasted deltasecs = (double)((INT64)(finishprecise - enterprecise)) / I_GetPrecisePrecision(); deltatics = deltasecs * NEWTICRATE; @@ -873,6 +878,8 @@ void D_SRB2Loop(void) } // Capture the time once more to get the real delta time. finishprecise = I_GetPreciseTime(); + deltasecs = (double)((INT64)(finishprecise - enterprecise)) / I_GetPrecisePrecision(); + deltatics = deltasecs * NEWTICRATE; } } @@ -1749,6 +1756,8 @@ void D_SRB2Main(void) savedata.lives = 0; // flag this as not-used + loaded_config = true; // so pallettechange doesent get called 500 times at startup lol + //------------------------------------------------ COMMAND LINE PARAMS // this must be done after loading gamedata, diff --git a/src/d_main.h b/src/d_main.h index d4d3e6e95..851eaa8b5 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -20,6 +20,8 @@ // make sure not to write back the config until it's been correctly loaded extern tic_t rendergametic; +extern boolean loaded_config; + extern char srb2home[256]; //Alam: My Home extern boolean usehome; //Alam: which path? extern const char *pandf; //Alam: how to path? diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 190879704..cd93e0355 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1076,6 +1076,11 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_controlperkey); CV_RegisterVar(&cv_turnsmooth); + CV_RegisterVar(&cv_rumble[0]); + CV_RegisterVar(&cv_rumble[1]); + CV_RegisterVar(&cv_rumble[2]); + CV_RegisterVar(&cv_rumble[3]); + CV_RegisterVar(&cv_usemouse); CV_RegisterVar(&cv_usemouse2); CV_RegisterVar(&cv_invertmouse); @@ -5795,8 +5800,7 @@ static void Command_Archivetest_f(void) i = 1; for (th = thinkercap.next; th != &thinkercap; th = th->next) if (th->function.acp1 == (actionf_p1)P_MobjThinker) - if (th->function.acp1 != (actionf_p1)P_RemoveThinkerDelayed) - ((mobj_t *)th)->mobjnum = i++; + ((mobj_t *)th)->mobjnum = i++; // allocate buffer buf = save_p = ZZ_Alloc(1024); @@ -6064,6 +6068,8 @@ static void Command_SkinSearch(void) */ static void Color_OnChange(void) { + G_SetPlayerGamepadIndicatorColor(0, 0); // i want this to always change so its here + if (!Playing()) return; // do whatever you want @@ -6083,6 +6089,8 @@ static void Color_OnChange(void) CV_StealthSetValue(&cv_playercolor, players[consoleplayer].skincolor); } + + G_SetPlayerGamepadIndicatorColor(0, 0); // update again } /** Sends a color change for the secondary splitscreen player, unless that @@ -6105,6 +6113,8 @@ static void Color2_OnChange(void) CV_StealthSetValue(&cv_playercolor2, players[displayplayers[1]].skincolor); } + + G_SetPlayerGamepadIndicatorColor(1, 0); } static void Color3_OnChange(void) @@ -6122,6 +6132,8 @@ static void Color3_OnChange(void) CV_StealthSetValue(&cv_playercolor3, players[displayplayers[2]].skincolor); } + + G_SetPlayerGamepadIndicatorColor(2, 0); } static void Color4_OnChange(void) @@ -6139,6 +6151,8 @@ static void Color4_OnChange(void) CV_StealthSetValue(&cv_playercolor4, players[displayplayers[3]].skincolor); } + + G_SetPlayerGamepadIndicatorColor(3, 0); } /** Displays the result of the chat being muted or unmuted. diff --git a/src/g_game.c b/src/g_game.c index 9032a0377..2526b88ac 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -525,6 +525,8 @@ consvar_t cv_sliptideroll = {"sliptideroll", "Off", CV_SAVE, CV_OnOff, NULL, 0, consvar_t cv_cechotoggle = {"show_cecho", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +static void G_FixCamera(UINT8 view); + #if MAXPLAYERS > 16 #error "please update player_name table using the new value for MAXPLAYERS" #endif @@ -2085,7 +2087,6 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) UINT8 viewd; INT32 *displayplayerp; - camera_t *camerap; INT32 olddisplayplayer; INT32 playersviewable; @@ -2124,34 +2125,21 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) (*displayplayerp) = playernum; if ((*displayplayerp) != olddisplayplayer) { - camerap = &camera[viewnum-1]; - P_ResetCamera(&players[(*displayplayerp)], camerap); - - // Make sure the viewport doesn't interpolate at all into - // its new position -- just snap instantly into place. - R_ResetViewInterpolation(viewnum); + G_FixCamera(viewnum); } if (viewnum > splits) { for (viewd = splits+1; viewd < viewnum; ++viewd) { - displayplayerp = (&displayplayers[viewd-1]); - camerap = &camera[viewd]; - - (*displayplayerp) = G_FindView(0, viewd, onlyactive, false); - - P_ResetCamera(&players[(*displayplayerp)], camerap); - - - // Make sure the viewport doesn't interpolate at all into - // its new position -- just snap instantly into place. - R_ResetViewInterpolation(viewd); + G_FixCamera(viewd); } } if (viewnum == 1 && demo.playback) consoleplayer = displayplayers[0]; + + G_SetPlayerGamepadIndicatorColor(viewnum-1, 0); } // @@ -2204,6 +2192,26 @@ void G_ResetViews(void) } } +// +// G_FixCamera +// Reset camera position, angle and interpolation on a view +// after changing state. +// +static void G_FixCamera(UINT8 view) +{ + player_t *player = &players[displayplayers[view - 1]]; + + // The order of displayplayers can change, which would + // invalidate localangle. + localangle[view - 1] = player->cmd.angleturn; + + P_ResetCamera(player, &camera[view - 1]); + + // Make sure the viewport doesn't interpolate at all into + // its new position -- just snap instantly into place. + R_ResetViewInterpolation(view); +} + // // G_Ticker // Make ticcmd_ts for the players. @@ -3053,9 +3061,6 @@ void G_ChangePlayerReferences(mobj_t *oldmo, mobj_t *newmo) if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - mo2 = (mobj_t *)th; if (!(mo2->flags & MF_MISSILE)) @@ -3077,6 +3082,12 @@ void G_DoReborn(INT32 playernum) player_t *player = &players[playernum]; boolean starpost = false; + /*if (modeattacking) // Not needed for SRB2Kart. + { + M_EndModeAttackRun(); + return; + }*/ + // Make sure objectplace is OFF when you first start the level! OP_ResetObjectplace(); @@ -3090,13 +3101,74 @@ void G_DoReborn(INT32 playernum) oldmo = player->mo; // Don't leave your carcass stuck 10-billion feet in the ground! P_RemoveMobj(player->mo); - P_SetTarget(&player->mo, NULL); } B_RespawnBot(playernum); if (oldmo) G_ChangePlayerReferences(oldmo, players[playernum].mo); } + /*else if (countdowntimeup || (!multiplayer && !modeattacking)) + { + // reload the level from scratch + if (countdowntimeup) + { + player->starpostangle = 0; + player->starposttime = 0; + player->starpostx = 0; + player->starposty = 0; + player->starpostz = 0; + player->starpostnum = 0; + } + if (!countdowntimeup && (mapheaderinfo[gamemap-1]->levelflags & LF_NORELOAD)) + { + INT32 i; + + player->playerstate = PST_REBORN; + + P_LoadThingsOnly(); + + // Do a wipe + wipegamestate = -1; + + if (player->starpostnum) // SRB2kart + starpost = true; + + for (i = 0; i <= splitscreen; i++) + { + if (camera[i].chase) + P_ResetCamera(&players[displayplayers[i]], &camera[i]); + } + + // clear cmd building stuff + memset(gamekeydown, 0, sizeof (gamekeydown)); + for (i = 0;i < JOYAXISSET; i++) + { + joyxmove[i] = joyymove[i] = 0; + joy2xmove[i] = joy2ymove[i] = 0; + joy3xmove[i] = joy3ymove[i] = 0; + joy4xmove[i] = joy4ymove[i] = 0; + } + mousex = mousey = 0; + mouse2x = mouse2y = 0; + + // clear hud messages remains (usually from game startup) + CON_ClearHUD(); + + // Starpost support + G_SpawnPlayer(playernum, starpost); + + if (botingame) + { // Bots respawn next to their master. + players[displayplayers[1]].playerstate = PST_REBORN; + G_SpawnPlayer(displayplayers[1], false); + } + } + else + { + LUAh_MapChange(gamemap); + G_DoLoadLevel(true); + } + }*/ else { // respawn at the start @@ -3113,7 +3185,6 @@ void G_DoReborn(INT32 playernum) oldmo = player->mo; // Don't leave your carcass stuck 10-billion feet in the ground! P_RemoveMobj(player->mo); - P_SetTarget(&player->mo, NULL); } G_SpawnPlayer(playernum, starpost); @@ -5660,13 +5731,12 @@ void G_ConsGhostTic(INT32 playernum) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mobj = (mobj_t *)th; if (mobj->type == (mobjtype_t)type && mobj->x == x && mobj->y == y && mobj->z == z) break; + mobj = NULL; // wasn't this one, keep searching. } - if ((th != &thinkercap && th->function.acp1 != (actionf_p1)P_MobjThinker) && mobj->health != health) // Wasn't damaged?! This is desync! Fix it! + if (mobj && mobj->health != health) // Wasn't damaged?! This is desync! Fix it! { if (demosynced) CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced!\n")); @@ -8133,14 +8203,11 @@ void G_DoPlayMetal(void) if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - mo = (mobj_t *)th; if (mo->type == MT_METALSONIC_RACE) break; } - if (th == &thinkercap && th->function.acp1 == (actionf_p1)P_MobjThinker) + if (!mo) { CONS_Alert(CONS_ERROR, M_GetText("Failed to find bot entity.\n")); Z_Free(metalbuffer); @@ -8479,7 +8546,12 @@ boolean G_DemoTitleResponder(event_t *ev) // void G_SetGamestate(gamestate_t newstate) { + SINT8 i; gamestate = newstate; + + for (i = 0; i <= splitscreen; i++) + G_SetPlayerGamepadIndicatorColor(i, 0); // dumb hack but works + #ifdef HAVE_DISCORDRPC DRPC_UpdatePresence(); #endif diff --git a/src/g_input.c b/src/g_input.c index 536ea0c83..f7057d4e4 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -14,11 +14,17 @@ #include "doomdef.h" #include "doomstat.h" #include "g_input.h" +#include "g_game.h" #include "keys.h" #include "hu_stuff.h" // need HUFONT start & end #include "d_net.h" #include "console.h" +#include "i_system.h" +#include "i_video.h" +#include "r_draw.h" +#include "v_video.h" + #define MAXMOUSESENSITIVITY 100 // sensitivity steps static CV_PossibleValue_t mousesens_cons_t[] = {{1, "MIN"}, {MAXMOUSESENSITIVITY, "MAX"}, {0, NULL}}; @@ -33,6 +39,46 @@ consvar_t cv_mouseysens2 = {"mouseysens2", "20", CV_SAVE, mousesens_cons_t, NULL consvar_t cv_controlperkey = {"controlperkey", "One", CV_SAVE, onecontrolperkey_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_turnsmooth = {"turnsmoothing", "Slow", CV_SAVE, turnsmooth_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +static void G_ResetPlayerDeviceRumble(INT32 player); +static void rumble_off_handle(void); +static void rumble_off_handle2(void); +static void rumble_off_handle3(void); +static void rumble_off_handle4(void); + +consvar_t cv_rumble[MAXSPLITSCREENPLAYERS] = { + {"rumble", "Off", CV_SAVE, CV_OnOff, rumble_off_handle, 0, NULL, NULL, 0, 0, NULL}, + {"rumble2", "Off", CV_SAVE, CV_OnOff, rumble_off_handle2, 0, NULL, NULL, 0, 0, NULL}, + {"rumble3", "Off", CV_SAVE, CV_OnOff, rumble_off_handle3, 0, NULL, NULL, 0, 0, NULL}, + {"rumble4", "Off", CV_SAVE, CV_OnOff, rumble_off_handle4, 0, NULL, NULL, 0, 0, NULL} +}; + +static void rumble_off_handle(void) +{ + if (cv_rumble[0].value == 0) + G_ResetPlayerDeviceRumble(0); +} + + +static void rumble_off_handle2(void) +{ + if (cv_rumble[1].value == 0) + G_ResetPlayerDeviceRumble(1); +} + + +static void rumble_off_handle3(void) +{ + if (cv_rumble[2].value == 0) + G_ResetPlayerDeviceRumble(2); +} + + +static void rumble_off_handle4(void) +{ + if (cv_rumble[3].value == 0) + G_ResetPlayerDeviceRumble(3); +} + INT32 mousex, mousey; INT32 mlooky; // like mousey but with a custom sensitivity for mlook @@ -817,6 +863,113 @@ static const char *gamecontrolname[num_gamecontrols] = #define NUMKEYNAMES (sizeof (keynames)/sizeof (keyname_t)) +#include "k_kart.h" + +static INT32 G_GetDeviceForPlayer(INT32 player) +{ + switch (player) + { + case 0: + return cv_usejoystick.value; + break; + case 1: + return cv_usejoystick2.value; + break; + case 2: + return cv_usejoystick3.value; + break; + case 3: + return cv_usejoystick4.value; + break; + default: + return 0; + break; + } +} + +static UINT16 G_GetSkinColor(INT32 player) +{ + if (players[displayplayers[player]].skincolor && gamestate == GS_LEVEL) + return players[displayplayers[player]].skincolor; + + switch (player) + { + case 0: + return cv_playercolor.value; + break; + case 1: + return cv_playercolor2.value; + break; + case 2: + return cv_playercolor3.value; + break; + case 3: + return cv_playercolor4.value; + break; + default: + return 0; + break; + } +} + +void G_SetPlayerGamepadIndicatorColor(INT32 player, UINT16 color) +{ + INT32 device; + UINT16 skincolor; + byteColor_t byte_color; + + I_Assert(player >= 0 && player < MAXSPLITSCREENPLAYERS); + + device = G_GetDeviceForPlayer(player); + + if (device <= 0) + { + return; + } + + if (color) + skincolor = color; + else + skincolor = G_GetSkinColor(player); + + byte_color = V_GetColor(colortranslations[skincolor][8]).s; + + I_SetGamepadIndicatorColor(device, byte_color.red, byte_color.green, byte_color.blue); +} + +static void G_ResetPlayerDeviceRumble(INT32 player) +{ + INT32 device_id; + + device_id = G_GetDeviceForPlayer(player); + + if (device_id < 1) + { + return; + } + + I_GamepadRumble(device_id, 0, 0, 0); +} + +void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength, UINT32 duration) +{ + INT32 device_id; + + if (cv_rumble[player].value == 0) + { + return; + } + + device_id = G_GetDeviceForPlayer(player); + + if (device_id < 1) + { + return; + } + + I_GamepadRumble(device_id, low_strength, high_strength, duration); +} + // // Detach any keys associated to the given game control // - pass the pointer to the gamecontrol table for the player being edited diff --git a/src/g_input.h b/src/g_input.h index 635e1f64b..92444cccc 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -15,6 +15,7 @@ #define __G_INPUT__ #include "d_event.h" +#include "doomstat.h" #include "keys.h" #include "command.h" @@ -106,6 +107,7 @@ typedef enum extern consvar_t cv_mousesens, cv_mouseysens; extern consvar_t cv_mousesens2, cv_mouseysens2; extern consvar_t cv_controlperkey, cv_turnsmooth; +extern consvar_t cv_rumble[MAXSPLITSCREENPLAYERS]; extern INT32 mousex, mousey; extern INT32 mlooky; //mousey with mlookSensitivity @@ -130,6 +132,9 @@ extern INT32 gamecontrol4[num_gamecontrols][2]; // peace to my little coder fingers! // check a gamecontrol being active or not +void G_SetPlayerGamepadIndicatorColor(INT32 player, UINT16 color); +void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength, UINT32 duration); + // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 542a99b33..4a8a5dd9c 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -28,7 +28,7 @@ typedef struct gr_vissprite_s float x1, x2; float z1, z2; float gz, gzt; - float tz, ty; + float tz; float scale; float spritexscale, spriteyscale; float spritexoffset, spriteyoffset; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 676c018d1..3b65f1e96 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -500,9 +500,6 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col tint_color.rgba = (colormap != NULL) ? (UINT32)colormap->rgba : GL_DEFAULTMIX; fade_color.rgba = (colormap != NULL) ? (UINT32)colormap->fadergba : GL_DEFAULTFOG; - // Clamp the light level, since it can sometimes go out of the 0-255 range from animations - light_level = CLAMP(SOFTLIGHT(light_level), cv_secbright.value, 255); - // Crappy backup coloring if you can't do shaders if (!HWR_UseShader()) { @@ -540,6 +537,9 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col poly_color.s.blue = (UINT8)blue; } + // Clamp the light level, since it can sometimes go out of the 0-255 range from animations + light_level = CLAMP(SOFTLIGHT(light_level), cv_secbright.value, 255); + // in palette rendering mode, this is not needed since it properly takes the changes to the palette itself if (!HWR_ShouldUsePaletteRendering()) { @@ -3173,7 +3173,7 @@ static void HWR_Subsector(size_t num) false, *rover->bottomheight, *gr_frontsector->lightlist[light].lightlevel, - rover->alpha, rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, + CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, false, gr_frontsector->lightlist[light].extra_colormap); } else @@ -3217,7 +3217,7 @@ static void HWR_Subsector(size_t num) true, *rover->topheight, *gr_frontsector->lightlist[light].lightlevel, - rover->alpha, rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, + CLAMP(rover->alpha, 0 ,255), rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, false, gr_frontsector->lightlist[light].extra_colormap); } else @@ -3711,12 +3711,10 @@ static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts static void HWR_SplitSprite(gr_vissprite_t *spr) { - float this_scale = 1.0f; FOutVector wallVerts[4]; FOutVector baseWallVerts[4]; // This is what the verts should end up as GLPatch_t *gpatch; FSurfaceInfo Surf; - const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->flags & SF_HIRES); extracolormap_t *colormap; FUINT lightlevel; FBITFIELD blend = 0; @@ -3736,11 +3734,6 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) fixed_t v1x, v1y, v2x, v2y; INT32 shader = SHADER_NONE; - this_scale = FIXED_TO_FLOAT(spr->mobj->scale); - - if (hires) - this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->highresscale); - gpatch = spr->gpatch; //W_CachePatchNum(spr->patchlumpnum, PU_CACHE); // cache the patch in the graphics card memory @@ -3801,7 +3794,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) // push it toward the camera to mitigate floor-clipping sprites { - float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->ty - gr_viewz)*(spr->ty - gr_viewz)); + float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; for (i = 0; i < 4; i++) { @@ -3872,7 +3865,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) continue; if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i-1].lightlevel; + lightlevel = min(*list[i-1].lightlevel, 255); colormap = list[i-1].extra_colormap; break; } @@ -3886,7 +3879,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (!(list[i].flags & FF_NOSHADE) && (list[i].flags & FF_CUTSPRITES)) { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i].lightlevel; + lightlevel = min(*list[i-1].lightlevel, 255); colormap = list[i].extra_colormap; } @@ -3990,7 +3983,6 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) // -----------------+ static void HWR_DrawSprite(gr_vissprite_t *spr) { - float this_scale = 1.0f; FOutVector wallVerts[4]; GLPatch_t *gpatch; // sprite patch converted to hardware FSurfaceInfo Surf; @@ -4009,12 +4001,6 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) return; } - const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->flags & SF_HIRES); - if (spr->mobj) - this_scale = FIXED_TO_FLOAT(spr->mobj->scale); - if (hires) - this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->highresscale); - // cache sprite graphics //12/12/99: Hurdler: // OK, I don't change anything for MD2 support because I want to be @@ -4083,7 +4069,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) // push it toward the camera to mitigate floor-clipping sprites { - float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->ty - gr_viewz)*(spr->ty - gr_viewz)); + float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; size_t i; for (i = 0; i < 4; i++) @@ -4104,7 +4090,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) extracolormap_t *colormap = sector->extra_colormap; if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = sector->lightlevel; + lightlevel = min(sector->lightlevel, 255); HWR_Lighting(&Surf, lightlevel, colormap); @@ -4169,8 +4155,8 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) // 0--1 wallVerts[0].x = wallVerts[3].x = spr->x1; wallVerts[2].x = wallVerts[1].x = spr->x2; - wallVerts[2].y = wallVerts[3].y = spr->ty; - wallVerts[0].y = wallVerts[1].y = spr->ty - gpatch->height; + wallVerts[2].y = wallVerts[3].y = spr->gzt; + wallVerts[0].y = wallVerts[1].y = spr->gz; // make a wall polygon (with 2 triangles), using the floor/ceiling heights, // and the 2d map coords of start/end vertices @@ -4203,7 +4189,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) light = R_GetPlaneLight(sector, spr->mobj->z + spr->mobj->height, false); // Always use the light at the top instead of whatever I was doing before if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *sector->lightlist[light].lightlevel; + lightlevel = min(*sector->lightlist[light].lightlevel, 255); if (sector->lightlist[light].extra_colormap) colormap = sector->lightlist[light].extra_colormap; @@ -4211,7 +4197,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) else { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = sector->lightlevel; + lightlevel = min(sector->lightlevel, 255); if (sector->extra_colormap) colormap = sector->extra_colormap; @@ -4405,7 +4391,7 @@ void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, boolean planeinfo->lumpnum = lumpnum; planeinfo->xsub = xsub; - planeinfo->alpha = CLAMP(alpha, 0, 255); + planeinfo->alpha = alpha; planeinfo->FOFSector = FOFSector; planeinfo->blend = blend; planeinfo->fogplane = fogplane; @@ -4425,7 +4411,7 @@ void HWR_AddTransparentPolyobjectFloor(lumpnum_t lumpnum, polyobj_t *polysector, polyplaneinfo->lumpnum = lumpnum; polyplaneinfo->polysector = polysector; - polyplaneinfo->alpha = CLAMP(alpha, 0, 255); + polyplaneinfo->alpha = alpha; polyplaneinfo->FOFSector = FOFSector; polyplaneinfo->blend = blend; polyplaneinfo->planecolormap = planecolormap; @@ -4767,7 +4753,7 @@ void HWR_ProjectSprite(mobj_t *thing) float x1, x2; float z1, z2; float rightsin, rightcos; - float this_scale, this_xscale, this_yscale; + float this_scale; float spritexscale, spriteyscale; float gz, gzt; spritedef_t *sprdef; @@ -5001,20 +4987,20 @@ void HWR_ProjectSprite(mobj_t *thing) rightcos = FIXED_TO_FLOAT(FINECOSINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); } - this_xscale = spritexscale * this_scale; - this_yscale = spriteyscale * this_scale; + spritexscale *= this_scale; + spriteyscale *= this_scale; flip = !flip != !hflip; if (flip) { - x1 = (FIXED_TO_FLOAT(spr_width - spr_offset) * this_xscale); - x2 = (FIXED_TO_FLOAT(spr_offset) * this_xscale); + x1 = (FIXED_TO_FLOAT(spr_width - spr_offset) * spritexscale); + x2 = (FIXED_TO_FLOAT(spr_offset) * spritexscale); } else { - x1 = (FIXED_TO_FLOAT(spr_offset) * this_xscale); - x2 = (FIXED_TO_FLOAT(spr_width - spr_offset) * this_xscale); + x1 = (FIXED_TO_FLOAT(spr_offset) * spritexscale); + x2 = (FIXED_TO_FLOAT(spr_width - spr_offset) * spritexscale); } z1 = tr_y + x1 * rightsin; @@ -5022,16 +5008,15 @@ void HWR_ProjectSprite(mobj_t *thing) x1 = tr_x + x1 * rightcos; x2 = tr_x - x2 * rightcos; - if (thing->eflags & MFE_VERTICALFLIP) { - gz = FIXED_TO_FLOAT(interp.z + thing->height) - (FIXED_TO_FLOAT(spr_topoffset) * this_yscale); - gzt = gz + (FIXED_TO_FLOAT(spr_height) * this_yscale); + gz = FIXED_TO_FLOAT(interp.z + thing->height) - (FIXED_TO_FLOAT(spr_topoffset) * spriteyscale); + gzt = gz + (FIXED_TO_FLOAT(spr_height) * spriteyscale); } else { - gzt = FIXED_TO_FLOAT(interp.z) + (FIXED_TO_FLOAT(spr_topoffset) * this_yscale); - gz = gzt - (FIXED_TO_FLOAT(spr_height) * this_yscale); + gzt = FIXED_TO_FLOAT(interp.z) + (FIXED_TO_FLOAT(spr_topoffset) * spriteyscale); + gz = gzt - (FIXED_TO_FLOAT(spr_height) * spriteyscale); } if (thing->subsector->sector->cullheight) @@ -5114,8 +5099,6 @@ void HWR_ProjectSprite(mobj_t *thing) } // set top/bottom coords - vis->ty = gzt; - vis->gzt = gzt; vis->gz = gz; @@ -5244,8 +5227,6 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) #endif // set top/bottom coords - vis->ty = FIXED_TO_FLOAT(interp.z + spritecachedinfo[lumpoff].topoffset); - vis->gzt = FIXED_TO_FLOAT(interp.z + spritecachedinfo[lumpoff].topoffset); vis->gz = vis->gzt - FIXED_TO_FLOAT(spritecachedinfo[lumpoff].height); diff --git a/src/http-mserv.c b/src/http-mserv.c index d1ef80ae4..9e32f9ea7 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -532,7 +532,9 @@ HMS_fetch_rules (char *buffer, size_t buffer_size) if (! hms) return NULL; - if (HMS_do(hms)) + boolean ok = HMS_do(hms); + + if (ok) { char *p = strstr(hms->buffer, "\n\n"); @@ -550,6 +552,9 @@ HMS_fetch_rules (char *buffer, size_t buffer_size) HMS_end(hms); + if (!ok) + return NULL; + return buffer; } diff --git a/src/i_system.h b/src/i_system.h index a78eb5c5e..f49bca4a1 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -34,6 +34,9 @@ extern UINT8 graphics_started; */ extern UINT8 keyboard_started; +/** \brief Set to true when inside a signal handler that will exit the program. */ +extern boolean g_in_exiting_signal_handler; + /** \brief The I_GetFreeMem function \param total total memory in the system @@ -227,6 +230,9 @@ INT32 I_NumJoys(void); */ const char *I_GetJoyName(INT32 joyindex); +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength, UINT32 duration); +void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue); + #ifndef NOMUMBLE #include "p_mobj.h" // mobj_t #include "s_sound.h" // listener_t diff --git a/src/k_director.c b/src/k_director.c index eb4e458ed..c0687494d 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -21,11 +21,21 @@ #define SWITCHTIME TICRATE * 5 // cooldown between unforced switches #define BOREDOMTIME 3 * TICRATE / 2 // how long until players considered far apart? #define TRANSFERTIME TICRATE // how long to delay reaction shots? -#define BREAKAWAYDIST 4000 // how *far* until players considered far apart? +#define BREAKAWAYDIST 2000 // how *far* until players considered far apart? #define WALKBACKDIST 600 // how close should a trailing player be before we switch? -#define PINCHDIST 30000 // how close should the leader be to be considered "end of race"? +#define PINCHDIST 20000 // how close should the leader be to be considered "end of race"? -struct directorinfo directorinfo; +struct directorinfo +{ + tic_t cooldown; // how long has it been since we last switched? + tic_t freeze; // when nonzero, fixed switch pending, freeze logic! + INT32 attacker; // who to switch to when freeze delay elapses + INT32 maxdist; // how far is the closest player from finishing? + + INT32 sortedplayers[MAXPLAYERS]; // position-1 goes in, player index comes out. + INT32 gap[MAXPLAYERS]; // gap between a given position and their closest pursuer + INT32 boredom[MAXPLAYERS]; // how long has a given position had no credible attackers? +} directorinfo; static boolean race_rules() { @@ -164,7 +174,7 @@ static void K_UpdateDirectorPositions(void) if (directorinfo.gap[position] >= BREAKAWAYDIST) { - directorinfo.boredom[position] = min(BOREDOMTIME * 2, directorinfo.boredom[position] + 1); + directorinfo.boredom[position] = (INT32)(min(BOREDOMTIME * 2, directorinfo.boredom[position] + 1)); } else if (directorinfo.boredom[position] > 0) { @@ -183,13 +193,6 @@ static void K_UpdateDirectorPositions(void) static boolean K_CanSwitchDirector(void) { - /*INT32 *displayplayerp = &displayplayers[0]; - - if (players[*displayplayerp].trickpanel > 0) - { - return false; - }*/ - if (directorinfo.cooldown > 0) { return false; @@ -283,10 +286,10 @@ void K_DrawDirectorDebugger(void) V_DrawThinString(10, ytxt, V_70TRANS, va("%d", position)); V_DrawThinString(20, ytxt, V_70TRANS, va("%d", position + 1)); - /*if (players[leader].positiondelay) + if (players[leader].kartstuff[k_positiondelay]) { V_DrawThinString(40, ytxt, V_70TRANS, va("NG")); - }*/ + } V_DrawThinString(80, ytxt, V_70TRANS, va("%d", directorinfo.gap[position])); @@ -377,14 +380,20 @@ void K_UpdateDirector(void) target = directorinfo.sortedplayers[targetposition]; + // stop here since we're already viewing this player + if (*displayplayerp == target) + { + break; + } + // if we're certain the back half of the pair is actually in this position, try to switch - if (*displayplayerp != target /*&& !players[target].positiondelay*/) + if (!players[target].kartstuff[k_positiondelay]) { K_DirectorSwitch(target, false); } // even if we're not certain, if we're certain we're watching the WRONG player, try to switch - if (players[*displayplayerp].kartstuff[k_position] != targetposition+1 /*&& !players[target].positiondelay*/) + if (players[*displayplayerp].kartstuff[k_position] != targetposition+1 && !players[*displayplayerp].kartstuff[k_positiondelay]) { K_DirectorSwitch(target, false); } diff --git a/src/k_director.h b/src/k_director.h index 7218cc7e3..3be71b675 100644 --- a/src/k_director.h +++ b/src/k_director.h @@ -10,18 +10,6 @@ /// \file k_director.h /// \brief SRB2kart automatic spectator camera. -extern struct directorinfo -{ - tic_t cooldown; // how long has it been since we last switched? - tic_t freeze; // when nonzero, fixed switch pending, freeze logic! - INT32 attacker; // who to switch to when freeze delay elapses - INT32 maxdist; // how far is the closest player from finishing? - - INT32 sortedplayers[MAXPLAYERS]; // position-1 goes in, player index comes out. - INT32 gap[MAXPLAYERS]; // gap between a given position and their closest pursuer - INT32 boredom[MAXPLAYERS]; // how long has a given position had no credible attackers? -} directorinfo; - void K_InitDirector(void); void K_UpdateDirector(void); void K_DrawDirectorDebugger(void); diff --git a/src/k_kart.c b/src/k_kart.c index 3f134ef33..293e5209b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -617,10 +617,8 @@ UINT8 K_GetKartColorByName(const char *name) UINT8 K_GetHudColor(void) { - if (cv_colorizedhud.value){ - if (cv_colorizedhudcolor.value) return cv_colorizedhudcolor.value; - } - if (stplyr && P_IsLocalPlayer(stplyr) && gamestate == GS_LEVEL) return stplyr->skincolor; + if (cv_colorizedhud.value && cv_colorizedhudcolor.value) return cv_colorizedhudcolor.value; + return ((stplyr && gamestate == GS_LEVEL) ? stplyr->skincolor : cv_playercolor.value); } @@ -4139,13 +4137,6 @@ void K_UpdateHnextList(player_t *player, boolean clean) P_RemoveMobj(work); } - - if (player->mo->hnext == NULL || P_MobjWasRemoved(player->mo->hnext)) - { - // Like below, try to clean up the pointer if it's NULL. - // Maybe this was a cause of the shrink/eggbox fails? - P_SetTarget(&player->mo->hnext, NULL); - } } // For getting hit! @@ -10663,6 +10654,9 @@ void K_drawKartHUD(void) if (cv_kartdebugcheckpoint.value) K_drawCheckpointDebugger(); + if (cv_kartdebugdirector.value) + K_DrawDirectorDebugger(); + if (cv_kartdebugnodes.value) { UINT8 p; diff --git a/src/lua_baselib.c b/src/lua_baselib.c index be561e7ba..f5763dc09 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -20,6 +20,7 @@ #include "m_random.h" #include "s_sound.h" #include "g_game.h" +#include "g_input.h" #include "hu_stuff.h" // HU_AddChatText #include "console.h" #include "k_kart.h" // SRB2Kart @@ -3000,6 +3001,57 @@ static int lib_kSetHyuCountdown(lua_State *L) return 0; } +// G_INPUT +//////////// + +static int lib_gSetPlayerGamepadIndicatorColor(lua_State *L) +{ + INT32 player = -1; + player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); // retrieve player + UINT16 color = (UINT16)luaL_checkinteger(L, 2); // skincolor + + for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) + { + if (plr - players == displayplayers[i]) + { + player = i; + break; + } + } + + // Not a local player + if (player == -1) return 0; + + G_SetPlayerGamepadIndicatorColor(player, color); + + return 0; +} + +static int lib_gPlayerDeviceRumble(lua_State *L) +{ + INT32 player = -1; + player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); // retrieve player + UINT16 low_strength = (UINT16)luaL_checkinteger(L, 2); // low frequency rumble motor strenght + UINT16 high_strength = (UINT16)luaL_checkinteger(L, 3); // high frequency rumble motor strenght + UINT32 duration = (UINT32)luaL_optinteger(L, 4, 84); // duration of rumble in ms + + for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) + { + if (plr - players == displayplayers[i]) + { + player = i; + break; + } + } + + // Not a local player + if (player == -1) return 0; + + G_PlayerDeviceRumble(player, low_strength, high_strength, duration); + + return 0; +} + static luaL_Reg lib[] = { {"print", lib_print}, {"chatprint", lib_chatprint}, @@ -3247,6 +3299,10 @@ static luaL_Reg lib[] = { {"K_SetIndirectItemCooldown",lib_kSetIndirectItemCountdown}, {"K_SetHyudoroCooldown",lib_kSetHyuCountdown}, + //g_input + {"G_SetPlayerGamepadIndicatorColor",lib_gSetPlayerGamepadIndicatorColor}, + {"G_PlayerDeviceRumble",lib_gPlayerDeviceRumble}, + {NULL, NULL} }; @@ -3266,4 +3322,4 @@ int LUA_BaseLib(lua_State *L) lua_pushvalue(L, LUA_GLOBALSINDEX); luaL_register(L, NULL, lib); return 0; -} \ No newline at end of file +} diff --git a/src/lua_blockmaplib.c b/src/lua_blockmaplib.c index 2367673cd..0b93766b8 100644 --- a/src/lua_blockmaplib.c +++ b/src/lua_blockmaplib.c @@ -53,12 +53,10 @@ static UINT8 lib_searchBlockmap_Objects(lua_State *L, INT32 x, INT32 y, mobj_t * CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); lua_pop(gL, 1); blockfuncerror = true; - P_SetTarget(&bnext, NULL); return 0; // *shrugs* } if (!lua_isnil(gL, -1)) { // if nil, continue - P_SetTarget(&bnext, NULL); if (lua_toboolean(gL, -1)) return 2; // stop whole search else @@ -258,4 +256,4 @@ int LUA_BlockmapLib(lua_State *L) { lua_register(L, "searchBlockmap", lib_searchBlockmap); return 0; -} +} \ No newline at end of file diff --git a/src/lua_script.c b/src/lua_script.c index 6528a515e..85aefbfbd 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1597,17 +1597,12 @@ void LUA_Archive(void) if (gamestate == GS_LEVEL) { for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - - // archive function will determine when to skip mobjs, - // and write mobjnum in otherwise. - ArchiveExtVars(th, "mobj"); - } + if (th->function.acp1 == (actionf_p1)P_MobjThinker) + { + // archive function will determine when to skip mobjs, + // and write mobjnum in otherwise. + ArchiveExtVars(th, "mobj"); + } } WRITEUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. @@ -1637,15 +1632,9 @@ void LUA_UnArchive(void) do { mobjnum = READUINT32(save_p); // read a mobjnum for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj - continue; - UnArchiveExtVars(th); // apply variables - } + if (th->function.acp1 == (actionf_p1)P_MobjThinker + && ((mobj_t *)th)->mobjnum == mobjnum) // find matching mobj + UnArchiveExtVars(th); // apply variables } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. LUAh_NetArchiveHook(NetUnArchive); // call the NetArchive hook in unarchive mode diff --git a/src/m_cheat.c b/src/m_cheat.c index 6b93461f3..91ca536c8 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -906,14 +906,11 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)th; // get offset from mt, which points to old mapthings, then add new location - if (!mo->spawnpoint) - continue; - mo->spawnpoint = (mo->spawnpoint - mt) + mapthings; + if (mo->spawnpoint) + mo->spawnpoint = (mo->spawnpoint - mt) + mapthings; } } diff --git a/src/m_menu.c b/src/m_menu.c index 05dd511b8..87f9bc902 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10416,6 +10416,8 @@ static UINT8 setupm_skinypos; static INT32 setupm_skinselect; static boolean setupm_skinlockedselect; +static UINT8 setupm_playernum; //brap + #define SELECTEDSTATSCOUNT skinstatscount[setupm_skinxpos][setupm_skinypos] #define LASTSELECTEDSTAT skinstats[setupm_skinxpos][setupm_skinypos][skinstatscount[setupm_skinxpos][setupm_skinypos]] @@ -11257,6 +11259,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor--; + G_SetPlayerGamepadIndicatorColor(setupm_playernum, setupm_fakecolor); } break; @@ -11312,6 +11315,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor++; + G_SetPlayerGamepadIndicatorColor(setupm_playernum, setupm_fakecolor); } break; @@ -11351,6 +11355,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { S_StartSound(NULL,sfx_menu1); // Tails setupm_fakecolor = col; + G_SetPlayerGamepadIndicatorColor(setupm_playernum, setupm_fakecolor); } } break; @@ -11484,6 +11489,8 @@ static void M_SetupMultiPlayer(INT32 choice) setupm_skinypos = 0; setupm_skinlockedselect = false; + setupm_playernum = 0; + // For whatever reason this doesn't work right if you just use ->value setupm_fakeskin = R_SkinAvailable(setupm_cvskin->string); if (setupm_fakeskin == -1) @@ -11523,6 +11530,8 @@ static void M_SetupMultiPlayer2(INT32 choice) setupm_skinypos = 0; setupm_skinlockedselect = false; + setupm_playernum = 1; + // For whatever reason this doesn't work right if you just use ->value setupm_fakeskin = R_SkinAvailable(setupm_cvskin->string); if (setupm_fakeskin == -1) @@ -11562,6 +11571,8 @@ static void M_SetupMultiPlayer3(INT32 choice) setupm_skinypos = 0; setupm_skinlockedselect = false; + setupm_playernum = 2; + // For whatever reason this doesn't work right if you just use ->value setupm_fakeskin = R_SkinAvailable(setupm_cvskin->string); if (setupm_fakeskin == -1) @@ -11601,6 +11612,8 @@ static void M_SetupMultiPlayer4(INT32 choice) setupm_skinypos = 0; setupm_skinlockedselect = false; + setupm_playernum = 3; + // For whatever reason this doesn't work right if you just use ->value setupm_fakeskin = R_SkinAvailable(setupm_cvskin->string); if (setupm_fakeskin == -1) @@ -11639,6 +11652,7 @@ static boolean M_QuitMultiPlayerMenu(void) // you know what? always putting these in the buffer won't hurt anything. COM_BufAddText (va("%s \"%s\"\n",setupm_cvskin->name,skins[setupm_fakeskin].name)); COM_BufAddText (va("%s %d\n",setupm_cvcolor->name,setupm_fakecolor)); + return true; } diff --git a/src/p_enemy.c b/src/p_enemy.c index 1a23317ed..caa85e331 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -2418,11 +2418,9 @@ void A_1upThinker(mobj_t *actor) if (closestplayer == -1 || skins[players[closestplayer].skin].spritedef.numframes <= states[S_PLAY_BOX1].frame) { // Closest player not found (no players in game?? may be empty dedicated server!), or does not have correct sprite. actor->frame = 0; - if (actor->tracer) - { - mobj_t *tracer = actor->tracer; - P_SetTarget(&actor->tracer, NULL); - P_RemoveMobj(tracer); + if (actor->tracer) { + P_RemoveMobj(actor->tracer); + P_SetTarget(&actor->target, NULL); } return; } @@ -2635,8 +2633,6 @@ void A_BossDeath(mobj_t *mo) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2 != mo && (mo2->flags & MF_BOSS) && mo2->health > 0) @@ -2695,8 +2691,6 @@ bossjustdie: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -5304,8 +5298,6 @@ void A_RingExplode(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -6874,23 +6866,13 @@ void A_Boss3Path(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; - - if (mo2->type != MT_BOSS3WAYPOINT) - continue; - - if(!mo2->spawnpoint) - continue; - - if (mo2->spawnpoint->angle != actor->threshold) - continue; - - - P_SetTarget(&actor->target, mo2); - break; + if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && mo2->spawnpoint->angle == actor->threshold) + { + P_SetTarget(&actor->target, mo2); + break; + } } if (!actor->target) // Should NEVER happen @@ -7321,8 +7303,6 @@ void A_FindTarget(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -7387,8 +7367,6 @@ void A_FindTracer(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -7931,8 +7909,6 @@ void A_RemoteAction(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -8711,8 +8687,6 @@ void A_MementosTPParticles(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_MEMENTOSTP && mo2 != actor) @@ -8812,8 +8786,6 @@ void A_ReaperThinker(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -8870,6 +8842,7 @@ void A_ReaperThinker(mobj_t *actor) // Waypoint behavior. if (actor->target->type == MT_REAPERWAYPOINT) { + if (R_PointToDist2(actor->x, actor->y, actor->target->x, actor->target->y) < 22<target, NULL); // remove target so we can default back to first waypoint if things go ham. @@ -8879,8 +8852,6 @@ void A_ReaperThinker(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -9056,8 +9027,6 @@ void A_SetObjectTypeState(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -9680,8 +9649,6 @@ void A_CheckThingCount(mobj_t *actor) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; diff --git a/src/p_floor.c b/src/p_floor.c index bebc9a272..27460eda6 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -1968,8 +1968,32 @@ void T_ThwompSector(levelspecthink_t *thwomp) } else // Not going anywhere, so look for players. { + //thinker_t *th; + //mobj_t *mo; + thwomp->direction = -1; + /* // SRB2kart 170217 - Thwomps are automatic. + // scan the thinkers to find players! + if (!rover || (rover->flags & FF_EXISTS)) + { + // scan the thinkers to find players! + for (th = thinkercap.next; th != &thinkercap; th = th->next) + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + + mo = (mobj_t *)th; + if (mo->type == MT_PLAYER && mo->health && mo->player && !mo->player->spectator + && mo->z <= thwomp->sector->ceilingheight + && P_AproxDistance(thwompx - mo->x, thwompy - mo->y) <= 96*FRACUNIT) + { + thwomp->direction = -1; + break; + } + } + }*/ + thwomp->sector->ceilspeed = 0; thwomp->sector->floorspeed = 0; } diff --git a/src/p_inter.c b/src/p_inter.c index c23bfe286..054ff16a1 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1055,8 +1055,6 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_KOOPA) @@ -1951,8 +1949,6 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)th; if (mo->type == (mobjtype_t)target->info->mass && mo->tracer == target) diff --git a/src/p_map.c b/src/p_map.c index bcb2b6a73..6051d5d1c 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1548,13 +1548,13 @@ static boolean PIT_CheckThing(mobj_t *thing) { tmfloorz = tmceilingz = topz; // block while in air tmceilingslope = NULL; - P_SetTarget(&tmfloorthing, thing); // needed for side collision + tmfloorthing = thing; // needed for side collision } else if (topz < tmceilingz && tmthing->z <= thing->z+thing->height) { tmceilingz = topz; tmceilingslope = NULL; - P_SetTarget(&tmfloorthing, thing); // thing we may stand on + tmfloorthing = thing; // thing we may stand on } } else @@ -1585,13 +1585,13 @@ static boolean PIT_CheckThing(mobj_t *thing) { tmfloorz = tmceilingz = topz; // block while in air tmfloorslope = NULL; - P_SetTarget(&tmfloorthing, thing); // needed for side collision + tmfloorthing = thing; // needed for side collision } else if (topz > tmfloorz && tmthing->z+tmthing->height >= thing->z) { tmfloorz = topz; tmfloorslope = NULL; - P_SetTarget(&tmfloorthing, thing); // thing we may stand on + tmfloorthing = thing; // thing we may stand on } } } @@ -1991,8 +1991,8 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) } // tmfloorthing is set when tmfloorz comes from a thing's top - P_SetTarget(&tmfloorthing, NULL); - P_SetTarget(&tmhitthing, NULL); + tmfloorthing = NULL; + tmhitthing = NULL; validcount++; @@ -2489,10 +2489,8 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) if (tmceilingz - tmfloorz < thing->height) { - if (tmfloorthing != NULL) - { - P_SetTarget(&tmhitthing, tmfloorthing); - } + if (tmfloorthing) + tmhitthing = tmfloorthing; return false; // doesn't fit } diff --git a/src/p_mobj.c b/src/p_mobj.c index 5e5b9924b..a0d80b413 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3223,8 +3223,6 @@ void P_DestroyRobots(void) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) continue; // not a mobj thinker - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)think; if (mo->health <= 0 || !(mo->flags & MF_ENEMY || mo->flags & MF_BOSS)) @@ -4033,8 +4031,6 @@ static void P_Boss3Thinker(mobj_t *mobj) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == (mobjtype_t)mobj->info->mass && mo2->tracer == mobj) @@ -4126,25 +4122,13 @@ static void P_Boss3Thinker(mobj_t *mobj) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; - - if (!mo2) - continue; - - if (mo2->type != MT_BOSS3WAYPOINT) - continue; - - if (!mo2->spawnpoint) - continue; - - if (mo2->spawnpoint->angle != mobj->threshold) - continue; - - P_SetTarget(&mobj->target, mo2); - break; + if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && mo2->spawnpoint->angle == mobj->threshold) + { + P_SetTarget(&mobj->target, mo2); + break; + } } if (!mobj->target) // Should NEVER happen @@ -4759,8 +4743,6 @@ static void P_Boss7Thinker(mobj_t *mobj) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint) @@ -4816,8 +4798,6 @@ static void P_Boss7Thinker(mobj_t *mobj) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && (mo2->spawnpoint->options & 7) == waypointNum) @@ -4941,8 +4921,6 @@ static void P_Boss9Thinker(mobj_t *mobj) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_BOSS9GATHERPOINT) @@ -5403,8 +5381,6 @@ mobj_t *P_GetClosestAxis(mobj_t *source) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -6112,8 +6088,7 @@ void P_MobjThinker(mobj_t *mobj) mobj->flags2 &= ~MF2_PUSHED; mobj->eflags &= ~(MFE_SPRUNG|MFE_JUSTBOUNCEDWALL); - P_SetTarget(&tmfloorthing, NULL); - P_SetTarget(&tmhitthing, NULL); + tmfloorthing = tmhitthing = NULL; // 970 allows ANY mobj to trigger a linedef exec if (mobj->subsector && GETSECSPECIAL(mobj->subsector->sector->special, 2) == 8) @@ -10067,67 +10042,71 @@ void P_RemoveMobj(mobj_t *mobj) // killough 11/98: // // Remove any references to other mobjs. - P_SetTarget(&mobj->target, NULL); - P_SetTarget(&mobj->tracer, NULL); + P_SetTarget(&mobj->target, P_SetTarget(&mobj->tracer, NULL)); // repair hnext chain - mobj_t *cachenext = mobj->hnext; - - if (mobj->hnext && !P_MobjWasRemoved(mobj->hnext)) { - if (mobj->hnext->hprev == mobj) + mobj_t *cachenext = mobj->hnext; + + if (mobj->hnext && !P_MobjWasRemoved(mobj->hnext)) { P_SetTarget(&mobj->hnext->hprev, mobj->hprev); + P_SetTarget(&mobj->hnext, NULL); } - P_SetTarget(&mobj->hnext, NULL); - } - - if (mobj->hprev && !P_MobjWasRemoved(mobj->hprev)) - { - if (mobj->hprev->hnext == mobj) + if (mobj->hprev && !P_MobjWasRemoved(mobj->hprev)) { P_SetTarget(&mobj->hprev->hnext, cachenext); + P_SetTarget(&mobj->hprev, NULL); } - - P_SetTarget(&mobj->hprev, NULL); } // clear the reference from the mapthing if (mobj->spawnpoint) - P_SetTarget(&mobj->spawnpoint->mobj, NULL); + mobj->spawnpoint->mobj = NULL; R_RemoveMobjInterpolator(mobj); // free block - if (!mobj->thinker.next) + // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error. + if (mobj->flags & MF_NOTHINK && !mobj->thinker.next) { // Uh-oh, the mobj doesn't think, P_RemoveThinker would never go through! - INT32 prevreferences; if (!mobj->thinker.references) { - Z_Free(mobj); // No references? Can be removed immediately! :D - return; - } - - prevreferences = mobj->thinker.references; - P_AddThinker((thinker_t *)mobj); - mobj->thinker.references = prevreferences; - } - - P_RemoveThinker((thinker_t *)mobj); - - // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error. #ifdef SCRAMBLE_REMOVED - // Invalidate mobj_t data to cause crashes if accessed! - memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); + // Invalidate mobj_t data to cause crashes if accessed! + memset(mobj, 0xff, sizeof(mobj_t)); #endif + Z_Free(mobj); // No refrences? Can be removed immediately! :D + } + else + { // Add thinker just to delay removing it until refrences are gone. + mobj->flags &= ~MF_NOTHINK; + P_AddThinker((thinker_t *)mobj); +#ifdef SCRAMBLE_REMOVED + // Invalidate mobj_t data to cause crashes if accessed! + memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); +#endif + P_RemoveThinker((thinker_t *)mobj); + } + } + else + { +#ifdef SCRAMBLE_REMOVED + // Invalidate mobj_t data to cause crashes if accessed! + memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); +#endif + P_RemoveThinker((thinker_t *)mobj); + } } // This does not need to be added to Lua. // To test it in Lua, check mobj.valid boolean P_MobjWasRemoved(mobj_t *mobj) { - return !(mobj && mobj->thinker.function.acp1 == (actionf_p1)P_MobjThinker); + if (mobj && mobj->thinker.function.acp1 == (actionf_p1)P_MobjThinker) + return false; + return true; } void P_RemovePrecipMobj(precipmobj_t *mobj) @@ -10419,8 +10398,6 @@ void P_RespawnSpecials(void) if (th->function.acp1 != (actionf_p1)P_MobjThinker) // not a mobj continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; box = (mobj_t *)th; @@ -10620,9 +10597,7 @@ void P_SpawnPlayer(INT32 playernum) mobj = P_SpawnMobj(0, 0, 0, MT_PLAYER); I_Assert(mobj != NULL); - - mobj->player = p; - P_SetTarget(&p->mo, mobj); + (mobj->player = p)->mo = mobj; mobj->angle = 0; @@ -11567,8 +11542,6 @@ ML_NOCLIMB : Direction not controllable { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -11839,12 +11812,11 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) { P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); + //mobj->hprev = nextmobj; + //mobj->hprev->hnext = mobj; } else - { - P_SetTarget(&mobj->hprev, NULL); - P_SetTarget(&mobj->hnext, NULL); - } + mobj->hprev = mobj->hnext = NULL; nextmobj = mobj; } @@ -11870,9 +11842,11 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - P_SetTarget(&mobj->hnext, NULL); + mobj->hnext = NULL; P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); + //mobj->hprev = nextmobj; + //mobj->hprev->hnext = mobj; nextmobj = mobj; } @@ -11897,9 +11871,11 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - P_SetTarget(&mobj->hnext, NULL); + mobj->hnext = NULL; P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); + //mobj->hprev = nextmobj; + //mobj->hprev->hnext = mobj; nextmobj = mobj; } @@ -11982,12 +11958,11 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) { P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); + //mobj->hprev = nextmobj; + //mobj->hprev->hnext = mobj; } else - { - P_SetTarget(&mobj->hprev, NULL); - P_SetTarget(&mobj->hnext, NULL); - } + mobj->hprev = mobj->hnext = NULL; nextmobj = mobj; } @@ -12024,9 +11999,11 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - P_SetTarget(&mobj->hnext, NULL); + mobj->hnext = NULL; P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); + //mobj->hprev = nextmobj; + //mobj->hprev->hnext = mobj; nextmobj = mobj; } diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 03df03905..9a3376595 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1514,31 +1514,29 @@ void Polyobj_InitLevel(void) // the mobj_t pointers on a queue for use below. for (th = thinkercap.next; th != &thinkercap; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - - mobj_t *mo = (mobj_t *)th; - - if (mo->info->doomednum == POLYOBJ_SPAWN_DOOMEDNUM || - mo->info->doomednum == POLYOBJ_SPAWNCRUSH_DOOMEDNUM) + if (th->function.acp1 == (actionf_p1)P_MobjThinker) { - ++numPolyObjects; + mobj_t *mo = (mobj_t *)th; - qitem = malloc(sizeof(mobjqitem_t)); - memset(qitem, 0, sizeof(mobjqitem_t)); - qitem->mo = mo; - M_QueueInsert(&(qitem->mqitem), &spawnqueue); - } - else if (mo->info->doomednum == POLYOBJ_ANCHOR_DOOMEDNUM) - { - ++numAnchors; + if (mo->info->doomednum == POLYOBJ_SPAWN_DOOMEDNUM || + mo->info->doomednum == POLYOBJ_SPAWNCRUSH_DOOMEDNUM) + { + ++numPolyObjects; - qitem = malloc(sizeof(mobjqitem_t)); - memset(qitem, 0, sizeof(mobjqitem_t)); - qitem->mo = mo; - M_QueueInsert(&(qitem->mqitem), &anchorqueue); + qitem = malloc(sizeof(mobjqitem_t)); + memset(qitem, 0, sizeof(mobjqitem_t)); + qitem->mo = mo; + M_QueueInsert(&(qitem->mqitem), &spawnqueue); + } + else if (mo->info->doomednum == POLYOBJ_ANCHOR_DOOMEDNUM) + { + ++numAnchors; + + qitem = malloc(sizeof(mobjqitem_t)); + memset(qitem, 0, sizeof(mobjqitem_t)); + qitem->mo = mo; + M_QueueInsert(&(qitem->mqitem), &anchorqueue); + } } } @@ -1573,6 +1571,39 @@ void Polyobj_InitLevel(void) Polyobj_linkToBlockmap(&PolyObjects[i]); } +#if 0 + // haleyjd 02/22/06: temporary debug + printf("DEBUG: numPolyObjects = %d\n", numPolyObjects); + for (i = 0; i < numPolyObjects; ++i) + { + INT32 j; + polyobj_t *po = &PolyObjects[i]; + + printf("polyobj %d:\n", i); + printf("id = %d, first = %d, next = %d\n", po->id, po->first, po->next); + printf("segCount = %d, numSegsAlloc = %d\n", po->segCount, po->numSegsAlloc); + for (j = 0; j < po->segCount; ++j) + printf("\tseg %d: %p\n", j, po->segs[j]); + printf("numVertices = %d, numVerticesAlloc = %d\n", po->numVertices, po->numVerticesAlloc); + for (j = 0; j < po->numVertices; ++j) + { + printf("\tvtx %d: (%d, %d) / orig: (%d, %d)\n", + j, po->vertices[j]->x>>FRACBITS, po->vertices[j]->y>>FRACBITS, + po->origVerts[j].x>>FRACBITS, po->origVerts[j].y>>FRACBITS); + } + printf("numLines = %d, numLinesAlloc = %d\n", po->numLines, po->numLinesAlloc); + for (j = 0; j < po->numLines; ++j) + printf("\tline %d: %p\n", j, po->lines[j]); + printf("spawnSpot = (%d, %d)\n", po->spawnSpot.x >> FRACBITS, po->spawnSpot.y >> FRACBITS); + printf("centerPt = (%d, %d)\n", po->centerPt.x >> FRACBITS, po->centerPt.y >> FRACBITS); + printf("attached = %d, linked = %d, validcount = %d, isBad = %d\n", + po->attached, po->linked, po->validcount, po->isBad); + printf("blockbox: [%d, %d, %d, %d]\n", + po->blockbox[BOXLEFT], po->blockbox[BOXRIGHT], po->blockbox[BOXBOTTOM], + po->blockbox[BOXTOP]); + } +#endif + // done with mobj queues M_QueueFree(&spawnqueue); M_QueueFree(&anchorqueue); @@ -1789,22 +1820,17 @@ void T_PolyObjWaypoint(polywaypoint_t *th) { if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != th->sequence) - continue; - - if (mo2->health != th->pointnum) - continue; - - target = mo2; - break; + if (mo2->threshold == th->sequence && mo2->health == th->pointnum) + { + target = mo2; + break; + } } if (!target) @@ -1875,31 +1901,29 @@ void T_PolyObjWaypoint(polywaypoint_t *th) { if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != th->sequence) - continue; - - if (th->direction == -1) + if (mo2->threshold == th->sequence) { - if (mo2->health == target->health - 1) + if (th->direction == -1) { - waypoint = mo2; - break; + if (mo2->health == target->health - 1) + { + waypoint = mo2; + break; + } } - } - else - { - if (mo2->health == target->health + 1) + else { - waypoint = mo2; - break; + if (mo2->health == target->health + 1) + { + waypoint = mo2; + break; + } } } } @@ -1916,30 +1940,28 @@ void T_PolyObjWaypoint(polywaypoint_t *th) { if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != th->sequence) - continue; - - if (th->direction == -1) + if (mo2->threshold == th->sequence) { - if (waypoint == NULL) - waypoint = mo2; - else if (mo2->health > waypoint->health) - waypoint = mo2; - } - else - { - if (mo2->health == 0) + if (th->direction == -1) { - waypoint = mo2; - break; + if (waypoint == NULL) + waypoint = mo2; + else if (mo2->health > waypoint->health) + waypoint = mo2; + } + else + { + if (mo2->health == 0) + { + waypoint = mo2; + break; + } } } } @@ -1955,31 +1977,29 @@ void T_PolyObjWaypoint(polywaypoint_t *th) { if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != th->sequence) - continue; - - if (th->direction == -1) + if (mo2->threshold == th->sequence) { - if (mo2->health == target->health - 1) + if (th->direction == -1) { - waypoint = mo2; - break; + if (mo2->health == target->health - 1) + { + waypoint = mo2; + break; + } } - } - else - { - if (mo2->health == target->health + 1) + else { - waypoint = mo2; - break; + if (mo2->health == target->health + 1) + { + waypoint = mo2; + break; + } } } } @@ -2477,39 +2497,37 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) { if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (wp->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)wp; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != th->sequence) - continue; - - if (th->direction == -1) // highest waypoint # + if (mo2->threshold == th->sequence) { - if (mo2->health == 0) - last = mo2; - else + if (th->direction == -1) // highest waypoint # { - if (first == NULL) - first = mo2; - else if (mo2->health > first->health) - first = mo2; + if (mo2->health == 0) + last = mo2; + else + { + if (first == NULL) + first = mo2; + else if (mo2->health > first->health) + first = mo2; + } } - } - else // waypoint 0 - { - if (mo2->health == 0) - first = mo2; - else + else // waypoint 0 { - if (last == NULL) - last = mo2; - else if (mo2->health > last->health) - last = mo2; + if (mo2->health == 0) + first = mo2; + else + { + if (last == NULL) + last = mo2; + else if (mo2->health > last->health) + last = mo2; + } } } } @@ -2546,6 +2564,36 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) // Find the actual target movement waypoint target = first; + /*for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) + { + if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker + continue; + + mo2 = (mobj_t *)wp; + + if (mo2->type != MT_TUBEWAYPOINT) + continue; + + if (mo2->threshold == th->sequence) + { + if (th->direction == -1) // highest waypoint # + { + if (mo2->health == first->health - 1) + { + target = mo2; + break; + } + } + else // waypoint 0 + { + if (mo2->health == first->health + 1) + { + target = mo2; + break; + } + } + } + }*/ if (!target) { diff --git a/src/p_saveg.c b/src/p_saveg.c index a6ed1b807..f416feb3a 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1903,14 +1903,10 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mobj = (mobj_t *)th; - if (mobj->mobjnum != oldposition) - continue; - - return mobj; + if (mobj->mobjnum == oldposition) + return mobj; } CONS_Debug(DBG_GAMELOGIC, "mobj not found\n"); return NULL; @@ -2909,14 +2905,12 @@ static void P_NetUnArchiveThinkers(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)T_ExecutorDelay) - continue; - - delay = (void *)currentthinker; - if (!(mobjnum = (UINT32)(size_t)delay->caller)) - continue; - - delay->caller = P_FindNewPosition(mobjnum); + if (currentthinker->function.acp1 == (actionf_p1)T_ExecutorDelay) + { + delay = (void *)currentthinker; + if ((mobjnum = (UINT32)(size_t)delay->caller)) + delay->caller = P_FindNewPosition(mobjnum); + } } } } @@ -3025,12 +3019,11 @@ static inline void P_FinishMobjs(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (currentthinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - mobj = (mobj_t *)currentthinker; - mobj->info = &mobjinfo[mobj->type]; + if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)currentthinker; + mobj->info = &mobjinfo[mobj->type]; + } } } @@ -3044,71 +3037,69 @@ static void P_RelinkPointers(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (currentthinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; + if (currentthinker->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)currentthinker; - mobj = (mobj_t *)currentthinker; + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - - if (mobj->tracer) - { - temp = (UINT32)(size_t)mobj->tracer; - mobj->tracer = NULL; - if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); - } - if (mobj->target) - { - temp = (UINT32)(size_t)mobj->target; - mobj->target = NULL; - if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); - } - if (mobj->hnext) - { - temp = (UINT32)(size_t)mobj->hnext; - mobj->hnext = NULL; - if (!P_SetTarget(&mobj->hnext, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); - } - if (mobj->hprev) - { - temp = (UINT32)(size_t)mobj->hprev; - mobj->hprev = NULL; - if (!P_SetTarget(&mobj->hprev, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->capsule) - { - temp = (UINT32)(size_t)mobj->player->capsule; - mobj->player->capsule = NULL; - if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->axis1) - { - temp = (UINT32)(size_t)mobj->player->axis1; - mobj->player->axis1 = NULL; - if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->axis2) - { - temp = (UINT32)(size_t)mobj->player->axis2; - mobj->player->axis2 = NULL; - if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); - } - if (mobj->player && mobj->player->awayviewmobj) - { - temp = (UINT32)(size_t)mobj->player->awayviewmobj; - mobj->player->awayviewmobj = NULL; - if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) - CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); + if (mobj->tracer) + { + temp = (UINT32)(size_t)mobj->tracer; + mobj->tracer = NULL; + if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); + } + if (mobj->target) + { + temp = (UINT32)(size_t)mobj->target; + mobj->target = NULL; + if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); + } + if (mobj->hnext) + { + temp = (UINT32)(size_t)mobj->hnext; + mobj->hnext = NULL; + if (!P_SetTarget(&mobj->hnext, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); + } + if (mobj->hprev) + { + temp = (UINT32)(size_t)mobj->hprev; + mobj->hprev = NULL; + if (!P_SetTarget(&mobj->hprev, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->capsule) + { + temp = (UINT32)(size_t)mobj->player->capsule; + mobj->player->capsule = NULL; + if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->axis1) + { + temp = (UINT32)(size_t)mobj->player->axis1; + mobj->player->axis1 = NULL; + if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->axis2) + { + temp = (UINT32)(size_t)mobj->player->axis2; + mobj->player->axis2 = NULL; + if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); + } + if (mobj->player && mobj->player->awayviewmobj) + { + temp = (UINT32)(size_t)mobj->player->awayviewmobj; + mobj->player->awayviewmobj = NULL; + if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) + CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); + } } } } @@ -3506,14 +3497,13 @@ void P_SaveNetGame(boolean resending) { for (th = thinkercap.next; th != &thinkercap; th = th->next) { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - mobj = (mobj_t *)th; - if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) - continue; - mobj->mobjnum = i++; + if (th->function.acp1 == (actionf_p1)P_MobjThinker) + { + mobj = (mobj_t *)th; + if (mobj->type == MT_HOOP || mobj->type == MT_HOOPCOLLIDE || mobj->type == MT_HOOPCENTER) + continue; + mobj->mobjnum = i++; + } } } diff --git a/src/p_setup.c b/src/p_setup.c index 9ab6e6b5c..ed2d7165f 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -752,8 +752,6 @@ void P_ReloadRings(void) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)th; @@ -2200,6 +2198,7 @@ static void P_LevelInitStuff(boolean reloadinggamestate) void P_LoadThingsOnly(void) { // Search through all the thinkers. + mobj_t *mo; thinker_t *think; virtres_t* virt = vres_GetMap(lastloadedmaplumpnum); @@ -2208,10 +2207,12 @@ void P_LoadThingsOnly(void) for (think = thinkercap.next; think != &thinkercap; think = think->next) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - P_RemoveMobj((mobj_t *)think); + continue; // not a mobj thinker + + mo = (mobj_t *)think; + + if (mo) + P_RemoveMobj(mo); } P_LevelInitStuff(false); diff --git a/src/p_spec.c b/src/p_spec.c index 4fa7a5275..87036a892 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2483,6 +2483,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 422: // Cut away to another view { mobj_t *altview; + INT32 i; if (!mo || !mo->player) // only players have views return; @@ -2497,6 +2498,14 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) P_SetTarget(&mo->player->awayviewmobj, altview); mo->player->awayviewtics = P_AproxDistance(line->dx, line->dy)>>FRACBITS; + for (i = 0; i <= splitscreen; i++) + { + if (displayplayers[i] == (mo->player - players)) + { + R_ResetViewInterpolation(i + 1); + } + } + if (line->flags & ML_NOCLIMB) // lets you specify a vertical angle { INT32 aim; @@ -2989,8 +2998,6 @@ void P_SetupSignExit(player_t *player) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) continue; // not a mobj thinker - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; thing = (mobj_t *)think; if (thing->type != MT_SIGN) @@ -3034,20 +3041,23 @@ boolean P_IsFlagAtBase(mobjtype_t flag) { thinker_t *think; mobj_t *mo; - INT32 specialnum = (flag == MT_REDFLAG) ? 3 : 4; + INT32 specialnum = 0; for (think = thinkercap.next; think != &thinkercap; think = think->next) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) continue; // not a mobj thinker - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)think; if (mo->type != flag) continue; + if (mo->type == MT_REDFLAG) + specialnum = 3; + else if (mo->type == MT_BLUEFLAG) + specialnum = 4; + if (GETSECSPECIAL(mo->subsector->sector->special, 4) == specialnum) return true; else if (mo->subsector->sector->ffloors) // Check the 3D floors @@ -3062,11 +3072,9 @@ boolean P_IsFlagAtBase(mobjtype_t flag) if (GETSECSPECIAL(rover->master->frontsector->special, 4) != specialnum) continue; - if (!(mo->z <= P_GetSpecialTopZ(mo, sectors + rover->secnum, mo->subsector->sector) - && mo->z >= P_GetSpecialBottomZ(mo, sectors + rover->secnum, mo->subsector->sector))) - continue; - - return true; + if (mo->z <= P_GetSpecialTopZ(mo, sectors + rover->secnum, mo->subsector->sector) + && mo->z >= P_GetSpecialBottomZ(mo, sectors + rover->secnum, mo->subsector->sector)) + return true; } } } @@ -3476,15 +3484,10 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; - - if (mo2->type != MT_EGGTRAP) - continue; - - P_KillMobj(mo2, NULL, player->mo); + if (mo2->type == MT_EGGTRAP) + P_KillMobj(mo2, NULL, player->mo); } // clear the special so you can't push the button twice. @@ -3820,20 +3823,15 @@ DoneSection2: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; - if (mo2->type != MT_TUBEWAYPOINT) - continue; - if (mo2->threshold != sequence) - continue; - if (mo2->health != 0) - continue; - - waypoint = mo2; - break; + if (mo2->type == MT_TUBEWAYPOINT && mo2->threshold == sequence + && mo2->health == 0) + { + waypoint = mo2; + break; + } } if (!waypoint) @@ -3901,20 +3899,16 @@ DoneSection2: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; - if (mo2->type != MT_TUBEWAYPOINT) - continue; - if (mo2->threshold != sequence) - continue; - - if (!waypoint) - waypoint = mo2; - else if (mo2->health > waypoint->health) - waypoint = mo2; + if (mo2->type == MT_TUBEWAYPOINT && mo2->threshold == sequence) + { + if (!waypoint) + waypoint = mo2; + else if (mo2->health > waypoint->health) + waypoint = mo2; + } } if (!waypoint) @@ -4124,8 +4118,6 @@ DoneSection2: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -4164,8 +4156,6 @@ DoneSection2: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -4193,8 +4183,6 @@ DoneSection2: { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; diff --git a/src/p_tick.c b/src/p_tick.c index 6bf32f1c3..5acb8b5fb 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -155,8 +155,6 @@ void Command_CountMobjs_f(void) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; if (((mobj_t *)th)->type == i) count++; @@ -177,8 +175,6 @@ void Command_CountMobjs_f(void) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; if (((mobj_t *)th)->type == i) count++; @@ -230,27 +226,23 @@ static thinker_t *currentthinker; // remove it, and set currentthinker to one node preceeding it, so // that the next step in P_RunThinkers() will get its successor. // -void P_RemoveThinkerDelayed(thinker_t *thinker) +void P_RemoveThinkerDelayed(void *pthinker) { - thinker_t *next; -#ifdef PARANOIA - if (thinker->next) - thinker->next = NULL; - else if (thinker->references) // Usually gets cleared up in one frame; what's going on here, then? - CONS_Printf("Number of potentially faulty references: %d\n", thinker->references); -#endif - if (thinker->references) - return; - - /* Remove from main thinker list */ - next = thinker->next; - /* Note that currentthinker is guaranteed to point to us, - * and since we're freeing our memory, we had better change that. So - * point it to thinker->prev, so the iterator will correctly move on to - * thinker->prev->next = thinker->next */ - (next->prev = currentthinker = thinker->prev)->next = next; - R_DestroyLevelInterpolators(thinker); - Z_Free(thinker); + thinker_t *thinker = pthinker; + if (!thinker->references) + { + { + /* Remove from main thinker list */ + thinker_t *next = thinker->next; + /* Note that currentthinker is guaranteed to point to us, + * and since we're freeing our memory, we had better change that. So + * point it to thinker->prev, so the iterator will correctly move on to + * thinker->prev->next = thinker->next */ + (next->prev = currentthinker = thinker->prev)->next = next; + } + R_DestroyLevelInterpolators(thinker); + Z_Free(thinker); + } } // @@ -268,7 +260,7 @@ void P_RemoveThinkerDelayed(thinker_t *thinker) void P_RemoveThinker(thinker_t *thinker) { LUA_InvalidateUserdata(thinker); - thinker->function.acp1 = (actionf_p1)P_RemoveThinkerDelayed; + thinker->function.acp1 = P_RemoveThinkerDelayed; } /* @@ -287,7 +279,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; } @@ -318,13 +310,64 @@ static inline void P_RunThinkers(void) { for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { -#ifdef PARANOIA - I_Assert(currentthinker->function.acp1 != NULL) -#endif + if (currentthinker->function.acp1) currentthinker->function.acp1(currentthinker); } } +static inline void P_DeviceRumbleTick(void) +{ + UINT8 i; + + if (cv_rumble[0].value == 0 && cv_rumble[1].value == 0 && cv_rumble[2].value == 0 && cv_rumble[3].value == 0) + { + return; + } + + for (i = 0; i <= splitscreen; i++) + { + player_t *player = &players[displayplayers[i]]; + UINT16 low = 0; + UINT16 high = 0; + + if (!P_IsLocalPlayer(player)) + continue; + + if (!playeringame[i] || player->spectator) + continue; + + if (player->exiting) + continue; + + if (player->mo == NULL) + continue; + + if (player->kartstuff[k_spinouttimer]) + { + low = high = 65536 / 4; + } + else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) + { + low = high = 65536 / 8; + } + else if ((player->kartstuff[k_offroad]) + && P_IsObjectOnGround(player->mo) && player->speed != 0) + { + low = high = 65536 / 64; + } + else if (player->kartstuff[k_brakedrift]) + { + low = 0; + high = 65536 / 256; + } + + if (low == 0 && high == 0) + continue; + + G_PlayerDeviceRumble(i, low, high, 57); // hack alert! i just dont want this think constantly resetting the rumble lol + } +} + void P_RunChaseCameras(void) { UINT8 i; @@ -464,6 +507,12 @@ void P_Ticker(boolean run) if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo)) P_PlayerAfterThink(&players[i]); + // Apply rumble to local players + if (!demo.playback) + { + P_DeviceRumbleTick(); + } + PS_START_TIMING(ps_lua_thinkframe_time); LUAh_ThinkFrame(); PS_STOP_TIMING(ps_lua_thinkframe_time); @@ -598,7 +647,6 @@ void P_Ticker(boolean run) if (run) { R_UpdateLevelInterpolators(); - R_UpdateViewInterpolation(); // Hack: ensure newview is assigned every tic. // Ensures view interpolation is T-1 to T in poor network conditions diff --git a/src/p_tick.h b/src/p_tick.h index 11b5889ed..d22995a11 100644 --- a/src/p_tick.h +++ b/src/p_tick.h @@ -28,7 +28,7 @@ void P_RunChaseCameras(void); void P_Ticker(boolean run); void P_PreTicker(INT32 frames); void P_DoTeamscrambling(void); -void P_RemoveThinkerDelayed(thinker_t *thinker); +void P_RemoveThinkerDelayed(void *pthinker); //killed mobj_t *P_SetTarget(mobj_t **mo, mobj_t *target); // killough 11/98 #endif diff --git a/src/p_user.c b/src/p_user.c index c14a4c541..d61044ba7 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1142,8 +1142,6 @@ void P_SpawnShieldOrb(player_t *player) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; shieldobj = (mobj_t *)th; @@ -1872,8 +1870,6 @@ void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; @@ -2626,25 +2622,21 @@ static void P_DoZoomTube(player_t *player) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold != sequence) - continue; - - if (reverse && mo2->health != player->mo->tracer->health - 1) - continue; - - if (!reverse && mo2->health != player->mo->tracer->health + 1) - continue; - - waypoint = mo2; - break; + if (mo2->threshold == sequence) + { + if ((reverse && mo2->health == player->mo->tracer->health - 1) + || (!reverse && mo2->health == player->mo->tracer->health + 1)) + { + waypoint = mo2; + break; + } + } } if (waypoint) @@ -2723,8 +2715,6 @@ void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) continue; // not a mobj thinker - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)think; @@ -2805,8 +2795,6 @@ boolean P_LookForEnemies(player_t *player) { if (think->function.acp1 != (actionf_p1)P_MobjThinker) continue; // not a mobj thinker - if (think->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo = (mobj_t *)think; if (!(mo->flags & (MF_ENEMY|MF_BOSS|MF_MONITOR|MF_SPRING))) @@ -2932,8 +2920,6 @@ void P_FindEmerald(void) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; if (mo2->type == MT_EMERHUNT) @@ -3979,7 +3965,6 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall { P_MoveChaseCamera(player, thiscam, false); R_ResetViewInterpolation(num + 1); - R_ResetViewInterpolation(num + 1); } return (x == thiscam->x && y == thiscam->y && z == thiscam->z && angle == thiscam->aiming); @@ -4039,7 +4024,7 @@ boolean P_SpectatorJoinGame(player_t *player) if (player->mo) { P_RemoveMobj(player->mo); - P_SetTarget(&player->mo, NULL); + player->mo = NULL; } player->spectator = false; player->pflags &= ~PF_WANTSTOJOIN; @@ -4656,8 +4641,6 @@ void P_PlayerThink(player_t *player) { if (th->function.acp1 != (actionf_p1)P_MobjThinker) continue; - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; mo2 = (mobj_t *)th; diff --git a/src/r_data.c b/src/r_data.c index a725d2ac9..ad8b420f3 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1687,8 +1687,7 @@ void R_PrecacheLevel(void) for (th = thinkercap.next; th != &thinkercap; th = th->next) if (th->function.acp1 == (actionf_p1)P_MobjThinker) - if (th->function.acp1 != (actionf_p1)P_RemoveThinkerDelayed) - spritepresent[((mobj_t *)th)->sprite] = 1; + spritepresent[((mobj_t *)th)->sprite] = 1; spritememory = 0; for (i = 0; i < numsprites; i++) diff --git a/src/r_main.c b/src/r_main.c index 764d34403..fb3ca1c1c 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -440,11 +440,6 @@ angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) 0; } -fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1) -{ - return FixedHypot(px1 - px2, py1 - py2); -} - angle_t R_PlayerSliptideAngle(player_t *player) { mobj_t *mo; @@ -489,12 +484,6 @@ angle_t R_PlayerSliptideAngle(player_t *player) return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), mo->player->sliproll*(mo->player->sliptidemem)); } -// Little extra utility. Works in the same way as R_PointToAngle2 -fixed_t R_PointToDist(fixed_t x, fixed_t y) -{ - return R_PointToDist2(viewx, viewy, x, y); -} - INT32 R_GetHudUncap(void) { return cv_uncappedhud.value ? rendertimefrac & FRACMASK : 0; diff --git a/src/r_main.h b/src/r_main.h index 6c59d9961..058a30c80 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -73,14 +73,16 @@ INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line); angle_t R_PointToAngle(fixed_t x, fixed_t y); angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); -fixed_t R_PointToDist(fixed_t x, fixed_t y); -fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PlayerSliptideAngle(player_t *player); fixed_t R_ScaleFromGlobalAngle(angle_t visangle); subsector_t *R_PointInSubsector(fixed_t x, fixed_t y); subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y); +#define R_PointToDist(x, y) R_PointToDist2(viewx, viewy, x, y) +#define R_PointToDist2(px2, py2, px1, py1) FixedHypot(px1 - px2, py1 - py2) + + boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixed_t bottomh, fixed_t toph); void R_GetRenderBlockMapDimensions(fixed_t drawdist, INT32 *xl, INT32 *xh, INT32 *yl, INT32 *yh); diff --git a/src/s_sound.c b/src/s_sound.c index e6f2af24a..0bc76bce2 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -311,8 +311,6 @@ void S_RegisterSoundStuff(void) static void SetChannelsNum(void) { - INT32 i; - // Allocating the internal channels for mixing // (the maximum number of sounds rendered // simultaneously) within zone memory. @@ -322,7 +320,6 @@ static void SetChannelsNum(void) Z_Free(channels); channels = NULL; - if (cv_numChannels.value == 999999999) //Alam_GBC: OH MY ROD!(ROD rimmiced with GOD!) CV_StealthSet(&cv_numChannels,cv_numChannels.defaultvalue); @@ -333,13 +330,10 @@ static void SetChannelsNum(void) return; } #endif - if (cv_numChannels.value) - channels = (channel_t *)Z_Malloc(cv_numChannels.value * sizeof (channel_t), PU_STATIC, NULL); - numofchannels = cv_numChannels.value; - // Free all channels for use - for (i = 0; i < numofchannels; i++) - channels[i].sfxinfo = 0; + if (cv_numChannels.value) + channels = (channel_t *)Z_Calloc(cv_numChannels.value * sizeof (channel_t), PU_STATIC, NULL); + numofchannels = (channels ? cv_numChannels.value : 0); } // Retrieve the lump number of sfx @@ -1046,7 +1040,8 @@ boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 if (sfxinfo->pitch & SF_OUTSIDESOUND) // Rain special case { - fixed_t x, y, yl, yh, xl, xh, newdist; + INT64 x, y, yl, yh, xl, xh; + fixed_t newdist; if (R_PointInSubsector(listensource.x, listensource.y)->sector->ceilingpic == skyflatnum) approx_dist = 0; diff --git a/src/screen.c b/src/screen.c index e5c1ebff4..8fe00e821 100644 --- a/src/screen.c +++ b/src/screen.c @@ -331,7 +331,7 @@ void SCR_SetDefaultMode(void) // remember the default screen size CV_SetValue(&cv_scr_width, vid.width); CV_SetValue(&cv_scr_height, vid.height); - CV_SetValue(&cv_scr_depth, vid.bpp*8); + //CV_SetValue(&cv_scr_depth, vid.bpp*8); } // Change fullscreen on/off according to cv_fullscreen diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index b20eeba7d..eabe017c4 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -446,6 +446,7 @@ SDL_bool consolevent = SDL_FALSE; SDL_bool framebuffer = SDL_FALSE; UINT8 keyboard_started = false; +boolean g_in_exiting_signal_handler = false; static void I_ReportSignal(int num, int coredumped) { @@ -512,6 +513,8 @@ static void I_ReportSignal(int num, int coredumped) #ifndef NEWSIGNALHANDLER FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) { + g_in_exiting_signal_handler = true; + D_QuitNetGame(); // Fix server freezes #ifdef HAVE_LIBBACKTRACE @@ -2663,6 +2666,42 @@ const char *I_GetJoyName(INT32 joyindex) return joyname; } +void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength, UINT32 duration) +{ +#if !(SDL_VERSION_ATLEAST(2,0,14)) + (void)device_id; + (void)left_strength; + (void)right_strength; +#else + I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher + + SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + return; + } + + SDL_GameControllerRumble(controller, low_strength, high_strength, duration); +#endif +} + +void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue) +{ +#if !(SDL_VERSION_ATLEAST(2,0,14)) + (void)device_id; +#else + I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher + + SDL_GameController *controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + return; + } + + SDL_GameControllerSetLED(controller, red, green, blue); +#endif +} + #ifndef NOMUMBLE #ifdef HAVE_MUMBLE // Best Mumble positional audio settings: @@ -3402,13 +3441,13 @@ INT32 I_StartupSystem(void) SDL_version SDLlinked; SDL_VERSION(&SDLcompiled) SDL_GetVersion(&SDLlinked); -#ifdef HAVE_THREADS - I_start_threads(); - I_AddExitFunc(I_stop_threads); -#endif I_StartupConsole(); #ifdef NEWSIGNALHANDLER I_Fork(); +#endif +#ifdef HAVE_THREADS + I_start_threads(); + I_AddExitFunc(I_stop_threads); #endif I_RegisterSignals(); I_OutputMsg("Compiled for SDL version: %d.%d.%d\n", diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 16f4c4336..da055265e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -775,6 +775,7 @@ void I_DownSample(void) static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { +#define FOCUSUNION (mousefocus | (kbfocus << 1)) static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; @@ -782,6 +783,8 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) static SDL_bool windowmoved = SDL_FALSE; #endif + const unsigned int oldfocus = FOCUSUNION; + switch (evt.event) { case SDL_WINDOWEVENT_ENTER: @@ -807,6 +810,18 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) #endif } +#ifdef USE_FBO_OGL + if (windowmoved && rendermode == render_opengl) + { + I_DownSample(); + } +#endif + + if (FOCUSUNION == oldfocus) // No state change + { + return; + } + if (mousefocus && kbfocus) { // Tell game we got focus back, resume music if necessary @@ -843,13 +858,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) SDLdoUngrabMouse(); } } - -#ifdef USE_FBO_OGL - if (windowmoved && rendermode == render_opengl) - { - I_DownSample(); - } -#endif +#undef FOCUSUNION } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) diff --git a/src/st_stuff.c b/src/st_stuff.c index 7e28edfc8..df4ba7db9 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -456,7 +456,9 @@ void ST_Start(void) ST_Stop(); ST_InitData(); - st_stopped = false; + + if (!dedicated) + st_stopped = false; } // diff --git a/src/v_video.c b/src/v_video.c index 4c5e1cfd3..202b5d288 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -14,6 +14,7 @@ /// Functions to blit a block to the screen. #include "doomdef.h" +#include "d_main.h" #include "r_local.h" #include "p_local.h" #include "v_video.h" @@ -132,6 +133,9 @@ static boolean InitCube(void) float globalgammamul, globalgammaoffs; boolean doinggamma; + if (loaded_config == false) + return false; + #define diffcons(cv) (cv.value != atoi(cv.defaultvalue)) doinggamma = diffcons(cv_globalgamma); @@ -568,6 +572,8 @@ void V_SetPaletteLump(const char *pal) static void CV_palette_OnChange(void) { + if (loaded_config == false) + return; // reload palette LoadMapPalette(); V_SetPalette(0); diff --git a/src/w_wad.c b/src/w_wad.c index 762cdc417..8df0654f0 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -464,27 +464,53 @@ static lumpinfo_t* ResGetLumpsWad (FILE* handle, UINT16* nlmp, const char* filen */ static boolean ResFindSignature (FILE* handle, char endPat[], UINT32 startpos) { + //the Wii U has rather slow filesystem access, and fgetc is *unbearable* + //so I reimplemented this function to buffer 128k chunks char *s; int c; + fseek(handle, 0, SEEK_END); + size_t len = ftell(handle); + fseek(handle, startpos, SEEK_SET); + size_t remaining = len - startpos; + size_t chunkpos = startpos; + s = endPat; - while((c = fgetc(handle)) != EOF) - { - if (*s != c && s > endPat) // No match? - s = endPat; // We "reset" the counter by sending the s pointer back to the start of the array. - if (*s == c) - { - s++; - if (*s == 0x00) // The array pointer has reached the key char which marks the end. It means we have matched the signature. + + //128k buffers + size_t buffer_size = min(128 * 1024 * sizeof(char), remaining); + char* buffer = (char*)(malloc(buffer_size)); + + size_t bytes_read = 0; + while ((bytes_read = fread(buffer, 1, buffer_size, handle)) > 0) { + for (size_t i = 0; i < bytes_read; i++) { + c = (int)buffer[i]; + + if (*s != c && s > endPat) // No match? + s = endPat; // We "reset" the counter by sending the s pointer back to the start of the array. + if (*s == c) { - return true; + s++; + if (*s == 0x00) // The array pointer has reached the key char which marks the end. It means we have matched the signature. + { + //the original function would leave the FILE* seeked to the end of the match + size_t foundpos = chunkpos + i + 1; + fseek(handle, foundpos, SEEK_SET); + + free(buffer); + return true; + } } } + chunkpos += bytes_read; } + + free(buffer); return false; } + #if defined(_MSC_VER) #pragma pack(1) #endif @@ -544,7 +570,6 @@ typedef struct zlentry_s static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) { zend_t zend; - zentry_t zentry; zlentry_t zlentry; UINT16 numlumps = *nlmp; @@ -570,42 +595,45 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) CONS_Alert(CONS_ERROR, "Corrupt central directory (%s)\n", M_FileError(handle)); return NULL; } - numlumps = zend.entries; + numlumps = SHORT(zend.entries); lump_p = lumpinfo = Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL); - fseek(handle, zend.cdiroffset, SEEK_SET); + fseek(handle, LONG(zend.cdiroffset), SEEK_SET); + + char *cdir = (Z_MallocAlign(LONG(zend.cdirsize), PU_STATIC, &cdir, 7)); + + if (fread(cdir, 1, LONG(zend.cdirsize), handle) < (UINT32)(LONG(zend.cdirsize))) + { + CONS_Alert(CONS_ERROR, "Failed to read central directory (%s)\n", M_FileError(handle)); + Z_Free(cdir); + Z_Free(lumpinfo); + return NULL; + } + + size_t offset = 0; + for (i = 0; i < numlumps; i++, lump_p++) { + zentry_t *zentry = (zentry_t*)(cdir + offset); char* fullname; char* trimname; char* dotpos; - if (fread(&zentry, 1, sizeof(zentry_t), handle) < sizeof(zentry_t)) - { - CONS_Alert(CONS_ERROR, "Failed to read central directory (%s)\n", M_FileError(handle)); - Z_Free(lumpinfo); - return NULL; - } - if (memcmp(zentry.signature, pat_central, 4)) + if (memcmp(zentry->signature, pat_central, 4)) { CONS_Alert(CONS_ERROR, "Central directory is corrupt\n"); + Z_Free(cdir); Z_Free(lumpinfo); return NULL; } - lump_p->position = zentry.offset; // NOT ACCURATE YET: we still need to read the local entry to find our true position - lump_p->disksize = zentry.compsize; - lump_p->size = zentry.size; + lump_p->position = LONG(zentry->offset); // NOT ACCURATE YET: we still need to read the local entry to find our true position + lump_p->disksize = LONG(zentry->compsize); + lump_p->size = LONG(zentry->size); - fullname = malloc(zentry.namelen + 1); - if (fgets(fullname, zentry.namelen + 1, handle) != fullname) - { - CONS_Alert(CONS_ERROR, "Unable to read lumpname (%s)\n", M_FileError(handle)); - Z_Free(lumpinfo); - free(fullname); - return NULL; - } + fullname = (char*)(malloc(SHORT(zentry->namelen) + 1)); + strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. if ((trimname = strrchr(fullname, '/')) != 0) @@ -622,10 +650,10 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) lump_p->longname = Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL); strlcpy(lump_p->longname, trimname, dotpos - trimname + 1); - lump_p->fullname = Z_Calloc(zentry.namelen + 1, PU_STATIC, NULL); - strncpy(lump_p->fullname, fullname, zentry.namelen); + lump_p->fullname = (char*)(Z_Calloc(SHORT(zentry->namelen) + 1, PU_STATIC, NULL)); + strncpy(lump_p->fullname, fullname, SHORT(zentry->namelen)); - switch(zentry.compression) + switch(SHORT(zentry->compression)) { case 0: lump_p->compression = CM_NOCOMPRESSION; @@ -646,14 +674,11 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) free(fullname); // skip and ignore comments/extra fields - if (fseek(handle, zentry.xtralen + zentry.commlen, SEEK_CUR) != 0) - { - CONS_Alert(CONS_ERROR, "Central directory is corrupt\n"); - Z_Free(lumpinfo); - return NULL; - } + offset += sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen); } + Z_Free(cdir); + // Adjust lump position values properly for (i = 0, lump_p = lumpinfo; i < numlumps; i++, lump_p++) { @@ -665,7 +690,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) return NULL; } - lump_p->position += sizeof(zlentry_t) + zlentry.namelen + zlentry.xtralen; + lump_p->position += sizeof(zlentry_t) + SHORT(zlentry.namelen) + SHORT(zlentry.xtralen); } *nlmp = numlumps; @@ -1895,14 +1920,11 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) int verified = true; zend_t zend; - zentry_t zentry; zlentry_t zlentry; long file_size;/* size of zip file */ long data_size;/* size of data inside zip file */ - long old_position; - UINT16 numlumps; size_t i; @@ -1928,28 +1950,31 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) data_size = sizeof zend; - numlumps = zend.entries; + numlumps = SHORT(zend.entries); + + fseek(fp, LONG(zend.cdiroffset), SEEK_SET); + + char *cdir = (char*)(malloc(LONG(zend.cdirsize))); + + if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize))) + return true; + + size_t offset = 0; - fseek(fp, zend.cdiroffset, SEEK_SET); for (i = 0; i < numlumps; i++) { + zentry_t *zentry = (zentry_t*)(cdir + offset); char* fullname; char* trimname; char* dotpos; - if (fread(&zentry, 1, sizeof(zentry_t), fp) < sizeof(zentry_t)) - return true; - if (memcmp(zentry.signature, pat_central, 4)) + if (memcmp(zentry->signature, pat_central, 4) != 0) return true; if (verified == true) { - fullname = malloc(zentry.namelen + 1); - if (fgets(fullname, zentry.namelen + 1, fp) != fullname) - { - free(fullname); - return true; - } + fullname = (char*)(malloc(SHORT(zentry->namelen) + 1)); + strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. if ((trimname = strrchr(fullname, '/')) != 0) @@ -1974,34 +1999,25 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) } free(fullname); + } - // skip and ignore comments/extra fields - if (fseek(fp, zentry.xtralen + zentry.commlen, SEEK_CUR) != 0) - return true; - } - else - { - if (fseek(fp, zentry.namelen + zentry.xtralen + zentry.commlen, SEEK_CUR) != 0) - return true; - } + offset += sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen); data_size += - sizeof zentry + zentry.namelen + zentry.xtralen + zentry.commlen; + sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen); - old_position = ftell(fp); - - if (fseek(fp, zentry.offset, SEEK_SET) != 0) + if (fseek(fp, LONG(zentry->offset), SEEK_SET) != 0) return true; if (fread(&zlentry, 1, sizeof(zlentry_t), fp) < sizeof (zlentry_t)) return true; data_size += - sizeof zlentry + zlentry.namelen + zlentry.xtralen + zlentry.compsize; - - fseek(fp, old_position, SEEK_SET); + sizeof zlentry + SHORT(zlentry.namelen) + SHORT(zlentry.xtralen) + LONG(zlentry.compsize); } + free(cdir); + if (data_size < file_size) { const char * error = "ZIP file has holes (%ld extra bytes)\n"; @@ -2127,14 +2143,14 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) // Remember that we're assuming that the WAD will have a specific set of lumps in a specific order. UINT8 *wadData = W_CacheLumpNum(lumpnum, PU_LEVEL); - filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs); + filelump_t *fileinfo = (filelump_t *)(wadData + LONG(((wadinfo_t *)wadData)->infotableofs)); - i = ((wadinfo_t *)wadData)->numlumps; + i = LONG(((wadinfo_t *)wadData)->numlumps); vsizecache = Z_Malloc(sizeof(size_t)*i, PU_LEVEL, NULL); for (realentry = 0; realentry < i; realentry++) { - vsizecache[realentry] = (size_t)(((filelump_t *)(fileinfo + realentry))->size); + vsizecache[realentry] = (size_t)(LONG(((filelump_t *)(fileinfo + realentry))->size)); if (!vsizecache[realentry]) continue; @@ -2154,7 +2170,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) memcpy(vlumps[i].name, (fileinfo + realentry)->name, 8); vlumps[i].name[8] = '\0'; vlumps[i].data = Z_Malloc(vlumps[i].size, PU_LEVEL, NULL); // This is memory inefficient, sorry about that. - memcpy(vlumps[i].data, wadData + (fileinfo + realentry)->filepos, vlumps[i].size); + memcpy(vlumps[i].data, wadData + LONG((fileinfo + realentry)->filepos), vlumps[i].size); i++; } diff --git a/src/y_inter.c b/src/y_inter.c index 5d292f36c..8527ff799 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -728,8 +728,16 @@ void Y_Ticker(void) return; } - if (intertic < TICRATE || intertic & 1 || endtic != -1) + if (intertic < TICRATE || endtic != -1) + { return; + } + + if (data.match.rankingsmode && intertic & 1) + { + memset(data.match.jitter, 0, sizeof (data.match.jitter)); + return; + } if (intertype == int_race || intertype == int_match) { diff --git a/src/z_zone.c b/src/z_zone.c index b0223460b..dd10f36e3 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -25,6 +25,9 @@ /// allocator was fragmenting badly. Finally, this version is a bit /// simpler (about half the lines of code). +#include +#include + #include "doomdef.h" #include "doomstat.h" #include "r_patch.h" @@ -67,8 +70,9 @@ typedef struct memblock_s struct memblock_s *next, *prev; } memblock_t; -#define MEMORY(x) (void *)((uintptr_t)(x) + sizeof(memblock_t)) -#define MEMBLOCK(x) (memblock_t *)((uintptr_t)(x) - sizeof(memblock_t)) +#define ALIGNPAD (((sizeof (memblock_t) + (alignof (max_align_t) - 1)) & ~(alignof (max_align_t) - 1)) - sizeof (memblock_t)) +#define MEMORY(x) (void *)((uintptr_t)(x) + sizeof(memblock_t) + ALIGNPAD) +#define MEMBLOCK(x) (memblock_t *)((uintptr_t)(x) - ALIGNPAD - sizeof(memblock_t)) // both the head and tail of the zone memory block list static memblock_t head; @@ -219,15 +223,16 @@ void *Z_MallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) { memblock_t *block; void *ptr; - (void)(alignbits); // no longer used, so silence warnings. + + (void)(alignbits); // no longer used, so silence warnings. TODO we should figure out a solution for this #ifdef ZDEBUG2 CONS_Debug(DBG_MEMORY, "Z_Malloc %s:%d\n", file, line); #endif - block = xm(sizeof (memblock_t) + size); + block = xm(sizeof (memblock_t) + ALIGNPAD + size); ptr = MEMORY(block); - I_Assert((intptr_t)ptr % sizeof (void *) == 0); + I_Assert((intptr_t)ptr % alignof (max_align_t) == 0); #ifdef HAVE_VALGRIND Z_calloc = false;