host.h (5810B)
1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #pragma once 5 6 #include "util/host.h" 7 8 #include "common/small_string.h" 9 #include "common/types.h" 10 11 #include <functional> 12 #include <mutex> 13 #include <span> 14 #include <string> 15 #include <string_view> 16 #include <vector> 17 18 class Error; 19 class SettingsInterface; 20 struct WindowInfo; 21 enum class AudioBackend : u8; 22 enum class AudioExpansionMode : u8; 23 enum class AudioStretchMode : u8; 24 enum class RenderAPI : u32; 25 class AudioStream; 26 class CDImage; 27 28 namespace Host { 29 // Base setting retrieval, bypasses layers. 30 std::string GetBaseStringSettingValue(const char* section, const char* key, const char* default_value = ""); 31 SmallString GetBaseSmallStringSettingValue(const char* section, const char* key, const char* default_value = ""); 32 TinyString GetBaseTinyStringSettingValue(const char* section, const char* key, const char* default_value = ""); 33 bool GetBaseBoolSettingValue(const char* section, const char* key, bool default_value = false); 34 s32 GetBaseIntSettingValue(const char* section, const char* key, s32 default_value = 0); 35 u32 GetBaseUIntSettingValue(const char* section, const char* key, u32 default_value = 0); 36 float GetBaseFloatSettingValue(const char* section, const char* key, float default_value = 0.0f); 37 double GetBaseDoubleSettingValue(const char* section, const char* key, double default_value = 0.0); 38 std::vector<std::string> GetBaseStringListSetting(const char* section, const char* key); 39 40 // Allows the emucore to write settings back to the frontend. Use with care. 41 // You should call CommitBaseSettingChanges() if you directly write to the layer (i.e. not these functions), or it may 42 // not be written to disk. 43 void SetBaseBoolSettingValue(const char* section, const char* key, bool value); 44 void SetBaseIntSettingValue(const char* section, const char* key, s32 value); 45 void SetBaseUIntSettingValue(const char* section, const char* key, u32 value); 46 void SetBaseFloatSettingValue(const char* section, const char* key, float value); 47 void SetBaseStringSettingValue(const char* section, const char* key, const char* value); 48 void SetBaseStringListSettingValue(const char* section, const char* key, const std::vector<std::string>& values); 49 bool AddValueToBaseStringListSetting(const char* section, const char* key, const char* value); 50 bool RemoveValueFromBaseStringListSetting(const char* section, const char* key, const char* value); 51 bool ContainsBaseSettingValue(const char* section, const char* key); 52 void DeleteBaseSettingValue(const char* section, const char* key); 53 void CommitBaseSettingChanges(); 54 55 // Settings access, thread-safe. 56 std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = ""); 57 SmallString GetSmallStringSettingValue(const char* section, const char* key, const char* default_value = ""); 58 TinyString GetTinyStringSettingValue(const char* section, const char* key, const char* default_value = ""); 59 bool GetBoolSettingValue(const char* section, const char* key, bool default_value = false); 60 int GetIntSettingValue(const char* section, const char* key, s32 default_value = 0); 61 u32 GetUIntSettingValue(const char* section, const char* key, u32 default_value = 0); 62 float GetFloatSettingValue(const char* section, const char* key, float default_value = 0.0f); 63 double GetDoubleSettingValue(const char* section, const char* key, double default_value = 0.0); 64 std::vector<std::string> GetStringListSetting(const char* section, const char* key); 65 66 /// Direct access to settings interface. Must hold the lock when calling GetSettingsInterface() and while using it. 67 std::unique_lock<std::mutex> GetSettingsLock(); 68 SettingsInterface* GetSettingsInterface(); 69 70 /// Debugger feedback. 71 void ReportDebuggerMessage(std::string_view message); 72 73 /// Returns a list of supported languages and codes (suffixes for translation files). 74 std::span<const std::pair<const char*, const char*>> GetAvailableLanguageList(); 75 76 /// Refreshes the UI when the language is changed. 77 bool ChangeLanguage(const char* new_language); 78 79 /// Displays a loading screen with the logo, rendered with ImGui. Use when executing possibly-time-consuming tasks 80 /// such as compiling shaders when starting up. 81 void DisplayLoadingScreen(const char* message, int progress_min = -1, int progress_max = -1, int progress_value = -1); 82 83 /// Safely executes a function on the VM thread. 84 void RunOnCPUThread(std::function<void()> function, bool block = false); 85 86 /// Attempts to create the rendering device backend. 87 bool CreateGPUDevice(RenderAPI api, Error* error); 88 89 /// Handles fullscreen transitions and such. 90 void UpdateDisplayWindow(); 91 92 /// Called when the window is resized. 93 void ResizeDisplayWindow(s32 width, s32 height, float scale); 94 95 /// Destroys any active rendering device. 96 void ReleaseGPUDevice(); 97 98 /// Called at the end of the frame, before presentation. 99 void FrameDone(); 100 101 namespace Internal { 102 /// Retrieves the base settings layer. Must call with lock held. 103 SettingsInterface* GetBaseSettingsLayer(); 104 105 /// Retrieves the game settings layer, if present. Must call with lock held. 106 SettingsInterface* GetGameSettingsLayer(); 107 108 /// Retrieves the input settings layer, if present. Must call with lock held. 109 SettingsInterface* GetInputSettingsLayer(); 110 111 /// Sets the base settings layer. Should be called by the host at initialization time. 112 void SetBaseSettingsLayer(SettingsInterface* sif); 113 114 /// Sets the game settings layer. Called by VMManager when the game changes. 115 void SetGameSettingsLayer(SettingsInterface* sif, std::unique_lock<std::mutex>& lock); 116 117 /// Sets the input profile settings layer. Called by VMManager when the game changes. 118 void SetInputSettingsLayer(SettingsInterface* sif, std::unique_lock<std::mutex>& lock); 119 } // namespace Internal 120 } // namespace Host