Renders on PSP again
This commit is contained in:
@@ -22,7 +22,7 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
INPUT_SDL=1
|
||||
INPUT_SDL2=1
|
||||
INPUT_GAMEPAD=1
|
||||
)
|
||||
endif()
|
||||
@@ -22,16 +22,23 @@ void inputInit(void) {
|
||||
INPUT.actions[i].currentValue = 0.0f;
|
||||
}
|
||||
|
||||
stringCopy(&INPUT_BUTTON_DATA[0].command[0], "echo \"test\";", CONSOLE_LINE_MAX);
|
||||
INPUT_BUTTON_DATA[0].actionType = INPUT_BUTTON_ACTION_TYPE_COMMAND;
|
||||
|
||||
INPUT_BUTTON_DATA[1].actionType = INPUT_BUTTON_ACTION_TYPE_ACTION;
|
||||
INPUT_BUTTON_DATA[1].action = INPUT_ACTION_UP;
|
||||
INPUT.deadzone = 0.1f;
|
||||
}
|
||||
|
||||
void inputUpdate(void) {
|
||||
#if INPUT_SDL2 == 1
|
||||
INPUT.keyboardState = SDL_GetKeyboardState(NULL);
|
||||
#if INPUT_GAMEPAD == 1
|
||||
INPUT.controller = NULL;
|
||||
|
||||
for(int32_t i = 0; i < SDL_NumJoysticks(); i++) {
|
||||
if(!SDL_IsGameController(i)) continue;
|
||||
INPUT.controller = SDL_GameControllerOpen(i);
|
||||
if(INPUT.controller) break;
|
||||
}
|
||||
#endif
|
||||
#if INPUT_KEYBOARD == 1
|
||||
INPUT.keyboardState = SDL_GetKeyboardState(NULL);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Reset all actions
|
||||
|
||||
@@ -12,7 +12,15 @@
|
||||
typedef struct {
|
||||
inputactiondata_t actions[INPUT_ACTION_COUNT];
|
||||
|
||||
#if INPUT_GAMEPAD == 1
|
||||
float_t deadzone;
|
||||
#endif
|
||||
|
||||
#if INPUT_SDL2 == 1
|
||||
#if INPUT_GAMEPAD == 1
|
||||
SDL_GameController *controller;
|
||||
#endif
|
||||
|
||||
#if INPUT_KEYBOARD == 1
|
||||
const uint8_t *keyboardState;
|
||||
#endif
|
||||
|
||||
@@ -14,6 +14,23 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = {
|
||||
#if INPUT_SDL2 == 1
|
||||
#if INPUT_GAMEPAD == 1
|
||||
#if PSP
|
||||
{ .name = "triangle", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_Y } },
|
||||
{ .name = "cross", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_A } },
|
||||
{ .name = "circle", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_B } },
|
||||
{ .name = "square", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_X } },
|
||||
{ .name = "start", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_START } },
|
||||
{ .name = "select", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_BACK } },
|
||||
{ .name = "up", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_UP } },
|
||||
{ .name = "down", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_DOWN } },
|
||||
{ .name = "left", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_LEFT } },
|
||||
{ .name = "right", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_DPAD_RIGHT } },
|
||||
{ .name = "l", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_LEFTSHOULDER } },
|
||||
{ .name = "r", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER } },
|
||||
|
||||
{ .name = "lstick_positive_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = true } } },
|
||||
{ .name = "lstick_negative_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = false } } },
|
||||
{ .name = "lstick_positive_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = true } } },
|
||||
{ .name = "lstick_negative_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = false } } },
|
||||
#else
|
||||
#endif
|
||||
#endif
|
||||
@@ -145,11 +162,12 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = {
|
||||
inputbutton_t inputButtonGetByName(const char_t *name) {
|
||||
assertNotNull(name, "name must not be NULL");
|
||||
|
||||
uint32_t len = sizeof(INPUT_BUTTON_DATA) / sizeof(inputbuttondata_t);
|
||||
|
||||
for(uint32_t i = 0; i < len; i++) {
|
||||
if(stringCompareInsensitive(INPUT_BUTTON_DATA[i].name, name) != 0) continue;
|
||||
return INPUT_BUTTON_DATA[i].button;
|
||||
inputbuttondata_t *data = INPUT_BUTTON_DATA;
|
||||
while(data->name != NULL) {
|
||||
if(stringCompareInsensitive(data->name, name) == 0) {
|
||||
return data->button;
|
||||
}
|
||||
data++;
|
||||
}
|
||||
|
||||
return (inputbutton_t){ .type = INPUT_BUTTON_TYPE_NONE };
|
||||
@@ -170,12 +188,23 @@ float_t inputButtonGetValue(const inputbutton_t button) {
|
||||
#if INPUT_GAMEPAD == 1
|
||||
case INPUT_BUTTON_TYPE_GAMEPAD: {
|
||||
#if INPUT_SDL2 == 1
|
||||
if(SDL_GameControllerGetButton(
|
||||
SDL_GameControllerFromInstanceID(0), button.gpButton
|
||||
)) return 1.0f;
|
||||
if(SDL_GameControllerGetButton(INPUT.controller, button.gpButton)) {
|
||||
return 1.0f;
|
||||
}
|
||||
#endif
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
case INPUT_BUTTON_TYPE_GAMEPAD_AXIS: {
|
||||
#if INPUT_SDL2 == 1
|
||||
Sint16 axis = SDL_GameControllerGetAxis(INPUT.controller, button.gpAxis.axis);
|
||||
if(!button.gpAxis.positive) axis = -axis;
|
||||
float_t value = (float_t)axis / 32767.0f;
|
||||
// Deadzone
|
||||
if(value < INPUT.deadzone) return 0.0f;
|
||||
return value;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
default: {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#if INPUT_GAMEPAD == 1
|
||||
#if INPUT_SDL2 == 1
|
||||
typedef SDL_GameControllerButton inputgamepadbutton_t;
|
||||
typedef SDL_GameControllerAxis inputgamepadaxis_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -37,6 +38,7 @@ typedef enum {
|
||||
#endif
|
||||
#if INPUT_GAMEPAD == 1
|
||||
INPUT_BUTTON_TYPE_GAMEPAD,
|
||||
INPUT_BUTTON_TYPE_GAMEPAD_AXIS,
|
||||
#endif
|
||||
|
||||
INPUT_BUTTON_TYPE_COUNT
|
||||
@@ -48,6 +50,10 @@ typedef struct {
|
||||
union {
|
||||
#if INPUT_GAMEPAD == 1
|
||||
inputgamepadbutton_t gpButton;
|
||||
struct {
|
||||
inputgamepadaxis_t axis;
|
||||
bool_t positive;
|
||||
} gpAxis;
|
||||
#endif
|
||||
|
||||
#if INPUT_KEYBOARD == 1
|
||||
|
||||
Reference in New Issue
Block a user