In splitscreen mode, tie controller joystick input to a specific player

This commit is contained in:
UnknownShadow200 2024-04-26 13:39:27 +10:00
parent 4be7d08f20
commit a58ede8911
5 changed files with 12 additions and 24 deletions

View File

@ -746,7 +746,7 @@ static const struct EntityVTABLE localPlayer_VTABLE = {
LocalPlayer_Tick, Player_Despawn, LocalPlayer_SetLocation, Entity_GetColor,
LocalPlayer_RenderModel, LocalPlayer_ShouldRenderName
};
static void LocalPlayer_Init(struct LocalPlayer* p) {
static void LocalPlayer_Init(struct LocalPlayer* p, int index) {
struct HacksComp* hacks = &p->Hacks;
Entity_Init(&p->Base);
@ -764,6 +764,7 @@ static void LocalPlayer_Init(struct LocalPlayer* p) {
p->Physics.Hacks = &p->Hacks;
p->Physics.Collisions = &p->Collisions;
p->Base.VTABLE = &localPlayer_VTABLE;
p->index = index;
hacks->Enabled = !Game_PureClassic && Options_GetBool(OPT_HACKS_ENABLED, true);
/* p->Base.Health = 20; TODO: survival mode stuff */
@ -1045,7 +1046,7 @@ static void Entities_Init(void) {
for (i = 0; i < Game_NumLocalPlayers; i++)
{
LocalPlayer_Init(&LocalPlayer_Instances[i]);
LocalPlayer_Init(&LocalPlayer_Instances[i], i);
Entities.List[MAX_NET_PLAYERS + i] = &LocalPlayer_Instances[i].Base;
}
Entities.CurPlayer = &LocalPlayer_Instances[0];

View File

@ -243,6 +243,7 @@ struct LocalPlayer {
struct CollisionsComp Collisions;
struct PhysicsComp Physics;
cc_bool _warnedRespawn, _warnedFly, _warnedNoclip, _warnedZoom;
cc_uint8 index;
};
extern struct LocalPlayer LocalPlayer_Instances[MAX_LOCAL_PLAYERS];

View File

@ -606,7 +606,6 @@ static void OnAxisUpdate(void* obj, int port, int axis, float x, float y) {
}
/*########################################################################################################################*
*------------------------------------------------------Gui component------------------------------------------------------*
*#########################################################################################################################*/

View File

@ -490,6 +490,9 @@ static void PlayerInputGamepad(struct LocalPlayer* p, float* xMoving, float* zMo
int port;
for (port = 0; port < INPUT_MAX_GAMEPADS; port++)
{
/* In splitscreen mode, tie a controller to a specific player*/
if (Game_NumLocalPlayers > 1 && p->index != port) continue;
PlayerInputPad(port, PAD_AXIS_LEFT, p, xMoving, zMoving);
PlayerInputPad(port, PAD_AXIS_RIGHT, p, xMoving, zMoving);
}

View File

@ -2306,10 +2306,6 @@ static void MenuInputOverlay_Render(void* screen, double delta) {
}
static void MenuInputOverlay_Free(void* screen) {
struct MenuInputOverlay* s = (struct MenuInputOverlay*)screen;
Elem_Free(&s->input.base);
Elem_Free(&s->ok);
Elem_Free(&s->Default);
OnscreenKeyboard_Close();
}
@ -2583,10 +2579,9 @@ static void MenuOptionsScreen_Init(void* screen) {
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
int i;
s->widgets = menuOpts_widgets;
s->numWidgets = 0;
s->maxWidgets = MENUOPTS_MAX_OPTS + 1; /* always have back button */
s->maxVertices = BUTTONWIDGET_MAX;
s->widgets = menuOpts_widgets;
s->numWidgets = 0;
s->maxWidgets = MENUOPTS_MAX_OPTS + 1; /* always have back button */
/* The various menu options screens might have different number of widgets */
for (i = 0; i < MENUOPTS_MAX_OPTS; i++) {
@ -2601,6 +2596,8 @@ static void MenuOptionsScreen_Init(void* screen) {
TextGroupWidget_Create(&s->extHelp, 5, s->extHelpTextures, MenuOptionsScreen_GetDesc);
s->extHelp.lines = 0;
Event_Register_(&UserEvents.HackPermsChanged, screen, MenuOptionsScreen_OnHacksChanged);
s->maxVertices = Screen_CalcDefaultMaxVertices(s);
}
#define EXTHELP_PAD 5 /* padding around extended help box */
@ -2759,7 +2756,6 @@ static void ClassicOptionsScreen_InitWidgets(struct MenuOptionsScreen* s) {
{ 0, 60, "Hacks enabled", MenuOptionsScreen_Bool,
ClassicOptionsScreen_GetHacks, ClassicOptionsScreen_SetHacks }
};
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX + BUTTONWIDGET_MAX;
s->DoRecreateExtra = ClassicOptionsScreen_RecreateExtra;
MenuOptionsScreen_AddButtons(s, buttons, Array_Elems(buttons), Menu_SwitchPause);
@ -2839,8 +2835,6 @@ static void EnvSettingsScreen_InitWidgets(struct MenuOptionsScreen* s) {
{ 1, 50, "Water level", MenuOptionsScreen_Input,
EnvSettingsScreen_GetEdgeHeight, EnvSettingsScreen_SetEdgeHeight }
};
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX;
MenuOptionsScreen_AddButtons(s, buttons, Array_Elems(buttons), Menu_SwitchOptions);
}
@ -2928,8 +2922,6 @@ static void GraphicsOptionsScreen_InitWidgets(struct MenuOptionsScreen* s) {
{ 1, 50, "Anaglyph 3D", MenuOptionsScreen_Bool,
ClassicOptionsScreen_GetAnaglyph, ClassicOptionsScreen_SetAnaglyph }
};
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX;
MenuOptionsScreen_AddButtons(s, buttons, Array_Elems(buttons), Menu_SwitchOptions);
s->descriptions[0] = "&eChange the smoothness of the smooth camera.";
@ -3012,8 +3004,6 @@ static void ChatOptionsScreen_InitWidgets(struct MenuOptionsScreen* s) {
{ -1,-50, "Scale with window", MenuOptionsScreen_Bool,
ChatOptionsScreen_GetAutoScaleChat, ChatOptionsScreen_SetAutoScaleChat }
};
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX;
MenuOptionsScreen_AddButtons(s, buttons, Array_Elems(buttons), Menu_SwitchOptions);
}
@ -3076,8 +3066,6 @@ static void GuiOptionsScreen_InitWidgets(struct MenuOptionsScreen* s) {
{ 1, 50, "Select system font", Menu_SwitchFont,
NULL, NULL }
};
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX;
MenuOptionsScreen_AddButtons(s, buttons, Array_Elems(buttons), Menu_SwitchOptions);
}
@ -3198,7 +3186,6 @@ static void HacksSettingsScreen_InitWidgets(struct MenuOptionsScreen* s) {
{ 1, 50, "Field of view", MenuOptionsScreen_Input,
HacksSettingsScreen_GetFOV, HacksSettingsScreen_SetFOV },
};
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX;
s->OnHacksChanged = HacksSettingsScreen_CheckHacksAllowed;
MenuOptionsScreen_AddButtons(s, buttons, Array_Elems(buttons), Menu_SwitchOptions);
@ -3275,7 +3262,6 @@ static void MiscSettingsScreen_InitWidgets(struct MenuOptionsScreen* s) {
{ 1, 50, "Mouse sensitivity", MenuOptionsScreen_Input,
MiscOptionsScreen_GetSensitivity, MiscOptionsScreen_SetSensitivity }
};
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX;
MenuOptionsScreen_AddButtons(s, buttons, Array_Elems(buttons), Menu_SwitchOptions);
/* Disable certain options */
@ -3412,7 +3398,6 @@ static void NostalgiaAppearanceScreen_InitWidgets(struct MenuOptionsScreen* s) {
{ 1, 50, "Classic options", MenuOptionsScreen_Bool,
NostalgiaScreen_GetOpts, NostalgiaScreen_SetOpts },
};
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX;
MenuOptionsScreen_AddButtons(s, buttons, Array_Elems(buttons), Menu_SwitchNostalgia);
}
@ -3473,7 +3458,6 @@ static void NostalgiaFunctionalityScreen_InitWidgets(struct MenuOptionsScreen* s
{ 1, 0, "Game version", NostalgiaScreen_Version,
NostalgiaScreen_GetVersion, NostalgiaScreen_SetVersion }
};
s->maxVertices += Array_Elems(buttons) * BUTTONWIDGET_MAX + TEXTWIDGET_MAX;
s->DoRecreateExtra = NostalgiaScreen_RecreateExtra;
MenuOptionsScreen_AddButtons(s, buttons, Array_Elems(buttons), Menu_SwitchNostalgia);