mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 07:59:42 +00:00
(UWP) Cleanups/style nits
(Joypad drivers) Cleanup/slim down axis code
This commit is contained in:
parent
8b200f552d
commit
5ae2b9f753
@ -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];
|
||||
break;
|
||||
}
|
||||
if(do_clamp) {
|
||||
|
||||
if (do_clamp)
|
||||
{
|
||||
if (data->is_negative && value > 0)
|
||||
return 0;
|
||||
if (!data->is_negative && value < 0)
|
||||
|
@ -77,13 +77,13 @@ static int16_t android_joypad_axis_state(
|
||||
{
|
||||
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)
|
||||
return val;
|
||||
}
|
||||
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)
|
||||
return val;
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
int val = 0;
|
||||
int axis = -1;
|
||||
bool is_neg = false;
|
||||
bool is_pos = false;
|
||||
|
||||
if (joyaxis == AXIS_NONE || port >= PS4_MAX_ORBISPADS)
|
||||
return 0;
|
||||
|
||||
if (AXIS_NEG_GET(joyaxis) < 4)
|
||||
{
|
||||
axis = AXIS_NEG_GET(joyaxis);
|
||||
is_neg = true;
|
||||
int16_t val = 0;
|
||||
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)
|
||||
{
|
||||
axis = AXIS_POS_GET(joyaxis);
|
||||
is_pos = true;
|
||||
int16_t val = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t ps4_joypad_state(
|
||||
@ -200,19 +202,19 @@ static int16_t ps4_joypad_state(
|
||||
int16_t ret = 0;
|
||||
uint16_t port_idx = joypad_info->joy_idx;
|
||||
|
||||
if (port_idx >= PS4_MAX_ORBISPADS)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||
if (port_idx < PS4_MAX_ORBISPADS)
|
||||
{
|
||||
/* Auto-binds are per joypad, not per user. */
|
||||
const uint64_t joykey = (binds[i].joykey != NO_BTN)
|
||||
? binds[i].joykey : joypad_info->auto_binds[i].joykey;
|
||||
if (
|
||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||
{
|
||||
/* Auto-binds are per joypad, not per user. */
|
||||
const uint64_t joykey = (binds[i].joykey != NO_BTN)
|
||||
? binds[i].joykey : joypad_info->auto_binds[i].joykey;
|
||||
if (
|
||||
(uint16_t)joykey != NO_BTN
|
||||
&& pad_state[port_idx] & (UINT64_C(1) << (uint16_t)joykey)
|
||||
)
|
||||
ret |= ( 1 << i);
|
||||
&& pad_state[port_idx] & (UINT64_C(1) << (uint16_t)joykey)
|
||||
)
|
||||
ret |= ( 1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
118
uwp/uwp_main.cpp
118
uwp/uwp_main.cpp
@ -829,43 +829,43 @@ extern "C" {
|
||||
|
||||
bool win32_get_metrics(void* data,
|
||||
enum display_metric_types type, float* value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DISPLAY_METRIC_PIXEL_WIDTH:
|
||||
*value = uwp_get_width();
|
||||
return true;
|
||||
case DISPLAY_METRIC_PIXEL_HEIGHT:
|
||||
*value = uwp_get_height();
|
||||
return true;
|
||||
case DISPLAY_METRIC_MM_WIDTH:
|
||||
/* 25.4 mm in an inch. */
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DISPLAY_METRIC_PIXEL_WIDTH:
|
||||
*value = uwp_get_width();
|
||||
return true;
|
||||
case DISPLAY_METRIC_PIXEL_HEIGHT:
|
||||
*value = uwp_get_height();
|
||||
return true;
|
||||
case DISPLAY_METRIC_MM_WIDTH:
|
||||
/* 25.4 mm in an inch. */
|
||||
{
|
||||
int pixels_x = DisplayInformation::GetForCurrentView()->ScreenWidthInRawPixels;
|
||||
int raw_dpi_x = DisplayInformation::GetForCurrentView()->RawDpiX;
|
||||
int physical_width = pixels_x / raw_dpi_x;
|
||||
*value = 254 * physical_width / 10;
|
||||
}
|
||||
return true;
|
||||
case DISPLAY_METRIC_MM_HEIGHT:
|
||||
/* 25.4 mm in an inch. */
|
||||
return true;
|
||||
case DISPLAY_METRIC_MM_HEIGHT:
|
||||
/* 25.4 mm in an inch. */
|
||||
{
|
||||
int pixels_y = DisplayInformation::GetForCurrentView()->ScreenHeightInRawPixels;
|
||||
int raw_dpi_y = DisplayInformation::GetForCurrentView()->RawDpiY;
|
||||
int physical_height = pixels_y / raw_dpi_y;
|
||||
*value = 254 * physical_height / 10;
|
||||
}
|
||||
return true;
|
||||
case DISPLAY_METRIC_DPI:
|
||||
*value = DisplayInformation::GetForCurrentView()->RawDpiX;
|
||||
return true;
|
||||
case DISPLAY_METRIC_NONE:
|
||||
default:
|
||||
*value = 0;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
case DISPLAY_METRIC_DPI:
|
||||
*value = DisplayInformation::GetForCurrentView()->RawDpiX;
|
||||
return true;
|
||||
case DISPLAY_METRIC_NONE:
|
||||
default:
|
||||
*value = 0;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void win32_check_window(void *data,
|
||||
bool *quit, bool *resize, unsigned *width, unsigned *height)
|
||||
@ -1099,50 +1099,50 @@ extern "C" {
|
||||
}
|
||||
|
||||
const char* uwp_get_cpu_model_name(void)
|
||||
{
|
||||
{
|
||||
/* TODO/FIXME - Xbox codepath should have a hardcoded CPU model name */
|
||||
if (is_running_on_xbox()) { }
|
||||
if (is_running_on_xbox()) { }
|
||||
else
|
||||
{
|
||||
Platform::String^ cpu_id = nullptr;
|
||||
Platform::String^ cpu_name = nullptr;
|
||||
{
|
||||
Platform::String^ cpu_id = nullptr;
|
||||
Platform::String^ cpu_name = nullptr;
|
||||
|
||||
/* GUID_DEVICE_PROCESSOR: {97FADB10-4E33-40AE-359C-8BEF029DBDD0} */
|
||||
Platform::String^ if_filter = L"System.Devices.InterfaceClassGuid:=\"{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}\"";
|
||||
|
||||
/* Enumerate all CPU DeviceInterfaces, and get DeviceInstanceID of the first one. */
|
||||
cpu_id = RunAsyncAndCatchErrors<Platform::String^>([&]() {
|
||||
return create_task(DeviceInformation::FindAllAsync(if_filter)).then(
|
||||
[&](DeviceInformationCollection^ collection)
|
||||
{
|
||||
return dynamic_cast<Platform::String^>(
|
||||
collection->GetAt(0)->Properties->Lookup(L"System.Devices.DeviceInstanceID"));
|
||||
});
|
||||
}, nullptr);
|
||||
/* Enumerate all CPU DeviceInterfaces, and get DeviceInstanceID of the first one. */
|
||||
cpu_id = RunAsyncAndCatchErrors<Platform::String^>([&]() {
|
||||
return create_task(DeviceInformation::FindAllAsync(if_filter)).then(
|
||||
[&](DeviceInformationCollection^ collection)
|
||||
{
|
||||
return dynamic_cast<Platform::String^>(
|
||||
collection->GetAt(0)->Properties->Lookup(L"System.Devices.DeviceInstanceID"));
|
||||
});
|
||||
}, nullptr);
|
||||
|
||||
if (cpu_id)
|
||||
{
|
||||
Platform::String^ dev_filter = L"System.Devices.DeviceInstanceID:=\"" + cpu_id + L"\"";
|
||||
if (cpu_id)
|
||||
{
|
||||
Platform::String^ dev_filter = L"System.Devices.DeviceInstanceID:=\"" + cpu_id + L"\"";
|
||||
|
||||
/* Get the Device with the same ID as the DeviceInterface
|
||||
* Then get the name (description) of that Device
|
||||
* We have to do this because the DeviceInterface we get doesn't have a proper description. */
|
||||
cpu_name = RunAsyncAndCatchErrors<Platform::String^>([&]() {
|
||||
return create_task(
|
||||
DeviceInformation::FindAllAsync(dev_filter, {}, DeviceInformationKind::Device)).then(
|
||||
[&](DeviceInformationCollection^ collection)
|
||||
{
|
||||
return cpu_name = collection->GetAt(0)->Name;
|
||||
});
|
||||
}, nullptr);
|
||||
}
|
||||
/* Get the Device with the same ID as the DeviceInterface
|
||||
* Then get the name (description) of that Device
|
||||
* We have to do this because the DeviceInterface we get doesn't have a proper description. */
|
||||
cpu_name = RunAsyncAndCatchErrors<Platform::String^>([&]() {
|
||||
return create_task(
|
||||
DeviceInformation::FindAllAsync(dev_filter, {}, DeviceInformationKind::Device)).then(
|
||||
[&](DeviceInformationCollection^ collection)
|
||||
{
|
||||
return cpu_name = collection->GetAt(0)->Name;
|
||||
});
|
||||
}, nullptr);
|
||||
}
|
||||
|
||||
if (cpu_name)
|
||||
if (cpu_name)
|
||||
{
|
||||
wcstombs(win32_cpu_model_name, cpu_name->Data(), sizeof(win32_cpu_model_name));
|
||||
return win32_cpu_model_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user