From 27acba620c8716f866904942f29820c1c9d2c714 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Wed, 22 Jul 2020 19:19:35 -0500 Subject: [PATCH] Core: Add new Free Look settings and config --- Source/Core/Common/CommonPaths.h | 1 + Source/Core/Common/Config/Enums.h | 1 + Source/Core/Common/FileUtil.cpp | 1 + Source/Core/Common/FileUtil.h | 1 + Source/Core/Core/CMakeLists.txt | 4 ++ Source/Core/Core/Config/FreeLookSettings.cpp | 21 ++++++++ Source/Core/Core/Config/FreeLookSettings.h | 23 +++++++++ .../Core/ConfigLoaders/BaseConfigLoader.cpp | 1 + .../Core/ConfigLoaders/IsSettingSaveable.cpp | 5 +- Source/Core/Core/Core.vcxproj | 4 ++ Source/Core/Core/FreeLookConfig.cpp | 48 +++++++++++++++++++ Source/Core/Core/FreeLookConfig.h | 41 ++++++++++++++++ 12 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 Source/Core/Core/Config/FreeLookSettings.cpp create mode 100644 Source/Core/Core/Config/FreeLookSettings.h create mode 100644 Source/Core/Core/FreeLookConfig.cpp create mode 100644 Source/Core/Core/FreeLookConfig.h diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index a1d87800f4..d1ef058228 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -87,6 +87,7 @@ #define DEBUGGER_CONFIG "Debugger.ini" #define LOGGER_CONFIG "Logger.ini" #define DUALSHOCKUDPCLIENT_CONFIG "DSUClient.ini" +#define FREELOOK_CONFIG "FreeLook.ini" // Files in the directory returned by GetUserPath(D_LOGS_IDX) #define MAIN_LOG "dolphin.log" diff --git a/Source/Core/Common/Config/Enums.h b/Source/Core/Common/Config/Enums.h index 831726ae1e..5c75a01893 100644 --- a/Source/Core/Common/Config/Enums.h +++ b/Source/Core/Common/Config/Enums.h @@ -31,6 +31,7 @@ enum class System Logger, Debugger, DualShockUDPClient, + FreeLook, }; constexpr std::array SEARCH_ORDER{{ diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 0d41395209..0a58c2417f 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -866,6 +866,7 @@ static void RebuildUserDirectories(unsigned int dir_index) s_user_paths[F_LOGGERCONFIG_IDX] = s_user_paths[D_CONFIG_IDX] + LOGGER_CONFIG; s_user_paths[F_DUALSHOCKUDPCLIENTCONFIG_IDX] = s_user_paths[D_CONFIG_IDX] + DUALSHOCKUDPCLIENT_CONFIG; + s_user_paths[F_FREELOOKCONFIG_IDX] = s_user_paths[D_CONFIG_IDX] + FREELOOK_CONFIG; s_user_paths[F_MAINLOG_IDX] = s_user_paths[D_LOGS_IDX] + MAIN_LOG; s_user_paths[F_MEM1DUMP_IDX] = s_user_paths[D_DUMP_IDX] + MEM1_DUMP; s_user_paths[F_MEM2DUMP_IDX] = s_user_paths[D_DUMP_IDX] + MEM2_DUMP; diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index 7e0b2e6990..d4d909695b 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -72,6 +72,7 @@ enum F_MEMORYWATCHERSOCKET_IDX, F_WIISDCARD_IDX, F_DUALSHOCKUDPCLIENTCONFIG_IDX, + F_FREELOOKCONFIG_IDX, NUM_PATH_INDICES }; diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 03c87e6db3..10ed707a27 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -17,6 +17,8 @@ add_library(core CoreTiming.h DSPEmulator.cpp DSPEmulator.h + FreeLookConfig.cpp + FreeLookConfig.h GeckoCodeConfig.cpp GeckoCodeConfig.h GeckoCode.cpp @@ -58,6 +60,8 @@ add_library(core Boot/ElfReader.cpp Boot/ElfReader.h Boot/ElfTypes.h + Config/FreeLookSettings.cpp + Config/FreeLookSettings.h Config/GraphicsSettings.cpp Config/GraphicsSettings.h Config/MainSettings.cpp diff --git a/Source/Core/Core/Config/FreeLookSettings.cpp b/Source/Core/Core/Config/FreeLookSettings.cpp new file mode 100644 index 0000000000..5f69b4c390 --- /dev/null +++ b/Source/Core/Core/Config/FreeLookSettings.cpp @@ -0,0 +1,21 @@ +// Copyright 2020 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "Core/Config/FreeLookSettings.h" +#include "Core/FreeLookConfig.h" + +#include + +#include "Common/Config/Config.h" + +namespace Config +{ +// Configuration Information +const Info FREE_LOOK_ENABLED{{System::FreeLook, "General", "Enabled"}, false}; + +// FreeLook.Controller1 +const Info FL1_CONTROL_TYPE{{System::FreeLook, "Camera1", "ControlType"}, + FreeLook::ControlType::SixAxis}; + +} // namespace Config diff --git a/Source/Core/Core/Config/FreeLookSettings.h b/Source/Core/Core/Config/FreeLookSettings.h new file mode 100644 index 0000000000..d17ecbe456 --- /dev/null +++ b/Source/Core/Core/Config/FreeLookSettings.h @@ -0,0 +1,23 @@ +// Copyright 2020 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include "Common/Config/Config.h" + +namespace FreeLook +{ +enum class ControlType : int; +} + +namespace Config +{ +// Configuration Information + +extern const Info FREE_LOOK_ENABLED; + +// FreeLook.Controller1 +extern const Info FL1_CONTROL_TYPE; + +} // namespace Config diff --git a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp index f54e2ac9f5..65b46ec4bd 100644 --- a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp +++ b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp @@ -90,6 +90,7 @@ const std::map system_to_ini = { {Config::System::Logger, F_LOGGERCONFIG_IDX}, {Config::System::Debugger, F_DEBUGGERCONFIG_IDX}, {Config::System::DualShockUDPClient, F_DUALSHOCKUDPCLIENTCONFIG_IDX}, + {Config::System::FreeLook, F_FREELOOKCONFIG_IDX}, }; // INI layer configuration loader diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index a8d25a4bdc..fcb5eb0f4e 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -16,8 +16,9 @@ namespace ConfigLoaders { bool IsSettingSaveable(const Config::Location& config_location) { - for (Config::System system : {Config::System::SYSCONF, Config::System::GFX, - Config::System::DualShockUDPClient, Config::System::Logger}) + for (Config::System system : + {Config::System::SYSCONF, Config::System::GFX, Config::System::DualShockUDPClient, + Config::System::Logger, Config::System::FreeLook}) { if (config_location.system == system) return true; diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index f672f088d1..1694450783 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -25,6 +25,7 @@ + @@ -83,6 +84,7 @@ + @@ -386,6 +388,7 @@ + @@ -436,6 +439,7 @@ + diff --git a/Source/Core/Core/FreeLookConfig.cpp b/Source/Core/Core/FreeLookConfig.cpp new file mode 100644 index 0000000000..f58a9e893b --- /dev/null +++ b/Source/Core/Core/FreeLookConfig.cpp @@ -0,0 +1,48 @@ +// Copyright 2020 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "Core/FreeLookConfig.h" +#include "Core/Config/FreeLookSettings.h" +#include "Core/ConfigManager.h" +#include "Core/Core.h" + +namespace FreeLook +{ +static Config s_config; +static Config s_active_config; +static bool s_has_registered_callback = false; + +Config& GetConfig() +{ + return s_config; +} + +const Config& GetActiveConfig() +{ + return s_active_config; +} + +void UpdateActiveConfig() +{ + s_active_config = s_config; +} + +Config::Config() +{ + camera_config.control_type = ControlType::SixAxis; + enabled = false; +} + +void Config::Refresh() +{ + if (!s_has_registered_callback) + { + ::Config::AddConfigChangedCallback([] { Core::RunAsCPUThread([] { s_config.Refresh(); }); }); + s_has_registered_callback = true; + } + + camera_config.control_type = ::Config::Get(::Config::FL1_CONTROL_TYPE); + enabled = ::Config::Get(::Config::FREE_LOOK_ENABLED); +} +} // namespace FreeLook diff --git a/Source/Core/Core/FreeLookConfig.h b/Source/Core/Core/FreeLookConfig.h new file mode 100644 index 0000000000..f012bde3e8 --- /dev/null +++ b/Source/Core/Core/FreeLookConfig.h @@ -0,0 +1,41 @@ +// Copyright 2020 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +// IMPORTANT: UI etc should modify the value returned by FreeLook::GetConfig(). +// Free Look code should read from the value returned by FreeLook::GetActiveConfig(). +// The reason for this is to get rid of race conditions etc when the +// configuration changes in the middle of a frame. + +#pragma once + +namespace FreeLook +{ +enum class ControlType : int +{ + SixAxis, + FPS, + Orbital +}; + +struct CameraConfig +{ + ControlType control_type; +}; + +// NEVER inherit from this class. +struct Config final +{ + Config(); + void Refresh(); + + CameraConfig camera_config; + bool enabled; +}; + +Config& GetConfig(); +const Config& GetActiveConfig(); + +// Called every frame. +void UpdateActiveConfig(); +} // namespace FreeLook