(UWP) Cleanups/style nits

(Joypad drivers) Cleanup/slim down axis code
This commit is contained in:
libretroadmin 2023-02-19 19:32:05 +01:00
parent 8b200f552d
commit 5ae2b9f753
4 changed files with 106 additions and 102 deletions

View File

@ -69,7 +69,9 @@ int16_t gamepad_get_axis_value_raw(int16_t state[3][2], axis_data *data, bool do
value = state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][0]; value = state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][0];
break; break;
} }
if(do_clamp) {
if (do_clamp)
{
if (data->is_negative && value > 0) if (data->is_negative && value > 0)
return 0; return 0;
if (!data->is_negative && value < 0) if (!data->is_negative && value < 0)

View File

@ -77,13 +77,13 @@ static int16_t android_joypad_axis_state(
{ {
if (AXIS_NEG_GET(joyaxis) < MAX_AXIS) if (AXIS_NEG_GET(joyaxis) < MAX_AXIS)
{ {
int val = android_app->analog_state[port][AXIS_NEG_GET(joyaxis)]; int16_t val = android_app->analog_state[port][AXIS_NEG_GET(joyaxis)];
if (val < 0) if (val < 0)
return val; return val;
} }
else if (AXIS_POS_GET(joyaxis) < MAX_AXIS) else if (AXIS_POS_GET(joyaxis) < MAX_AXIS)
{ {
int val = android_app->analog_state[port][AXIS_POS_GET(joyaxis)]; int16_t val = android_app->analog_state[port][AXIS_POS_GET(joyaxis)];
if (val > 0) if (val > 0)
return val; return val;
} }

View File

@ -152,43 +152,45 @@ static int32_t ps4_joypad_button(unsigned port, uint16_t joykey)
static int16_t ps4_joypad_axis(unsigned port, uint32_t joyaxis) static int16_t ps4_joypad_axis(unsigned port, uint32_t joyaxis)
{ {
int val = 0;
int axis = -1;
bool is_neg = false;
bool is_pos = false;
if (joyaxis == AXIS_NONE || port >= PS4_MAX_ORBISPADS) if (joyaxis == AXIS_NONE || port >= PS4_MAX_ORBISPADS)
return 0; return 0;
if (AXIS_NEG_GET(joyaxis) < 4) if (AXIS_NEG_GET(joyaxis) < 4)
{ {
axis = AXIS_NEG_GET(joyaxis); int16_t val = 0;
is_neg = true; int16_t axis = AXIS_NEG_GET(joyaxis);
switch (axis)
{
case 0:
case 1:
val = analog_state[port][0][axis];
break;
case 2:
case 3:
val = analog_state[port][1][axis - 2];
break;
}
if (val < 0)
return val;
} }
else if (AXIS_POS_GET(joyaxis) < 4) else if (AXIS_POS_GET(joyaxis) < 4)
{ {
axis = AXIS_POS_GET(joyaxis); int16_t val = 0;
is_pos = true; int16_t axis = AXIS_POS_GET(joyaxis);
switch (axis)
{
case 0:
case 1:
val = analog_state[port][0][axis];
break;
case 2:
case 3:
val = analog_state[port][1][axis - 2];
break;
}
if (val > 0)
return val;
} }
return 0;
switch (axis)
{
case 0:
case 1:
val = analog_state[port][0][axis];
break;
case 2:
case 3:
val = analog_state[port][1][axis - 2];
break;
}
if (is_neg && val > 0)
val = 0;
else if (is_pos && val < 0)
val = 0;
return val;
} }
static int16_t ps4_joypad_state( static int16_t ps4_joypad_state(
@ -200,19 +202,19 @@ static int16_t ps4_joypad_state(
int16_t ret = 0; int16_t ret = 0;
uint16_t port_idx = joypad_info->joy_idx; uint16_t port_idx = joypad_info->joy_idx;
if (port_idx >= PS4_MAX_ORBISPADS) if (port_idx < PS4_MAX_ORBISPADS)
return 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{ {
/* Auto-binds are per joypad, not per user. */ for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
const uint64_t joykey = (binds[i].joykey != NO_BTN) {
? binds[i].joykey : joypad_info->auto_binds[i].joykey; /* Auto-binds are per joypad, not per user. */
if ( const uint64_t joykey = (binds[i].joykey != NO_BTN)
? binds[i].joykey : joypad_info->auto_binds[i].joykey;
if (
(uint16_t)joykey != NO_BTN (uint16_t)joykey != NO_BTN
&& pad_state[port_idx] & (UINT64_C(1) << (uint16_t)joykey) && pad_state[port_idx] & (UINT64_C(1) << (uint16_t)joykey)
) )
ret |= ( 1 << i); ret |= ( 1 << i);
}
} }
return ret; return ret;

View File

@ -829,43 +829,43 @@ extern "C" {
bool win32_get_metrics(void* data, bool win32_get_metrics(void* data,
enum display_metric_types type, float* value) enum display_metric_types type, float* value)
{ {
switch (type) switch (type)
{ {
case DISPLAY_METRIC_PIXEL_WIDTH: case DISPLAY_METRIC_PIXEL_WIDTH:
*value = uwp_get_width(); *value = uwp_get_width();
return true; return true;
case DISPLAY_METRIC_PIXEL_HEIGHT: case DISPLAY_METRIC_PIXEL_HEIGHT:
*value = uwp_get_height(); *value = uwp_get_height();
return true; return true;
case DISPLAY_METRIC_MM_WIDTH: case DISPLAY_METRIC_MM_WIDTH:
/* 25.4 mm in an inch. */ /* 25.4 mm in an inch. */
{ {
int pixels_x = DisplayInformation::GetForCurrentView()->ScreenWidthInRawPixels; int pixels_x = DisplayInformation::GetForCurrentView()->ScreenWidthInRawPixels;
int raw_dpi_x = DisplayInformation::GetForCurrentView()->RawDpiX; int raw_dpi_x = DisplayInformation::GetForCurrentView()->RawDpiX;
int physical_width = pixels_x / raw_dpi_x; int physical_width = pixels_x / raw_dpi_x;
*value = 254 * physical_width / 10; *value = 254 * physical_width / 10;
} }
return true; return true;
case DISPLAY_METRIC_MM_HEIGHT: case DISPLAY_METRIC_MM_HEIGHT:
/* 25.4 mm in an inch. */ /* 25.4 mm in an inch. */
{ {
int pixels_y = DisplayInformation::GetForCurrentView()->ScreenHeightInRawPixels; int pixels_y = DisplayInformation::GetForCurrentView()->ScreenHeightInRawPixels;
int raw_dpi_y = DisplayInformation::GetForCurrentView()->RawDpiY; int raw_dpi_y = DisplayInformation::GetForCurrentView()->RawDpiY;
int physical_height = pixels_y / raw_dpi_y; int physical_height = pixels_y / raw_dpi_y;
*value = 254 * physical_height / 10; *value = 254 * physical_height / 10;
} }
return true; return true;
case DISPLAY_METRIC_DPI: case DISPLAY_METRIC_DPI:
*value = DisplayInformation::GetForCurrentView()->RawDpiX; *value = DisplayInformation::GetForCurrentView()->RawDpiX;
return true; return true;
case DISPLAY_METRIC_NONE: case DISPLAY_METRIC_NONE:
default: default:
*value = 0; *value = 0;
break; break;
} }
return false; return false;
} }
void win32_check_window(void *data, void win32_check_window(void *data,
bool *quit, bool *resize, unsigned *width, unsigned *height) bool *quit, bool *resize, unsigned *width, unsigned *height)
@ -1099,50 +1099,50 @@ extern "C" {
} }
const char* uwp_get_cpu_model_name(void) const char* uwp_get_cpu_model_name(void)
{ {
/* TODO/FIXME - Xbox codepath should have a hardcoded CPU model name */ /* TODO/FIXME - Xbox codepath should have a hardcoded CPU model name */
if (is_running_on_xbox()) { } if (is_running_on_xbox()) { }
else else
{ {
Platform::String^ cpu_id = nullptr; Platform::String^ cpu_id = nullptr;
Platform::String^ cpu_name = nullptr; Platform::String^ cpu_name = nullptr;
/* GUID_DEVICE_PROCESSOR: {97FADB10-4E33-40AE-359C-8BEF029DBDD0} */ /* GUID_DEVICE_PROCESSOR: {97FADB10-4E33-40AE-359C-8BEF029DBDD0} */
Platform::String^ if_filter = L"System.Devices.InterfaceClassGuid:=\"{97FADB10-4E33-40AE-359C-8BEF029DBDD0}\""; Platform::String^ if_filter = L"System.Devices.InterfaceClassGuid:=\"{97FADB10-4E33-40AE-359C-8BEF029DBDD0}\"";
/* Enumerate all CPU DeviceInterfaces, and get DeviceInstanceID of the first one. */ /* Enumerate all CPU DeviceInterfaces, and get DeviceInstanceID of the first one. */
cpu_id = RunAsyncAndCatchErrors<Platform::String^>([&]() { cpu_id = RunAsyncAndCatchErrors<Platform::String^>([&]() {
return create_task(DeviceInformation::FindAllAsync(if_filter)).then( return create_task(DeviceInformation::FindAllAsync(if_filter)).then(
[&](DeviceInformationCollection^ collection) [&](DeviceInformationCollection^ collection)
{ {
return dynamic_cast<Platform::String^>( return dynamic_cast<Platform::String^>(
collection->GetAt(0)->Properties->Lookup(L"System.Devices.DeviceInstanceID")); collection->GetAt(0)->Properties->Lookup(L"System.Devices.DeviceInstanceID"));
}); });
}, nullptr); }, nullptr);
if (cpu_id) if (cpu_id)
{ {
Platform::String^ dev_filter = L"System.Devices.DeviceInstanceID:=\"" + cpu_id + L"\""; Platform::String^ dev_filter = L"System.Devices.DeviceInstanceID:=\"" + cpu_id + L"\"";
/* Get the Device with the same ID as the DeviceInterface /* Get the Device with the same ID as the DeviceInterface
* Then get the name (description) of that Device * Then get the name (description) of that Device
* We have to do this because the DeviceInterface we get doesn't have a proper description. */ * We have to do this because the DeviceInterface we get doesn't have a proper description. */
cpu_name = RunAsyncAndCatchErrors<Platform::String^>([&]() { cpu_name = RunAsyncAndCatchErrors<Platform::String^>([&]() {
return create_task( return create_task(
DeviceInformation::FindAllAsync(dev_filter, {}, DeviceInformationKind::Device)).then( DeviceInformation::FindAllAsync(dev_filter, {}, DeviceInformationKind::Device)).then(
[&](DeviceInformationCollection^ collection) [&](DeviceInformationCollection^ collection)
{ {
return cpu_name = collection->GetAt(0)->Name; return cpu_name = collection->GetAt(0)->Name;
}); });
}, nullptr); }, nullptr);
} }
if (cpu_name) if (cpu_name)
{ {
wcstombs(win32_cpu_model_name, cpu_name->Data(), sizeof(win32_cpu_model_name)); wcstombs(win32_cpu_model_name, cpu_name->Data(), sizeof(win32_cpu_model_name));
return win32_cpu_model_name; return win32_cpu_model_name;
} }
} }
return "Unknown"; return "Unknown";
} }
} }