Misc: Necessary emucore changes for Android
This commit is contained in:
parent
bdb486ccaa
commit
25d2148ae4
|
@ -48,6 +48,8 @@
|
|||
|
||||
Log_SetChannel(FileSystem);
|
||||
|
||||
#ifndef __ANDROID__
|
||||
|
||||
#ifdef _WIN32
|
||||
static std::time_t ConvertFileTimeToUnixTime(const FILETIME& ft)
|
||||
{
|
||||
|
@ -753,6 +755,8 @@ int FileSystem::OpenFDFile(const char* filename, int flags, int mode)
|
|||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
FileSystem::ManagedCFilePtr FileSystem::OpenManagedCFile(const char* filename, const char* mode)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
#else
|
||||
#elif !defined(__ANDROID__)
|
||||
|
||||
static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, const char* Path, const char* Pattern,
|
||||
u32 Flags, FileSystem::FindResultsArray* pResults)
|
||||
|
|
|
@ -410,8 +410,13 @@ struct Settings
|
|||
|
||||
static constexpr LOGLEVEL DEFAULT_LOG_LEVEL = LOGLEVEL_INFO;
|
||||
|
||||
#ifndef __ANDROID__
|
||||
static constexpr u32 DEFAULT_AUDIO_BUFFER_MS = 50;
|
||||
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;
|
||||
|
||||
// Enable console logging by default on Linux platforms.
|
||||
|
|
|
@ -131,6 +131,8 @@ void CommonHost::ReleaseHostDisplayResources()
|
|||
SaveStateSelectorUI::DestroyTextures();
|
||||
}
|
||||
|
||||
#ifndef __ANDROID__
|
||||
|
||||
std::unique_ptr<AudioStream> Host::CreateAudioStream(AudioBackend backend, u32 sample_rate, u32 channels, u32 buffer_ms,
|
||||
u32 latency_ms, AudioStretchMode stretch)
|
||||
{
|
||||
|
@ -154,6 +156,8 @@ std::unique_ptr<AudioStream> Host::CreateAudioStream(AudioBackend backend, u32 s
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void CommonHost::UpdateLogSettings()
|
||||
{
|
||||
Log::SetFilterLevel(g_settings.log_level);
|
||||
|
|
|
@ -101,6 +101,8 @@ static std::optional<InputBindingKey> ParseHostKeyboardKey(const std::string_vie
|
|||
const std::string_view& sub_binding);
|
||||
static std::optional<InputBindingKey> ParsePointerKey(const std::string_view& source,
|
||||
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 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,
|
||||
const Controller::ControllerInfo* cinfo);
|
||||
static void SetMacroButtonState(u32 pad, u32 index, bool state);
|
||||
static void ApplyMacroButton(u32 pad, const MacroButton& mb);
|
||||
static void UpdateMacroButtons();
|
||||
} // namespace InputManager
|
||||
|
@ -162,6 +163,7 @@ static constexpr const std::array<const char*, static_cast<u8>(InputPointerAxis:
|
|||
{"X", "Y", "WheelX", "WheelY"}};
|
||||
static constexpr const std::array<const char*, 3> s_pointer_button_names = {
|
||||
{"LeftButton", "RightButton", "MiddleButton"}};
|
||||
static constexpr const std::array<const char*, 3> s_sensor_accelerometer_names = {{"Turn", "Tilt", "Rotate"}};
|
||||
|
||||
struct PointerAxisState
|
||||
{
|
||||
|
@ -239,6 +241,10 @@ std::optional<InputBindingKey> InputManager::ParseInputBindingKey(const std::str
|
|||
{
|
||||
return ParsePointerKey(source, sub_binding);
|
||||
}
|
||||
else if (StringUtil::StartsWith(source, "Sensor"))
|
||||
{
|
||||
return ParseSensorKey(source, sub_binding);
|
||||
}
|
||||
else
|
||||
{
|
||||
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 ? '-' : '+');
|
||||
}
|
||||
}
|
||||
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)])
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
static std::array<const char*, static_cast<u32>(InputSourceType::Count)> s_input_class_names = {{
|
||||
"Keyboard",
|
||||
"Mouse",
|
||||
"Pointer",
|
||||
"Sensor",
|
||||
#ifdef _WIN32
|
||||
"DInput",
|
||||
"XInput",
|
||||
#endif
|
||||
#if defined(_WIN32)
|
||||
"RawInput",
|
||||
#endif
|
||||
#ifdef WITH_SDL2
|
||||
"SDL",
|
||||
#endif
|
||||
#ifdef __ANDROID__
|
||||
"Android",
|
||||
#endif
|
||||
}};
|
||||
|
||||
InputSource* InputManager::GetInputSourceInterface(InputSourceType type)
|
||||
|
@ -513,6 +536,38 @@ std::optional<InputBindingKey> InputManager::ParsePointerKey(const std::string_v
|
|||
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
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -1470,4 +1525,7 @@ void InputManager::ReloadSources(SettingsInterface& si, std::unique_lock<std::mu
|
|||
#ifdef WITH_SDL2
|
||||
UpdateInputSourceState(si, settings_lock, InputSourceType::SDL, &InputSource::CreateSDLSource, true);
|
||||
#endif
|
||||
#ifdef __ANDROID__
|
||||
UpdateInputSourceState(si, settings_lock, InputSourceType::Android, &InputSource::CreateAndroidSource, true);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ enum class InputSourceType : u32
|
|||
{
|
||||
Keyboard,
|
||||
Pointer,
|
||||
Sensor,
|
||||
#ifdef _WIN32
|
||||
DInput,
|
||||
XInput,
|
||||
|
@ -22,6 +23,9 @@ enum class InputSourceType : u32
|
|||
#endif
|
||||
#ifdef WITH_SDL2
|
||||
SDL,
|
||||
#endif
|
||||
#ifdef __ANDROID__
|
||||
Android,
|
||||
#endif
|
||||
Count,
|
||||
};
|
||||
|
@ -38,6 +42,8 @@ enum class InputSubclass : u32
|
|||
ControllerAxis = 1,
|
||||
ControllerMotor = 2,
|
||||
ControllerHaptic = 3,
|
||||
|
||||
SensorAccelerometer = 0,
|
||||
};
|
||||
|
||||
/// 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).
|
||||
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.
|
||||
std::optional<InputBindingKey> ParseInputBindingKey(const std::string_view& binding);
|
||||
|
||||
|
@ -243,6 +252,9 @@ void UpdatePointerAbsolutePosition(u32 index, float x, float y);
|
|||
/// reporting.
|
||||
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.
|
||||
bool IsUsingRawInput();
|
||||
|
||||
|
|
|
@ -69,4 +69,7 @@ public:
|
|||
#ifdef WITH_SDL2
|
||||
static std::unique_ptr<InputSource> CreateSDLSource();
|
||||
#endif
|
||||
#ifdef __ANDROID__
|
||||
static std::unique_ptr<InputSource> CreateAndroidSource();
|
||||
#endif
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue