diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 7c16ad754..7187be3a2 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2031,7 +2031,7 @@ static void CL_ReloadReceivedSavegame(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); + camera[i].subsector = R_PointInSubsectorFast(camera[i].x, camera[i].y); } cl_redownloadinggamestate = false; diff --git a/src/doomstat.h b/src/doomstat.h index cb0b26f65..f92e3faeb 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -446,19 +446,19 @@ extern UINT16 spacetimetics; extern UINT16 extralifetics; // SRB2kart -extern tic_t introtime; -extern tic_t starttime; -extern tic_t raceexittime; -extern tic_t battleexittime; -extern INT32 hyudorotime; -extern INT32 stealtime; -extern INT32 sneakertime; -extern INT32 itemtime; -extern INT32 comebacktime; -extern INT32 bumptime; -extern INT32 wipeoutslowtime; -extern INT32 wantedreduce; -extern INT32 wantedfrequency; +extern const tic_t introtime; +extern const tic_t starttime; +extern const tic_t raceexittime; +extern const tic_t battleexittime; +extern const INT32 hyudorotime; +extern const INT32 stealtime; +extern const INT32 sneakertime; +extern const INT32 itemtime; +extern const INT32 comebacktime; +extern const INT32 bumptime; +extern const INT32 wipeoutslowtime; +extern const INT32 wantedreduce; +extern const INT32 wantedfrequency; extern UINT8 introtoplay; extern UINT8 creditscutscene; diff --git a/src/g_game.c b/src/g_game.c index a442c8814..67292cb48 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -196,19 +196,19 @@ UINT16 spacetimetics = 11*TICRATE + (TICRATE/2); UINT16 extralifetics = 4*TICRATE; // SRB2kart -tic_t introtime = 108+5; // plus 5 for white fade -tic_t starttime = 6*TICRATE + (3*TICRATE/4); -tic_t raceexittime = 5*TICRATE + (2*TICRATE/3); -tic_t battleexittime = 8*TICRATE; -INT32 hyudorotime = 7*TICRATE; -INT32 stealtime = TICRATE/2; -INT32 sneakertime = TICRATE + (TICRATE/3); -INT32 itemtime = 8*TICRATE; -INT32 comebacktime = 10*TICRATE; -INT32 bumptime = 6; -INT32 wipeoutslowtime = 20; -INT32 wantedreduce = 5*TICRATE; -INT32 wantedfrequency = 10*TICRATE; +const tic_t introtime = 108+5; // plus 5 for white fade +const tic_t starttime = 6*TICRATE + (3*TICRATE/4); +const tic_t raceexittime = 5*TICRATE + (2*TICRATE/3); +const tic_t battleexittime = 8*TICRATE; +const INT32 hyudorotime = 7*TICRATE; +const INT32 stealtime = TICRATE/2; +const INT32 sneakertime = TICRATE + (TICRATE/3); +const INT32 itemtime = 8*TICRATE; +const INT32 comebacktime = 10*TICRATE; +const INT32 bumptime = 6; +const INT32 wipeoutslowtime = 20; +const INT32 wantedreduce = 5*TICRATE; +const INT32 wantedfrequency = 10*TICRATE; INT32 gameovertics = 15*TICRATE; diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index f3c073b47..e6f574951 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3316,7 +3316,7 @@ static gl_vissprite_t *HWR_NewVisSprite(void) // Finds a floor through which light does not pass. static fixed_t HWR_OpaqueFloorAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) { - const sector_t *sec = R_PointInSubsector(x, y)->sector; + const sector_t *sec = R_PointInSubsectorFast(x, y)->sector; fixed_t floorz = sec->floorheight; if (sec->ffloors) @@ -3734,6 +3734,9 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) blend = HWR_GetBlendModeFlag(blendmode)|PF_Occlude; } + if (cv_playerfade.value && spr->mobj->player) + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(spr->mobj), Surf.PolyColor.s.alpha); + if (HWR_UseShader()) { shader = SHADER_SPRITE; @@ -4020,6 +4023,9 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) blend = HWR_GetBlendModeFlag(blendmode)|PF_Occlude; } + if (cv_playerfade.value && spr->mobj->player) + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(spr->mobj), Surf.PolyColor.s.alpha); + if (HWR_UseShader()) { shader = SHADER_SPRITE; @@ -4452,6 +4458,15 @@ static void HWR_RenderDrawNodes(void) // -------------------------------------------------------------------------- // Draw all vissprites // -------------------------------------------------------------------------- +namespace +{ + enum class DrawSpritesType + { + kSprites, + kModels, + }; + +template static void HWR_DrawSprites(void) { UINT32 i; @@ -4466,56 +4481,44 @@ static void HWR_DrawSprites(void) continue; } - HWR_DrawSprite(spr); - } -} - -static void HWR_DrawModels(void) -{ - UINT32 i; - - for (i = 0; i < gl_visspritecount; i++) - { - gl_vissprite_t *spr = gl_vsprorder[i]; - - if (spr->precip) + if constexpr (Type == DrawSpritesType::kModels) { - HWR_DrawPrecipitationSprite(spr); - continue; - } - - if (!spr->mobj) - continue; - - if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) - { - md2_t *md2; - - if (spr->mobj->localskin) + if (spr->mobj && spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) { - if (spr->mobj->skinlocal) - md2 = &md2_localplayermodels[(skin_t *)spr->mobj->localskin - localskins]; + md2_t *md2; + + if (spr->mobj->localskin) + { + if (spr->mobj->skinlocal) + md2 = &md2_localplayermodels[(skin_t *)spr->mobj->localskin - localskins]; + else + md2 = &md2_playermodels [(skin_t *)spr->mobj->localskin - skins]; + } else - md2 = &md2_playermodels [(skin_t *)spr->mobj->localskin - skins]; + md2 = &md2_playermodels[(skin_t *)spr->mobj->skin - skins]; + + // 8/1/19: Only don't display player models if no default SPR_PLAY is found. + if (((md2->notfound || md2->scale < 0.0f) && ((!cv_glfallbackplayermodel.value) || md2_models[SPR_PLAY].notfound || md2_models[SPR_PLAY].scale < 0.0f)) || spr->mobj->state == &states[S_PLAY_SIGN]) + HWR_DrawSprite(spr); + else + HWR_DrawMD2(spr); } else - md2 = &md2_playermodels[(skin_t *)spr->mobj->skin - skins]; - - // 8/1/19: Only don't display player models if no default SPR_PLAY is found. - if (((md2->notfound || md2->scale < 0.0f) && ((!cv_glfallbackplayermodel.value) || md2_models[SPR_PLAY].notfound || md2_models[SPR_PLAY].scale < 0.0f)) || spr->mobj->state == &states[S_PLAY_SIGN]) - HWR_DrawSprite(spr); - else - HWR_DrawMD2(spr); + { + if (md2_models[spr->mobj->sprite].notfound || md2_models[spr->mobj->sprite].scale < 0.0f) + HWR_DrawSprite(spr); + else + HWR_DrawMD2(spr); + } } - else + + if constexpr (Type == DrawSpritesType::kSprites) { - if (md2_models[spr->mobj->sprite].notfound || md2_models[spr->mobj->sprite].scale < 0.0f) - HWR_DrawSprite(spr); - else - HWR_DrawMD2(spr); + HWR_DrawSprite(spr); } } } +} // -------------------------------------------------------------------------- // HWR_AddSprites @@ -5565,10 +5568,10 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ HWR_SortVisSprites(); PS_STOP_TIMING(ps_hw_spritesorttime); PS_START_TIMING(ps_hw_spritedrawtime); - if (LIKELY(!cv_glmdls.value)) - HWR_DrawSprites(); + if (UNLIKELY(cv_glmdls.value)) + HWR_DrawSprites(); else - HWR_DrawModels(); + HWR_DrawSprites(); PS_STOP_TIMING(ps_hw_spritedrawtime); ps_numdrawnodes.value.i = 0; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index e1b31bda0..e39c0e6b8 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1227,6 +1227,9 @@ void HWR_DrawMD2(gl_vissprite_t *spr) Surf.PolyFlags = HWR_GetBlendModeFlag(blendmode); } + if (cv_playerfade.value && spr->mobj->player) + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(spr->mobj), Surf.PolyColor.s.alpha); + // dont forget to enabled the depth test because we can't do this like // before: polygons models are not sorted @@ -1241,7 +1244,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) else { md2s = md2_playermodels; - skinnum = (skin_t *)spr->mobj->localskin - skins; + skinnum = (skin_t *)spr->mobj->localskin - skins; } } else @@ -1266,6 +1269,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) if (md2->error) return; // we already failed loading this before :( + if (!md2->model) { CONS_Debug(DBG_RENDER, "Loading model... (%s, %s)", sprnames[spr->mobj->sprite], md2->filename); @@ -1284,6 +1288,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) return; } } + //Hurdler: arf, I don't like that implementation at all... too much crappy gpatch = md2->glpatch; if (gpatch) diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index 909214171..db17d05bf 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -132,7 +132,7 @@ void HWR_PortalFrame(gl_portal_t* portal) { portalclipline = NULL; portalcullsector = NULL; - viewsector = R_PointInSubsector(viewx, viewy)->sector; + viewsector = R_PointInSubsectorFast(viewx, viewy)->sector; } } diff --git a/src/k_kart.c b/src/k_kart.c index dc140d04f..dfc30c177 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4628,7 +4628,7 @@ static void K_CalculateBananaSlope(mobj_t *mobj, fixed_t x, fixed_t y, fixed_t z //sec = R_PointInSubsector(x, y)->sector; if (mobj->x != x || mobj->y != y || mobj->subsector == NULL) - sec = R_PointInSubsector(x, y)->sector; + sec = R_PointInSubsectorFast(x, y)->sector; else sec = mobj->subsector->sector; diff --git a/src/m_menu.c b/src/m_menu.c index a4894b4b8..880fbb451 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -107,7 +107,7 @@ #define SMALLLINEHEIGHT 8 #define SLIDER_RANGE 10 #define SLIDER_WIDTH (8*SLIDER_RANGE+6) -#define SERVERS_PER_PAGE 11 +#define SERVERS_PER_PAGE 10 #define MAXSTAT 9 //Max number a stat can have typedef enum @@ -183,6 +183,8 @@ static char joystickInfo[8][29]; static UINT32 serverlistpage; static UINT32 oldserverlistpage; static float serverlistslidex; +static INT32 serverlistsearched[MAXSERVERLIST] = {0}; +static UINT32 serverlistsearchedcount = 0; #endif //static saveinfo_t savegameinfo[MAXSAVEGAMES]; // Extra info about the save games. @@ -211,6 +213,8 @@ static void M_StopMessage(INT32 choice); #ifndef NONET static void M_HandleServerPage(INT32 choice); +static void M_HandleServerSearch(INT32 choice); +static void M_SearchServerList(void); #endif // Prototyping is fun, innit? @@ -1110,11 +1114,11 @@ static menuitem_t MP_PlayerSetupMenu[] = #ifndef NONET static menuitem_t MP_ConnectMenu[] = { - {IT_STRING | IT_CVAR, NULL, "Sort By", &cv_serversort, 4}, - {IT_STRING | IT_KEYHANDLER, NULL, "Page", M_HandleServerPage, 12}, - {IT_STRING | IT_CALL, NULL, "Refresh", M_Refresh, 20}, + {IT_STRING | IT_KEYHANDLER, NULL, "", M_HandleServerSearch,0}, + {IT_STRING | IT_CVAR, NULL, "Sort By", &cv_serversort, 16}, + {IT_STRING | IT_KEYHANDLER, NULL, "Page", M_HandleServerPage, 24}, + {IT_STRING | IT_CALL, NULL, "Refresh", M_Refresh, 32}, - {IT_STRING | IT_SPACE, NULL, "", M_Connect, 36}, {IT_STRING | IT_SPACE, NULL, "", M_Connect, 48}, {IT_STRING | IT_SPACE, NULL, "", M_Connect, 60}, {IT_STRING | IT_SPACE, NULL, "", M_Connect, 72}, @@ -1129,6 +1133,7 @@ static menuitem_t MP_ConnectMenu[] = enum { + mp_connect_search, mp_connect_sort, mp_connect_page, mp_connect_refresh, @@ -1522,6 +1527,7 @@ enum //op_exp_dirlight, op_exp_skybox, op_exp_accuratefps, + op_exp_votescrn, #ifdef HWRENDER op_exp_glscrtx, #ifdef USE_FBO_OGL @@ -2736,7 +2742,7 @@ menu_t MISC_AddonsDef = 50, 28, 0, NULL, - {NULL} + NULL }; menu_t MISC_ReplayHutDef = @@ -2749,7 +2755,7 @@ menu_t MISC_ReplayHutDef = 30, 80, 0, M_QuitReplayHut, - {NULL} + NULL }; menu_t MISC_ReplayOptionsDef = @@ -2762,7 +2768,7 @@ menu_t MISC_ReplayOptionsDef = 27, 40, 0, NULL, - {NULL} + NULL }; menu_t MISC_ReplayStartDef = @@ -2775,7 +2781,7 @@ menu_t MISC_ReplayStartDef = 30, 90, 0, NULL, - {NULL} + NULL }; menu_t PlaybackMenuDef = { @@ -2788,12 +2794,12 @@ menu_t PlaybackMenuDef = { BASEVIDWIDTH/2 - 88, 2, 0, NULL, - {NULL} + NULL }; menu_t MAPauseDef = PAUSEMENUSTYLE(MAPauseMenu, 40, 72); -menu_t SPauseDef = PAUSEMENUSTYLE(SPauseMenu, 40, 72); -menu_t MPauseDef = PAUSEMENUSTYLE(MPauseMenu, 40, 72); +menu_t SPauseDef = PAUSEMENUSTYLE(SPauseMenu, 40, 72); +menu_t MPauseDef = PAUSEMENUSTYLE(MPauseMenu, 40, 72); #ifdef HAVE_DISCORDRPC menu_t MISC_DiscordRequestsDef = { @@ -2805,16 +2811,16 @@ menu_t MISC_DiscordRequestsDef = { 0, 0, 0, NULL, - {NULL} + NULL }; #endif // Misc Main Menu -menu_t MISC_ScrambleTeamDef = DEFAULTMENUSTYLE(NULL, MISC_ScrambleTeamMenu, &MPauseDef, 27, 40); -menu_t MISC_ChangeTeamDef = DEFAULTMENUSTYLE(NULL, MISC_ChangeTeamMenu, &MPauseDef, 27, 40); -menu_t MISC_ChangeSpectateDef = DEFAULTMENUSTYLE(NULL, MISC_ChangeSpectateMenu, &MPauseDef, 27, 40); -menu_t MISC_ChangeLevelDef = MAPICONMENUSTYLE(NULL, MISC_ChangeLevelMenu, &MPauseDef); -menu_t MISC_HelpDef = IMAGEDEF(MISC_HelpMenu); +menu_t MISC_ScrambleTeamDef = DEFAULTMENUSTYLE(NULL, MISC_ScrambleTeamMenu, &MPauseDef, 27, 40, NULL); +menu_t MISC_ChangeTeamDef = DEFAULTMENUSTYLE(NULL, MISC_ChangeTeamMenu, &MPauseDef, 27, 40, NULL); +menu_t MISC_ChangeSpectateDef = DEFAULTMENUSTYLE(NULL, MISC_ChangeSpectateMenu, &MPauseDef, 27, 40, NULL); +menu_t MISC_ChangeLevelDef = MAPICONMENUSTYLE(NULL, MISC_ChangeLevelMenu, &MPauseDef); +menu_t MISC_HelpDef = IMAGEDEF(MISC_HelpMenu); // // M_GetGametypeColor @@ -2901,7 +2907,7 @@ menu_t SR_PandoraDef = 60, 40, 0, M_ExitPandorasBox, - {NULL} + NULL }; menu_t SR_MainDef = CENTERMENUSTYLE(NULL, SR_MainMenu, &MainDef, 72); @@ -2917,7 +2923,7 @@ menu_t SR_UnlockChecklistDef = 280, 185, 0, NULL, - {NULL} + NULL }; menu_t SR_MusicTestDef = @@ -2930,7 +2936,7 @@ menu_t SR_MusicTestDef = 60, 150, 0, NULL, - {NULL} + NULL }; menu_t SR_EmblemHintDef = @@ -2943,7 +2949,7 @@ menu_t SR_EmblemHintDef = 60, 150, 0, NULL, - {NULL} + NULL }; // Single Player @@ -2959,7 +2965,7 @@ menu_t SP_LevelStatsDef = 280, 185, 0, NULL, - {NULL} + NULL }; static menu_t SP_TimeAttackDef = @@ -2972,7 +2978,7 @@ static menu_t SP_TimeAttackDef = 34, 40, 0, M_QuitTimeAttackMenu, - {NULL} + NULL }; static menu_t SP_ReplayDef = { @@ -2984,7 +2990,7 @@ static menu_t SP_ReplayDef = 34, 40, 0, NULL, - {NULL} + NULL }; static menu_t SP_GuestReplayDef = { @@ -2996,7 +3002,7 @@ static menu_t SP_GuestReplayDef = 34, 40, 0, NULL, - {NULL} + NULL }; static menu_t SP_GhostDef = { @@ -3008,7 +3014,7 @@ static menu_t SP_GhostDef = 34, 40, 0, NULL, - {NULL} + NULL }; // Multiplayer @@ -3026,7 +3032,7 @@ menu_t MP_MainDef = #else NULL, #endif - {NULL} + NULL }; menu_t MP_OfflineServerDef = MAPICONMENUSTYLE("M_MULTI", MP_OfflineServerMenu, &MP_MainDef); @@ -3044,7 +3050,7 @@ menu_t MP_ConnectDef = 27,24, 0, M_CancelConnect, - {NULL} + NULL }; #endif menu_t MP_PlayerSetupDef = @@ -3057,7 +3063,7 @@ menu_t MP_PlayerSetupDef = 36, 14, 0, M_QuitMultiPlayerMenu, - {NULL} + NULL }; // Options @@ -3071,18 +3077,18 @@ menu_t OP_MainDef = 60, 25, 0, NULL, - {NULL} + NULL }; -menu_t OP_ControlsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_ControlsMenu, &OP_MainDef, 60, 30); +menu_t OP_ControlsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_ControlsMenu, &OP_MainDef, 60, 30, OP_ControlsTooltips); //WTF -menu_t OP_MouseOptionsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_MouseOptionsMenu, &OP_ControlsDef, 60, 30); -menu_t OP_AllControlsDef = CONTROLMENUSTYLE(OP_AllControlsMenu, &OP_ControlsDef); -menu_t OP_Joystick1Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick1Menu, &OP_AllControlsDef, 30, 36); -menu_t OP_Joystick2Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick2Menu, &OP_AllControlsDef, 30, 36); -menu_t OP_Joystick3Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick3Menu, &OP_AllControlsDef, 30, 36); -menu_t OP_Joystick4Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick4Menu, &OP_AllControlsDef, 30, 36); -menu_t OP_JoystickSetDef = +menu_t OP_MouseOptionsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_MouseOptionsMenu, &OP_ControlsDef, 60, 30, OP_MouseTooltips); +menu_t OP_AllControlsDef = CONTROLMENUSTYLE(OP_AllControlsMenu, &OP_ControlsDef); +menu_t OP_Joystick1Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick1Menu, &OP_AllControlsDef, 30, 36, NULL); +menu_t OP_Joystick2Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick2Menu, &OP_AllControlsDef, 30, 36, NULL); +menu_t OP_Joystick3Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick3Menu, &OP_AllControlsDef, 30, 36, NULL); +menu_t OP_Joystick4Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick4Menu, &OP_AllControlsDef, 30, 36, NULL); +menu_t OP_JoystickSetDef = { "M_CONTRO", sizeof (OP_JoystickSetMenu)/sizeof (menuitem_t), @@ -3092,7 +3098,7 @@ menu_t OP_JoystickSetDef = 50, 40, 0, NULL, - {NULL} + NULL }; menu_t OP_VideoOptionsDef = @@ -3105,7 +3111,7 @@ menu_t OP_VideoOptionsDef = 30, 15, 0, NULL, - {NULL} + OP_VideoTooltips }; menu_t OP_VideoModeDef = @@ -3118,7 +3124,7 @@ menu_t OP_VideoModeDef = 48, 26, 0, NULL, - {NULL} + NULL }; menu_t OP_ColorOptionsDef = @@ -3131,7 +3137,7 @@ menu_t OP_ColorOptionsDef = 30, 30, 0, NULL, - {NULL} + NULL }; menu_t OP_SoundOptionsDef = @@ -3144,7 +3150,7 @@ menu_t OP_SoundOptionsDef = 30, 20, 0, NULL, - {NULL} + OP_SoundTooltips }; @@ -3158,25 +3164,25 @@ menu_t OP_HUDOptionsDef = 30, 20, 0, NULL, - {NULL} + NULL }; -menu_t OP_CamOptionsDef = DEFAULTMENUSTYLE(NULL, OP_CamOptionsMenu, &OP_MainDef, 30, 30); -menu_t OP_Player1CamOptionsDef = DEFAULTMENUSTYLE(NULL, OP_Player1CamOptionsMenu, &OP_CamOptionsDef, 30, 30); -menu_t OP_Player2CamOptionsDef = DEFAULTMENUSTYLE(NULL, OP_Player2CamOptionsMenu, &OP_CamOptionsDef, 30, 30); -menu_t OP_Player3CamOptionsDef = DEFAULTMENUSTYLE(NULL, OP_Player3CamOptionsMenu, &OP_CamOptionsDef, 30, 30); -menu_t OP_Player4CamOptionsDef = DEFAULTMENUSTYLE(NULL, OP_Player4CamOptionsMenu, &OP_CamOptionsDef, 30, 30); +menu_t OP_CamOptionsDef = DEFAULTMENUSTYLE(NULL, OP_CamOptionsMenu, &OP_MainDef, 30, 30, OP_CamOptionsTooltips); +menu_t OP_Player1CamOptionsDef = DEFAULTMENUSTYLE(NULL, OP_Player1CamOptionsMenu, &OP_CamOptionsDef, 30, 30, OP_PlayerCamOptionsTooltips); +menu_t OP_Player2CamOptionsDef = DEFAULTMENUSTYLE(NULL, OP_Player2CamOptionsMenu, &OP_CamOptionsDef, 30, 30, OP_PlayerCamOptionsTooltips); +menu_t OP_Player3CamOptionsDef = DEFAULTMENUSTYLE(NULL, OP_Player3CamOptionsMenu, &OP_CamOptionsDef, 30, 30, OP_PlayerCamOptionsTooltips); +menu_t OP_Player4CamOptionsDef = DEFAULTMENUSTYLE(NULL, OP_Player4CamOptionsMenu, &OP_CamOptionsDef, 30, 30, OP_PlayerCamOptionsTooltips); -menu_t OP_ChatOptionsDef = DEFAULTMENUSTYLE("M_HUD", OP_ChatOptionsMenu, &OP_HUDOptionsDef, 30, 30); +menu_t OP_ChatOptionsDef = DEFAULTMENUSTYLE("M_HUD", OP_ChatOptionsMenu, &OP_HUDOptionsDef, 30, 30, OP_ChatOptionsTooltips); -menu_t OP_SoundAdvancedDef = DEFAULTSCROLLSTYLE("M_SOUND", OP_SoundAdvancedMenu, &OP_SoundOptionsDef, 30, 30); +menu_t OP_SoundAdvancedDef = DEFAULTSCROLLSTYLE("M_SOUND", OP_SoundAdvancedMenu, &OP_SoundOptionsDef, 30, 30, OP_SoundAdvancedTooltips); -menu_t OP_FocusOptionsDef = DEFAULTMENUSTYLE(NULL, OP_FocusOptionsMenu, &OP_MainDef, 17, 30); +menu_t OP_FocusOptionsDef = DEFAULTMENUSTYLE(NULL, OP_FocusOptionsMenu, &OP_MainDef, 17, 30, OP_FocusOptionsTooltips); -menu_t OP_GameOptionsDef = DEFAULTMENUSTYLE("M_GAME", OP_GameOptionsMenu, &OP_MainDef, 30, 20); -menu_t OP_ServerOptionsDef = DEFAULTMENUSTYLE("M_SERVER", OP_ServerOptionsMenu, &OP_MainDef, 24, 20); +menu_t OP_GameOptionsDef = DEFAULTMENUSTYLE("M_GAME", OP_GameOptionsMenu, &OP_MainDef, 30, 20, OP_GameTooltips); +menu_t OP_ServerOptionsDef = DEFAULTMENUSTYLE("M_SERVER", OP_ServerOptionsMenu, &OP_MainDef, 24, 20, OP_ServerOptionsTooltips); #ifndef NONET -menu_t OP_AdvServerOptionsDef = DEFAULTSCROLLSTYLE("M_SERVER", OP_AdvServerOptionsMenu, &OP_ServerOptionsDef, 24, 30); +menu_t OP_AdvServerOptionsDef = DEFAULTSCROLLSTYLE("M_SERVER", OP_AdvServerOptionsMenu, &OP_ServerOptionsDef, 24, 30, OP_AdvServerOptionsTooltips); #endif //menu_t OP_NetgameOptionsDef = DEFAULTMENUSTYLE("M_SERVER", OP_NetgameOptionsMenu, &OP_ServerOptionsDef, 30, 30); @@ -3192,38 +3198,38 @@ menu_t OP_MonitorToggleDef = 47, 30, 0, NULL, - {NULL} + NULL }; #ifdef HWRENDER -menu_t OP_OpenGLOptionsDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_OpenGLOptionsMenu, &OP_VideoOptionsDef, 30, 30); +menu_t OP_OpenGLOptionsDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_OpenGLOptionsMenu, &OP_VideoOptionsDef, 30, 30, OP_OpenGLTooltips); #endif -menu_t OP_ExpOptionsDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_ExpOptionsMenu, &OP_VideoOptionsDef, 30, 25); +menu_t OP_ExpOptionsDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_ExpOptionsMenu, &OP_VideoOptionsDef, 30, 25, OP_ExpTooltips); -menu_t OP_DataOptionsDef = DEFAULTMENUSTYLE("M_DATA", OP_DataOptionsMenu, &OP_MainDef, 60, 30); -menu_t OP_ScreenshotOptionsDef = DEFAULTSCROLLSTYLE("M_SCSHOT", OP_ScreenshotOptionsMenu, &OP_DataOptionsDef, 30, 30); -menu_t OP_AddonsOptionsDef = DEFAULTMENUSTYLE("M_ADDONS", OP_AddonsOptionsMenu, &OP_DataOptionsDef, 30, 30); -menu_t OP_ProtocolDef = DEFAULTMENUSTYLE(NULL, OP_ProtocolMenu, &OP_DataOptionsDef, 30, 30); +menu_t OP_DataOptionsDef = DEFAULTMENUSTYLE("M_DATA", OP_DataOptionsMenu, &OP_MainDef, 60, 30, NULL); +menu_t OP_ScreenshotOptionsDef = DEFAULTSCROLLSTYLE("M_SCSHOT", OP_ScreenshotOptionsMenu, &OP_DataOptionsDef, 30, 30, NULL); +menu_t OP_AddonsOptionsDef = DEFAULTMENUSTYLE("M_ADDONS", OP_AddonsOptionsMenu, &OP_DataOptionsDef, 30, 30, NULL); +menu_t OP_ProtocolDef = DEFAULTMENUSTYLE(NULL, OP_ProtocolMenu, &OP_DataOptionsDef, 30, 30, NULL); #ifdef HAVE_DISCORDRPC -menu_t OP_DiscordOptionsDef = DEFAULTMENUSTYLE(NULL, OP_DiscordOptionsMenu, &OP_DataOptionsDef, 30, 30); +menu_t OP_DiscordOptionsDef = DEFAULTMENUSTYLE(NULL, OP_DiscordOptionsMenu, &OP_DataOptionsDef, 30, 30, NULL); #endif -menu_t OP_EraseDataDef = DEFAULTMENUSTYLE("M_DATA", OP_EraseDataMenu, &OP_DataOptionsDef, 30, 30); +menu_t OP_EraseDataDef = DEFAULTMENUSTYLE("M_DATA", OP_EraseDataMenu, &OP_DataOptionsDef, 30, 30, NULL); -menu_t OP_SaturnDef = DEFAULTSCROLLSTYLE(NULL, OP_SaturnMenu, &OP_MainDef, 30, 30); -menu_t OP_PlayerDistortDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_PlayerDistortMenu, &OP_SaturnDef, 30, 30); -menu_t OP_HudOffsetDef = DEFAULTSCROLLSTYLE(NULL, OP_HudOffsetMenu, &OP_SaturnHudDef, 30, 30); -menu_t OP_SaturnHudDef = DEFAULTSCROLLSTYLE(NULL, OP_SaturnHudMenu, &OP_SaturnDef, 30, 30); +menu_t OP_SaturnDef = DEFAULTSCROLLSTYLE(NULL, OP_SaturnMenu, &OP_MainDef, 30, 30, OP_SaturnTooltips); +menu_t OP_SaturnCreditsDef = DEFAULTMENUSTYLE(NULL, OP_SaturnCreditsMenu, &OP_SaturnDef, 30, 0, NULL); // OP_CreditTooltips no space :c -menu_t OP_SaturnCreditsDef = DEFAULTMENUSTYLE(NULL, OP_SaturnCreditsMenu, &OP_SaturnDef, 30, 0); +menu_t OP_SaturnHudDef = DEFAULTSCROLLSTYLE(NULL, OP_SaturnHudMenu, &OP_SaturnDef, 30, 30, OP_SaturnHudTooltips); +menu_t OP_PlayerDistortDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_PlayerDistortMenu, &OP_SaturnDef, 30, 30, OP_PlayerDistortTooltips); +menu_t OP_HudOffsetDef = DEFAULTSCROLLSTYLE(NULL, OP_HudOffsetMenu, &OP_SaturnHudDef, 30, 30, NULL); -menu_t OP_BirdDef = DEFAULTMENUSTYLE(NULL, OP_BirdMenu, &OP_MainDef, 30, 30); +menu_t OP_BirdDef = DEFAULTMENUSTYLE(NULL, OP_BirdMenu, &OP_MainDef, 30, 30, OP_BirdTooltips); -menu_t OP_NametagDef = DEFAULTMENUSTYLE(NULL, OP_NametagMenu, &OP_SaturnHudDef, 30, 40); -menu_t OP_DriftGaugeDef = DEFAULTMENUSTYLE(NULL, OP_DriftGaugeMenu, &OP_SaturnHudDef, 30, 40); +menu_t OP_NametagDef = DEFAULTMENUSTYLE(NULL, OP_NametagMenu, &OP_SaturnHudDef, 30, 40, OP_NametagTooltips); +menu_t OP_DriftGaugeDef = DEFAULTMENUSTYLE(NULL, OP_DriftGaugeMenu, &OP_SaturnHudDef, 30, 40, OP_DriftGaugeTooltips); -menu_t OP_TiltDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_BirdDef, 30, 60); -menu_t OP_AdvancedBirdDef = DEFAULTMENUSTYLE(NULL, OP_AdvancedBirdMenu, &OP_BirdDef, 30, 60); +menu_t OP_TiltDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_BirdDef, 30, 60, OP_TiltTooltips); +menu_t OP_AdvancedBirdDef = DEFAULTMENUSTYLE(NULL, OP_AdvancedBirdMenu, &OP_BirdDef, 30, 60, OP_AdvancedBirdTooltips); INT16 ccvarposition = 0; @@ -3240,7 +3246,7 @@ static void M_CustomCvarMenu(INT32 choice) /*menu_t OP_CustomCvarMenuDef = DEFAULTSCROLLMENUSTYLE( MTREE3(MN_OP_MAIN, MN_OP_DATA, MN_OP_ADDONS), "M_ADDONS", OP_CustomCvarMenu, &OP_MainDef, 30, 30);*/ -menu_t OP_CustomCvarMenuDef = DEFAULTSCROLLSTYLE("M_ADDONS", OP_CustomCvarMenu, &OP_MainDef, 10, 30); +menu_t OP_CustomCvarMenuDef = DEFAULTSCROLLSTYLE("M_ADDONS", OP_CustomCvarMenu, &OP_MainDef, 10, 30, NULL); menu_t OP_ForkedBirdDef = { NULL, @@ -3251,10 +3257,10 @@ menu_t OP_ForkedBirdDef = { 30, 6, 0, NULL, - {NULL} + NULL }; -menu_t OP_LocalSkinDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_ForkedBirdDef, 30, 60); +menu_t OP_LocalSkinDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_ForkedBirdDef, 30, 60, NULL); // ========================================================================== @@ -4875,6 +4881,9 @@ void M_Init(void) //todo put this somewhere better... CV_RegisterVar(&cv_allcaps); + + memset(menu_text_input_buf, 0, sizeof menu_text_input_buf); + M_TextInputInit(&menuinput, menu_text_input_buf, sizeof menu_text_input_buf); } void M_InitCharacterTables(void) @@ -5191,6 +5200,16 @@ static void M_DrawSplitText(INT32 x, INT32 y, INT32 option, const char* str, INT free(clines); } +static void M_DoToolTips(menu_t* menu) +{ + if (!menu->tooltips || itemOn == -1 || !menu->tooltips[itemOn]) + return; + + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, menu->tooltips[itemOn], coolalphatimer); + + if ((coolalphatimer > 0) && interpTimerHackAllow) + coolalphatimer--; +} static void M_DrawGenericMenu(void) { @@ -5337,23 +5356,7 @@ static void M_DrawGenericMenu(void) // dumb hack // tooltips - // replaced with macro so it doesent look as terrible anymore lol - DoToolTips(OP_ControlsDef, OP_ControlsTooltips); - DoToolTips(OP_MouseOptionsDef, OP_MouseTooltips); - DoToolTips(OP_VideoOptionsDef, OP_VideoTooltips); - DoToolTips(OP_SoundOptionsDef, OP_SoundTooltips); - DoToolTips(OP_FocusOptionsDef, OP_FocusOptionsTooltips); - DoToolTips(OP_ChatOptionsDef, OP_ChatOptionsTooltips); - DoToolTips(OP_GameOptionsDef, OP_GameTooltips); - DoToolTips(OP_ServerOptionsDef, OP_ServerOptionsTooltips); - //DoToolTips(OP_SaturnCreditsDef, OP_CreditTooltips); // C: - DoToolTips(OP_BirdDef, OP_BirdTooltips); - DoToolTips(OP_TiltDef, OP_TiltTooltips); - DoToolTips(OP_AdvancedBirdDef, OP_AdvancedBirdTooltips); - DoToolTips(OP_NametagDef, OP_NametagTooltips); - DoToolTips(OP_DriftGaugeDef, OP_DriftGaugeTooltips); - DoToolTips(OP_CamOptionsDef, OP_CamOptionsTooltips); - DoToolTips(OP_Player1CamOptionsDef || currentMenu == &OP_Player2CamOptionsDef || currentMenu == &OP_Player3CamOptionsDef || currentMenu == &OP_Player4CamOptionsDef, OP_PlayerCamOptionsTooltips); // god this one is still terrible lmao + M_DoToolTips(currentMenu); } static void M_DrawGenericBackgroundMenu(void) @@ -5484,16 +5487,7 @@ static void M_DrawGenericScrollMenu(void) // dumb hack // tooltips - // same macro here - DoToolTips(OP_ExpOptionsDef, OP_ExpTooltips); -#ifdef HWRENDER - DoToolTips(OP_OpenGLOptionsDef, OP_OpenGLTooltips); -#endif - DoToolTips(OP_SaturnDef, OP_SaturnTooltips); - DoToolTips(OP_SaturnHudDef, OP_SaturnHudTooltips); - DoToolTips(OP_AdvServerOptionsDef, OP_AdvServerOptionsTooltips); - DoToolTips(OP_SoundAdvancedDef, OP_SoundAdvancedTooltips); - DoToolTips(OP_PlayerDistortDef, OP_PlayerDistortTooltips); + M_DoToolTips(currentMenu); } static void M_DrawPauseMenu(void) @@ -5808,7 +5802,7 @@ menu_t MessageDef = 0, 0, // x, y (TO HACK) 0, // lastOn, flags (TO HACK) NULL, - {0}, + NULL, }; @@ -9632,7 +9626,7 @@ Fetch_servers_thread (int *id) } #endif/*MASTERSERVER*/ -#define SERVERHEADERHEIGHT 36 +#define SERVERHEADERHEIGHT 48 #define SERVERLINEHEIGHT 12 #define S_LINEY(n) currentMenu->y + SERVERHEADERHEIGHT + (n * SERVERLINEHEIGHT) @@ -9640,6 +9634,57 @@ Fetch_servers_thread (int *id) #ifndef NONET static UINT32 localservercount; +static void M_SearchServerList(void) +{ + char servername[MAXSERVERNAME+1] = {0}; + serverlistsearchedcount = 0; + + for (UINT32 i = 0; i < serverlistcount; ++i) + { + StripColors(servername, serverlist[i].info.servername, MAXSERVERNAME); + if (menuinput.length == 0 || strcasestr(servername, menuinput.buffer) != NULL) + serverlistsearched[serverlistsearchedcount++] = i; + } + + if (menuinput.length > 0) + serverlistpage = 0; +} + +static void M_HandleServerSearch(INT32 choice) +{ + boolean exitmenu = false; // exit to previous menu + + switch (choice) + { + case KEY_DOWNARROW: + M_NextOpt(); + S_StartSound(NULL, sfx_menu1); + break; + case KEY_UPARROW: + M_PrevOpt(); + S_StartSound(NULL, sfx_menu1); + break; + case KEY_ESCAPE: + exitmenu = true; + break; + + default: + if (M_TextInputHandle(&menuinput, choice)) + { + S_StartSound(NULL, sfx_menu1); + M_SearchServerList(); + } + break; + } + if (exitmenu) + { + if (currentMenu->prevMenu) + M_SetupNextMenu(currentMenu->prevMenu); + else + M_ClearMenus(true); + } +} + static void M_HandleServerPage(INT32 choice) { boolean exitmenu = false; // exit to previous menu @@ -9662,7 +9707,7 @@ static void M_HandleServerPage(INT32 choice) case KEY_ENTER: case KEY_RIGHTARROW: S_StartSound(NULL, sfx_menu1); - if ((serverlistpage + 1) * SERVERS_PER_PAGE < serverlistcount) + if ((serverlistpage + 1) * SERVERS_PER_PAGE < serverlistsearchedcount) { oldserverlistpage = serverlistpage++; serverlistslidex = BASEVIDWIDTH; @@ -9693,7 +9738,7 @@ static void M_Connect(INT32 choice) { // do not call menuexitfunc M_ClearMenus(false); - COM_BufAddText(va("connect node %d\n", serverlist[choice-FIRSTSERVERLINE + serverlistpage * SERVERS_PER_PAGE].node)); + COM_BufAddText(va("connect node %d\n", serverlist[serverlistsearched[choice-FIRSTSERVERLINE + serverlistpage * SERVERS_PER_PAGE]].node)); } static void M_Refresh(INT32 choice) @@ -9751,11 +9796,11 @@ static void M_DrawServerCountAndHorizontalBar(void) radius = V_StringWidth(text, 0) / 2; - V_DrawCenteredString(center, currentMenu->y+28, 0, text); + V_DrawCenteredString(center, currentMenu->y+40, 0, text); // Horizontal line! - V_DrawFill(1, currentMenu->y+32, center - radius - 2, 1, 0); - V_DrawFill(center + radius + 2, currentMenu->y+32, BASEVIDWIDTH - 1, 1, 0); + V_DrawFill(1, currentMenu->y+44, center - radius - 2, 1, 0); + V_DrawFill(center + radius + 2, currentMenu->y+44, BASEVIDWIDTH - 1, 1, 0); } #endif @@ -9765,9 +9810,9 @@ static void M_DrawServerLines(INT32 x, INT32 page) const char *gt = "Unknown"; const char *spd = ""; - for (i = 0; i < min(serverlistcount - page * SERVERS_PER_PAGE, SERVERS_PER_PAGE); i++) + for (i = 0; i < min(serverlistsearchedcount - page * SERVERS_PER_PAGE, SERVERS_PER_PAGE); i++) { - INT32 slindex = i + page * SERVERS_PER_PAGE; + INT32 slindex = serverlistsearched[i + page * SERVERS_PER_PAGE]; UINT32 globalflags = ((serverlist[slindex].info.numberofplayer >= serverlist[slindex].info.maxplayer) ? V_TRANSLUCENT : 0) |((itemOn == FIRSTSERVERLINE+i) ? highlightflags : 0)|V_ALLOWLOWERCASE; @@ -9806,7 +9851,7 @@ static void M_DrawServerLines(INT32 x, INT32 page) static void M_DrawConnectMenu(void) { UINT16 i; - INT32 numPages = (serverlistcount+(SERVERS_PER_PAGE-1))/SERVERS_PER_PAGE; + INT32 numPages = (serverlistsearchedcount+(SERVERS_PER_PAGE-1))/SERVERS_PER_PAGE; INT32 mservflags = V_ALLOWLOWERCASE; for (i = FIRSTSERVERLINE; i < min(localservercount, SERVERS_PER_PAGE)+FIRSTSERVERLINE; i++) @@ -9856,6 +9901,16 @@ static void M_DrawConnectMenu(void) M_DrawServerLines(currentMenu->x, serverlistpage); } + V_DrawFill(currentMenu->x, currentMenu->y, MAXSTRINGLENGTH*8+6, 8+6, 239); + + const INT32 xoff = 3, yoff = 3; + + + if (itemOn != 0) + V_DrawString(currentMenu->x+xoff, currentMenu->y+yoff, V_ALLOWLOWERCASE, menuinput.buffer); + else + M_DrawTextInput(currentMenu->x+xoff, currentMenu->y+yoff, &menuinput, 0); + localservercount = serverlistcount; M_DrawGenericMenu(); @@ -9935,6 +9990,7 @@ void M_SortServerList(void) qs22j(serverlist, serverlistcount, sizeof(serverelem_t), ServerListEntryComparator_gametype); break; } + M_SearchServerList(); #endif } @@ -9993,6 +10049,9 @@ static void M_ConnectMenu(INT32 choice) CL_UpdateServerList(); + // Reset + M_TextInputSetString(&menuinput, ""); + M_SetupNextMenu(&MP_ConnectDef); itemOn = 0; diff --git a/src/m_menu.h b/src/m_menu.h index 4cea66d2c..06e0273fe 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -212,14 +212,14 @@ extern menuitem_t PlayerMenu[MAXSKINS]; typedef struct menu_s { const char *menutitlepic; - INT16 numitems; // # of menu items - struct menu_s *prevMenu; // previous menu - menuitem_t *menuitems; // menu items - void (*drawroutine)(void); // draw routine - INT16 x, y; // x, y of menu - INT16 lastOn; // last item user was on in menu - boolean (*quitroutine)(void); // called before quit a menu return true if we can - const char* tooltips[MAXTOOLTIPS]; // tooltips! give me that info bitch + INT16 numitems; // # of menu items + struct menu_s *prevMenu; // previous menu + menuitem_t *menuitems; // menu items + void (*drawroutine)(void); // draw routine + INT16 x, y; // x, y of menu + INT16 lastOn; // last item user was on in menu + boolean (*quitroutine)(void); // called before quit a menu return true if we can + const char* *tooltips; // tooltips! give me that info bitch } menu_t; void M_SetupNextMenu(menu_t *menudef); @@ -335,7 +335,7 @@ void M_PopupMasterServerConnectError(void); void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* name); // These defines make it a little easier to make menus -#define DEFAULTMENUSTYLE(header, source, prev, x, y)\ +#define DEFAULTMENUSTYLE(header, source, prev, x, y, tooltip)\ {\ header,\ sizeof(source)/sizeof(menuitem_t),\ @@ -345,10 +345,10 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na x, y,\ 0,\ NULL,\ - {NULL}\ + tooltip\ } -#define DEFAULTSCROLLSTYLE(header, source, prev, x, y)\ +#define DEFAULTSCROLLSTYLE(header, source, prev, x, y, tooltip)\ {\ header,\ sizeof(source)/sizeof(menuitem_t),\ @@ -358,7 +358,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na x, y,\ 0,\ NULL,\ - {NULL}\ + tooltip\ } @@ -372,7 +372,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na x, y,\ 0,\ NULL,\ - {NULL}\ + NULL\ } #define CENTERMENUSTYLE(header, source, prev, y)\ @@ -385,7 +385,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na BASEVIDWIDTH/2, y,\ 0,\ NULL,\ - {NULL}\ + NULL\ } #define MAPICONMENUSTYLE(header, source, prev)\ @@ -398,7 +398,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na 24,40,\ 0,\ NULL,\ - {NULL}\ + NULL\ } #define CONTROLMENUSTYLE(source, prev)\ @@ -411,7 +411,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na 26, 40,\ 0,\ NULL,\ - {NULL}\ + NULL\ } #define IMAGEDEF(source)\ @@ -424,18 +424,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na 0, 0,\ 0,\ NULL,\ - {NULL}\ -} - -#define DoToolTips(menu, tooltip)\ -if (currentMenu == &menu)\ -{\ - if (!(tooltip[itemOn] == NULL))\ - {\ - M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, tooltip[itemOn], coolalphatimer);\ - if (coolalphatimer > 0 && interpTimerHackAllow)\ - coolalphatimer--;\ - }\ + NULL\ } #ifdef __cplusplus diff --git a/src/m_misc.c b/src/m_misc.c index eb2932b90..8dd7bf9b5 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1828,6 +1828,21 @@ void CopyCaretColors(char *p, const char *s, int n) strncpy(p, s, n); } +void StripColors(char *dst, char *src, size_t n) +{ + size_t j = 0; + + for (size_t i = 0; j < n && src[i] != 0; ++i) + { + char c = src[i]; + + if ((c & 0x80) == 0) + dst[j++] = c; + } + + dst[j] = 0; +} + /** Token parser for TEXTURES, ANIMDEFS, and potentially other lumps later down the line. * Was originally R_GetTexturesToken when I was coding up the TEXTURES parser, until I realized I needed it for ANIMDEFS too. * Parses up to the next whitespace character or comma. When finding the start of the next token, whitespace is skipped. diff --git a/src/m_misc.h b/src/m_misc.h index 91008edb4..17ec9823a 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -87,6 +87,9 @@ INT32 axtoi(const char *hexStg); void CopyCaretColors(char *p, const char *s, int n); +// Remove color codes from string +void StripColors(char *dst, char *src, size_t n); + const char *GetRevisionString(void); // Vector/matrix math diff --git a/src/p_map.c b/src/p_map.c index a11963014..656dec34b 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1995,7 +1995,7 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) tmbbox[BOXLEFT] = x - thiscam->radius; if (thiscam->x != x || thiscam->y != y || thiscam->subsector == NULL) - newsubsec = R_PointInSubsector(x, y); + newsubsec = R_PointInSubsectorFast(x, y); else newsubsec = thiscam->subsector; @@ -2181,7 +2181,7 @@ boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam) return false; if (thiscam->x != x || thiscam->y != y || thiscam->subsector == NULL) - s = R_PointInSubsector(x, y); + s = R_PointInSubsectorFast(x, y); else s = thiscam->subsector; diff --git a/src/p_maputl.c b/src/p_maputl.c index 7b748c22e..11e7a1050 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -908,7 +908,7 @@ void P_SetUnderlayPosition(mobj_t *thing) void P_SetPrecipitationThingPosition(precipmobj_t *thing) { - thing->subsector = R_PointInSubsector(thing->x, thing->y); + thing->subsector = R_PointInSubsectorFast(thing->x, thing->y); // NOTE: this works because bnext/bprev are at the same // offsets in precipmobj_t and mobj_t diff --git a/src/p_mobj.c b/src/p_mobj.c index 18d6b6854..a7a00e355 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -755,7 +755,7 @@ fixed_t P_CameraFloorZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, fix testy += y; // If the highest point is in the sector, then we have it easy! Just get the Z at that point - if (R_PointInSubsector(testx, testy)->sector == (boundsec ? boundsec : sector)) + if (R_PointInSubsectorFast(testx, testy)->sector == (boundsec ? boundsec : sector)) return P_GetSlopeZAt(slope, testx, testy); // If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point @@ -835,7 +835,7 @@ fixed_t P_CameraCeilingZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, f testy += y; // If the highest point is in the sector, then we have it easy! Just get the Z at that point - if (R_PointInSubsector(testx, testy)->sector == (boundsec ? boundsec : sector)) + if (R_PointInSubsectorFast(testx, testy)->sector == (boundsec ? boundsec : sector)) return P_GetSlopeZAt(slope, testx, testy); // If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point @@ -3289,7 +3289,7 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled } } - thiscam->subsector = R_PointInSubsector(thiscam->x, thiscam->y); + thiscam->subsector = R_PointInSubsectorFast(thiscam->x, thiscam->y); thiscam->floorz = tmfloorz; thiscam->ceilingz = tmceilingz; @@ -10371,7 +10371,7 @@ void P_PrecipitationEffects(void) for (y = yl; y <= yh; y += RADIUSSTEP) for (x = xl; x <= xh; x += RADIUSSTEP) { - if (R_PointInSubsector((fixed_t)x, (fixed_t)y)->sector->ceilingpic != skyflatnum) // Found the outdoors! + if (R_PointInSubsectorFast((fixed_t)x, (fixed_t)y)->sector->ceilingpic != skyflatnum) // Found the outdoors! continue; newdist = S_CalculateSoundDistance(players[displayplayers[0]].mo->x, players[displayplayers[0]].mo->y, 0, (fixed_t)x, (fixed_t)y, 0); diff --git a/src/p_setup.c b/src/p_setup.c index a26bd9ab8..bac128ba1 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2511,7 +2511,6 @@ static void P_SetupCamera(UINT8 pnum, camera_t *cam) cam->y = players[pnum].mo->y; cam->z = players[pnum].mo->z; cam->angle = players[pnum].mo->angle; - cam->subsector = R_PointInSubsector(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) } else { @@ -2536,9 +2535,10 @@ static void P_SetupCamera(UINT8 pnum, camera_t *cam) cam->y = thing->y; cam->z = thing->z; cam->angle = FixedAngle((fixed_t)thing->angle << FRACBITS); - cam->subsector = R_PointInSubsector(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) } + cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) + cam->chase = false; // tell camera to reset its position next tic } diff --git a/src/p_spec.c b/src/p_spec.c index f279ca9c7..9b0fc932e 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2022,7 +2022,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) camera[i].y += y; camera[i].z += z; camera[i].reset = true; - camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); + camera[i].subsector = R_PointInSubsectorFast(camera[i].x, camera[i].y); R_RelativeTeleportViewInterpolation(i, x, y, z, 0); break; } diff --git a/src/p_user.c b/src/p_user.c index b48fe0f26..dd2f4cd2b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3406,7 +3406,7 @@ static void P_DemoCameraMovement(camera_t *cam, UINT8 num) } // update subsector to avoid crashes; - cam->subsector = R_PointInSubsector(cam->x, cam->y); + cam->subsector = R_PointInSubsectorFast(cam->x, cam->y); } void P_ResetCamera(player_t *player, camera_t *thiscam) @@ -3450,7 +3450,7 @@ void P_ResetCamera(player_t *player, camera_t *thiscam) thiscam->relativex = 0; - thiscam->subsector = R_PointInSubsector(thiscam->x,thiscam->y); + thiscam->subsector = R_PointInSubsectorFast(thiscam->x,thiscam->y); thiscam->radius = 20*FRACUNIT; thiscam->height = 16*FRACUNIT; @@ -3686,7 +3686,7 @@ static void P_MoveCameraToSpawn(UINT8 playernum) thiscam->angle = player->mo->angle; thiscam->aiming = 0; - thiscam->subsector = R_PointInSubsector(thiscam->x,thiscam->y); + thiscam->subsector = R_PointInSubsectorFast(thiscam->x,thiscam->y); thiscam->reset_aiming = true; diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 0e81a4198..a05bf70c4 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -196,10 +196,10 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, mobj_t *pviewmobj = viewplayer->mo; INT32 heightsec; boolean underwater; - UINT8 i = R_GetViewNumber(); + camera_t *thiscam = &camera[R_GetViewNumber()]; - if (viewplayer == &players[displayplayers[i]] && camera[i].chase) - heightsec = camera->subsector->sector->heightsec; + if (thiscam->chase) + heightsec = thiscam->subsector->sector->heightsec; else if (viewmobj) heightsec = pviewmobj->subsector->sector->heightsec; else diff --git a/src/r_fps.c b/src/r_fps.c index 1d5cc1baf..0c3a58737 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -232,7 +232,7 @@ void R_InterpolateView(fixed_t frac, boolean forceinvalid) viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); viewplayer = newview->player; - viewsector = R_PointInSubsector(viewx, viewy)->sector; + viewsector = R_PointInSubsectorFast(viewx, viewy)->sector; R_SetupFreelook(); } diff --git a/src/r_main.cpp b/src/r_main.cpp index ebea32638..fa4425f19 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -141,10 +141,10 @@ static CV_PossibleValue_t drawdist_precip_cons_t[] = { #endif static CV_PossibleValue_t maxinterpdist_cons_t[] = { - /*{256, "256"},*/ {512, "512"}, {768, "768"}, - {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, - {3072, "3072"}, {4096, "4096"}, {6144, "6144"}, - {8192, "8192"}, {0, "Infinite"}, {0, NULL}}; + /*{256, "256"},*/ {512, "512"}, {768, "768"}, + {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, + {3072, "3072"}, {4096, "4096"}, {6144, "6144"}, + {8192, "8192"}, {0, "Infinite"}, {0, NULL}}; static CV_PossibleValue_t fov_cons_t[] = {{MINFOV*FRACUNIT, "MIN"}, {MAXFOV*FRACUNIT, "MAX"}, {0, NULL}}; @@ -170,14 +170,14 @@ consvar_t cv_tailspickup = {"tailspickup", "On", CV_NETVAR|CV_NOSHOWHELP, CV_OnO consvar_t cv_precachetextures = {"precachetextures", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_chasecam[MAXSPLITSCREENPLAYERS] = { - {"chasecam", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"chasecam", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, {"chasecam2", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, {"chasecam3", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, {"chasecam4", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL} }; consvar_t cv_flipcam[MAXSPLITSCREENPLAYERS] = { - {"flipcam", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam_OnChange, 0, NULL, NULL, 0, 0, NULL}, + {"flipcam", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam_OnChange, 0, NULL, NULL, 0, 0, NULL}, {"flipcam2", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam2_OnChange, 0, NULL, NULL, 0, 0, NULL}, {"flipcam3", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam3_OnChange, 0, NULL, NULL, 0, 0, NULL}, {"flipcam4", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam4_OnChange, 0, NULL, NULL, 0, 0, NULL} @@ -195,6 +195,7 @@ consvar_t cv_drawdist_precip = {"drawdist_precip", "1024", CV_SAVE|CV_CALL|CV_NO consvar_t cv_lessprecip = {"lessweathereffects", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Precipstuff_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_mobjscaleprecip = {"scaleprecipmobjscale", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Precipstuff_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_maxinterpdist = {"maxinterpdist", "Infinite", CV_SAVE, maxinterpdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_playerfade = {"playerfade", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_ripplewater = {"waterripples", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // Okay, whoever said homremoval causes a performance hit should be shot. @@ -211,6 +212,7 @@ consvar_t cv_randomdirlight = {"randomdirectionallight", "Off", CV_SAVE|CV_CALL consvar_t cv_showhud = {"showhud", "Yes", CV_CALL, CV_YesNo, R_SetViewSize, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_translucenthud = {"translucenthud", "10", CV_SAVE, translucenthud_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_uncappedhud = {"uncappedhud", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_soniccd = {"soniccd", "Off", CV_NETVAR|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_allowmlook = {"allowmlook", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -400,7 +402,8 @@ angle_t R_PlayerSliptideAngle(player_t *player) sprframe = &sprdef->spriteframes[rot]; // No sprite frame? I guess it is possible - if (!sprframe) return 0; + if (!sprframe) + return 0; if (sprframe->rotate != SRF_SINGLE || (mo->frame & FF_PAPERSPRITE)) ang = R_PointToAngle(mo->x, mo->y) - mo->angle; @@ -460,6 +463,7 @@ boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixe return false; cullplane = cullheight->frontsector->floorheight; + if (cullheight->flags & ML_NOCLIMB) // Group culling { if (!viewcullheight) @@ -579,8 +583,6 @@ static void R_InitTextureMapping(void) doubleclipangle = clipangle*2; } - - // // R_InitLightTables // Only inits the zlight table, @@ -1047,6 +1049,33 @@ void R_Init(void) framecount = 0; } +// +// R_IsPointInSubsector, same as above but returns 0 if not in subsector +// +subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y) +{ + node_t *node; + INT32 side, i; + size_t nodenum; + subsector_t *ret; + + nodenum = numnodes - 1; + + while (!(nodenum & NF_SUBSECTOR)) + { + node = &nodes[nodenum]; + side = R_PointOnSide(x, y, node); + nodenum = node->children[side]; + } + + ret = &subsectors[nodenum & ~NF_SUBSECTOR]; + for (i = 0; i < ret->numlines; i++) + if (P_PointOnLineSide(x, y, segs[ret->firstline + i].linedef) != segs[ret->firstline + i].side) + return 0; + + return ret; +} + // // R_SetupFrame // @@ -1066,7 +1095,7 @@ static void R_SetupCommonFrame(player_t * player, sector_t * sector) if (sector != NULL) newview->sector = sector; else - newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; + newview->sector = R_PointInSubsectorFast(newview->x, newview->y)->sector; R_InterpolateView(rendertimefrac_unpaused, false); } @@ -1167,7 +1196,7 @@ void R_SkyboxFrame(int s) { player_t *player = &players[displayplayers[s]]; camera_t *thiscam = &camera[s]; - subsector_t * subsector = NULL; + subsector_t *subsector = NULL; mapheader_t *mh = mapheaderinfo[gamemap-1]; R_SetViewContext(static_cast(VIEWCONTEXT_SKY1 + s)); @@ -1306,7 +1335,7 @@ static void R_PortalFrame(portal_t *portal) { portalclipline = NULL; portalcullsector = NULL; - viewsector = R_PointInSubsector(viewx, viewy)->sector; + viewsector = R_PointInSubsectorFast(viewx, viewy)->sector; } } @@ -1522,11 +1551,6 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_fovchange); CV_RegisterVar(&cv_fov); - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - CV_RegisterVar(&cv_chasecam[i]); - } - CV_RegisterVar(&cv_shadow); CV_RegisterVar(&cv_shadowoffs); CV_RegisterVar(&cv_skybox); @@ -1536,6 +1560,8 @@ void R_RegisterEngineStuff(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { + CV_RegisterVar(&cv_chasecam[i]); + CV_RegisterVar(&cv_cam_dist[i]); CV_RegisterVar(&cv_cam_still[i]); CV_RegisterVar(&cv_cam_height[i]); @@ -1569,6 +1595,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_randomdirlight); CV_RegisterVar(&cv_maxinterpdist); + CV_RegisterVar(&cv_playerfade); CV_RegisterVar(&cv_ripplewater); diff --git a/src/r_main.h b/src/r_main.h index 29a6b308e..295e6e34d 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -88,7 +88,7 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // // killough 5/2/98: reformatted // -FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t * restrict node) +FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t* restrict node) { if (!node->dx) return x <= node->x ? node->dy > 0 : node->dy < 0; @@ -117,10 +117,10 @@ FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSideFast(fixed_t x, fixed_t FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line) { - fixed_t lx = line->v1->x; - fixed_t ly = line->v1->y; - fixed_t ldx = line->v2->x - lx; - fixed_t ldy = line->v2->y - ly; + fixed_t lx = line->v1->x; + fixed_t ly = line->v1->y; + fixed_t ldx = line->v2->x - lx; + fixed_t ldy = line->v2->y - ly; // use cross product to determine side quickly INT64 v = ((INT64)y - ly) * ldx - ((INT64)x - lx) * ldy; @@ -137,42 +137,19 @@ fixed_t R_ScaleFromGlobalAngle(angle_t visangle); // // R_PointInSubsector // -FUNCINLINE static ATTRINLINE subsector_t *R_PointInSubsector(fixed_t x, fixed_t y) -{ - size_t nodenum = numnodes-1; - - while (!(nodenum & NF_SUBSECTOR)) - nodenum = nodes[nodenum].children[R_PointOnSide(x, y, nodes+nodenum)]; - - return &subsectors[nodenum & ~NF_SUBSECTOR]; +#define R_POINTINSUBSECTOR(FUNCNAME, SIDEFUNC)\ +FUNCINLINE static ATTRINLINE subsector_t *FUNCNAME(fixed_t x, fixed_t y)\ +{\ + size_t nodenum = numnodes-1;\ + while (!(nodenum & NF_SUBSECTOR))\ + nodenum = nodes[nodenum].children[SIDEFUNC(x, y, nodes+nodenum)];\ + return &subsectors[nodenum & ~NF_SUBSECTOR];\ } -// -// R_IsPointInSubsector, same as above but returns 0 if not in subsector -// -FUNCINLINE static ATTRINLINE subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y) -{ - node_t *node; - INT32 side, i; - size_t nodenum; - subsector_t *ret; +R_POINTINSUBSECTOR(R_PointInSubsector, R_PointOnSide) +R_POINTINSUBSECTOR(R_PointInSubsectorFast, R_PointOnSideFast) - nodenum = numnodes - 1; - - while (!(nodenum & NF_SUBSECTOR)) - { - node = &nodes[nodenum]; - side = R_PointOnSide(x, y, node); - nodenum = node->children[side]; - } - - ret = &subsectors[nodenum & ~NF_SUBSECTOR]; - for (i = 0; i < ret->numlines; i++) - if (P_PointOnLineSide(x, y, segs[ret->firstline + i].linedef) != segs[ret->firstline + i].side) - return 0; - - return ret; -} +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)) @@ -218,6 +195,7 @@ extern consvar_t cv_fov, cv_fovchange; extern consvar_t cv_skybox; extern consvar_t cv_tailspickup; extern consvar_t cv_maxinterpdist; +extern consvar_t cv_playerfade; extern consvar_t cv_ripplewater; extern consvar_t cv_randomdirlight; diff --git a/src/r_things.cpp b/src/r_things.cpp index 542b271a7..9c8b1036c 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -737,6 +737,13 @@ static void R_DrawFlippedMaskedColumn(drawcolumndata_t* dc, column_t *column) dc->texturemid = basetexturemid; } + +// Based off of R_GetLinedefTransTable +transnum_t R_GetThingTransTable(fixed_t alpha, transnum_t transmap) +{ + return static_cast((20*(FRACUNIT - ((alpha * (10 - transmap))/10) - 1) + FRACUNIT) >> (FRACBITS+1)); +} + // // R_DrawVisSprite // mfloorclip and mceilingclip should also be set. @@ -1596,6 +1603,9 @@ static void R_ProjectSprite(mobj_t *thing) else trans = 0; + if (cv_playerfade.value && oldthing->player) + trans = static_cast(R_GetThingTransTable(R_DoPlayerFade(oldthing), static_cast(trans))); + //SoM: 3/17/2000: Disregard sprites that are out of view.. if (vflip) { @@ -2931,6 +2941,32 @@ boolean R_ThingWithinDist(mobj_t *thing, INT32 limit_dist) return true; } +fixed_t R_DoPlayerFade(mobj_t *thing) +{ + fixed_t fadealpha = FRACUNIT; + static constexpr tic_t countdownstarttime = (15 * TICRATE) / 4; // starttime - (3*TICRATE) + + if (thing->player == viewplayer || viewplayer->exiting || camera[R_GetViewNumber()].freecam || leveltime < countdownstarttime) + return fadealpha; + + const INT32 playerdist = (FixedMul((thing->x - viewx), viewcos) + FixedMul((thing->y - viewy), viewsin)) >> FRACBITS; + const INT32 viewplayerdist = (FixedMul((viewplayer->mo->x - viewx), viewcos) + FixedMul((viewplayer->mo->y - viewy), viewsin)) >> FRACBITS; + + if (playerdist < viewplayerdist) + { + if (playerdist < viewplayerdist / 2) // stronger fade when very close + { + fadealpha = (playerdist * FRACUNIT) / (viewplayerdist / 2) / 3; + } + else + { + fadealpha = (playerdist * FRACUNIT) / viewplayerdist; + } + } + + return fadealpha; +} + boolean R_CheckInterpDist(mobj_t *thing) { if (!cv_maxinterpdist.value) diff --git a/src/r_things.h b/src/r_things.h index e7afe7498..5eb383e93 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -87,9 +87,12 @@ typedef struct void R_DrawMasked(maskcount_t* masks, INT32 nummasks); +transnum_t R_GetThingTransTable(fixed_t alpha, transnum_t transmap); + boolean R_ThingVisible(mobj_t *thing); boolean R_ThingWithinDist(mobj_t *thing, INT32 limit_dist); boolean R_CheckInterpDist(mobj_t *thing); +fixed_t R_DoPlayerFade(mobj_t *thing); boolean R_ThingIsFullBright(mobj_t *thing); boolean R_ThingIsSemiBright(mobj_t *thing); diff --git a/src/s_sound.c b/src/s_sound.c index 03a70cf89..c93570232 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -957,7 +957,7 @@ boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 INT64 x, y, yl, yh, xl, xh; fixed_t newdist; - if (R_PointInSubsector(listensource.x, listensource.y)->sector->ceilingpic == skyflatnum) + if (R_PointInSubsectorFast(listensource.x, listensource.y)->sector->ceilingpic == skyflatnum) approx_dist = 0; else { @@ -970,7 +970,7 @@ boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 for (y = yl; y <= yh; y += FRACUNIT*64) for (x = xl; x <= xh; x += FRACUNIT*64) { - if (R_PointInSubsector(x, y)->sector->ceilingpic == skyflatnum) + if (R_PointInSubsectorFast(x, y)->sector->ceilingpic == skyflatnum) { // Found the outdoors! newdist = S_CalculateSoundDistance(listensource.x, listensource.y, 0, x, y, 0); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 26a6d84db..f4a2c288c 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -122,7 +122,7 @@ static void KeyboardLayout_OnChange(void) boolean I_UseNativeKeyboard(void) { - return cv_keyboardlayout.value == 2 && (chat_on || CON_Ready() || (menu_text_input && menuactive)); + return (cv_keyboardlayout.value == 2) && (chat_on || CON_Ready() || (menu_text_input && menuactive)); } static CV_PossibleValue_t keyboardlayout_cons_t[] = {{1,"Default US"}, {2, "Native"}, {3, "AZERTY"}, {0, NULL}}; @@ -222,7 +222,6 @@ static INT32 custom_height = 0; static void Impl_VideoSetupSDLBuffer(void); static void Impl_VideoSetupBuffer(void); static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); -//static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); static void SDLdoGrabMouse(void); @@ -254,102 +253,6 @@ static void mousegrabOnChange(void) SDLdoUngrabMouse(); } -static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) -{ - static SDL_bool wasfullscreen = SDL_FALSE; - Uint32 rmask; - Uint32 gmask; - Uint32 bmask; - Uint32 amask; - int bpp = 16; - int sw_texture_format = SDL_PIXELFORMAT_ABGR8888; - - realwidth = vid.width; - realheight = vid.height; - - if (window) - { - if (fullscreen) - { - wasfullscreen = SDL_TRUE; - SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); - } - else // windowed mode - { - if (wasfullscreen) - { - wasfullscreen = SDL_FALSE; - SDL_SetWindowFullscreen(window, 0); - } - // Reposition window only in windowed mode - SDL_SetWindowSize(window, width, height); - SDL_SetWindowPosition(window, - SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)), - SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)) - ); - } - } - else - { - Impl_CreateWindow(fullscreen); - wasfullscreen = fullscreen; - SDL_SetWindowSize(window, width, height); - if (fullscreen) - { - SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); - } - } - -#ifdef HWRENDER - if (rendermode == render_opengl) - { - I_CheckDesktopRes(); -#ifdef USE_FBO_OGL - I_DownSample(); -#endif - OglSdlSurface(vid.width, vid.height); - } -#endif - - if (rendermode == render_soft) - { - SDL_RenderClear(renderer); - SDL_RenderSetLogicalSize(renderer, width, height); - // Set up Texture - realwidth = width; - realheight = height; - if (texture != NULL) - { - SDL_DestroyTexture(texture); - } - - if (!usesdl2soft) - { - sw_texture_format = SDL_PIXELFORMAT_RGB565; - } - else - { - bpp = 32; - sw_texture_format = SDL_PIXELFORMAT_RGBA8888; - } - - texture = SDL_CreateTexture(renderer, sw_texture_format, SDL_TEXTUREACCESS_STREAMING, width, height); - - // Set up SW surface - if (vidSurface != NULL) - { - SDL_FreeSurface(vidSurface); - } - if (vid.buffer) - { - free(vid.buffer); - vid.buffer = NULL; - } - SDL_PixelFormatEnumToMasks(sw_texture_format, &bpp, &rmask, &gmask, &bmask, &amask); - vidSurface = SDL_CreateRGBSurface(0, width, height, bpp, rmask, gmask, bmask, amask); - } -} - static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) { if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z) @@ -357,6 +260,7 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) // get lowercase ASCII return code - SDL_SCANCODE_A + 'a'; } + if (code >= SDL_SCANCODE_1 && code <= SDL_SCANCODE_9) { return code - SDL_SCANCODE_1 + '1'; @@ -365,10 +269,12 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) { return '0'; } + if (code >= SDL_SCANCODE_F1 && code <= SDL_SCANCODE_F10) { return KEY_F1 + (code - SDL_SCANCODE_F1); } + switch (code) { // F11 and F12 are separated from the rest of the function keys @@ -436,6 +342,7 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) case SDL_SCANCODE_RGUI: return KEY_RIGHTWIN; default: break; } + return 0; } @@ -445,19 +352,18 @@ static INT32 GetTypedChar(SDL_Keysym keysym) SDL_Event next_event; SDL_Keycode keycode = keysym.sym; SDL_Scancode scancode = keysym.scancode; - const boolean Text_Input_Only = (chat_on || CON_Ready() || (menu_text_input && menuactive)); // only use this this if on chat or console or the current menu wants inputs from us (except if its the control setup menu ig) - // Special cases, where we always return a fixed value. - switch (keycode) + if (I_UseNativeKeyboard()) // only use this this if on chat or console or the current menu wants inputs from us (except if its the control setup menu ig) { - case SDLK_BACKSPACE: return KEY_BACKSPACE; - case SDLK_RETURN: return KEY_ENTER; - default: - break; - } + // Special cases, where we always return a fixed value. + switch (keycode) + { + case SDLK_BACKSPACE: return KEY_BACKSPACE; + case SDLK_RETURN: return KEY_ENTER; + default: + break; + } - if (Text_Input_Only) - { if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 && next_event.type == SDL_TEXTINPUT) { if (next_event.text.text[1] == '\0') // limit to ASCII @@ -465,7 +371,7 @@ static INT32 GetTypedChar(SDL_Keysym keysym) } } - return Impl_SDL_Scancode_To_Keycode(scancode); // fallback + return Impl_SDL_Scancode_To_Keycode(scancode); // fallback to scancodes } static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym) @@ -542,6 +448,7 @@ static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym) default: break; } + return Impl_SDL_Scancode_To_Keycode(scancode); } @@ -549,6 +456,7 @@ static void SDLdoGrabMouse(void) { SDL_ShowCursor(SDL_DISABLE); SDL_SetWindowGrab(window, SDL_TRUE); + if (SDL_SetRelativeMouseMode(SDL_TRUE) == 0) // already warps mouse if successful wrapmouseok = SDL_TRUE; // TODO: is wrapmouseok or HalfWarpMouse needed anymore? } @@ -603,65 +511,26 @@ static void SurfaceInfo(const SDL_Surface *infoSurface, const char *SurfaceText) static void VID_Command_Info_f (void) { -#if 0 - SDL2STUB(); -#else -#if 0 - const SDL_VideoInfo *videoInfo; - videoInfo = SDL_GetVideoInfo(); //Alam: Double-Check - if (videoInfo) - { - CONS_Printf("%s", M_GetText("Video Interface Capabilities:\n")); - if (videoInfo->hw_available) - CONS_Printf("%s", M_GetText(" Hardware surfaces\n")); - if (videoInfo->wm_available) - CONS_Printf("%s", M_GetText(" Window manager\n")); - //UnusedBits1 :6 - //UnusedBits2 :1 - if (videoInfo->blit_hw) - CONS_Printf("%s", M_GetText(" Accelerated blits HW-2-HW\n")); - if (videoInfo->blit_hw_CC) - CONS_Printf("%s", M_GetText(" Accelerated blits HW-2-HW with Colorkey\n")); - if (videoInfo->wm_available) - CONS_Printf("%s", M_GetText(" Accelerated blits HW-2-HW with Alpha\n")); - if (videoInfo->blit_sw) - { - CONS_Printf("%s", M_GetText(" Accelerated blits SW-2-HW\n")); - if (!M_CheckParm("-noblit")) videoblitok = SDL_TRUE; - } - if (videoInfo->blit_sw_CC) - CONS_Printf("%s", M_GetText(" Accelerated blits SW-2-HW with Colorkey\n")); - if (videoInfo->blit_sw_A) - CONS_Printf("%s", M_GetText(" Accelerated blits SW-2-HW with Alpha\n")); - if (videoInfo->blit_fill) - CONS_Printf("%s", M_GetText(" Accelerated Color filling\n")); - //UnusedBits3 :16 - if (videoInfo->video_mem) - CONS_Printf(M_GetText(" There is %i KB of video memory\n"), videoInfo->video_mem); - else - CONS_Printf("%s", M_GetText(" There no video memory for SDL\n")); - //*vfmt - } -#else - if (!M_CheckParm("-noblit")) videoblitok = SDL_TRUE; -#endif + if (!M_CheckParm("-noblit")) + videoblitok = SDL_TRUE; + SurfaceInfo(bufSurface, M_GetText("Current Engine Mode")); SurfaceInfo(vidSurface, M_GetText("Current Video Mode")); -#endif } static void VID_Command_ModeList_f(void) { // List windowed modes INT32 i = 0; + CONS_Printf("NOTE: Under SDL2, all modes are supported on all platforms.\n"); CONS_Printf("Under opengl, fullscreen only supports native desktop resolution.\n"); CONS_Printf("Under software, the mode is stretched up to desktop resolution.\n"); + for (i = 0; i < MAXWINMODES; i++) { CONS_Printf("%2d: %dx%d\n", i, windowedModes[i][0], windowedModes[i][1]); } - } static void VID_Command_Mode_f (void) @@ -688,16 +557,23 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) INT32 raxis = axis/32; UINT8 pid; - if (which == ev_joystick) - pid = 0; - else if (which == ev_joystick2) - pid = 1; - else if (which == ev_joystick3) - pid = 2; - else if (which == ev_joystick4) - pid = 3; - else - return 0; + switch (which) + { + case ev_joystick: + pid = 0; + break; + case ev_joystick2: + pid = 1; + break; + case ev_joystick3: + pid = 2; + break; + case ev_joystick4: + pid = 3; + break; + default: + return 0; + } if (Joystick[pid].bGamepadStyle) { @@ -721,6 +597,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } +// Get the desktop resolution from the current display the gamewindow resides on static void I_CheckDesktopRes(void) { int currentDisplayIndex = -1; @@ -746,6 +623,7 @@ static void I_CheckDesktopRes(void) desktopheight = curmode.h; } +// Check if the game resolution matches the desktop resolution boolean I_CheckNativeRes(void) { return (vid.width == desktopwidth && vid.height == desktopheight); @@ -849,15 +727,15 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { if (cv_usemouse.value) I_StartupMouse(); } - //else firsttimeonmouse = SDL_FALSE; } else if (!mousefocus && !kbfocus) { // Tell game we lost focus, pause music window_notinfocus = true; - if (! cv_playmusicifunfocused.value) + + if (!cv_playmusicifunfocused.value) I_SetMusicVolume(0); - if (! cv_playsoundifunfocused.value) + if (!cv_playsoundifunfocused.value) S_StopSounds(); if (!disable_mouse) @@ -879,17 +757,16 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) { event_t event; - if (type == SDL_KEYUP) + switch (type) { - event.type = ev_keyup; - } - else if (type == SDL_KEYDOWN) - { - event.type = ev_keydown; - } - else - { - return; + case SDL_KEYUP: + event.type = ev_keyup; + break; + case SDL_KEYDOWN: + event.type = ev_keydown; + break; + default: + return; } switch (cv_keyboardlayout.value) @@ -905,7 +782,8 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) break; } - if (event.data1) D_PostEvent(&event); + if (event.data1) + D_PostEvent(&event); } static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) @@ -982,25 +860,37 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type) { SDL_memset(&event, 0, sizeof(event_t)); - if (type == SDL_MOUSEBUTTONUP) + switch (type) { - event.type = ev_keyup; + case SDL_MOUSEBUTTONUP: + event.type = ev_keyup; + break; + case SDL_MOUSEBUTTONDOWN: + event.type = ev_keydown; + break; + default: + return; } - else if (type == SDL_MOUSEBUTTONDOWN) + + switch (evt.button) { - event.type = ev_keydown; + case SDL_BUTTON_MIDDLE: + event.data1 = KEY_MOUSE1+2; + break; + case SDL_BUTTON_RIGHT: + event.data1 = KEY_MOUSE1+1; + break; + case SDL_BUTTON_LEFT: + event.data1 = KEY_MOUSE1; + break; + case SDL_BUTTON_X1: + event.data1 = KEY_MOUSE1+3; + break; + case SDL_BUTTON_X2: + event.data1 = KEY_MOUSE1+4; + break; } - else return; - if (evt.button == SDL_BUTTON_MIDDLE) - event.data1 = KEY_MOUSE1+2; - else if (evt.button == SDL_BUTTON_RIGHT) - event.data1 = KEY_MOUSE1+1; - else if (evt.button == SDL_BUTTON_LEFT) - event.data1 = KEY_MOUSE1; - else if (evt.button == SDL_BUTTON_X1) - event.data1 = KEY_MOUSE1+3; - else if (evt.button == SDL_BUTTON_X2) - event.data1 = KEY_MOUSE1+4; + if (event.type == ev_keyup || event.type == ev_keydown) { D_PostEvent(&event); @@ -1069,7 +959,8 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt) { event.type = ev_joystick4; } - else return; + else + return; //axis if (evt.axis > JOYAXISSET*2) @@ -1121,7 +1012,7 @@ static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint joyid[i] = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev)); } - if (evt.button == SDL_CONTROLLER_BUTTON_DPAD_UP + if ( evt.button == SDL_CONTROLLER_BUTTON_DPAD_UP || evt.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN || evt.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT || evt.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) @@ -1146,35 +1037,180 @@ static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint { event.data1 = KEY_4JOY1; } - else return; + else + return; - if (type == SDL_CONTROLLERBUTTONUP) + switch (type) { - event.type = ev_keyup; + case SDL_CONTROLLERBUTTONUP: + event.type = ev_keyup; + break; + case SDL_CONTROLLERBUTTONDOWN: + event.type = ev_keydown; + break; + default: + return; } - else if (type == SDL_CONTROLLERBUTTONDOWN) - { - event.type = ev_keydown; - } - else return; if (evt.button < JOYBUTTONS) { event.data1 += evt.button; } - else return; + else + return; - if (event.type != ev_console) D_PostEvent(&event); + if (event.type != ev_console) + D_PostEvent(&event); +} + +static void Impl_HandleControllerAddedEvent(SDL_Event evt) +{ + INT32 i; + + // OH BOY are you in for a good time! #abominationstation + SDL_GameController *newcontroller = SDL_GameControllerOpen(evt.cdevice.which); + + CONS_Debug(DBG_GAMELOGIC, "Joystick device index %d added\n", evt.jdevice.which + 1); + + //////////////////////////////////////////////////////////// + // Because SDL's device index is unstable, we're going to cheat here a bit: + // For the first joystick setting that is NOT active: + // + // 1. Set cv_usejoystickX.value to the new device index (this does not change what is written to config.cfg) + // + // 2. Set OTHERS' cv_usejoystickX.value to THEIR new device index, because it likely changed + // * If device doesn't exist, switch cv_usejoystick back to default value (.string) + // * BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! + //////////////////////////////////////////////////////////// + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { + if (newcontroller && (!JoyInfo[i].dev || !SDL_GameControllerGetAttached(JoyInfo[i].dev))) + { + UINT8 j; + + for (j = 0; j < MAXSPLITSCREENPLAYERS; j++) + { + if (i == j) + continue; + + if (JoyInfo[j].dev == newcontroller) + break; + } + + if (j == MAXSPLITSCREENPLAYERS) + { + // ensures we aren't overriding a currently active device + cv_usejoystick[i].value = evt.jdevice.which + 1; + I_UpdateJoystickDeviceIndices(0); + } + } + } + + //////////////////////////////////////////////////////////// + // Was cv_usejoystick disabled in settings? + //////////////////////////////////////////////////////////// + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { + if (!strcmp(cv_usejoystick[i].string, "0") || !cv_usejoystick[i].value) + cv_usejoystick[i].value = 0; + else if (atoi(cv_usejoystick[i].string) <= I_NumJoys() // don't mess if we intentionally set higher than NumJoys + && cv_usejoystick[i].value) // update the cvar ONLY if a device exists + CV_SetValue(&cv_usejoystick[i], cv_usejoystick[i].value); + } + + //////////////////////////////////////////////////////////// + // Update all joysticks' init states + // This is a little wasteful since cv_usejoystick already calls this, but + // we need to do this in case CV_SetValue did nothing because the string was already same. + // if the device is already active, this should do nothing, effectively. + //////////////////////////////////////////////////////////// + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { + I_InitJoystick(i); + G_SetPlayerGamepadIndicatorColor(i, G_GetSkinColor(i)); // gotta update the controller led again on reconnect + } + + //////////////////////////////////////////////////////////// + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + CONS_Debug(DBG_GAMELOGIC, "Joystick%d device index: %d\n", i+1, JoyInfo[i].oldjoy); + + // update the menu + if (currentMenu == &OP_JoystickSetDef) + M_SetupJoystickMenu(0); + + numcontrollers = I_NumJoys(); + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { + if (JoyInfo[i].dev == newcontroller) + break; + } + + if (i == MAXSPLITSCREENPLAYERS) + SDL_GameControllerClose(newcontroller); +} + +static void Impl_HandleControllerRemovedEvent(void) +{ + INT32 i; + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { + if (JoyInfo[i].dev && !SDL_GameControllerGetAttached(JoyInfo[i].dev)) + { + CONS_Debug(DBG_GAMELOGIC, "Joystick%d removed, device index: %d\n", i+1, JoyInfo[i].oldjoy); + I_ShutdownJoystick(i); + } + } + + //////////////////////////////////////////////////////////// + // Update the device indexes, because they likely changed + // * If device doesn't exist, switch cv_usejoystick back to default value (.string) + // * BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! + //////////////////////////////////////////////////////////// + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { + I_UpdateJoystickDeviceIndex(i); + } + + //////////////////////////////////////////////////////////// + // Was cv_usejoystick disabled in settings? + //////////////////////////////////////////////////////////// + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { + if (!strcmp(cv_usejoystick[i].string, "0")) + { + cv_usejoystick[i].value = 0; + } + else if (atoi(cv_usejoystick[i].string) <= I_NumJoys() // don't mess if we intentionally set higher than NumJoys + && cv_usejoystick[i].value) // update the cvar ONLY if a device exists + { + CV_SetValue(&cv_usejoystick[i], cv_usejoystick[i].value); + } + } + + //////////////////////////////////////////////////////////// + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + CONS_Debug(DBG_GAMELOGIC, "Joystick%d device index: %d\n", i+1, JoyInfo[i].oldjoy); + + // update the menu + if (currentMenu == &OP_JoystickSetDef) + M_SetupJoystickMenu(0); + + numcontrollers = I_NumJoys(); } void I_GetEvent(void) { SDL_Event evt; char* dropped_filedir; - // We only want the first motion event, - // otherwise we'll end up catching the warp back to center. - //int mouseMotionOnce = 0; - INT32 i; if (!graphics_started) { @@ -1195,9 +1231,7 @@ void I_GetEvent(void) Impl_HandleKeyboardEvent(evt.key, evt.type); break; case SDL_MOUSEMOTION: - //if (!mouseMotionOnce) Impl_HandleMouseMotionEvent(evt.motion); - //mouseMotionOnce = 1; break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: @@ -1209,160 +1243,15 @@ void I_GetEvent(void) case SDL_CONTROLLERAXISMOTION: Impl_HandleControllerAxisEvent(evt.caxis); break; -#if 0 - case SDL_JOYHATMOTION: - Impl_HandleJoystickHatEvent(evt.jhat) - break; -#endif case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERBUTTONDOWN: Impl_HandleControllerButtonEvent(evt.cbutton, evt.type); break; - - //////////////////////////////////////////////////////////// - case SDL_CONTROLLERDEVICEADDED: - { - // OH BOY are you in for a good time! #abominationstation - - SDL_GameController *newcontroller = SDL_GameControllerOpen(evt.cdevice.which); - - CONS_Debug(DBG_GAMELOGIC, "Joystick device index %d added\n", evt.jdevice.which + 1); - - //////////////////////////////////////////////////////////// - // Because SDL's device index is unstable, we're going to cheat here a bit: - // For the first joystick setting that is NOT active: - // - // 1. Set cv_usejoystickX.value to the new device index (this does not change what is written to config.cfg) - // - // 2. Set OTHERS' cv_usejoystickX.value to THEIR new device index, because it likely changed - // * If device doesn't exist, switch cv_usejoystick back to default value (.string) - // * BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! - //////////////////////////////////////////////////////////// - - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - if (newcontroller && (!JoyInfo[i].dev || !SDL_GameControllerGetAttached(JoyInfo[i].dev))) - { - UINT8 j; - - for (j = 0; j < MAXSPLITSCREENPLAYERS; j++) - { - if (i == j) - continue; - - if (JoyInfo[j].dev == newcontroller) - break; - } - - if (j == MAXSPLITSCREENPLAYERS) - { - // ensures we aren't overriding a currently active device - cv_usejoystick[i].value = evt.jdevice.which + 1; - I_UpdateJoystickDeviceIndices(0); - } - } - } - - //////////////////////////////////////////////////////////// - // Was cv_usejoystick disabled in settings? - //////////////////////////////////////////////////////////// - - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - if (!strcmp(cv_usejoystick[i].string, "0") || !cv_usejoystick[i].value) - cv_usejoystick[i].value = 0; - else if (atoi(cv_usejoystick[i].string) <= I_NumJoys() // don't mess if we intentionally set higher than NumJoys - && cv_usejoystick[i].value) // update the cvar ONLY if a device exists - CV_SetValue(&cv_usejoystick[i], cv_usejoystick[i].value); - } - - //////////////////////////////////////////////////////////// - // Update all joysticks' init states - // This is a little wasteful since cv_usejoystick already calls this, but - // we need to do this in case CV_SetValue did nothing because the string was already same. - // if the device is already active, this should do nothing, effectively. - //////////////////////////////////////////////////////////// - - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - I_InitJoystick(i); - G_SetPlayerGamepadIndicatorColor(i, G_GetSkinColor(i)); // gotta update the controller led again on reconnect - } - - //////////////////////////////////////////////////////////// - - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - CONS_Debug(DBG_GAMELOGIC, "Joystick%d device index: %d\n", i+1, JoyInfo[i].oldjoy); - - // update the menu - if (currentMenu == &OP_JoystickSetDef) - M_SetupJoystickMenu(0); - - numcontrollers = I_NumJoys(); - - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - if (JoyInfo[i].dev == newcontroller) - break; - } - - if (i == MAXSPLITSCREENPLAYERS) - SDL_GameControllerClose(newcontroller); - } + Impl_HandleControllerAddedEvent(evt); break; - - //////////////////////////////////////////////////////////// - case SDL_CONTROLLERDEVICEREMOVED: - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - if (JoyInfo[i].dev && !SDL_GameControllerGetAttached(JoyInfo[i].dev)) - { - CONS_Debug(DBG_GAMELOGIC, "Joystick%d removed, device index: %d\n", i+1, JoyInfo[i].oldjoy); - I_ShutdownJoystick(i); - } - } - - //////////////////////////////////////////////////////////// - // Update the device indexes, because they likely changed - // * If device doesn't exist, switch cv_usejoystick back to default value (.string) - // * BUT: If that default index is being occupied, use ANOTHER cv_usejoystick's default value! - //////////////////////////////////////////////////////////// - - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - I_UpdateJoystickDeviceIndex(i); - } - - //////////////////////////////////////////////////////////// - // Was cv_usejoystick disabled in settings? - //////////////////////////////////////////////////////////// - - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - if (!strcmp(cv_usejoystick[i].string, "0")) - { - cv_usejoystick[i].value = 0; - } - else if (atoi(cv_usejoystick[i].string) <= I_NumJoys() // don't mess if we intentionally set higher than NumJoys - && cv_usejoystick[i].value) // update the cvar ONLY if a device exists - { - CV_SetValue(&cv_usejoystick[i], cv_usejoystick[i].value); - } - } - - //////////////////////////////////////////////////////////// - - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - CONS_Debug(DBG_GAMELOGIC, "Joystick%d device index: %d\n", i+1, JoyInfo[i].oldjoy); - - // update the menu - if (currentMenu == &OP_JoystickSetDef) - M_SetupJoystickMenu(0); - - numcontrollers = I_NumJoys(); - + Impl_HandleControllerRemovedEvent(); break; case SDL_DROPFILE: dropped_filedir = evt.drop.file; @@ -1382,7 +1271,6 @@ void I_GetEvent(void) event_t event; int wwidth, wheight; SDL_GetWindowSize(window, &wwidth, &wheight); - //SDL_memset(&event, 0, sizeof(event_t)); event.type = ev_mouse; event.data1 = 0; event.data2 = (INT32)lround(mousemovex * ((float)wwidth / (float)realwidth)); @@ -1408,6 +1296,7 @@ void I_StartupMouse(void) } else firsttimeonmouse = SDL_FALSE; + if (cv_usemouse.value || cv_alwaysgrabmouse.value) SDLdoGrabMouse(); else @@ -1424,9 +1313,11 @@ void I_OsPolling(void) if (consolevent) I_GetConsoleEvents(); + if (SDL_WasInit(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == (SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER)) { SDL_GameControllerUpdate(); + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) I_GetJoystickEvents(i); } @@ -1446,6 +1337,105 @@ void I_OsPolling(void) if (mod & KMOD_CAPS) capslock = true; } +static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) +{ + static SDL_bool wasfullscreen = SDL_FALSE; + Uint32 rmask, gmask, bmask, amask; + int bpp = 16; + int sw_texture_format = SDL_PIXELFORMAT_ABGR8888; + + realwidth = vid.width; + realheight = vid.height; + + if (window) + { + if (fullscreen) + { + wasfullscreen = SDL_TRUE; + SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); + } + else // windowed mode + { + if (wasfullscreen) + { + wasfullscreen = SDL_FALSE; + SDL_SetWindowFullscreen(window, 0); + } + + // Reposition window only in windowed mode + SDL_SetWindowSize(window, width, height); + SDL_SetWindowPosition(window, + SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)), + SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)) + ); + } + } + else + { + Impl_CreateWindow(fullscreen); + wasfullscreen = fullscreen; + SDL_SetWindowSize(window, width, height); + + if (fullscreen) + { + SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); + } + } + +#ifdef HWRENDER + if (rendermode == render_opengl) + { + I_CheckDesktopRes(); +#ifdef USE_FBO_OGL + I_DownSample(); +#endif + OglSdlSurface(vid.width, vid.height); + } +#endif + + if (rendermode == render_soft) + { + SDL_RenderClear(renderer); + SDL_RenderSetLogicalSize(renderer, width, height); + + // Set up Texture + realwidth = width; + realheight = height; + + if (texture != NULL) + { + SDL_DestroyTexture(texture); + } + + if (!usesdl2soft) + { + sw_texture_format = SDL_PIXELFORMAT_RGB565; + } + else + { + bpp = 32; + sw_texture_format = SDL_PIXELFORMAT_RGBA8888; + } + + texture = SDL_CreateTexture(renderer, sw_texture_format, SDL_TEXTUREACCESS_STREAMING, width, height); + + // Set up SW surface + if (vidSurface != NULL) + { + SDL_FreeSurface(vidSurface); + } + + if (vid.buffer) + { + free(vid.buffer); + vid.buffer = NULL; + } + + SDL_PixelFormatEnumToMasks(sw_texture_format, &bpp, &rmask, &gmask, &bmask, &amask); + vidSurface = SDL_CreateRGBSurface(0, width, height, bpp, rmask, gmask, bmask, amask); + } +} + // // I_UpdateNoBlit // @@ -1453,6 +1443,7 @@ void I_UpdateNoBlit(void) { if (rendermode == render_none) return; + if (exposevideo) { #ifdef HWRENDER @@ -1468,6 +1459,7 @@ void I_UpdateNoBlit(void) SDL_RenderPresent(renderer); } } + exposevideo = SDL_FALSE; } @@ -1517,7 +1509,6 @@ void I_FinishUpdate(void) SDL_RenderCopy(renderer, texture, &src_rect, NULL); SDL_RenderPresent(renderer); } - #ifdef HWRENDER else if (rendermode == render_opengl) { @@ -1556,12 +1547,14 @@ void I_ReadScreen(UINT8 *scr) void I_SetPalette(RGBA_t *palette) { size_t i; - for (i=0; i<256; i++) + + for (i = 0; i < 256; i++) { localPalette[i].r = palette[i].s.red; localPalette[i].g = palette[i].s.green; localPalette[i].b = palette[i].s.blue; } + //if (vidSurface) SDL_SetPaletteColors(vidSurface->format->palette, localPalette, 0, 256); // Fury -- SDL2 vidSurface is a 32-bit surface buffer copied to the texture. It's not palletized, like bufSurface. if (bufSurface) SDL_SetPaletteColors(bufSurface->format->palette, localPalette, 0, 256); @@ -1578,37 +1571,25 @@ INT32 VID_NumModes(void) const char *VID_GetModeName(INT32 modeNum) { -#if 0 - if (USE_FULLSCREEN && numVidModes != -1) // fullscreen modes - { - modeNum += firstEntry; - if (modeNum >= numVidModes) - return NULL; - - sprintf(&vidModeName[modeNum][0], "%dx%d", - modeList[modeNum]->w, - modeList[modeNum]->h); - } - else // windowed modes - { -#endif if (modeNum == -1) { return fallback_resolution_name; } - if (modeNum > MAXWINMODES) - return NULL; - sprintf(&vidModeName[modeNum][0], "%dx%d", - windowedModes[modeNum][0], - windowedModes[modeNum][1]); - //} + if (modeNum > MAXWINMODES) + return NULL; + + sprintf(&vidModeName[modeNum][0], "%dx%d", + windowedModes[modeNum][0], + windowedModes[modeNum][1]); + return &vidModeName[modeNum][0]; } INT32 VID_GetModeForSize(INT32 w, INT32 h) { int i; + for (i = 0; i < MAXWINMODES; i++) { if (windowedModes[i][0] == w && windowedModes[i][1] == h) @@ -1616,6 +1597,7 @@ INT32 VID_GetModeForSize(INT32 w, INT32 h) return i; } } + // did not find mode from list, make custom resolution if the values somewhat make sense // opengl mode does not mind about max resolution defined in screen.h // if not using opengl, check against the maximum as well @@ -1626,104 +1608,14 @@ INT32 VID_GetModeForSize(INT32 w, INT32 h) custom_height = h; return CUSTOMMODENUM; } + return -1; -#if 0 - INT32 matchMode = -1, i; - VID_PrepareModeList(); - if (USE_FULLSCREEN && numVidModes != -1) - { - for (i=firstEntry; iw == w && - modeList[i]->h == h) - { - matchMode = i; - break; - } - } - if (-1 == matchMode) // use smaller mode - { - w -= w%BASEVIDWIDTH; - h -= h%BASEVIDHEIGHT; - for (i=firstEntry; iw == w && - modeList[i]->h == h) - { - matchMode = i; - break; - } - } - if (-1 == matchMode) // use smallest mode - matchMode = numVidModes-1; - } - matchMode -= firstEntry; - } - else - { - for (i=0; iw <= MAXVIDWIDTH && - modeList[i]->h <= MAXVIDHEIGHT) - { - firstEntry = i; - break; - } - } - } - } - allow_fullscreen = true; -#endif } static UINT32 refresh_rate; @@ -1783,7 +1675,6 @@ INT32 VID_SetMode(INT32 modeNum) } vid.modenum = -1; } - //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); Impl_VideoSetupBuffer(); @@ -1815,11 +1706,13 @@ static SDL_bool Impl_CreateContext(void) { if (!sdlglcontext) sdlglcontext = SDL_GL_CreateContext(window); + if (sdlglcontext == NULL) { SDL_DestroyWindow(window); I_Error("Failed to create a GL context: %s\n", SDL_GetError()); } + SDL_GL_MakeCurrent(window, sdlglcontext); } else @@ -1912,24 +1805,13 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) return Impl_CreateContext(); } -/* -static void Impl_SetWindowName(const char *title) -{ - if (window == NULL) - { - return; - } - SDL_SetWindowTitle(window, title); -} -*/ - static void Impl_SetWindowIcon(void) { if (window == NULL || icoSurface == NULL) { return; } - //SDL2STUB(); // Monster Iestyn: why is this stubbed? + SDL_SetWindowIcon(window, icoSurface); } @@ -1957,19 +1839,16 @@ static void Impl_VideoSetupSDLBuffer(void) static void Impl_VideoSetupBuffer(void) { // Set up game's software render buffer - //if (rendermode == render_soft) + vid.rowbytes = vid.width; + + if (vid.buffer) + free(vid.buffer); + + vid.buffer = calloc(vid.rowbytes*vid.height, NUMSCREENS); + + if (!vid.buffer) { - vid.rowbytes = vid.width; - - if (vid.buffer) - free(vid.buffer); - - vid.buffer = calloc(vid.rowbytes*vid.height, NUMSCREENS); - - if (!vid.buffer) - { - I_Error("%s", M_GetText("Not enough memory for video buffer\n")); - } + I_Error("%s", M_GetText("Not enough memory for video buffer\n")); } } @@ -1987,6 +1866,7 @@ void I_StartupGraphics(void) rendermode = render_none; return; } + if (graphics_started) return; @@ -2053,6 +1933,7 @@ void I_StartupGraphics(void) char line[16]; char * word; FILE * file = OpenRendererFile("r"); + if (file != NULL) { while (fgets(line, sizeof line, file) != NULL) @@ -2169,8 +2050,6 @@ void I_StartupGraphics(void) // SDL_GL_LoadLibrary to work well on Windows // Create window - //Impl_CreateWindow(USE_FULLSCREEN); - //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); VID_SetMode(VID_GetModeForSize(BASEVIDWIDTH, BASEVIDHEIGHT)); vid.width = BASEVIDWIDTH; // Default size for startup @@ -2190,16 +2069,7 @@ void I_StartupGraphics(void) if (M_CheckParm("-nomousegrab")) mousegrabok = SDL_FALSE; -#if 0 // defined (_DEBUG) - else - { - char videodriver[4] = {'S','D','L',0}; - if (!M_CheckParm("-mousegrab") && - *strncpy(videodriver, SDL_GetCurrentVideoDriver(), 4) != '\0' && - strncasecmp("x11",videodriver,4) == 0) - mousegrabok = SDL_FALSE; //X11's XGrabPointer not good - } -#endif + realwidth = (Uint16)vid.width; realheight = (Uint16)vid.height; @@ -2221,15 +2091,23 @@ void I_ShutdownGraphics(void) const rendermode_t oldrendermode = rendermode; rendermode = render_none; - if (icoSurface) SDL_FreeSurface(icoSurface); + + if (icoSurface) + SDL_FreeSurface(icoSurface); icoSurface = NULL; + if (oldrendermode == render_soft) { - if (vidSurface) SDL_FreeSurface(vidSurface); + if (vidSurface) + SDL_FreeSurface(vidSurface); vidSurface = NULL; - if (vid.buffer) free(vid.buffer); + + if (vid.buffer) + free(vid.buffer); vid.buffer = NULL; - if (bufSurface) SDL_FreeSurface(bufSurface); + + if (bufSurface) + SDL_FreeSurface(bufSurface); bufSurface = NULL; } @@ -2241,6 +2119,7 @@ void I_ShutdownGraphics(void) I_OutputMsg("graphics never started\n"); return; } + graphics_started = false; I_OutputMsg("shut down\n"); diff --git a/src/win32/Srb2win.rc b/src/win32/Srb2win.rc index d7a26dc85..da6c64d82 100644 --- a/src/win32/Srb2win.rc +++ b/src/win32/Srb2win.rc @@ -1,5 +1,3 @@ -#include - //Microsoft Developer Studio generated resource script. // #include "resource.h"