Game no longer crashes on Dolphin
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
inputdolphin.c
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "input/input.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
inputbuttondata_t INPUT_BUTTON_DATA[] = {
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
{ .name = "a", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_A } },
|
||||
{ .name = "b", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_B } },
|
||||
{ .name = "x", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_X } },
|
||||
{ .name = "y", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_Y } },
|
||||
{ .name = "start", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_START } },
|
||||
{ .name = "up", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_UP } },
|
||||
{ .name = "down", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_DOWN } },
|
||||
{ .name = "left", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_LEFT } },
|
||||
{ .name = "right", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_RIGHT } },
|
||||
{ .name = "l", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_L } },
|
||||
{ .name = "r", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_R } },
|
||||
{ .name = "z", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_Z } },
|
||||
{ .name = "menu", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_MENU } },
|
||||
{ .name = "lstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_X, .positive = true } } },
|
||||
{ .name = "lstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_X, .positive = false } } },
|
||||
{ .name = "lstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_Y, .positive = true } } },
|
||||
{ .name = "lstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_Y, .positive = false } } },
|
||||
{ .name = "rstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_X, .positive = true } } },
|
||||
{ .name = "rstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_X, .positive = false } } },
|
||||
{ .name = "rstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_Y, .positive = true } } },
|
||||
{ .name = "rstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_Y, .positive = false } } },
|
||||
{ .name = "ltrigger", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_TRIGGER_LEFT, .positive = true } } },
|
||||
{ .name = "rtrigger", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_TRIGGER_RIGHT, .positive = true } } },
|
||||
#endif
|
||||
|
||||
{ .name = NULL }
|
||||
};
|
||||
|
||||
void inputUpdateDolphin(void) {
|
||||
PAD_ScanPads();
|
||||
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
for(uint8_t i = 0; i < INPUT_PAD_COUNT; i++) {
|
||||
INPUT.platform.padState[i] = PAD_ButtonsDown(i);
|
||||
|
||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_LEFT_X] = (
|
||||
INPUT_DOLPHIN_AXIS(PAD_StickX(i))
|
||||
);
|
||||
|
||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_LEFT_Y] = (
|
||||
INPUT_DOLPHIN_AXIS(PAD_StickY(i))
|
||||
);
|
||||
|
||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_C_X] = (
|
||||
INPUT_DOLPHIN_AXIS(PAD_SubStickX(i))
|
||||
);
|
||||
|
||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_C_Y] = (
|
||||
INPUT_DOLPHIN_AXIS(PAD_SubStickY(i))
|
||||
);
|
||||
|
||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_TRIGGER_LEFT] = (
|
||||
INPUT_DOLPHIN_AXIS(PAD_TriggerL(i))
|
||||
);
|
||||
|
||||
INPUT.platform.pads[i][INPUT_GAMEPAD_AXIS_TRIGGER_RIGHT] = (
|
||||
INPUT_DOLPHIN_AXIS(PAD_TriggerR(i))
|
||||
);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
float_t inputButtonGetValueDolphin(const inputbutton_t button) {
|
||||
switch(button.type) {
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
case INPUT_BUTTON_TYPE_GAMEPAD: {
|
||||
if(INPUT.padState[0] & button.gpButton) return 1.0f;
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
case INPUT_BUTTON_TYPE_GAMEPAD_AXIS: {
|
||||
float_t value = INPUT.pads[0][button.gpAxis.axis];
|
||||
if(!button.gpAxis.positive) value = -value;
|
||||
if(value >= INPUT.deadzone) return value;
|
||||
return 0.0f;
|
||||
}
|
||||
#endif
|
||||
|
||||
default: {
|
||||
assertUnreachable("Unknown input button type");
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
#define INPUT_DOLPHIN_PAD_COUNT PAD_CHANMAX
|
||||
#define INPUT_DOLPHIN_AXIS(value) ((float_t)(value) / 128.0f)
|
||||
|
||||
typedef struct inputbutton_s inputbutton_t;
|
||||
|
||||
#ifdef DUSK_INPUT_POINTER
|
||||
#error "Wii not implemented"
|
||||
#endif
|
||||
|
||||
#ifdef DUSK_INPUT_KEYBOARD
|
||||
#error "Keyboard not implemented"
|
||||
#endif
|
||||
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
// TODO: Can I support wiimote, gamecube, pro controller, etc?
|
||||
|
||||
typedef u16 inputgamepadbuttondolphin_t;
|
||||
typedef enum {
|
||||
INPUT_GAMEPAD_AXIS_LEFT_X,
|
||||
INPUT_GAMEPAD_AXIS_LEFT_Y,
|
||||
INPUT_GAMEPAD_AXIS_C_X,
|
||||
INPUT_GAMEPAD_AXIS_C_Y,
|
||||
INPUT_GAMEPAD_AXIS_TRIGGER_LEFT,
|
||||
INPUT_GAMEPAD_AXIS_TRIGGER_RIGHT,
|
||||
|
||||
INPUT_GAMEPAD_AXIS_COUNT
|
||||
} inputgamepadaxisdolphin_t;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
int padState[INPUT_DOLPHIN_PAD_COUNT];
|
||||
float_t pads[INPUT_DOLPHIN_PAD_COUNT][INPUT_GAMEPAD_AXIS_COUNT];
|
||||
#endif
|
||||
} inputdolphin_t;
|
||||
|
||||
/**
|
||||
* Updates the input state for Dolphin.
|
||||
*/
|
||||
void inputUpdateDolphin(void);
|
||||
|
||||
/**
|
||||
* Returns the input value (between 0 and 1) of the given button.
|
||||
*
|
||||
* @param button The button to get the value of.
|
||||
* @return The value of the button, between 0 and 1.
|
||||
*/
|
||||
float_t inputButtonGetValueDolphin(const inputbutton_t button);
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "inputdolphin.h"
|
||||
|
||||
#ifdef DUSK_INPUT_GAMEPAD
|
||||
typedef inputgamepadbuttondolphin_t inputgamepadbuttonplatform_t;
|
||||
typedef inputgamepadaxisdolphin_t inputgamepadaxissplatform_t;
|
||||
#endif
|
||||
|
||||
typedef inputdolphin_t inputplatform_t;
|
||||
|
||||
#define inputUpdatePlatform inputUpdateDolphin
|
||||
#define inputButtonGetValuePlatform inputButtonGetValueDolphin
|
||||
Reference in New Issue
Block a user