mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-10 16:03:15 -04:00
WIP on making movement input generic
This commit is contained in:
parent
e31e42c665
commit
20a392cdfb
19
src/Entity.c
19
src/Entity.c
@ -781,15 +781,18 @@ void LocalPlayer_SetInterpPosition(float t) {
|
|||||||
static void LocalPlayer_HandleInput(float* xMoving, float* zMoving) {
|
static void LocalPlayer_HandleInput(float* xMoving, float* zMoving) {
|
||||||
struct LocalPlayer* p = &LocalPlayer_Instance;
|
struct LocalPlayer* p = &LocalPlayer_Instance;
|
||||||
struct HacksComp* hacks = &p->Hacks;
|
struct HacksComp* hacks = &p->Hacks;
|
||||||
|
struct LocalPlayerInput* input;
|
||||||
|
|
||||||
if (Gui_GetInputGrab()) {
|
if (Gui_GetInputGrab()) {
|
||||||
p->Physics.Jumping = false; hacks->Speeding = false;
|
p->Physics.Jumping = false; hacks->Speeding = false;
|
||||||
hacks->FlyingUp = false; hacks->FlyingDown = false;
|
hacks->FlyingUp = false; hacks->FlyingDown = false;
|
||||||
} else {
|
} else {
|
||||||
if (KeyBind_IsPressed(KEYBIND_FORWARD)) *zMoving -= 0.98f;
|
/* keyboard input, touch, joystick, etc */
|
||||||
if (KeyBind_IsPressed(KEYBIND_BACK)) *zMoving += 0.98f;
|
for (input = &p->input; input; input = input->next) {
|
||||||
if (KeyBind_IsPressed(KEYBIND_LEFT)) *xMoving -= 0.98f;
|
input->GetMovement(xMoving, zMoving);
|
||||||
if (KeyBind_IsPressed(KEYBIND_RIGHT)) *xMoving += 0.98f;
|
}
|
||||||
|
*xMoving *= 0.98f;
|
||||||
|
*zMoving *= 0.98f;
|
||||||
|
|
||||||
p->Physics.Jumping = KeyBind_IsPressed(KEYBIND_JUMP);
|
p->Physics.Jumping = KeyBind_IsPressed(KEYBIND_JUMP);
|
||||||
hacks->Speeding = hacks->Enabled && KeyBind_IsPressed(KEYBIND_SPEED);
|
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 = {
|
static const struct EntityVTABLE localPlayer_VTABLE = {
|
||||||
LocalPlayer_Tick, Player_Despawn, LocalPlayer_SetLocation, Entity_GetCol,
|
LocalPlayer_Tick, Player_Despawn, LocalPlayer_SetLocation, Entity_GetCol,
|
||||||
LocalPlayer_RenderModel, LocalPlayer_RenderName
|
LocalPlayer_RenderModel, LocalPlayer_RenderName
|
||||||
@ -883,6 +893,7 @@ static void LocalPlayer_Init(void) {
|
|||||||
Entity_SetSkin(&p->Base, &Game_Username);
|
Entity_SetSkin(&p->Base, &Game_Username);
|
||||||
Event_Register_(&UserEvents.HackPermissionsChanged, NULL, LocalPlayer_CheckJumpVelocity);
|
Event_Register_(&UserEvents.HackPermissionsChanged, NULL, LocalPlayer_CheckJumpVelocity);
|
||||||
|
|
||||||
|
p->input.GetMovement = LocalPlayer_GetMovement;
|
||||||
p->Collisions.Entity = &p->Base;
|
p->Collisions.Entity = &p->Base;
|
||||||
HacksComp_Init(hacks);
|
HacksComp_Init(hacks);
|
||||||
PhysicsComp_Init(&p->Physics, &p->Base);
|
PhysicsComp_Init(&p->Physics, &p->Base);
|
||||||
|
@ -183,6 +183,12 @@ struct NetPlayer {
|
|||||||
CC_API void NetPlayer_Init(struct NetPlayer* player);
|
CC_API void NetPlayer_Init(struct NetPlayer* player);
|
||||||
extern struct NetPlayer NetPlayers_List[ENTITIES_SELF_ID];
|
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. */
|
/* Represents the user/player's own entity. */
|
||||||
struct LocalPlayer {
|
struct LocalPlayer {
|
||||||
struct Entity Base;
|
struct Entity Base;
|
||||||
@ -194,6 +200,7 @@ struct LocalPlayer {
|
|||||||
struct CollisionsComp Collisions;
|
struct CollisionsComp Collisions;
|
||||||
struct PhysicsComp Physics;
|
struct PhysicsComp Physics;
|
||||||
cc_bool _warnedRespawn, _warnedFly, _warnedNoclip, _warnedZoom;
|
cc_bool _warnedRespawn, _warnedFly, _warnedNoclip, _warnedZoom;
|
||||||
|
struct LocalPlayerInput input;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct LocalPlayer LocalPlayer_Instance;
|
extern struct LocalPlayer LocalPlayer_Instance;
|
||||||
|
@ -456,6 +456,8 @@ static void OnFileChanged(void* obj, struct Stream* stream, const cc_string* nam
|
|||||||
Game_UpdateTexture(&Gui.GuiClassicTex, stream, name, NULL);
|
Game_UpdateTexture(&Gui.GuiClassicTex, stream, name, NULL);
|
||||||
} else if (String_CaselessEqualsConst(name, "icons.png")) {
|
} else if (String_CaselessEqualsConst(name, "icons.png")) {
|
||||||
Game_UpdateTexture(&Gui.IconsTex, stream, name, NULL);
|
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.GuiTex);
|
||||||
Gfx_DeleteTexture(&Gui.GuiClassicTex);
|
Gfx_DeleteTexture(&Gui.GuiClassicTex);
|
||||||
Gfx_DeleteTexture(&Gui.IconsTex);
|
Gfx_DeleteTexture(&Gui.IconsTex);
|
||||||
|
Gfx_DeleteTexture(&Gui.TouchTex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnInit(void) {
|
static void OnInit(void) {
|
||||||
|
@ -41,7 +41,7 @@ CC_VAR extern struct _GuiData {
|
|||||||
/* Whether FPS counter (and other info) is shown in top left. */
|
/* Whether FPS counter (and other info) is shown in top left. */
|
||||||
cc_bool ShowFPS;
|
cc_bool ShowFPS;
|
||||||
float RawHotbarScale, RawChatScale, RawInventoryScale;
|
float RawHotbarScale, RawChatScale, RawInventoryScale;
|
||||||
GfxResourceID GuiTex, GuiClassicTex, IconsTex;
|
GfxResourceID GuiTex, GuiClassicTex, IconsTex, TouchTex;
|
||||||
} Gui;
|
} Gui;
|
||||||
|
|
||||||
float Gui_Scale(float value);
|
float Gui_Scale(float value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user