Sweeper
This commit is contained in:
@@ -146,6 +146,4 @@ void quadBuffer3D(
|
||||
vertices[5].pos[0] = min[0];
|
||||
vertices[5].pos[1] = max[1];
|
||||
vertices[5].pos[2] = min[2];
|
||||
|
||||
printf("UVS: (%f, %f), (%f, %f)\n", uvMin[0], uvMin[1], uvMax[0], uvMax[1]);
|
||||
}
|
||||
@@ -16,7 +16,7 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
PUBLIC
|
||||
INPUT_SDL2=1
|
||||
INPUT_KEYBOARD=1
|
||||
INPUT_MOUSE=1
|
||||
INPUT_POINTER=1
|
||||
INPUT_GAMEPAD=1
|
||||
)
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "util/math.h"
|
||||
#include "time/time.h"
|
||||
#include "debug/debug.h"
|
||||
#include "display/display.h"
|
||||
|
||||
input_t INPUT;
|
||||
|
||||
@@ -51,9 +52,22 @@ void inputUpdate(void) {
|
||||
if(INPUT.controller) break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if INPUT_KEYBOARD == 1
|
||||
INPUT.keyboardState = SDL_GetKeyboardState(NULL);
|
||||
#endif
|
||||
|
||||
#if INPUT_POINTER == 1
|
||||
int pointerX, pointerY;
|
||||
SDL_GetMouseState(&pointerX, &pointerY);
|
||||
|
||||
int windowWidth, windowHeight;
|
||||
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
|
||||
|
||||
INPUT.mouseX = (float_t)pointerX / (float_t)windowWidth;
|
||||
INPUT.mouseY = (float_t)pointerY / (float_t)windowHeight;
|
||||
#endif
|
||||
|
||||
#elif DOLPHIN
|
||||
PAD_ScanPads();
|
||||
|
||||
|
||||
@@ -5,4 +5,6 @@ LEFT,
|
||||
RIGHT,
|
||||
ACCEPT,
|
||||
CANCEL,
|
||||
RAGEQUIT
|
||||
RAGEQUIT
|
||||
POINTERX,
|
||||
POINTERY,
|
||||
|
@@ -43,6 +43,12 @@ typedef struct {
|
||||
const uint8_t *keyboardState;
|
||||
#endif
|
||||
|
||||
#if INPUT_POINTER == 1
|
||||
#if INPUT_SDL2 == 1
|
||||
float_t mouseX, mouseY;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif DOLPHIN
|
||||
int padState[INPUT_PAD_COUNT];
|
||||
float_t pads[INPUT_PAD_COUNT][INPUT_GAMEPAD_AXIS_COUNT];
|
||||
|
||||
@@ -31,9 +31,41 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = {
|
||||
{ .name = "lstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = false } } },
|
||||
{ .name = "lstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = true } } },
|
||||
{ .name = "lstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = false } } },
|
||||
#else
|
||||
{ .name = "a", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_A } },
|
||||
{ .name = "b", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_B } },
|
||||
{ .name = "x", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_X } },
|
||||
{ .name = "y", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_Y } },
|
||||
{ .name = "start", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_START } },
|
||||
{ .name = "back", { .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 = "l1", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_LEFTSHOULDER } },
|
||||
{ .name = "r1", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER } },
|
||||
{ .name = "l3", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_LEFTSTICK } },
|
||||
{ .name = "r3", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = SDL_CONTROLLER_BUTTON_RIGHTSTICK } },
|
||||
{ .name = "lstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = true } } },
|
||||
{ .name = "lstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = false } } },
|
||||
{ .name = "lstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = true } } },
|
||||
{ .name = "lstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = false } } },
|
||||
{ .name = "rstick_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTY, .positive = true } } },
|
||||
{ .name = "rstick_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTY, .positive = false } } },
|
||||
{ .name = "rstick_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTX, .positive = true } } },
|
||||
{ .name = "rstick_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_RIGHTX, .positive = false } } },
|
||||
{ .name = "l2", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_TRIGGERLEFT, .positive = true } } },
|
||||
{ .name = "r2", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_TRIGGERRIGHT, .positive = true } } },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if INPUT_POINTER == 1
|
||||
{ .name = "mouse_x", { .type = INPUT_BUTTON_TYPE_POINTER, .pointerAxis = INPUT_POINTER_AXIS_X } },
|
||||
{ .name = "mouse_y", { .type = INPUT_BUTTON_TYPE_POINTER, .pointerAxis = INPUT_POINTER_AXIS_Y } },
|
||||
// { .name = "mouse_wheel_x", { .type = INPUT_BUTTON_TYPE_POINTER, .pointerAxis = INPUT_POINTER_AXIS_WHEEL_X } },
|
||||
// { .name = "mouse_wheel_y", { .type = INPUT_BUTTON_TYPE_POINTER, .pointerAxis = INPUT_POINTER_AXIS_WHEEL_Y } },
|
||||
#endif
|
||||
|
||||
#if INPUT_KEYBOARD == 1
|
||||
{ .name = "a", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_A } },
|
||||
{ .name = "b", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_B } },
|
||||
@@ -229,6 +261,29 @@ float_t inputButtonGetValue(const inputbutton_t button) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if INPUT_POINTER == 1
|
||||
case INPUT_BUTTON_TYPE_POINTER: {
|
||||
switch(button.pointerAxis) {
|
||||
case INPUT_POINTER_AXIS_X:
|
||||
#if INPUT_SDL2 == 1
|
||||
return INPUT.mouseX;
|
||||
#endif
|
||||
return 0.0f;
|
||||
|
||||
case INPUT_POINTER_AXIS_Y:
|
||||
#if INPUT_SDL2 == 1
|
||||
return INPUT.mouseY;
|
||||
#endif
|
||||
return 0.0f;
|
||||
|
||||
default: {
|
||||
assertUnreachable("Unknown pointer axis");
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if INPUT_GAMEPAD == 1
|
||||
case INPUT_BUTTON_TYPE_GAMEPAD: {
|
||||
#if INPUT_SDL2 == 1
|
||||
|
||||
@@ -28,6 +28,13 @@
|
||||
#if INPUT_SDL2 == 1
|
||||
typedef SDL_GameControllerButton inputgamepadbutton_t;
|
||||
typedef SDL_GameControllerAxis inputgamepadaxis_t;
|
||||
typedef enum {
|
||||
INPUT_POINTER_AXIS_X,
|
||||
INPUT_POINTER_AXIS_Y,
|
||||
INPUT_POINTER_AXIS_Z,
|
||||
INPUT_POINTER_AXIS_WHEEL_X,
|
||||
INPUT_POINTER_AXIS_WHEEL_Y,
|
||||
} inputpointeraxis_t;
|
||||
#elif DOLPHIN == 1
|
||||
typedef u16 inputgamepadbutton_t;
|
||||
typedef enum {
|
||||
@@ -49,6 +56,14 @@ typedef enum {
|
||||
#if INPUT_KEYBOARD == 1
|
||||
INPUT_BUTTON_TYPE_KEYBOARD,
|
||||
#endif
|
||||
|
||||
#if INPUT_POINTER == 1
|
||||
INPUT_BUTTON_TYPE_POINTER,
|
||||
#endif
|
||||
|
||||
#if INPUT_TOUCH == 1
|
||||
INPUT_BUTTON_TYPE_TOUCH,
|
||||
#endif
|
||||
|
||||
#if INPUT_GAMEPAD == 1
|
||||
INPUT_BUTTON_TYPE_GAMEPAD,
|
||||
@@ -73,6 +88,10 @@ typedef struct {
|
||||
#if INPUT_KEYBOARD == 1
|
||||
inputscancode_t scancode;
|
||||
#endif
|
||||
|
||||
#if INPUT_POINTER == 1
|
||||
inputpointeraxis_t pointerAxis;
|
||||
#endif
|
||||
};
|
||||
} inputbutton_t;
|
||||
|
||||
|
||||
@@ -28,6 +28,11 @@ void moduleInput(scriptcontext_t *context) {
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
#if INPUT_POINTER == 1
|
||||
"INPUT_POINTER = true\n"
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
#if INPUT_SDL2 == 1
|
||||
"INPUT_SDL2 = true\n"
|
||||
#else
|
||||
@@ -51,6 +56,10 @@ void moduleInput(scriptcontext_t *context) {
|
||||
|
||||
// Bind methods
|
||||
lua_register(context->luaState, "inputBind", moduleInputBind);
|
||||
lua_register(context->luaState, "inputIsDown", moduleInputIsDown);
|
||||
lua_register(context->luaState, "inputPressed", moduleInputPressed);
|
||||
lua_register(context->luaState, "inputReleased", moduleInputReleased);
|
||||
lua_register(context->luaState, "inputGetValue", moduleInputGetValue);
|
||||
}
|
||||
|
||||
int moduleInputIndex(lua_State *l) {
|
||||
@@ -112,4 +121,79 @@ int moduleInputBind(lua_State *L) {
|
||||
|
||||
inputBind(btn, action);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int moduleInputIsDown(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be NULL");
|
||||
|
||||
if(!lua_isnumber(L, 1)) {
|
||||
luaL_error(L, "inputIsDown: Expected action ID as first argument");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const inputaction_t action = (inputaction_t)lua_tonumber(L, 1);
|
||||
|
||||
if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
luaL_error(L, "inputIsDown: Invalid action ID %d", action);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_pushboolean(L, inputIsDown(action));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int moduleInputPressed(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be NULL");
|
||||
|
||||
if(!lua_isnumber(L, 1)) {
|
||||
luaL_error(L, "inputPressed: Expected action ID as first argument");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const inputaction_t action = (inputaction_t)lua_tonumber(L, 1);
|
||||
|
||||
if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
luaL_error(L, "inputPressed: Invalid action ID %d", action);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_pushboolean(L, inputPressed(action));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int moduleInputReleased(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be NULL");
|
||||
|
||||
if(!lua_isnumber(L, 1)) {
|
||||
luaL_error(L, "inputReleased: Expected action ID as first argument");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const inputaction_t action = (inputaction_t)lua_tonumber(L, 1);
|
||||
|
||||
if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
luaL_error(L, "inputReleased: Invalid action ID %d", action);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_pushboolean(L, inputReleased(action));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int moduleInputGetValue(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be NULL");
|
||||
|
||||
if(!lua_isnumber(L, 1)) {
|
||||
luaL_error(L, "inputGetValue: Expected action ID as first argument");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const inputaction_t action = (inputaction_t)lua_tonumber(L, 1);
|
||||
if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
luaL_error(L, "inputGetValue: Invalid action ID %d", action);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_pushnumber(L, inputGetCurrentValue(action));
|
||||
return 1;
|
||||
}
|
||||
@@ -28,4 +28,36 @@ int moduleInputIndex(lua_State *l);
|
||||
* @param L The Lua state.
|
||||
* @return Number of return values on the Lua stack.
|
||||
*/
|
||||
int moduleInputBind(lua_State *L);
|
||||
int moduleInputBind(lua_State *L);
|
||||
|
||||
/**
|
||||
* Script binding for checking if an input action is currently pressed.
|
||||
*
|
||||
* @param L The Lua state.
|
||||
* @return Number of return values on the Lua stack.
|
||||
*/
|
||||
int moduleInputIsDown(lua_State *L);
|
||||
|
||||
/**
|
||||
* Script binding for checking if an input action was pressed this frame.
|
||||
*
|
||||
* @param L The Lua state.
|
||||
* @return Number of return values on the Lua stack.
|
||||
*/
|
||||
int moduleInputPressed(lua_State *L);
|
||||
|
||||
/**
|
||||
* Script binding for checking if an input action was released this frame.
|
||||
*
|
||||
* @param L The Lua state.
|
||||
* @return Number of return values on the Lua stack.
|
||||
*/
|
||||
int moduleInputReleased(lua_State *L);
|
||||
|
||||
/**
|
||||
* Script binding for getting the value of an input axis.
|
||||
*
|
||||
* @param L The Lua state.
|
||||
* @return Number of return values on the Lua stack.
|
||||
*/
|
||||
int moduleInputGetValue(lua_State *L);
|
||||
Reference in New Issue
Block a user