Misc: Necessary emucore changes for Android

This commit is contained in:
Connor McLaughlin 2022-08-05 17:05:18 +10:00
parent bdb486ccaa
commit 25d2148ae4
6 changed files with 91 additions and 5 deletions

View File

@ -48,6 +48,8 @@
Log_SetChannel(FileSystem); Log_SetChannel(FileSystem);
#ifndef __ANDROID__
#ifdef _WIN32 #ifdef _WIN32
static std::time_t ConvertFileTimeToUnixTime(const FILETIME& ft) static std::time_t ConvertFileTimeToUnixTime(const FILETIME& ft)
{ {
@ -753,6 +755,8 @@ int FileSystem::OpenFDFile(const char* filename, int flags, int mode)
#endif #endif
} }
#endif
FileSystem::ManagedCFilePtr FileSystem::OpenManagedCFile(const char* filename, const char* mode) FileSystem::ManagedCFilePtr FileSystem::OpenManagedCFile(const char* filename, const char* mode)
{ {
return ManagedCFilePtr(OpenCFile(filename, mode), [](std::FILE* fp) { std::fclose(fp); }); return ManagedCFilePtr(OpenCFile(filename, mode), [](std::FILE* fp) { std::fclose(fp); });
@ -1625,7 +1629,7 @@ bool FileSystem::SetPathCompression(const char* path, bool enable)
return result; return result;
} }
#else #elif !defined(__ANDROID__)
static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, const char* Path, const char* Pattern, static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, const char* Path, const char* Pattern,
u32 Flags, FileSystem::FindResultsArray* pResults) u32 Flags, FileSystem::FindResultsArray* pResults)

View File

@ -410,8 +410,13 @@ struct Settings
static constexpr LOGLEVEL DEFAULT_LOG_LEVEL = LOGLEVEL_INFO; static constexpr LOGLEVEL DEFAULT_LOG_LEVEL = LOGLEVEL_INFO;
#ifndef __ANDROID__
static constexpr u32 DEFAULT_AUDIO_BUFFER_MS = 50; static constexpr u32 DEFAULT_AUDIO_BUFFER_MS = 50;
static constexpr u32 DEFAULT_AUDIO_OUTPUT_LATENCY_MS = 20; static constexpr u32 DEFAULT_AUDIO_OUTPUT_LATENCY_MS = 20;
#else
static constexpr u32 DEFAULT_AUDIO_BUFFER_MS = 100;
static constexpr u32 DEFAULT_AUDIO_OUTPUT_LATENCY_MS = 20;
#endif
static constexpr AudioStretchMode DEFAULT_AUDIO_STRETCH_MODE = AudioStretchMode::TimeStretch; static constexpr AudioStretchMode DEFAULT_AUDIO_STRETCH_MODE = AudioStretchMode::TimeStretch;
// Enable console logging by default on Linux platforms. // Enable console logging by default on Linux platforms.

View File

