From 30aec86479781791493dc19072328a8f91145ad8 Mon Sep 17 00:00:00 2001 From: SinnamonLat Date: Fri, 20 May 2022 21:36:43 +0200 Subject: [PATCH] Allow P1 to add splitscreen players on command, allow console in menus --- src/d_main.c | 33 ++++++++++++++------------- src/d_netcmd.c | 4 ++++ src/d_netcmd.h | 4 ++++ src/k_menufunc.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 83 insertions(+), 17 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 4a20ccace..55b55c15c 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -206,6 +206,23 @@ void D_ProcessEvents(void) continue; } + // console input +#ifdef HAVE_THREADS + I_lock_mutex(&con_mutex); +#endif + { + eaten = CON_Responder(ev); + } +#ifdef HAVE_THREADS + I_unlock_mutex(con_mutex); +#endif + + if (eaten) + { + hu_keystrokes = true; + continue; // ate the event + } + // Menu input menuresponse = true; #ifdef HAVE_THREADS @@ -228,22 +245,6 @@ void D_ProcessEvents(void) continue; // demo ate the event */ - // console input -#ifdef HAVE_THREADS - I_lock_mutex(&con_mutex); -#endif - { - eaten = CON_Responder(ev); - } -#ifdef HAVE_THREADS - I_unlock_mutex(con_mutex); -#endif - - if (eaten) - { - hu_keystrokes = true; - continue; // ate the event - } G_Responder(ev); } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index ffef4ec32..b4fb2f938 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -316,6 +316,9 @@ consvar_t cv_lastprofile[MAXSPLITSCREENPLAYERS] = { // You choose this profile when starting the game, this will also set lastprofile[0] consvar_t cv_currprofile = CVAR_INIT ("currprofile", "-1", CV_HIDDEN, lastprofile_cons_t, NULL); +// Cvar for using splitscreen with 1 device. +consvar_t cv_splitdevice = CVAR_INIT ("splitdevice", "Off", CV_HIDDEN, CV_OnOff, NULL); + consvar_t cv_skipmapcheck = CVAR_INIT ("skipmapcheck", "Off", CV_SAVE, CV_OnOff, NULL); INT32 cv_debug; @@ -881,6 +884,7 @@ void D_RegisterClientCommands(void) } CV_RegisterVar(&cv_currprofile); + CV_RegisterVar(&cv_splitdevice); // preferred number of players CV_RegisterVar(&cv_splitplayers); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index bcaa051b9..fb3a5ab03 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -29,6 +29,10 @@ extern consvar_t cv_lastprofile[MAXSPLITSCREENPLAYERS]; // Used to know how to make the options menu behave among other things. extern consvar_t cv_currprofile; +// CVar that allows starting as many splitscreens as you want with one device +// Intended for use with testing +extern consvar_t cv_splitdevice; + // preferred number of players extern consvar_t cv_splitplayers; diff --git a/src/k_menufunc.c b/src/k_menufunc.c index 26e854aba..1360185d2 100644 --- a/src/k_menufunc.c +++ b/src/k_menufunc.c @@ -991,6 +991,7 @@ void M_StartControlPanel(void) itemOn = 0; CV_StealthSetValue(&cv_currprofile, -1); // Make sure to reset that as it is set by PR_ApplyProfile which we kind of hack together to force it. + CV_StealthSetValue(&cv_splitdevice, 0); // Disable this option by default. } else { @@ -2102,6 +2103,10 @@ void M_CharacterSelectInit(void) } //CONS_Printf("========\n"); + // On main menu, reset that! + if (gamestate == GS_MENU) + CV_StealthSetValue(&cv_splitdevice, 0); + memset(setup_chargrid, -1, sizeof(setup_chargrid)); for (i = 0; i < 9; i++) { @@ -2329,8 +2334,12 @@ static boolean M_HandlePressStart(setup_player_t *p, UINT8 num) static boolean M_HandleCSelectProfile(setup_player_t *p, UINT8 num) { const UINT8 maxp = PR_GetNumProfiles() -1; + UINT8 realnum = num; // Used for profile when using splitdevice. UINT8 i; + if (cv_splitdevice.value) + num = 0; + if (menucmd[num].dpad_ud > 0) { p->profilen++; @@ -2378,7 +2387,7 @@ static boolean M_HandleCSelectProfile(setup_player_t *p, UINT8 num) else if (M_MenuConfirmPressed(num)) { // Apply the profile. - PR_ApplyProfile(p->profilen, num); + PR_ApplyProfile(p->profilen, realnum); // Otherwise P1 would inherit the last player's profile in splitdevice and that's not what we want... M_SetupProfileGridPos(p); p->mdepth = CSSTEP_CHARS; @@ -2395,6 +2404,9 @@ static boolean M_HandleCharacterGrid(setup_player_t *p, UINT8 num) UINT8 numclones; + if (cv_splitdevice.value) + num = 0; + if (menucmd[num].dpad_ud > 0) { p->gridy++; @@ -2513,6 +2525,9 @@ static void M_HandleCharRotate(setup_player_t *p, UINT8 num) { UINT8 numclones = setup_chargrid[p->gridx][p->gridy].numskins; + if (cv_splitdevice.value) + num = 0; + if (menucmd[num].dpad_lr > 0) { p->clonenum++; @@ -2548,6 +2563,10 @@ static void M_HandleCharRotate(setup_player_t *p, UINT8 num) static void M_HandleColorRotate(setup_player_t *p, UINT8 num) { + + if (cv_splitdevice.value) + num = 0; + if (menucmd[num].dpad_lr > 0) { p->color++; @@ -2619,6 +2638,9 @@ static void M_AnimateFollower(setup_player_t *p) static void M_HandleChooseFollower(setup_player_t *p, UINT8 num) { + if (cv_splitdevice.value) + num = 0; + M_AnimateFollower(p); if (menucmd[num].dpad_lr > 0 && numfollowers) @@ -2667,6 +2689,10 @@ static void M_HandleChooseFollower(setup_player_t *p, UINT8 num) static void M_HandleFollowerColorRotate(setup_player_t *p, UINT8 num) { + + if (cv_splitdevice.value) + num = 0; + M_AnimateFollower(p); if (menucmd[num].dpad_lr > 0) @@ -2715,6 +2741,24 @@ static void M_HandleFollowerColorRotate(setup_player_t *p, UINT8 num) } } +// +static void M_HandleSplitDevice(void) +{ + + const UINT8 pid = 0; + setup_player_t *p = &setup_player[setup_numplayers]; + + if (M_MenuButtonPressed(pid, MBT_C)) + { + if (!cv_splitdevice.value) + M_StartMessage(M_GetText("Split device enabled.\nP1 can add additional players with [C].\nP1 must set all Players' parameters.\n\nIntended for use for multiplayer games\non the same device (Keyboard...)\nand testing purposes.\n\nPress any key"), NULL, MM_NOTHING); + + CV_StealthSetValue(&cv_splitdevice, 1); + S_StartSound(NULL, sfx_s3k65); + p->mdepth = CSSTEP_PROFILE; // Ready the player setup. + } +} + boolean M_CharacterSelectHandler(INT32 choice) { INT32 i; @@ -2728,6 +2772,19 @@ boolean M_CharacterSelectHandler(INT32 choice) if (p->delay == 0 && menucmd[i].delay == 0) { + + if (p->mdepth > CSSTEP_NONE && i == 0) + M_HandleSplitDevice(); + + // If splitdevice is true, only do the last non-ready setups. + if (cv_splitdevice.value) + { + // Previous setup isn't ready, go there. + // In any case, do setup 0 first. + if (i > 0 && setup_player[i-1].mdepth < CSSTEP_READY) + continue; + } + switch (p->mdepth) { case CSSTEP_NONE: // Enter Game