New input mapping complete!
This commit is contained in:
parent
5984352744
commit
ed1ed67292
3 changed files with 97 additions and 88 deletions
|
@ -346,10 +346,45 @@ GAMEPAD_3_MAX = GAMEPAD_1_MAX + 200
|
||||||
GAMEPAD_4_MIN = GAMEPAD_1_MAX + 300
|
GAMEPAD_4_MIN = GAMEPAD_1_MAX + 300
|
||||||
GAMEPAD_4_MAX = GAMEPAD_1_MAX + 300
|
GAMEPAD_4_MAX = GAMEPAD_1_MAX + 300
|
||||||
|
|
||||||
|
MOUSE_1 = {
|
||||||
|
BUTTON_LEFT = { name = "BUTTON_LEFT", value = 1000 },
|
||||||
|
BUTTON_RIGHT = { name = "BUTTON_RIGHT", value = 1001 },
|
||||||
|
BUTTON_MIDDLE = { name = "BUTTON_MIDDLE", value = 1002 },
|
||||||
|
BUTTON_X1 = { name = "BUTTON_X1", value = 1003 },
|
||||||
|
BUTTON_X2 = { name = "BUTTON_X2", value = 1004 },
|
||||||
|
WHEEL_UP = { name = "WHEEL_UP", value = 1005 },
|
||||||
|
WHEEL_DOWN = { name = "WHEEL_DOWN", value = 1006 }
|
||||||
|
}
|
||||||
|
|
||||||
|
MOUSE_1_MIN = 1000
|
||||||
|
MOUSE_1_MAX = 1006
|
||||||
|
|
||||||
|
MOUSE_2 = deepcopy(MOUSE_1)
|
||||||
|
MOUSE_3 = deepcopy(MOUSE_1)
|
||||||
|
MOUSE_4 = deepcopy(MOUSE_1)
|
||||||
|
|
||||||
|
for key, value in pairs(MOUSE_1) do
|
||||||
|
MOUSE_2[key].value = MOUSE_2[key].value + 100
|
||||||
|
MOUSE_3[key].value = MOUSE_3[key].value + 200
|
||||||
|
MOUSE_4[key].value = MOUSE_4[key].value + 300
|
||||||
|
end
|
||||||
|
|
||||||
|
MOUSE_2_MIN = MOUSE_1_MAX + 100
|
||||||
|
MOUSE_2_MAX = MOUSE_1_MAX + 100
|
||||||
|
|
||||||
|
MOUSE_3_MIN = MOUSE_1_MAX + 200
|
||||||
|
MOUSE_3_MAX = MOUSE_1_MAX + 200
|
||||||
|
|
||||||
|
MOUSE_4_MIN = MOUSE_1_MAX + 300
|
||||||
|
MOUSE_4_MAX = MOUSE_1_MAX + 300
|
||||||
|
|
||||||
SWITCH_BUTTON4 = 21
|
SWITCH_BUTTON4 = 21
|
||||||
SWITCH_TILT = 22
|
SWITCH_TILT = 22
|
||||||
SWITCH_GRAB = 23
|
SWITCH_GRAB = 23
|
||||||
|
|
||||||
|
MOUSE_SINGLE = 100
|
||||||
|
MOUSE_MANY = 200
|
||||||
|
|
||||||
|
|
||||||
-- Singe 1.xx Features
|
-- Singe 1.xx Features
|
||||||
|
|
||||||
|
@ -389,3 +424,6 @@ SOUND_ERROR_FULL = -2
|
||||||
|
|
||||||
OVERLAY_NOT_UPDATED = 0
|
OVERLAY_NOT_UPDATED = 0
|
||||||
OVERLAY_UPDATED = 1
|
OVERLAY_UPDATED = 1
|
||||||
|
|
||||||
|
SINGLE_MOUSE = 100
|
||||||
|
MANY_MOUSE = 200
|
||||||
|
|
|
@ -10,10 +10,10 @@ INPUT_1P_COIN = { SCANCODE.MAIN_5, SCANCODE.C, GAMEPAD_1.BUTTON_LEFT_BUMPER
|
||||||
INPUT_2P_COIN = { SCANCODE.MAIN_6 }
|
INPUT_2P_COIN = { SCANCODE.MAIN_6 }
|
||||||
INPUT_1P_START = { SCANCODE.MAIN_1, GAMEPAD_1.BUTTON_RIGHT_BUMPER }
|
INPUT_1P_START = { SCANCODE.MAIN_1, GAMEPAD_1.BUTTON_RIGHT_BUMPER }
|
||||||
INPUT_2P_START = { SCANCODE.MAIN_2 }
|
INPUT_2P_START = { SCANCODE.MAIN_2 }
|
||||||
INPUT_ACTION_1 = { SCANCODE.SPACE, SCANCODE.LCTRL, GAMEPAD_1.BUTTON_A }
|
INPUT_ACTION_1 = { SCANCODE.SPACE, SCANCODE.LCTRL, GAMEPAD_1.BUTTON_A, MOUSE_1.BUTTON_LEFT }
|
||||||
INPUT_ACTION_2 = { SCANCODE.LALT, GAMEPAD_1.BUTTON_B }
|
INPUT_ACTION_2 = { SCANCODE.LALT, GAMEPAD_1.BUTTON_B, MOUSE_1.BUTTON_RIGHT }
|
||||||
INPUT_ACTION_3 = { SCANCODE.LSHIFT, GAMEPAD_1.BUTTON_X }
|
INPUT_ACTION_3 = { SCANCODE.LSHIFT, GAMEPAD_1.BUTTON_X, MOUSE_1.BUTTON_MIDDLE }
|
||||||
INPUT_ACTION_4 = { SCANCODE.RSHIFT, GAMEPAD_1.BUTTON_Y }
|
INPUT_ACTION_4 = { SCANCODE.RSHIFT, GAMEPAD_1.BUTTON_Y, MOUSE_1.BUTTON_X1 }
|
||||||
INPUT_SKILL_EASY = { SCANCODE.KP_DIVIDE }
|
INPUT_SKILL_EASY = { SCANCODE.KP_DIVIDE }
|
||||||
INPUT_SKILL_MEDIUM = { SCANCODE.KP_MULTIPLY }
|
INPUT_SKILL_MEDIUM = { SCANCODE.KP_MULTIPLY }
|
||||||
INPUT_SKILL_HARD = { SCANCODE.KP_MINUS }
|
INPUT_SKILL_HARD = { SCANCODE.KP_MINUS }
|
||||||
|
|
135
singe/singe.c
135
singe/singe.c
|
@ -103,37 +103,6 @@ typedef struct MappingS {
|
||||||
} MappingT;
|
} MappingT;
|
||||||
|
|
||||||
|
|
||||||
//***TODO*** Replacing these with INPUT_* defines.
|
|
||||||
enum {
|
|
||||||
SWITCH_UP,
|
|
||||||
SWITCH_LEFT,
|
|
||||||
SWITCH_DOWN,
|
|
||||||
SWITCH_RIGHT,
|
|
||||||
SWITCH_START1,
|
|
||||||
SWITCH_START2,
|
|
||||||
SWITCH_BUTTON1,
|
|
||||||
SWITCH_BUTTON2,
|
|
||||||
SWITCH_BUTTON3,
|
|
||||||
SWITCH_COIN1,
|
|
||||||
SWITCH_COIN2,
|
|
||||||
SWITCH_SKILL1,
|
|
||||||
SWITCH_SKILL2,
|
|
||||||
SWITCH_SKILL3,
|
|
||||||
SWITCH_SERVICE,
|
|
||||||
SWITCH_TEST,
|
|
||||||
SWITCH_RESET,
|
|
||||||
SWITCH_SCREENSHOT,
|
|
||||||
SWITCH_QUIT,
|
|
||||||
SWITCH_PAUSE,
|
|
||||||
SWITCH_CONSOLE,
|
|
||||||
SWITCH_TILT,
|
|
||||||
SWITCH_GRAB,
|
|
||||||
SWITCH_MOUSE_SCROLL_UP,
|
|
||||||
SWITCH_MOUSE_SCROLL_DOWN,
|
|
||||||
SWITCH_MOUSE_DISCONNECT,
|
|
||||||
SWITCH_COUNT
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
KEYBD_NORMAL = 0,
|
KEYBD_NORMAL = 0,
|
||||||
KEYBD_FULL
|
KEYBD_FULL
|
||||||
|
@ -1596,6 +1565,8 @@ int32_t apiMouseSetMode(lua_State *L) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//utilSay("MouseMode now %d", _mouseMode);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
luaTrace(L, "mouseSetMode", "%d", _mouseMode);
|
luaTrace(L, "mouseSetMode", "%d", _mouseMode);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2138,15 +2109,16 @@ void processKey(bool down, int32_t keysym, int32_t scancode) {
|
||||||
int32_t move;
|
int32_t move;
|
||||||
int32_t index;
|
int32_t index;
|
||||||
|
|
||||||
utilSay("U:%d SY:%d SC:%d", down, keysym, scancode);
|
//utilSay("U:%d SY:%d SC:%d", down, keysym, scancode);
|
||||||
|
|
||||||
if (_keyboardMode == KEYBD_NORMAL) {
|
if (_keyboardMode == KEYBD_NORMAL) {
|
||||||
// Mappable keys
|
// Mappable keys
|
||||||
for (move=0; move<INPUT_COUNT; move++) {
|
for (move=0; move<INPUT_COUNT; move++) {
|
||||||
if (_controlMappings[move].inputCount > 0) {
|
if (_controlMappings[move].inputCount > 0) {
|
||||||
for (index=0; index<_controlMappings[move].inputCount; index++) {
|
for (index=0; index<_controlMappings[move].inputCount; index++) {
|
||||||
utilSay("Checking %s %d = %d", _controlMappings[move].name, _controlMappings[move].input[index], scancode);
|
//utilSay("Checking %s %d = %d", _controlMappings[move].name, _controlMappings[move].input[index], scancode);
|
||||||
if (_controlMappings[move].input[index] == scancode) {
|
if (_controlMappings[move].input[index] == scancode) {
|
||||||
|
//utilSay("Found %s %d", _controlMappings[move].name, _controlMappings[move].input[index]);
|
||||||
if (!down) {
|
if (!down) {
|
||||||
if ((move == INPUT_PAUSE) && (_pauseEnabled)) {
|
if ((move == INPUT_PAUSE) && (_pauseEnabled)) {
|
||||||
//***TODO*** g_game->toggle_game_pause();
|
//***TODO*** g_game->toggle_game_pause();
|
||||||
|
@ -2171,13 +2143,11 @@ void processKey(bool down, int32_t keysym, int32_t scancode) {
|
||||||
_requestScreenShot = true;
|
_requestScreenShot = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (move != INPUT_PAUSE) {
|
|
||||||
callLua(down ? "onInputPressed" : "onInputReleased", "ii", move, NOMOUSE);
|
callLua(down ? "onInputPressed" : "onInputReleased", "ii", move, NOMOUSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Full keyboard
|
// Full keyboard
|
||||||
callLua(down ? "onInputPressed" : "onInputReleased", "ii", keysym, NOMOUSE);
|
callLua(down ? "onInputPressed" : "onInputReleased", "ii", keysym, NOMOUSE);
|
||||||
|
@ -2211,14 +2181,6 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
ManyMouseEvent mouseEvent;
|
ManyMouseEvent mouseEvent;
|
||||||
MouseT *mouse = NULL;
|
MouseT *mouse = NULL;
|
||||||
int32_t mouseButtonMap[] = {
|
|
||||||
SWITCH_BUTTON1, // Left
|
|
||||||
SWITCH_BUTTON3, // Middle
|
|
||||||
SWITCH_BUTTON2, // Right
|
|
||||||
SWITCH_BUTTON1, // Wheel Up
|
|
||||||
SWITCH_BUTTON2, // Wheel Down
|
|
||||||
SWITCH_MOUSE_DISCONNECT
|
|
||||||
};
|
|
||||||
|
|
||||||
// Hang on to some SDL stuff
|
// Hang on to some SDL stuff
|
||||||
_window = window;
|
_window = window;
|
||||||
|
@ -2563,6 +2525,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_CONTROLLERBUTTONDOWN:
|
||||||
case SDL_CONTROLLERBUTTONUP:
|
case SDL_CONTROLLERBUTTONUP:
|
||||||
// Determine which "scancode" to process - see Framework.singe
|
// Determine which "scancode" to process - see Framework.singe
|
||||||
// Controller codes begin at 500 and increment in 100
|
// Controller codes begin at 500 and increment in 100
|
||||||
|
@ -2570,17 +2533,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
||||||
// The button values line up with the enumeration used by SDL + 18
|
// The button values line up with the enumeration used by SDL + 18
|
||||||
x += event.cbutton.button + 18;
|
x += event.cbutton.button + 18;
|
||||||
// Fire down event
|
// Fire down event
|
||||||
processKey(false, 0, x);
|
processKey((event.type == SDL_CONTROLLERBUTTONDOWN) ? true : false, 0, x);
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_CONTROLLERBUTTONDOWN:
|
|
||||||
// Determine which "scancode" to process - see Framework.singe
|
|
||||||
// Controller codes begin at 500 and increment in 100
|
|
||||||
x = event.cbutton.which * 100 + 500;
|
|
||||||
// The button values line up with the enumeration used by SDL + 18
|
|
||||||
x += event.cbutton.button + 18;
|
|
||||||
// Fire down event
|
|
||||||
processKey(true, 0, x);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_CONTROLLERDEVICEADDED:
|
case SDL_CONTROLLERDEVICEADDED:
|
||||||
|
@ -2590,11 +2543,8 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
processKey(true, event.key.keysym.sym, event.key.keysym.scancode);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
processKey(false, event.key.keysym.sym, event.key.keysym.scancode);
|
processKey((event.type == SDL_KEYDOWN) ? true : false, event.key.keysym.sym, event.key.keysym.scancode);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
|
@ -2608,20 +2558,39 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
for (x=0; x<MOUSE_ARRAY_SIZE; x++) {
|
case SDL_MOUSEBUTTONUP:
|
||||||
if (event.button.button == x) {
|
if ((_mouseEnabled) && (_mouseMode == MOUSE_SINGLE)) {
|
||||||
callLua("onInputPressed", "ii", mouseButtonMap[x], NOMOUSE);
|
// Mouse events start at "scancode" 1000
|
||||||
|
x = 1000;
|
||||||
|
// SDL maps buttons L,M,R,X1,X2 starting at 1
|
||||||
|
switch (event.button.button) {
|
||||||
|
case 2:
|
||||||
|
y = 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
y = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
y = event.button.button - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
x += y;
|
||||||
|
// Fire event
|
||||||
|
processKey((event.type == SDL_MOUSEBUTTONDOWN) ? true : false, 0, x);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEWHEEL:
|
||||||
for (x=0; x<MOUSE_ARRAY_SIZE; x++) {
|
if ((_mouseEnabled) && (_mouseMode == MOUSE_SINGLE)) {
|
||||||
if (event.button.button == x) {
|
// Mouse events start at "scancode" 1000
|
||||||
callLua("onInputReleased", "ii", mouseButtonMap[x], NOMOUSE);
|
x = 1000;
|
||||||
break;
|
// Scroll events start at 1005 and are mapped UP then DOWN
|
||||||
}
|
x += 5 + (event.wheel.y > 0 ? 0 : 1);
|
||||||
|
// Fire events
|
||||||
|
processKey(true, 0, x);
|
||||||
|
processKey(false, 0, x);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2679,19 +2648,24 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
||||||
y = (int32_t)(mouse->y * _overlayScaleY);
|
y = (int32_t)(mouse->y * _overlayScaleY);
|
||||||
xr = (int32_t)(mouse->relx * _overlayScaleX);
|
xr = (int32_t)(mouse->relx * _overlayScaleX);
|
||||||
yr = (int32_t)(mouse->relx * _overlayScaleY);
|
yr = (int32_t)(mouse->relx * _overlayScaleY);
|
||||||
utilSay("Mouse %d: Absolute %d, %d", mouseEvent.device, x, y);
|
//utilSay("Mouse %d: Absolute %d, %d", mouseEvent.device, x, y);
|
||||||
callLua("onMouseMoved", "iiiii", x, y, xr, yr, mouseEvent.device);
|
callLua("onMouseMoved", "iiiii", x, y, xr, yr, mouseEvent.device);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MANYMOUSE_EVENT_BUTTON:
|
case MANYMOUSE_EVENT_BUTTON:
|
||||||
if (mouseEvent.item < 32) {
|
if (mouseEvent.item < 5 /* 32 */) { // Limited to 5 buttons so it matches single-mouse mode
|
||||||
|
//utilSay("ManyMouse %d Button: %d", mouseEvent.device, mouseEvent.item);
|
||||||
|
// Mouse events start at "scancode" 1000 with 100 spacing
|
||||||
|
x = mouseEvent.device * 100 + 1000;
|
||||||
|
// ManyMouse maps buttons L,R,M,X1,X2 starting at 0
|
||||||
|
x += mouseEvent.item;
|
||||||
if (mouseEvent.value == 1) {
|
if (mouseEvent.value == 1) {
|
||||||
// Button pressed
|
// Button pressed
|
||||||
callLua("onInputPressed", "ii", mouseButtonMap[mouseEvent.item], mouseEvent.device);
|
processKey(true, 0, x);
|
||||||
mouse->buttons |= (1 << mouseEvent.item);
|
mouse->buttons |= (1 << mouseEvent.item);
|
||||||
} else {
|
} else {
|
||||||
// Button released
|
// Button released
|
||||||
callLua("onInputReleased", "ii", mouseButtonMap[mouseEvent.item], mouseEvent.device);
|
processKey(false, 0, x);
|
||||||
mouse->buttons &= ~(1 << mouseEvent.item);
|
mouse->buttons &= ~(1 << mouseEvent.item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2699,22 +2673,18 @@ void singe(SDL_Window *window, SDL_Renderer *renderer) {
|
||||||
|
|
||||||
case MANYMOUSE_EVENT_SCROLL:
|
case MANYMOUSE_EVENT_SCROLL:
|
||||||
if (mouseEvent.item == 0) {
|
if (mouseEvent.item == 0) {
|
||||||
if (mouseEvent.value > 0) {
|
// Mouse events start at "scancode" 1000 with 100 spacing
|
||||||
// Scroll up
|
x = mouseEvent.device * 100 + 1000;
|
||||||
callLua("onInputPressed", "ii", SWITCH_MOUSE_SCROLL_UP, mouseEvent.device);
|
// Scroll events start at 1005 and are mapped UP then DOWN
|
||||||
callLua("onInputReleased", "ii", SWITCH_MOUSE_SCROLL_UP, mouseEvent.device);
|
x += 5 + (mouseEvent.value > 0 ? 0 : 1);
|
||||||
} else {
|
// Fire events
|
||||||
// Scroll down
|
processKey(true, 0, x);
|
||||||
callLua("onInputPressed", "ii", SWITCH_MOUSE_SCROLL_DOWN, mouseEvent.device);
|
processKey(false, 0, x);
|
||||||
callLua("onInputReleased", "ii", SWITCH_MOUSE_SCROLL_DOWN, mouseEvent.device);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MANYMOUSE_EVENT_DISCONNECT:
|
case MANYMOUSE_EVENT_DISCONNECT:
|
||||||
mouse->connected = false;
|
mouse->connected = false;
|
||||||
callLua("onInputPressed", "ii", SWITCH_MOUSE_DISCONNECT, mouseEvent.device);
|
|
||||||
callLua("onInputReleased", "ii", SWITCH_MOUSE_DISCONNECT, mouseEvent.device);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MANYMOUSE_EVENT_MAX:
|
case MANYMOUSE_EVENT_MAX:
|
||||||
|
@ -2912,6 +2882,7 @@ void takeScreenshot(void) {
|
||||||
surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 32, 0, 0, 0, 0);
|
surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 32, 0, 0, 0, 0);
|
||||||
if (!surface) utilDie("%s", SDL_GetError());
|
if (!surface) utilDie("%s", SDL_GetError());
|
||||||
if (SDL_RenderReadPixels(_renderer, NULL, surface->format->format, surface->pixels, surface->pitch) != 0) utilDie("%s", SDL_GetError());
|
if (SDL_RenderReadPixels(_renderer, NULL, surface->format->format, surface->pixels, surface->pitch) != 0) utilDie("%s", SDL_GetError());
|
||||||
|
//***FIX*** This crashes with a SEGFAULT sometimes. Not sure why.
|
||||||
if (IMG_SavePNG(surface, filename) < 0) utilDie("%s", IMG_GetError());
|
if (IMG_SavePNG(surface, filename) < 0) utilDie("%s", IMG_GetError());
|
||||||
SDL_FreeSurface(surface);
|
SDL_FreeSurface(surface);
|
||||||
free(pixels);
|
free(pixels);
|
||||||
|
|
Loading…
Add table
Reference in a new issue