diff --git a/src/Entity.c b/src/Entity.c index ca91dc200..d2d3efac9 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -781,15 +781,18 @@ void LocalPlayer_SetInterpPosition(float t) { static void LocalPlayer_HandleInput(float* xMoving, float* zMoving) { struct LocalPlayer* p = &LocalPlayer_Instance; struct HacksComp* hacks = &p->Hacks; + struct LocalPlayerInput* input; if (Gui_GetInputGrab()) { p->Physics.Jumping = false; hacks->Speeding = false; hacks->FlyingUp = false; hacks->FlyingDown = false; } else { - if (KeyBind_IsPressed(KEYBIND_FORWARD)) *zMoving -= 0.98f; - if (KeyBind_IsPressed(KEYBIND_BACK)) *zMoving += 0.98f; - if (KeyBind_IsPressed(KEYBIND_LEFT)) *xMoving -= 0.98f; - if (KeyBind_IsPressed(KEYBIND_RIGHT)) *xMoving += 0.98f; + /* keyboard input, touch, joystick, etc */ + for (input = &p->input; input; input = input->next) { + input->GetMovement(xMoving, zMoving); + } + *xMoving *= 0.98f; + *zMoving *= 0.98f; p->Physics.Jumping = KeyBind_IsPressed(KEYBIND_JUMP); hacks->Speeding = hacks->Enabled && KeyBind_IsPressed(KEYBIND_SPEED); @@ -870,6 +873,13 @@ static void LocalPlayer_CheckJumpVelocity(void* obj) { } } +static void LocalPlayer_GetMovement(float* xMoving, float* zMoving) { + if (KeyBind_IsPressed(KEYBIND_FORWARD)) *zMoving -= 1; + if (KeyBind_IsPressed(KEYBIND_BACK)) *zMoving += 1; + if (KeyBind_IsPressed(KEYBIND_LEFT)) *xMoving -= 1; + if (KeyBind_IsPressed(KEYBIND_RIGHT)) *xMoving += 1; +} + static const struct EntityVTABLE localPlayer_VTABLE = { LocalPlayer_Tick, Player_Despawn, LocalPlayer_SetLocation, Entity_GetCol, LocalPlayer_RenderModel, LocalPlayer_RenderName @@ -883,6 +893,7 @@ static void LocalPlayer_Init(void) { Entity_SetSkin(&p->Base, &Game_Username); Event_Register_(&UserEvents.HackPermissionsChanged, NULL, LocalPlayer_CheckJumpVelocity); + p->input.GetMovement = LocalPlayer_GetMovement; p->Collisions.Entity = &p->Base; HacksComp_Init(hacks); PhysicsComp_Init(&p->Physics, &p->Base); @@ -900,9 +911,9 @@ static void LocalPlayer_Init(void) { hacks->SpeedMultiplier = Options_GetFloat(OPT_SPEED_FACTOR, 0.1f, 50.0f, 10.0f); hacks->PushbackPlacing = Options_GetBool(OPT_PUSHBACK_PLACING, false); - hacks->NoclipSlide = Options_GetBool(OPT_NOCLIP_SLIDE, false); - hacks->WOMStyleHacks = Options_GetBool(OPT_WOM_STYLE_HACKS, false); - hacks->FullBlockStep = Options_GetBool(OPT_FULL_BLOCK_STEP, false); + hacks->NoclipSlide = Options_GetBool(OPT_NOCLIP_SLIDE, false); + hacks->WOMStyleHacks = Options_GetBool(OPT_WOM_STYLE_HACKS, false); + hacks->FullBlockStep = Options_GetBool(OPT_FULL_BLOCK_STEP, false); p->Physics.UserJumpVel = Options_GetFloat(OPT_JUMP_VELOCITY, 0.0f, 52.0f, 0.42f); p->Physics.JumpVel = p->Physics.UserJumpVel; hackPermMsgs = Options_GetBool(OPT_HACK_PERM_MSGS, true); diff --git a/src/Entity.h b/src/Entity.h index 466546cd1..3cf2838fd 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -183,6 +183,12 @@ struct NetPlayer { CC_API void NetPlayer_Init(struct NetPlayer* player); extern struct NetPlayer NetPlayers_List[ENTITIES_SELF_ID]; +struct LocalPlayerInput; +struct LocalPlayerInput { + void (*GetMovement)(float* xMoving, float* zMoving); + struct LocalPlayerInput* next; +}; + /* Represents the user/player's own entity. */ struct LocalPlayer { struct Entity Base; @@ -194,6 +200,7 @@ struct LocalPlayer { struct CollisionsComp Collisions; struct PhysicsComp Physics; cc_bool _warnedRespawn, _warnedFly, _warnedNoclip, _warnedZoom; + struct LocalPlayerInput input; }; extern struct LocalPlayer LocalPlayer_Instance; diff --git a/src/Gui.c b/src/Gui.c index 6429b36f6..7dddfd531 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -456,6 +456,8 @@ static void OnFileChanged(void* obj, struct Stream* stream, const cc_string* nam Game_UpdateTexture(&Gui.GuiClassicTex, stream, name, NULL); } else if (String_CaselessEqualsConst(name, "icons.png")) { Game_UpdateTexture(&Gui.IconsTex, stream, name, NULL); + } else if (String_CaselessEqualsConst(name, "touch.png")) { + Game_UpdateTexture(&Gui.TouchTex, stream, name, NULL); } } @@ -488,6 +490,7 @@ static void OnContextLost(void* obj) { Gfx_DeleteTexture(&Gui.GuiTex); Gfx_DeleteTexture(&Gui.GuiClassicTex); Gfx_DeleteTexture(&Gui.IconsTex); + Gfx_DeleteTexture(&Gui.TouchTex); } static void OnInit(void) { diff --git a/src/Gui.h b/src/Gui.h index fd6047a19..58903facb 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -41,7 +41,7 @@ CC_VAR extern struct _GuiData { /* Whether FPS counter (and other info) is shown in top left. */ cc_bool ShowFPS; float RawHotbarScale, RawChatScale, RawInventoryScale; - GfxResourceID GuiTex, GuiClassicTex, IconsTex; + GfxResourceID GuiTex, GuiClassicTex, IconsTex, TouchTex; } Gui; float Gui_Scale(float value);