mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-01-30 19:13:45 +00:00
Emulator state (#3906)
* moved getShowFpsCounter to emu state * more state variables * fps counter is back * removed fpscolor
This commit is contained in:
parent
f7a473b391
commit
be99cb4d5b
@ -840,6 +840,8 @@ set(CORE src/core/aerolib/stubs.cpp
|
||||
src/core/thread.h
|
||||
src/core/tls.cpp
|
||||
src/core/tls.h
|
||||
src/core/emulator_state.cpp
|
||||
src/core/emulator_state.h
|
||||
)
|
||||
|
||||
if (ARCHITECTURE STREQUAL "x86_64")
|
||||
|
||||
@ -198,7 +198,6 @@ static ConfigEntry<bool> pipelineCacheArchive(false);
|
||||
static ConfigEntry<bool> isDebugDump(false);
|
||||
static ConfigEntry<bool> isShaderDebug(false);
|
||||
static ConfigEntry<bool> isSeparateLogFilesEnabled(false);
|
||||
static ConfigEntry<bool> isFpsColor(true);
|
||||
static ConfigEntry<bool> showFpsCounter(false);
|
||||
static ConfigEntry<bool> logEnabled(true);
|
||||
|
||||
@ -223,16 +222,6 @@ static string config_version = Common::g_scm_rev;
|
||||
// These entries aren't stored in the config
|
||||
static bool overrideControllerColor = false;
|
||||
static int controllerCustomColorRGB[3] = {0, 0, 255};
|
||||
static bool isGameRunning = false;
|
||||
static bool load_auto_patches = true;
|
||||
|
||||
bool getGameRunning() {
|
||||
return isGameRunning;
|
||||
}
|
||||
|
||||
void setGameRunning(bool running) {
|
||||
isGameRunning = running;
|
||||
}
|
||||
|
||||
std::filesystem::path getSysModulesPath() {
|
||||
if (sys_modules_path.empty()) {
|
||||
@ -463,10 +452,6 @@ bool isPipelineCacheArchived() {
|
||||
return pipelineCacheArchive.get();
|
||||
}
|
||||
|
||||
bool fpsColor() {
|
||||
return isFpsColor.get();
|
||||
}
|
||||
|
||||
bool getShowFpsCounter() {
|
||||
return showFpsCounter.get();
|
||||
}
|
||||
@ -855,13 +840,6 @@ void setUsbDeviceBackend(int value, bool is_game_specific) {
|
||||
usbDeviceBackend.set(value, is_game_specific);
|
||||
}
|
||||
|
||||
bool getLoadAutoPatches() {
|
||||
return load_auto_patches;
|
||||
}
|
||||
void setLoadAutoPatches(bool enable) {
|
||||
load_auto_patches = enable;
|
||||
}
|
||||
|
||||
void load(const std::filesystem::path& path, bool is_game_specific) {
|
||||
// If the configuration file does not exist, create it and return, unless it is game specific
|
||||
std::error_code error;
|
||||
@ -977,7 +955,6 @@ void load(const std::filesystem::path& path, bool is_game_specific) {
|
||||
isDebugDump.setFromToml(debug, "DebugDump", is_game_specific);
|
||||
isSeparateLogFilesEnabled.setFromToml(debug, "isSeparateLogFilesEnabled", is_game_specific);
|
||||
isShaderDebug.setFromToml(debug, "CollectShader", is_game_specific);
|
||||
isFpsColor.setFromToml(debug, "FPSColor", is_game_specific);
|
||||
showFpsCounter.setFromToml(debug, "showFpsCounter", is_game_specific);
|
||||
logEnabled.setFromToml(debug, "logEnabled", is_game_specific);
|
||||
current_version = toml::find_or<std::string>(debug, "ConfigVersion", current_version);
|
||||
@ -1197,7 +1174,6 @@ void save(const std::filesystem::path& path, bool is_game_specific) {
|
||||
data["GPU"]["internalScreenWidth"] = internalScreenWidth.base_value;
|
||||
data["GPU"]["internalScreenHeight"] = internalScreenHeight.base_value;
|
||||
data["GPU"]["patchShaders"] = shouldPatchShaders.base_value;
|
||||
data["Debug"]["FPSColor"] = isFpsColor.base_value;
|
||||
data["Debug"]["showFpsCounter"] = showFpsCounter.base_value;
|
||||
}
|
||||
|
||||
@ -1306,7 +1282,6 @@ void setDefaultValues(bool is_game_specific) {
|
||||
internalScreenHeight.base_value = 720;
|
||||
|
||||
// Debug
|
||||
isFpsColor.base_value = true;
|
||||
showFpsCounter.base_value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +125,6 @@ int getSpecialPadClass();
|
||||
bool getPSNSignedIn();
|
||||
void setPSNSignedIn(bool sign, bool is_game_specific = false);
|
||||
bool patchShaders(); // no set
|
||||
bool fpsColor(); // no set
|
||||
bool getShowFpsCounter();
|
||||
void setShowFpsCounter(bool enable, bool is_game_specific = false);
|
||||
bool isNeoModeConsole();
|
||||
@ -154,8 +153,6 @@ void setConnectedToNetwork(bool enable, bool is_game_specific = false);
|
||||
void setUserName(const std::string& name, bool is_game_specific = false);
|
||||
std::filesystem::path getSysModulesPath();
|
||||
void setSysModulesPath(const std::filesystem::path& path);
|
||||
bool getLoadAutoPatches();
|
||||
void setLoadAutoPatches(bool enable);
|
||||
|
||||
enum UsbBackendType : int { Real, SkylandersPortal, InfinityBase, DimensionsToypad };
|
||||
int getUsbDeviceBackend();
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2024-2026 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
@ -12,6 +12,7 @@
|
||||
#include "common/elf_info.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/path_util.h"
|
||||
#include "core/emulator_state.h"
|
||||
#include "core/file_format/psf.h"
|
||||
#include "memory_patcher.h"
|
||||
|
||||
@ -192,7 +193,7 @@ void OnGameLoaded() {
|
||||
} else {
|
||||
ApplyPatchesFromXML(file_path);
|
||||
}
|
||||
} else if (Config::getLoadAutoPatches()) {
|
||||
} else if (EmulatorState::GetInstance()->IsAutoPatchesLoadEnabled()) {
|
||||
for (auto const& repo : std::filesystem::directory_iterator(patch_dir)) {
|
||||
if (!repo.is_directory()) {
|
||||
continue;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2025-2026 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "layer.h"
|
||||
@ -11,6 +11,7 @@
|
||||
#include "common/singleton.h"
|
||||
#include "common/types.h"
|
||||
#include "core/debug_state.h"
|
||||
#include "core/emulator_state.h"
|
||||
#include "imgui/imgui_std.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "options.h"
|
||||
@ -273,14 +274,10 @@ void L::DrawAdvanced() {
|
||||
|
||||
void L::DrawSimple() {
|
||||
const float frameRate = DebugState.Framerate;
|
||||
if (Config::fpsColor()) {
|
||||
if (frameRate < 10) {
|
||||
PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); // Red
|
||||
} else if (frameRate >= 10 && frameRate < 20) {
|
||||
PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.5f, 0.0f, 1.0f)); // Orange
|
||||
} else {
|
||||
PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); // White
|
||||
}
|
||||
if (frameRate < 10) {
|
||||
PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); // Red
|
||||
} else if (frameRate >= 10 && frameRate < 20) {
|
||||
PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.5f, 0.0f, 1.0f)); // Orange
|
||||
} else {
|
||||
PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); // White
|
||||
}
|
||||
|
||||
37
src/core/emulator_state.cpp
Normal file
37
src/core/emulator_state.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025-2026 shadLauncher4 Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "emulator_state.h"
|
||||
|
||||
std::shared_ptr<EmulatorState> EmulatorState::s_instance = nullptr;
|
||||
std::mutex EmulatorState::s_mutex;
|
||||
|
||||
EmulatorState::EmulatorState() {}
|
||||
|
||||
EmulatorState::~EmulatorState() {}
|
||||
|
||||
std::shared_ptr<EmulatorState> EmulatorState::GetInstance() {
|
||||
std::lock_guard<std::mutex> lock(s_mutex);
|
||||
if (!s_instance)
|
||||
s_instance = std::make_shared<EmulatorState>();
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void EmulatorState::SetInstance(std::shared_ptr<EmulatorState> instance) {
|
||||
std::lock_guard<std::mutex> lock(s_mutex);
|
||||
s_instance = instance;
|
||||
}
|
||||
|
||||
bool EmulatorState::IsGameRunning() const {
|
||||
return m_running;
|
||||
}
|
||||
void EmulatorState::SetGameRunning(bool running) {
|
||||
m_running = running;
|
||||
}
|
||||
|
||||
bool EmulatorState::IsAutoPatchesLoadEnabled() const {
|
||||
return m_load_patches_auto;
|
||||
}
|
||||
void EmulatorState::SetAutoPatchesLoadEnabled(bool enable) {
|
||||
m_load_patches_auto = enable;
|
||||
}
|
||||
29
src/core/emulator_state.h
Normal file
29
src/core/emulator_state.h
Normal file
@ -0,0 +1,29 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025-2026 shadLauncher4 Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
class EmulatorState {
|
||||
public:
|
||||
EmulatorState();
|
||||
~EmulatorState();
|
||||
|
||||
static std::shared_ptr<EmulatorState> GetInstance();
|
||||
static void SetInstance(std::shared_ptr<EmulatorState> instance);
|
||||
|
||||
bool IsGameRunning() const;
|
||||
void SetGameRunning(bool running);
|
||||
bool IsAutoPatchesLoadEnabled() const;
|
||||
void SetAutoPatchesLoadEnabled(bool enable);
|
||||
|
||||
private:
|
||||
static std::shared_ptr<EmulatorState> s_instance;
|
||||
static std::mutex s_mutex;
|
||||
|
||||
// state variables
|
||||
bool m_running = false;
|
||||
bool m_load_patches_auto = true;
|
||||
};
|
||||
@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2025-2026 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "ipc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "common/types.h"
|
||||
#include "core/debug_state.h"
|
||||
#include "core/debugger.h"
|
||||
#include "core/emulator_state.h"
|
||||
#include "core/libraries/audio/audioout.h"
|
||||
#include "input/input_handler.h"
|
||||
#include "sdl_window.h"
|
||||
@ -71,7 +72,7 @@ void IPC::Init() {
|
||||
return;
|
||||
}
|
||||
|
||||
Config::setLoadAutoPatches(false);
|
||||
EmulatorState::GetInstance()->SetAutoPatchesLoadEnabled(false);
|
||||
|
||||
input_thread = std::jthread([this] {
|
||||
Common::SetCurrentThreadName("IPC Read thread");
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2025-2026 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <SDL3/SDL_messagebox.h>
|
||||
@ -8,6 +8,7 @@
|
||||
#include "system_error"
|
||||
#include "unordered_map"
|
||||
|
||||
#include <core/emulator_state.h>
|
||||
#include <fmt/core.h>
|
||||
#include "common/config.h"
|
||||
#include "common/logging/backend.h"
|
||||
@ -27,7 +28,9 @@ int main(int argc, char* argv[]) {
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
#endif
|
||||
IPC::Instance().Init();
|
||||
|
||||
// Init emulator state
|
||||
std::shared_ptr<EmulatorState> m_emu_state = std::make_shared<EmulatorState>();
|
||||
EmulatorState::SetInstance(m_emu_state);
|
||||
// Load configurations
|
||||
const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||
Config::load(user_dir / "config.toml");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user