add input_mapper scafolding

This commit is contained in:
radius 2017-09-07 22:30:42 -05:00
parent 0af92cc92e
commit fe8a0657b4
15 changed files with 237 additions and 18 deletions

View File

@ -1441,6 +1441,10 @@ ifeq ($(HAVE_NETWORKING), 1)
endif
endif
ifeq ($(HAVE_KEYMAPPER), 1)
OBJ += input/input_mapper.o
endif
ifeq ($(HAVE_NETWORKGAMEPAD), 1)
OBJ += input/input_remote.o \
cores/libretro-net-retropad/net_retropad_core.o

View File

@ -2491,6 +2491,14 @@ TODO: Add a setting for these tweaks */
command_event(CMD_EVENT_REMOTE_DEINIT, NULL);
input_driver_init_remote();
break;
case CMD_EVENT_MAPPER_DEINIT:
input_driver_deinit_mapper();
break;
case CMD_EVENT_MAPPER_INIT:
command_event(CMD_EVENT_MAPPER_DEINIT, NULL);
input_driver_init_mapper();
break;
case CMD_EVENT_LOG_FILE_DEINIT:
retro_main_log_file_deinit();
break;

View File

@ -193,6 +193,10 @@ enum event_command
CMD_EVENT_REMOTE_INIT,
/* Deinitializes remote gamepad interface. */
CMD_EVENT_REMOTE_DEINIT,
/* Initializes keyboard to gamepad mapper interface. */
CMD_EVENT_MAPPER_INIT,
/* Deinitializes keyboard to gamepad mapper interface. */
CMD_EVENT_MAPPER_DEINIT,
/* Reinitializes audio driver. */
CMD_EVENT_AUDIO_REINIT,
/* Resizes windowed scale. Will reinitialize video driver. */

View File

@ -1241,6 +1241,9 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings,
#ifdef HAVE_NETWORKGAMEPAD
SETTING_BOOL("network_remote_enable", &settings->bools.network_remote_enable, false, false /* TODO */, false);
#endif
#ifdef HAVE_KEYMAPPER
SETTING_BOOL("keyboard_mapper_enable", &settings->bools.keyboard_mapper_enable, false, false /* TODO */, false);
#endif
#ifdef HAVE_NETWORKING
SETTING_BOOL("netplay_nat_traversal", &settings->bools.netplay_nat_traversal, true, true, false);
#endif
@ -1343,6 +1346,9 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings,
#ifdef HAVE_NETWORKGAMEPAD
SETTING_UINT("network_remote_base_port", &settings->uints.network_remote_base_port, true, network_remote_base_port, false);
#endif
#ifdef HAVE_KEYMAPPER
SETTING_UINT("keyboard_mapper_port", &settings->uints.keyboard_mapper_port, true, network_remote_base_port, false);
#endif
#ifdef GEKKO
SETTING_UINT("video_viwidth", &settings->uints.video_viwidth, true, video_viwidth, false);
#endif

View File

@ -199,6 +199,7 @@ typedef struct settings
bool savestate_thumbnail_enable;
bool network_cmd_enable;
bool stdin_cmd_enable;
bool keyboard_mapper_enable;
bool network_remote_enable;
bool network_remote_enable_user[MAX_USERS];
bool load_dummy_on_core_shutdown;
@ -303,6 +304,7 @@ typedef struct settings
unsigned autosave_interval;
unsigned network_cmd_port;
unsigned network_remote_base_port;
unsigned keyboard_mapper_port;
unsigned video_window_x;
unsigned video_window_y;
unsigned video_monitor_index;

View File

@ -1097,6 +1097,10 @@ MENU
#include "../cores/libretro-net-retropad/net_retropad_core.c"
#endif
#ifdef HAVE_KEYMAPPER
#include "../input/input_mapper.c"
#endif
#include "../command.c"
#ifdef __cplusplus

View File