@ -131,6 +131,8 @@ void CommonHost::ReleaseHostDisplayResources()
SaveStateSelectorUI::DestroyTextures(); SaveStateSelectorUI::DestroyTextures();
} }
#ifndef __ANDROID__
std::unique_ptr<AudioStream> Host::CreateAudioStream(AudioBackend backend, u32 sample_rate, u32 channels, u32 buffer_ms, std::unique_ptr<AudioStream> Host::CreateAudioStream(AudioBackend backend, u32 sample_rate, u32 channels, u32 buffer_ms,
u32 latency_ms, AudioStretchMode stretch) u32 latency_ms, AudioStretchMode stretch)
{ {
@ -154,6 +156,8 @@ std::unique_ptr<AudioStream> Host::CreateAudioStream(AudioBackend backend, u32 s
} }
} }
#endif
void CommonHost::UpdateLogSettings() void CommonHost::UpdateLogSettings()
{ {
Log::SetFilterLevel(g_settings.log_level); Log::SetFilterLevel(g_settings.log_level);

View File

@ -101,6 +101,8 @@ static std::optional<InputBindingKey> ParseHostKeyboardKey(const std::string_vie
const std::string_view& sub_binding); const std::string_view& sub_binding);
static std::optional<InputBindingKey> ParsePointerKey(const std::string_view& source, static std::optional<InputBindingKey> ParsePointerKey(const std::string_view& source,
const std::string_view& sub_binding); const std::string_view& sub_binding);
static std::optional<InputBindingKey> ParseSensorKey(const std::string_view& source,
const std::string_view& sub_binding);
static std::vector<std::string_view> SplitChord(const std::string_view& binding); static std::vector<std::string_view> SplitChord(const std::string_view& binding);
static bool SplitBinding(const std::string_view& binding, std::string_view* source, std::string_view* sub_binding); static bool SplitBinding(const std::string_view& binding, std::string_view* source, std::string_view* sub_binding);
@ -120,7 +122,6 @@ static bool PreprocessEvent(InputBindingKey key, float value, GenericInputBindin
static void LoadMacroButtonConfig(SettingsInterface& si, const std::string& section, u32 pad, static void LoadMacroButtonConfig(SettingsInterface& si, const std::string& section, u32 pad,
const Controller::ControllerInfo* cinfo); const Controller::ControllerInfo* cinfo);
static void SetMacroButtonState(u32 pad, u32 index, bool state);
static void ApplyMacroButton(u32 pad, const MacroButton& mb); static void ApplyMacroButton(u32 pad, const MacroButton& mb);
static void UpdateMacroButtons(); static void UpdateMacroButtons();
} // namespace InputManager } // namespace InputManager
@ -162,6 +163,7 @@ static constexpr const std::array<const char*, static_cast<u8>(InputPointerAxis:
{"X", "Y", "WheelX", "WheelY"}}; {"X", "Y", "WheelX", "WheelY"}};
static constexpr const std::array<const char*, 3> s_pointer_button_names = { static constexpr const std::array<const char*, 3> s_pointer_button_names = {
{"LeftButton", "RightButton", "MiddleButton"}}; {"LeftButton", "RightButton", "MiddleButton"}};
static constexpr const std::array<const char*, 3> s_sensor_accelerometer_names = {{"Turn", "Tilt", "Rotate"}};
struct PointerAxisState struct PointerAxisState
{ {
@ -239,6 +241,10 @@ std::optional<InputBindingKey> InputManager::ParseInputBindingKey(const std::str
{ {
return ParsePointerKey(source, sub_binding); return ParsePointerKey(source, sub_binding);
} }
else if (StringUtil::StartsWith(source, "Sensor"))
{
return ParseSensorKey(source, sub_binding);
}
else else
{ {
for (u32 i = FIRST_EXTERNAL_INPUT_SOURCE; i < LAST_EXTERNAL_INPUT_SOURCE; i++) for (u32 i = FIRST_EXTERNAL_INPUT_SOURCE; i < LAST_EXTERNAL_INPUT_SOURCE; i++)
@ -301,6 +307,11 @@ std::string InputManager::ConvertInputBindingKeyToString(InputBindingKey key)
key.negative ? '-' : '+'); key.negative ? '-' : '+');
} }
} }
else if (key.source_type == InputSourceType::Sensor)
{
if (key.source_subtype == InputSubclass::SensorAccelerometer && key.data < s_sensor_accelerometer_names.size())
return fmt::format("Sensor/{}", s_sensor_accelerometer_names[key.data]);
}
else if (key.source_type < InputSourceType::Count && s_input_sources[static_cast<u32>(key.source_type)]) else if (key.source_type < InputSourceType::Count && s_input_sources[static_cast<u32>(key.source_type)])
{ {
return s_input_sources[static_cast<u32>(key.source_type)]->ConvertKeyToString(key); return s_input_sources[static_cast<u32>(key.source_type)]->ConvertKeyToString(key);
@ -403,23 +414,35 @@ InputBindingKey InputManager::MakePointerAxisKey(u32 index, InputPointerAxis axi
return key; return key;
} }
InputBindingKey InputManager::MakeSensorAxisKey(InputSubclass sensor, u32 axis)
{
InputBindingKey key = {};
key.data = static_cast<u32>(axis);
key.source_index = 0;
key.source_type = InputSourceType::Sensor;
key.source_subtype = sensor;
return key;
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Bind Encoders // Bind Encoders
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
static std::array<const char*, static_cast<u32>(InputSourceType::Count)> s_input_class_names = {{ static std::array<const char*, static_cast<u32>(InputSourceType::Count)> s_input_class_names = {{
"Keyboard", "Keyboard",
"Mouse", "Pointer",
"Sensor",
#ifdef _WIN32 #ifdef _WIN32
"DInput", "DInput",
"XInput", "XInput",
#endif
#if defined(_WIN32)
"RawInput", "RawInput",
#endif #endif
#ifdef WITH_SDL2 #ifdef WITH_SDL2
"SDL", "SDL",
#endif #endif
#ifdef __ANDROID__
"Android",
#endif
}}; }};
InputSource* InputManager::GetInputSourceInterface(InputSourceType type) InputSource* InputManager::GetInputSourceInterface(InputSourceType type)
@ -513,6 +536,38 @@ std::optional<InputBindingKey> InputManager::ParsePointerKey(const std::string_v
return std::nullopt; return std::nullopt;
} }
std::optional<InputBindingKey> InputManager::ParseSensorKey(const std::string_view& source,
const std::string_view& sub_binding)
{
if (source != "Sensor")
return std::nullopt;
InputBindingKey key = {};
key.source_type = InputSourceType::Sensor;
key.source_index = 0;
for (u32 i = 0; i < s_sensor_accelerometer_names.size(); i++)
{
if (StringUtil::StartsWith(sub_binding, s_sensor_accelerometer_names[i]))
{
key.source_subtype = InputSubclass::SensorAccelerometer;
key.data = i;
const std::string_view dir_part(sub_binding.substr(std::strlen(s_pointer_axis_names[i])));
if (dir_part == "+")
key.negative = false;
else if (dir_part == "-")
key.negative = true;
else
return std::nullopt;
return key;
}
}
return std::nullopt;
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Binding Enumeration // Binding Enumeration
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -1470,4 +1525,7 @@ void InputManager::ReloadSources(SettingsInterface& si, std::unique_lock<std::mu
#ifdef WITH_SDL2 #ifdef WITH_SDL2
UpdateInputSourceState(si, settings_lock, InputSourceType::SDL, &InputSource::CreateSDLSource, true); UpdateInputSourceState(si, settings_lock, InputSourceType::SDL, &InputSource::CreateSDLSource, true);
#endif #endif
#ifdef __ANDROID__
UpdateInputSourceState(si, settings_lock, InputSourceType::Android, &InputSource::CreateAndroidSource, true);
#endif
} }

View File

@ -15,6 +15,7 @@ enum class InputSourceType : u32
{ {
Keyboard, Keyboard,
Pointer, Pointer,
Sensor,
#ifdef _WIN32 #ifdef _WIN32
DInput, DInput,
XInput, XInput,
@ -22,6 +23,9 @@ enum class InputSourceType : u32
#endif #endif
#ifdef WITH_SDL2 #ifdef WITH_SDL2
SDL, SDL,
#endif
#ifdef __ANDROID__
Android,
#endif #endif
Count, Count,
}; };
@ -38,6 +42,8 @@ enum class InputSubclass : u32
ControllerAxis = 1, ControllerAxis = 1,
ControllerMotor = 2, ControllerMotor = 2,
ControllerHaptic = 3, ControllerHaptic = 3,
SensorAccelerometer = 0,
}; };
/// A composite type representing a full input key which is part of an event. /// A composite type representing a full input key which is part of an event.
@ -173,6 +179,9 @@ InputBindingKey MakePointerButtonKey(u32 index, u32 button_index);
/// (axis 0 = horizontal, 1 = vertical, 2 = wheel horizontal, 3 = wheel vertical). /// (axis 0 = horizontal, 1 = vertical, 2 = wheel horizontal, 3 = wheel vertical).
InputBindingKey MakePointerAxisKey(u32 index, InputPointerAxis axis); InputBindingKey MakePointerAxisKey(u32 index, InputPointerAxis axis);
/// Creates a key for a host-specific sensor.
InputBindingKey MakeSensorAxisKey(InputSubclass sensor, u32 axis);
/// Parses an input binding key string. /// Parses an input binding key string.
std::optional<InputBindingKey> ParseInputBindingKey(const std::string_view& binding); std::optional<InputBindingKey> ParseInputBindingKey(const std::string_view& binding);
@ -243,6 +252,9 @@ void UpdatePointerAbsolutePosition(u32 index, float x, float y);
/// reporting. /// reporting.
void UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis, float d, bool raw_input = false); void UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis, float d, bool raw_input = false);
/// Sets the state of the specified macro button.
void SetMacroButtonState(u32 pad, u32 index, bool state);
/// Returns true if the raw input source is being used. /// Returns true if the raw input source is being used.
bool IsUsingRawInput(); bool IsUsingRawInput();

View File

@ -69,4 +69,7 @@ public:
#ifdef WITH_SDL2 #ifdef WITH_SDL2
static std::unique_ptr<InputSource> CreateSDLSource(); static std::unique_ptr<InputSource> CreateSDLSource();
#endif #endif
#ifdef __ANDROID__
static std::unique_ptr<InputSource> CreateAndroidSource();
#endif
}; };