Skip to content

Commit

Permalink
System: Move private functions to separate header
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Oct 28, 2024
1 parent 21d19a6 commit 166c930
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 107 deletions.
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ add_library(core
spu.h
system.cpp
system.h
system_private.h
timers.cpp
timers.h
timing_event.cpp
Expand Down
1 change: 1 addition & 0 deletions src/core/core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<ClInclude Include="sio.h" />
<ClInclude Include="spu.h" />
<ClInclude Include="system.h" />
<ClInclude Include="system_private.h" />
<ClInclude Include="timers.h" />
<ClInclude Include="timing_event.h" />
<ClInclude Include="types.h" />
Expand Down
1 change: 1 addition & 0 deletions src/core/core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<ClInclude Include="gpu_dump.h" />
<ClInclude Include="cdrom_subq_replacement.h" />
<ClInclude Include="performance_counters.h" />
<ClInclude Include="system_private.h" />
</ItemGroup>
<ItemGroup>
<None Include="gpu_sw_rasterizer.inl" />
Expand Down
1 change: 1 addition & 0 deletions src/core/fullscreen_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "host.h"
#include "settings.h"
#include "system.h"
#include "system_private.h"

#include "scmversion/scmversion.h"

Expand Down
1 change: 0 additions & 1 deletion src/core/game_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <span>
#include <string>

class ByteStream;
class ProgressCallback;

struct SystemBootParameters;
Expand Down
3 changes: 3 additions & 0 deletions src/core/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "performance_counters.h"
#include "settings.h"
#include "system.h"
#include "system_private.h"
#include "timers.h"
#include "timing_event.h"

Expand Down Expand Up @@ -1063,6 +1064,7 @@ void GPU::CRTCTickEvent(TickCount ticks)
// TODO: move present in here I guess
FlushRender();
UpdateDisplay();
System::IncrementFrameNumber();
frame_done = true;

// switch fields early. this is needed so we draw to the correct one.
Expand Down Expand Up @@ -3105,6 +3107,7 @@ void GPU::ProcessGPUDumpPacket(GPUDump::PacketType type, const std::span<const u

FlushRender();
UpdateDisplay();
System::IncrementFrameNumber();
System::FrameDone();
}
break;
Expand Down
5 changes: 3 additions & 2 deletions src/core/performance_counters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "performance_counters.h"
#include "gpu.h"
#include "system.h"
#include "system_private.h"

#include "util/media_capture.h"

Expand Down Expand Up @@ -148,7 +149,7 @@ void PerformanceCounters::Reset()

s_state.last_frame_number = System::GetFrameNumber();
s_state.last_internal_frame_number = System::GetInternalFrameNumber();
s_state.last_cpu_time = System::Internal::GetCPUThreadHandle().GetCPUTime();
s_state.last_cpu_time = System::GetCPUThreadHandle().GetCPUTime();
if (const Threading::Thread* sw_thread = g_gpu->GetSWThread(); sw_thread)
s_state.last_sw_time = sw_thread->GetCPUTime();
else
Expand Down Expand Up @@ -202,7 +203,7 @@ void PerformanceCounters::Update(u32 frame_number, u32 internal_frame_number)
s_state.speed = (s_state.vps / System::GetVideoFrameRate()) * 100.0f;

const Threading::Thread* sw_thread = g_gpu->GetSWThread();
const u64 cpu_time = System::Internal::GetCPUThreadHandle().GetCPUTime();
const u64 cpu_time = System::GetCPUThreadHandle().GetCPUTime();
const u64 sw_time = sw_thread ? sw_thread->GetCPUTime() : 0;
const u64 cpu_delta = cpu_time - s_state.last_cpu_time;
const u64 sw_delta = sw_time - s_state.last_sw_time;
Expand Down
1 change: 0 additions & 1 deletion src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,6 @@ static const char* s_log_filters[] = {
"AutoUpdaterDialog",
"BIOS",
"Bus",
"ByteStream",
"CDImage",
"CDImageBin",
"CDImageCHD",
Expand Down
39 changes: 14 additions & 25 deletions src/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "save_state_version.h"
#include "sio.h"
#include "spu.h"
#include "system_private.h"
#include "timers.h"

#include "scmversion/scmversion.h"
Expand Down Expand Up @@ -113,7 +114,6 @@ SystemBootParameters::~SystemBootParameters() = default;

namespace System {

/// Memory save states - only for internal use.
namespace {

struct SaveStateBuffer
Expand All @@ -127,14 +127,6 @@ struct SaveStateBuffer
DynamicHeapArray<u8> state_data;
size_t state_size;
};
struct MemorySaveState
{
std::unique_ptr<GPUTexture> vram_texture;
DynamicHeapArray<u8> state_data;
#ifdef PROFILE_MEMORY_SAVE_STATES
size_t state_size;
#endif
};

} // namespace

Expand Down Expand Up @@ -197,15 +189,10 @@ static void UpdatePerGameMemoryCards();
static std::unique_ptr<MemoryCard> GetMemoryCardForSlot(u32 slot, MemoryCardType type);
static void UpdateMultitaps();

/// Returns the maximum size of a save state, considering the current configuration.
static size_t GetMaxSaveStateSize();

static std::string GetMediaPathFromSaveState(const char* path);
static bool SaveUndoLoadState();
static void UpdateMemorySaveStateSettings();
static bool LoadRewindState(u32 skip_saves = 0, bool consume_state = true);
static bool SaveMemoryState(MemorySaveState* mss);
static bool LoadMemoryState(const MemorySaveState& mss);
static bool LoadStateFromBuffer(const SaveStateBuffer& buffer, Error* error, bool update_display);
static bool LoadStateBufferFromFile(SaveStateBuffer* buffer, std::FILE* fp, Error* error, bool read_title,
bool read_media_path, bool read_screenshot, bool read_data);
Expand All @@ -216,7 +203,6 @@ static bool SaveStateBufferToFile(const SaveStateBuffer& buffer, std::FILE* fp,
SaveStateCompressionMode compression_mode);
static u32 CompressAndWriteStateData(std::FILE* fp, std::span<const u8> src, SaveStateCompressionMode method,
u32* header_type, Error* error);
static bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display, bool is_memory_state);

static bool IsExecutionInterrupted();
static void CheckForAndExitExecution();
Expand Down Expand Up @@ -337,7 +323,7 @@ static TinyString GetTimestampStringForFileName()
return TinyString::from_format("{:%Y-%m-%d-%H-%M-%S}", fmt::localtime(std::time(nullptr)));
}