@ -34,6 +34,10 @@
#include "input_remote.h"
#endif
#ifdef HAVE_KEYMAPPER
#include "input_mapper.h"
#endif
#include "input_driver.h"
#include "input_keymaps.h"
#include "input_remapping.h"
@ -346,6 +350,9 @@ static command_t *input_driver_command = NULL;
#ifdef HAVE_NETWORKGAMEPAD
static input_remote_t *input_driver_remote = NULL;
#endif
#ifdef HAVE_KEYMAPPER
static input_mapper_t *input_driver_mapper = NULL;
#endif
const input_driver_t *current_input = NULL;
void *current_input_data = NULL;
static bool input_driver_block_hotkey = false;
@ -1327,6 +1334,15 @@ void input_driver_deinit_remote(void)
#endif
}
void input_driver_deinit_mapper(void)
{
#ifdef HAVE_NETWORKGAMEPAD
if (input_driver_mapper)
input_mapper_free(input_driver_mapper);
input_driver_mapper = NULL;
#endif
}
bool input_driver_init_remote(void)
{
#ifdef HAVE_NETWORKGAMEPAD
@ -1347,6 +1363,26 @@ bool input_driver_init_remote(void)
return false;
}
bool input_driver_init_mapper(void)
{
#ifdef HAVE_KEYMAPPER
settings_t *settings = config_get_ptr();
if (!settings->bools.keyboard_mapper_enable)
return false;
input_driver_mapper = input_mapper_new(
settings->uints.keyboard_mapper_port);
if (input_driver_mapper)
return true;
RARCH_ERR("Failed to initialize input mapper.\n");
#endif
return false;
}
bool input_driver_grab_mouse(void)
{
if (!current_input || !current_input->grab_mouse)

View File

@ -397,6 +397,10 @@ void input_driver_deinit_remote(void);
bool input_driver_init_remote(void);
void input_driver_deinit_mapper(void);
bool input_driver_init_mapper(void);
bool input_driver_grab_mouse(void);
bool input_driver_ungrab_mouse(void);

96
input/input_mapper.c Normal file
View File

@ -0,0 +1,96 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Andrés Suárez
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif
#include <compat/strl.h>
#include <compat/posix_string.h>
#include <file/file_path.h>
#include <retro_miscellaneous.h>
#include <libretro.h>
#include <net/net_compat.h>
#include <net/net_socket.h>
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include "input_mapper.h"
#include "../configuration.h"
#include "../msg_hash.h"
#include "../verbosity.h"
struct input_mapper
{
#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD)
int net_fd[MAX_USERS];
#endif
bool state[RARCH_BIND_LIST_END];
};
typedef struct input_mapper_state
{
/* This is a bitmask of (1 << key_bind_id). */
uint64_t buttons;
/* Left X, Left Y, Right X, Right Y */
int16_t analog[4];
/* the whole keyboard state */
uint32_t keys[RETROK_LAST / 32 + 1];
} input_mapper_state_t;
input_mapper_t *input_mapper_new(uint16_t port)
{
return NULL;
}
void input_mapper_free(input_mapper_t *handle)
{
return;
}
void input_mapper_poll(input_mapper_t *handle, unsigned max_users)
{
return;
}
bool input_mapper_key_pressed(int key, unsigned port)
{
return false;
}
void input_mapper_state(
int16_t *ret,
unsigned port,
unsigned device,
unsigned idx,
unsigned id)
{
return;
}

51
input/input_mapper.h Normal file
View File

@ -0,0 +1,51 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Andrés Suárez
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INPUT_MAPPER_H__
#define INPUT_MAPPER_H__
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdint.h>
#include <boolean.h>
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
typedef struct input_mapper input_mapper_t;
input_mapper_t *input_mapper_new(uint16_t port);
void input_mapper_free(input_mapper_t *handle);
void input_mapper_poll(input_mapper_t *handle, unsigned max_users);
bool input_mapper_key_pressed(int key, unsigned port);
void input_mapper_state(
int16_t *ret,
unsigned port,
unsigned device,
unsigned idx,
unsigned id);
RETRO_END_DECLS
#endif

View File

@ -1,6 +1,6 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2015-2017 - Andrés Suárez
* Copyright (C) 2016-2017 - Andrés Suárez
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-

View File

@ -1,5 +1,6 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2017 - Andrés Suárez
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-

View File

@ -169,18 +169,18 @@ void input_remote_free(input_remote_t *handle, unsigned max_users)
#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD)
static void input_remote_parse_packet(struct remote_message *msg, unsigned user)
{
input_remote_state_t *ol_state = input_remote_get_state_ptr();
input_remote_state_t *input_state = input_remote_get_state_ptr();
/* Parse message */
switch (msg->device)
{
case RETRO_DEVICE_JOYPAD:
ol_state->buttons[user] &= ~(1 << msg->id);
input_state->buttons[user] &= ~(1 << msg->id);
if (msg->state)
ol_state->buttons[user] |= 1 << msg->id;
input_state->buttons[user] |= 1 << msg->id;
break;
case RETRO_DEVICE_ANALOG:
ol_state->analog[msg->index * 2 + msg->id][user] = msg->state;
input_state->analog[msg->index * 2 + msg->id][user] = msg->state;
break;
}
}
@ -202,17 +202,17 @@ void input_remote_state(
case RETRO_DEVICE_ANALOG:
{
unsigned base = 0;
input_remote_state_t *ol_state = input_remote_get_state_ptr();
input_remote_state_t *input_state = input_remote_get_state_ptr();
if (!ol_state)
if (!input_state)
return;
if (idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT)
base = 2;
if (id == RETRO_DEVICE_ID_ANALOG_Y)
base += 1;
if (ol_state && ol_state->analog[base][port])
*ret = ol_state->analog[base][port];
if (input_state && input_state->analog[base][port])
*ret = input_state->analog[base][port];
}
break;
}
@ -220,19 +220,19 @@ void input_remote_state(
bool input_remote_key_pressed(int key, unsigned port)
{
input_remote_state_t *ol_state = input_remote_get_state_ptr();
input_remote_state_t *input_state = input_remote_get_state_ptr();
if (!ol_state)
if (!input_state)
return false;
return (ol_state->buttons[port] & (UINT64_C(1) << key));
return (input_state->buttons[port] & (UINT64_C(1) << key));
}
void input_remote_poll(input_remote_t *handle, unsigned max_users)
{
unsigned user;
settings_t *settings = config_get_ptr();
input_remote_state_t *ol_state = input_remote_get_state_ptr();
input_remote_state_t *input_state = input_remote_get_state_ptr();
for(user = 0; user < max_users; user++)
{
@ -257,11 +257,11 @@ void input_remote_poll(input_remote_t *handle, unsigned max_users)
else if ((ret != -1) || ((errno != EAGAIN) && (errno != ENOENT)))
#endif
{
ol_state->buttons[user] = 0;
ol_state->analog[0][user] = 0;
ol_state->analog[1][user] = 0;
ol_state->analog[2][user] = 0;
ol_state->analog[3][user] = 0;
input_state->buttons[user] = 0;
input_state->analog[0][user] = 0;
input_state->analog[1][user] = 0;
input_state->analog[2][user] = 0;
input_state->analog[3][user] = 0;
}
}
}

View File

@ -28,6 +28,7 @@ HAVE_SSA=auto # SSA/ASS for FFmpeg subtitle support
HAVE_DYLIB=auto # Dynamic loading support
HAVE_NETWORKING=auto # Networking features (recommended)
HAVE_NETWORKGAMEPAD=auto # Networked game pad (plus baked-in core)
HAVE_KEYMAPPER=yes # Networked game pad (plus baked-in core)
C89_NETWORKGAMEPAD=no
HAVE_MINIUPNPC=auto # Mini UPnP client library (for NAT traversal)
HAVE_BUILTINMINIUPNPC=yes # Bake in Mini UPnP client library (for NAT traversal)

View File

@ -1289,6 +1289,7 @@ bool retroarch_main_init(int argc, char *argv[])
drivers_init(DRIVERS_CMD_ALL);
command_event(CMD_EVENT_COMMAND_INIT, NULL);
command_event(CMD_EVENT_REMOTE_INIT, NULL);
command_event(CMD_EVENT_MAPPER_INIT, NULL);
command_event(CMD_EVENT_REWIND_INIT, NULL);
command_event(CMD_EVENT_CONTROLLERS_INIT, NULL);
command_event(CMD_EVENT_RECORD_INIT, NULL);
@ -1455,6 +1456,7 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
command_event(CMD_EVENT_COMMAND_DEINIT, NULL);
command_event(CMD_EVENT_REMOTE_DEINIT, NULL);
command_event(CMD_EVENT_MAPPER_DEINIT, NULL);
command_event(CMD_EVENT_AUTOSAVE_DEINIT, NULL);