WIP on refactoring pad axis input

This commit is contained in:
UnknownShadow200 2025-03-11 21:33:20 +11:00
parent f18d9e0559
commit 1852e68b48
12 changed files with 44 additions and 42 deletions

View File

@ -280,11 +280,11 @@ static void OnRawMovement(void* obj, float deltaX, float deltaY) {
Camera.Active->OnRawMovement(deltaX, deltaY, 0);
}
static void OnAxisUpdate(void* obj, int port, int axis, float x, float y) {
static void OnAxisUpdate(void* obj, struct PadAxisUpdate* upd) {
if (!Input.RawMode) return;
if (Gamepad_AxisBehaviour[axis] != AXIS_BEHAVIOUR_CAMERA) return;
if (Gamepad_AxisBehaviour[upd->axis] != AXIS_BEHAVIOUR_CAMERA) return;
Camera.Active->OnRawMovement(x, y, port);
Camera.Active->OnRawMovement(upd->x, upd->y, upd->port);
}
static void OnHacksChanged(void* obj) {

View File

@ -181,10 +181,10 @@ void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDel
}
}
void Event_RaisePadAxis(struct Event_PadAxis* handlers, int port, int axis, float x, float y) {
void Event_RaisePadAxis(struct Event_PadAxis* handlers, struct PadAxisUpdate* upd) {
int i;
for (i = 0; i < handlers->Count; i++) {
handlers->Handlers[i](handlers->Objs[i], port, axis, x, y);
handlers->Handlers[i](handlers->Objs[i], upd);
}
}

View File

@ -11,6 +11,7 @@ CC_BEGIN_HEADER
#define EVENT_MAX_CALLBACKS 32
struct Stream;
struct InputDevice;
struct PadAxisUpdate;
typedef void (*Event_Void_Callback)(void* obj);
struct Event_Void {
@ -66,7 +67,7 @@ struct Event_RawMove {
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
};
typedef void (*Event_PadAxis_Callback)(void* obj, int port, int axis, float x, float y);
typedef void (*Event_PadAxis_Callback)(void* obj, struct PadAxisUpdate* upd);
struct Event_PadAxis {
Event_PadAxis_Callback Handlers[EVENT_MAX_CALLBACKS];
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
@ -117,7 +118,7 @@ void Event_RaiseString(struct Event_String* handlers, const cc_string* str);
/* Calls all registered callbacks for an event which has raw pointer movement arguments. */
void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDelta);
/* Calls all registered callbacks for an event which has pad axis arguments. */
void Event_RaisePadAxis(struct Event_PadAxis* handlers, int port, int axis, float x, float y);
void Event_RaisePadAxis(struct Event_PadAxis* handlers, struct PadAxisUpdate* upd);
/* Calls all registered callbacks for an event which has a channel and a 64 byte data argument. */
void Event_RaisePluginMessage(struct Event_PluginMessage* handlers, cc_uint8 channel, cc_uint8* data);
/* Calls all registered callbacks for an event called when the Lighting_LightingMode is changed */

View File

@ -8,7 +8,6 @@
#include <stdint.h>
#include <psxgpu.h>
#include <psxgte.h>
#include <psxpad.h>
#include <psxapi.h>
#include <psxetc.h>
#include <inline_c.h>
@ -907,7 +906,7 @@ void Gfx_EndFrame(void) {
if ((cc_uint8*)next_packet >= next_packet_end - sizeof(struct PSX_POLY_FT4)) {
Platform_LogConst("OUT OF VERTEX RAM");
}
DrawSync(0);
WaitUntilFinished();
VSync(0);
RenderBuffer* draw_buffer = &buffers[active_buffer];

View File

@ -626,7 +626,7 @@ static void OnPointerMove(void* obj, int idx) {
}
}
static void OnAxisUpdate(void* obj, int port, int axis, float x, float y) {
static void OnAxisUpdate(void* obj, struct PadAxisUpdate* upd) {
struct Screen* s;
int i;
@ -635,7 +635,7 @@ static void OnAxisUpdate(void* obj, int port, int axis, float x, float y) {
if (!s->VTABLE->HandlesPadAxis) continue;
s->dirty = true;
if (s->VTABLE->HandlesPadAxis(s, axis, x, y)) return;
if (s->VTABLE->HandlesPadAxis(s, upd)) return;
}
}

View File

@ -22,6 +22,7 @@ struct VertexTextured;
struct FontDesc;
struct Widget;
struct InputDevice;
struct PadAxisUpdate;
extern struct IGameComponent Gui_Component;
CC_VAR extern struct _GuiData {
@ -120,7 +121,7 @@ struct ScreenVTABLE {
/* Allocates graphics resources. (textures, vertex buffers, etc) */
void (*ContextRecreated)(void* elem);
/* Returns non-zero if a pad axis update is handled. */
int (*HandlesPadAxis)(void* elem, int axis, float x, float y);
int (*HandlesPadAxis)(void* elem, struct PadAxisUpdate* upd);
};
#define Screen_Body const struct ScreenVTABLE* VTABLE; \
cc_bool grabsInput; /* Whether this screen grabs input. Causes the cursor to become visible. */ \
@ -188,7 +189,7 @@ struct WidgetVTABLE {
/* Returns the maximum number of vertices this widget may use */
int (*GetMaxVertices)(void* elem);
/* Returns non-zero if a pad axis update is handled. */
int (*HandlesPadAxis)(void* elem, int axis, float x, float y);
int (*HandlesPadAxis)(void* elem, struct PadAxisUpdate* upd);
};
#define Widget_Body const struct WidgetVTABLE* VTABLE; \
@ -310,7 +311,7 @@ void TextAtlas_AddInt(struct TextAtlas* atlas, int value, struct VertexTextured*
#define Elem_OnPointerUp(elem, id, x, y) (elem)->VTABLE->OnPointerUp(elem, id, x, y)
#define Elem_HandlesPointerMove(elem, id, x, y) (elem)->VTABLE->HandlesPointerMove(elem, id, x, y)
#define Elem_HandlesPadAxis(elem, axis, x, y) (elem)->VTABLE->HandlesPadAxis(elem, axis, x, y)
#define Elem_HandlesPadAxis(elem, upd) (elem)->VTABLE->HandlesPadAxis(elem, upd)
#define Widget_BuildMesh(widget, vertices) (widget)->VTABLE->BuildMesh(widget, vertices)
#define Widget_Render2(widget, offset) (widget)->VTABLE->Render2(widget, offset)

View File

@ -576,16 +576,26 @@ void Gamepad_SetButton(int port, int btn, int pressed) {
}
void Gamepad_SetAxis(int port, int axis, float x, float y, float delta) {
struct GamepadDevice* dev = &Gamepad_Devices[port];
struct PadAxisUpdate upd;
float scale;
int sensi;
Gamepad_Devices[port].axisX[axis] = x;
Gamepad_Devices[port].axisY[axis] = y;
dev->axisX[axis] = x;
dev->axisY[axis] = y;
if (x == 0 && y == 0) return;
sensi = Gamepad_AxisSensitivity[axis];
scale = delta * 60.0f * axis_sensiFactor[sensi];
Event_RaisePadAxis(&ControllerEvents.AxisUpdate, port, axis, x * scale, y * scale);
sensi = Gamepad_AxisSensitivity[axis];
scale = delta * 60.0f * axis_sensiFactor[sensi];
upd.port = port;
upd.axis = axis;
upd.x = x * scale;
upd.y = y * scale;
upd.xSteps = Utils_AccumulateWheelDelta(&dev->padXAcc, upd.x / 100.0f);
upd.ySteps = Utils_AccumulateWheelDelta(&dev->padYAcc, upd.y / 100.0f);
Event_RaisePadAxis(&ControllerEvents.AxisUpdate, &upd);
}
void Gamepad_Tick(float delta) {

View File

@ -222,13 +222,18 @@ void Gamepad_Tick(float delta);
#define GAMEPAD_BEG_BTN CCPAD_1
#define GAMEPAD_BTN_COUNT (INPUT_COUNT - GAMEPAD_BEG_BTN)
struct PadAxisUpdate {
int port, axis;
float x, y;
int xSteps, ySteps;
};
struct GamepadDevice {
struct InputDevice base;
long deviceID;
float axisX[2], axisY[2];
cc_bool pressed[GAMEPAD_BTN_COUNT];
float holdtime[GAMEPAD_BTN_COUNT];
float padXAcc, padYAcc;
};
extern struct GamepadDevice Gamepad_Devices[INPUT_MAX_GAMEPADS];
int Gamepad_Connect(long deviceID, const struct BindMapping_* defaults);

View File

@ -1795,10 +1795,10 @@ static int InventoryScreen_MouseScroll(void* screen, float delta) {
return Elem_HandlesMouseScroll(&s->table, delta);
}
static int InventoryScreen_PadAxis(void* screen, int axis, float x, float y) {
static int InventoryScreen_PadAxis(void* screen, struct PadAxisUpdate* upd) {
struct InventoryScreen* s = (struct InventoryScreen*)screen;
return Elem_HandlesPadAxis(&s->table, axis, x, y);
return Elem_HandlesPadAxis(&s->table, upd);
}
static const struct ScreenVTABLE InventoryScreen_VTABLE = {

View File

@ -14,7 +14,6 @@
static cc_bool kb_inited, kb_shift, kb_needsHook;
static struct FontDesc kb_font;
static int kb_curX, kb_curY;
static float kb_padXAcc, kb_padYAcc;
static char kb_buffer[512];
static cc_string kb_str = String_FromArray(kb_buffer);
static void (*KB_MarkDirty)(void);
@ -294,14 +293,9 @@ static cc_bool VirtualKeyboard_OnInputDown(int key, struct InputDevice* device)
return true;
}
static void VirtualKeyboard_PadAxis(void* obj, int port, int axis, float x, float y) {
int xSteps, ySteps;
xSteps = Utils_AccumulateWheelDelta(&kb_padXAcc, x / 100.0f);
if (xSteps) VirtualKeyboard_Scroll(xSteps > 0 ? 1 : -1, 0);
ySteps = Utils_AccumulateWheelDelta(&kb_padYAcc, y / 100.0f);
if (ySteps) VirtualKeyboard_Scroll(0, ySteps > 0 ? 1 : -1);
static void VirtualKeyboard_PadAxis(void* obj, struct PadAxisUpdate* upd) {
if (upd->xSteps) VirtualKeyboard_Scroll(upd->xSteps > 0 ? 1 : -1, 0);
if (upd->ySteps) VirtualKeyboard_Scroll(0, upd->ySteps > 0 ? 1 : -1);
}
static cc_bool VirtualKeyboard_GetPointerPosition(int idx, int* kbX, int* kbY) {
@ -449,8 +443,6 @@ static void VirtualKeyboard_Open(struct OpenKeyboardArgs* args, cc_bool launcher
kb_needsHook = true;
kb_curX = -1;
kb_curY = 0;
kb_padXAcc = 0;
kb_padYAcc = 0;
kb_shift = false;
kb_yOffset = args->yOffset;

View File

@ -976,16 +976,12 @@ static int TableWidget_KeyDown(void* widget, int key, struct InputDevice* device
return false;
}
static int TableWidget_PadAxis(void* widget, int axis, float x, float y) {
static int TableWidget_PadAxis(void* widget, struct PadAxisUpdate* upd) {
struct TableWidget* w = (struct TableWidget*)widget;
int xSteps, ySteps;
if (w->selectedIndex == -1) return false;
xSteps = Utils_AccumulateWheelDelta(&w->padXAcc, x / 100.0f);
if (xSteps) TableWidget_ScrollRelative(w, xSteps > 0 ? 1 : -1);
ySteps = Utils_AccumulateWheelDelta(&w->padYAcc, y / 100.0f);
if (ySteps) TableWidget_ScrollRelative(w, ySteps > 0 ? w->blocksPerRow : -w->blocksPerRow);
if (upd->xSteps) TableWidget_ScrollRelative(w, upd->xSteps > 0 ? 1 : -1);
if (upd->ySteps) TableWidget_ScrollRelative(w, upd->ySteps > 0 ? w->blocksPerRow : -w->blocksPerRow);
return true;
}
@ -1008,7 +1004,6 @@ void TableWidget_Add(void* screen, struct TableWidget* w, int sbWidth) {
w->verAnchor = ANCHOR_CENTRE;
w->lastX = -20; w->lastY = -20;
w->scale = 1;
w->padXAcc = 0; w->padYAcc = 0;
if (!w->everCreated) {
w->everCreated = true;

View File

@ -97,7 +97,6 @@ struct TableWidget {
GfxResourceID vb;
cc_bool pendingClose, everCreated;
float scale;
float padXAcc, padYAcc;
BlockID blocks[BLOCK_COUNT];
struct ScrollbarWidget scroll;