bool System::Internal::PerformEarlyHardwareChecks(Error* error)
bool System::PerformEarlyHardwareChecks(Error* error)
{
// This shouldn't fail... if it does, just hope for the best.
cpuinfo_initialize();
Expand Down Expand Up @@ -457,7 +443,7 @@ void System::LogStartupInformation()
#endif
}

bool System::Internal::ProcessStartup(Error* error)
bool System::ProcessStartup(Error* error)
{
Common::Timer timer;

Expand All @@ -482,13 +468,13 @@ bool System::Internal::ProcessStartup(Error* error)
return true;
}

void System::Internal::ProcessShutdown()
void System::ProcessShutdown()
{
Bus::ReleaseMemory();
CPU::CodeCache::ProcessShutdown();
}

bool System::Internal::CPUThreadInitialize(Error* error)
bool System::CPUThreadInitialize(Error* error)
{
Threading::SetNameOfCurrentThread("CPU Thread");

Expand Down Expand Up @@ -520,7 +506,7 @@ bool System::Internal::CPUThreadInitialize(Error* error)
return true;
}

void System::Internal::CPUThreadShutdown()
void System::CPUThreadShutdown()
{
#ifdef ENABLE_DISCORD_PRESENCE
ShutdownDiscordPresence();
Expand All @@ -535,12 +521,12 @@ void System::Internal::CPUThreadShutdown()
#endif
}

const Threading::ThreadHandle& System::Internal::GetCPUThreadHandle()
const Threading::ThreadHandle& System::GetCPUThreadHandle()
{
return s_cpu_thread_handle;
}

void System::Internal::IdlePollUpdate()
void System::IdlePollUpdate()
{
InputManager::PollSources();

Expand Down Expand Up @@ -2048,8 +2034,6 @@ void System::Execute()

void System::FrameDone()
{
s_frame_number++;

// Vertex buffer is shared, need to flush what we have.
g_gpu->FlushRender();

Expand Down Expand Up @@ -2330,6 +2314,11 @@ void System::SingleStepCPU()
PauseSystem(false);
}

void System::IncrementFrameNumber()
{
s_frame_number++;
}

void System::IncrementInternalFrameNumber()
{
if (IsFastForwardingBoot()) [[unlikely]]
Expand Down Expand Up @@ -4886,7 +4875,7 @@ void System::DoRewind()

InvalidateDisplay();
Host::PumpMessagesOnCPUThread();
Internal::IdlePollUpdate();
IdlePollUpdate();

Throttle(Common::Timer::GetCurrentValue());
}
Expand Down
65 changes: 1 addition & 64 deletions src/core/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ void UpdateOverclock();
GlobalTicks GetGlobalTickCounter();
u32 GetFrameNumber();
u32 GetInternalFrameNumber();
void IncrementInternalFrameNumber();
void FrameDone();

const std::string& GetDiscPath();
const std::string& GetGameSerial();
Expand Down Expand Up @@ -437,72 +435,11 @@ void ReleaseSocketMultiplexer();
/// Called when rich presence changes.
void UpdateRichPresence(bool update_session_time);

namespace Internal {
/// Performs mandatory hardware checks.
bool PerformEarlyHardwareChecks(Error* error);

/// Called on process startup, as early as possible.
bool ProcessStartup(Error* error);

/// Called on process shutdown.
void ProcessShutdown();

/// Called on CPU thread initialization.
bool CPUThreadInitialize(Error* error);

/// Called on CPU thread shutdown.
void CPUThreadShutdown();

/// Returns a handle to the CPU thread.
const Threading::ThreadHandle& GetCPUThreadHandle();

/// Polls input, updates subsystems which are present while paused/inactive.
void IdlePollUpdate();
} // namespace Internal

} // namespace System

namespace Host {
/// Called with the settings lock held, when system settings are being loaded (should load input sources, etc).
void LoadSettings(const SettingsInterface& si, std::unique_lock<std::mutex>& lock);

/// Called after settings are updated.
void CheckForSettingsChanges(const Settings& old_settings);

/// Called when the VM is starting initialization, but has not been completed yet.
void OnSystemStarting();

/// Called when the VM is created.
void OnSystemStarted();

/// Called when the VM is shut down or destroyed.
void OnSystemDestroyed();

/// Called when the VM is paused.
void OnSystemPaused();

/// Called when the VM is resumed after being paused.
void OnSystemResumed();

/// Called when the pause state changes, or fullscreen UI opens.
void OnIdleStateChanged();

/// Called when performance metrics are updated, approximately once a second.
void OnPerformanceCountersUpdated();

/// Provided by the host; called when the running executable changes.
void OnGameChanged(const std::string& disc_path, const std::string& game_serial, const std::string& game_name);

/// Called when media capture starts/stops.
void OnMediaCaptureStarted();
void OnMediaCaptureStopped();

/// Provided by the host; called once per frame at guest vsync.
void PumpMessagesOnCPUThread();

/// Requests a specific display window size.
void RequestResizeHostDisplay(s32 width, s32 height);

/// Requests shut down of the current virtual machine.
void RequestSystemShutdown(bool allow_confirm, bool save_state);

} // namespace Host
Loading

0 comments on commit 166c930

Please sign in to comment.