Permalink
Browse files

PowerPC: Convert CPUCore enum into an enum class

Makes the enum values strongly-typed and prevents the identifiers from
polluting the PowerPC namespace. This also cleans up the parameters of
some functions where we were accepting an ambiguous int type and
expecting the correct values to be passed in.

Now those parameters accept a PowerPC::CPUCore type only, making it
immediately obvious which values should be passed in. It also turns out
we were storing these core types into other structures as plain ints,
which have also been corrected.

As this type is used directly with the configuration code, we need to
provide our own overloaded insertion (<<) and extraction (>>) operators
in order to make it compatible with it. These are fairly trivial to
implement, so there's no issue here.

A minor adjustment to TryParse() was required, as our generic function
was doing the following:

N tmp = 0;

which is problematic, as custom types may not be able to have that
assignment performed (e.g. strongly-typed enums), so we change this to:

N tmp;

which is sufficient, as the value is attempted to be initialized
immediately under that statement.
  • Loading branch information...
lioncash committed Jun 15, 2018
1 parent 5860670 commit 6f473b96d0fc8341eadc34c61a2c552c20245975
@@ -445,7 +445,7 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDi
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
jobject obj)
{
return PowerPC::DefaultCPUCore();
return static_cast<jint>(PowerPC::DefaultCPUCore());
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv* env,
@@ -55,14 +55,14 @@ static bool TryParse(const std::string& str, N* const output)
// separators
iss.imbue(std::locale("C"));
N tmp = 0;
N tmp;
if (iss >> tmp)
{
*output = tmp;
return true;
}
else
return false;
return false;
}
template <typename N>
@@ -28,16 +28,12 @@
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "Common/Config/Config.h"
#include "Core/Boot/Boot.h"
#include "Core/Config/MainSettings.h"
#include "Core/Config/SYSCONFSettings.h"
#include "Core/ConfigLoaders/BaseConfigLoader.h"
#include "Core/ConfigLoaders/GameConfigLoader.h"
#include "Core/ConfigLoaders/MovieConfigLoader.h"
#include "Core/ConfigLoaders/NetPlayConfigLoader.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
@@ -47,6 +43,7 @@
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "Core/Movie.h"
#include "Core/NetPlayProto.h"
#include "Core/PowerPC/PowerPC.h"
#include "DiscIO/Enums.h"
@@ -88,7 +85,7 @@ struct ConfigCache
bool bDSPHLE;
bool bHLE_BS2;
int iSelectedLanguage;
int iCPUCore;
PowerPC::CPUCore cpu_core;
int Volume;
float m_EmulationSpeed;
float m_OCFactor;
@@ -118,7 +115,7 @@ void ConfigCache::SaveConfig(const SConfig& config)
bDSPHLE = config.bDSPHLE;
bHLE_BS2 = config.bHLE_BS2;
iSelectedLanguage = config.SelectedLanguage;
iCPUCore = config.iCPUCore;
cpu_core = config.cpu_core;
Volume = config.m_Volume;
m_EmulationSpeed = config.m_EmulationSpeed;
strBackend = config.m_strVideoBackend;
@@ -159,7 +156,7 @@ void ConfigCache::RestoreConfig(SConfig* config)
config->bDSPHLE = bDSPHLE;
config->bHLE_BS2 = bHLE_BS2;
config->SelectedLanguage = iSelectedLanguage;
config->iCPUCore = iCPUCore;
config->cpu_core = cpu_core;
// Only change these back if they were actually set by game ini, since they can be changed while a
// game is running.
@@ -255,7 +252,7 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
core_section->Get("FastDiscSpeed", &StartUp.bFastDiscSpeed, StartUp.bFastDiscSpeed);
core_section->Get("DSPHLE", &StartUp.bDSPHLE, StartUp.bDSPHLE);
core_section->Get("GFXBackend", &StartUp.m_strVideoBackend, StartUp.m_strVideoBackend);
core_section->Get("CPUCore", &StartUp.iCPUCore, StartUp.iCPUCore);
core_section->Get("CPUCore", &StartUp.cpu_core, StartUp.cpu_core);
core_section->Get("HLE_BS2", &StartUp.bHLE_BS2, StartUp.bHLE_BS2);
core_section->Get("GameCubeLanguage", &StartUp.SelectedLanguage, StartUp.SelectedLanguage);
if (core_section->Get("EmulationSpeed", &StartUp.m_EmulationSpeed, StartUp.m_EmulationSpeed))
@@ -317,7 +314,7 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
StartUp.bCPUThread = Config::Get(Config::MAIN_CPU_THREAD);
StartUp.bDSPHLE = Config::Get(Config::MAIN_DSP_HLE);
StartUp.bFastDiscSpeed = Config::Get(Config::MAIN_FAST_DISC_SPEED);
StartUp.iCPUCore = Config::Get(Config::MAIN_CPU_CORE);
StartUp.cpu_core = Config::Get(Config::MAIN_CPU_CORE);
StartUp.bSyncGPU = Config::Get(Config::MAIN_SYNC_GPU);
if (!StartUp.bWii)
StartUp.SelectedLanguage = Config::Get(Config::MAIN_GC_LANGUAGE);
@@ -343,7 +340,7 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
StartUp.bDSPHLE = g_NetPlaySettings.m_DSPHLE;
StartUp.bEnableMemcardSdWriting = g_NetPlaySettings.m_WriteToMemcard;
StartUp.bCopyWiiSaveNetplay = g_NetPlaySettings.m_CopyWiiSave;
StartUp.iCPUCore = g_NetPlaySettings.m_CPUcore;
StartUp.cpu_core = g_NetPlaySettings.m_CPUcore;
StartUp.SelectedLanguage = g_NetPlaySettings.m_SelectedLanguage;
StartUp.bOverrideGCLanguage = g_NetPlaySettings.m_OverrideGCLanguage;
StartUp.m_DSPEnableJIT = g_NetPlaySettings.m_DSPEnableJIT;
@@ -16,7 +16,8 @@ namespace Config
// Main.Core
const ConfigInfo<bool> MAIN_SKIP_IPL{{System::Main, "Core", "SkipIPL"}, true};
const ConfigInfo<int> MAIN_CPU_CORE{{System::Main, "Core", "CPUCore"}, PowerPC::DefaultCPUCore()};
const ConfigInfo<PowerPC::CPUCore> MAIN_CPU_CORE{{System::Main, "Core", "CPUCore"},
PowerPC::DefaultCPUCore()};
const ConfigInfo<bool> MAIN_FASTMEM{{System::Main, "Core", "Fastmem"}, true};
const ConfigInfo<bool> MAIN_DSP_HLE{{System::Main, "Core", "DSPHLE"}, true};
const ConfigInfo<int> MAIN_TIMING_VARIANCE{{System::Main, "Core", "TimingVariance"}, 40};
@@ -8,12 +8,17 @@
#include "Common/Config/Config.h"
namespace PowerPC
{
enum class CPUCore;
}
namespace Config
{
// Main.Core
extern const ConfigInfo<bool> MAIN_SKIP_IPL;
extern const ConfigInfo<int> MAIN_CPU_CORE;
extern const ConfigInfo<PowerPC::CPUCore> MAIN_CPU_CORE;
extern const ConfigInfo<bool> MAIN_FASTMEM;
// Should really be in the DSP section, but we're kind of stuck with bad decisions made in the past.
extern const ConfigInfo<bool> MAIN_DSP_HLE;
@@ -8,10 +8,8 @@
#include <memory>
#include <string>
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
#include "Common/FileUtil.h"
#include "Core/Config/GraphicsSettings.h"
#include "Core/Config/MainSettings.h"
@@ -20,14 +18,19 @@
#include "Core/Movie.h"
#include "VideoCommon/VideoConfig.h"
namespace PowerPC
{
enum class CPUCore;
}
namespace ConfigLoaders
{
static void LoadFromDTM(Config::Layer* config_layer, Movie::DTMHeader* dtm)
{
config_layer->Set(Config::MAIN_CPU_THREAD, dtm->bDualCore);
config_layer->Set(Config::MAIN_DSP_HLE, dtm->bDSPHLE);
config_layer->Set(Config::MAIN_FAST_DISC_SPEED, dtm->bFastDiscSpeed);
config_layer->Set(Config::MAIN_CPU_CORE, static_cast<int>(dtm->CPUCore));
config_layer->Set(Config::MAIN_CPU_CORE, static_cast<PowerPC::CPUCore>(dtm->CPUCore));
config_layer->Set(Config::MAIN_SYNC_GPU, dtm->bSyncGPU);
config_layer->Set(Config::MAIN_GFX_BACKEND, dtm->videoBackend.data());
@@ -50,7 +53,7 @@ void SaveToDTM(Movie::DTMHeader* dtm)
dtm->bDualCore = Config::Get(Config::MAIN_CPU_THREAD);
dtm->bDSPHLE = Config::Get(Config::MAIN_DSP_HLE);
dtm->bFastDiscSpeed = Config::Get(Config::MAIN_FAST_DISC_SPEED);
dtm->CPUCore = Config::Get(Config::MAIN_CPU_CORE);
dtm->CPUCore = static_cast<u8>(Config::Get(Config::MAIN_CPU_CORE));
dtm->bSyncGPU = Config::Get(Config::MAIN_SYNC_GPU);
const std::string video_backend = Config::Get(Config::MAIN_GFX_BACKEND);
@@ -218,7 +218,7 @@ void SConfig::SaveCoreSettings(IniFile& ini)
core->Set("SkipIPL", bHLE_BS2);
core->Set("TimingVariance", iTimingVariance);
core->Set("CPUCore", iCPUCore);
core->Set("CPUCore", cpu_core);
core->Set("Fastmem", bFastmem);
core->Set("CPUThread", bCPUThread);
core->Set("DSPHLE", bDSPHLE);
@@ -505,11 +505,11 @@ void SConfig::LoadCoreSettings(IniFile& ini)
core->Get("SkipIPL", &bHLE_BS2, true);
#ifdef _M_X86
core->Get("CPUCore", &iCPUCore, PowerPC::CORE_JIT64);
core->Get("CPUCore", &cpu_core, PowerPC::CPUCore::JIT64);
#elif _M_ARM_64
core->Get("CPUCore", &iCPUCore, PowerPC::CORE_JITARM64);
core->Get("CPUCore", &cpu_core, PowerPC::CPUCore::JITARM64);
#else
core->Get("CPUCore", &iCPUCore, PowerPC::CORE_INTERPRETER);
core->Get("CPUCore", &cpu_core, PowerPC::CPUCore::Interpreter);
#endif
core->Get("Fastmem", &bFastmem, true);
core->Get("DSPHLE", &bDSPHLE, true);
@@ -763,7 +763,7 @@ void SConfig::LoadDefaults()
#endif
#endif
iCPUCore = PowerPC::DefaultCPUCore();
cpu_core = PowerPC::DefaultCPUCore();
iTimingVariance = 40;
bCPUThread = false;
bSyncGPUOnSkipIdleHack = true;
@@ -23,6 +23,7 @@ enum class Region;
struct Partition;
class Volume;
} // namespace DiscIO
namespace IOS
{
namespace ES
@@ -31,6 +32,11 @@ class TMDReader;
}
} // namespace IOS
namespace PowerPC
{
enum class CPUCore;
} // namespace PowerPC
// DSP Backend Types
#define BACKEND_NULLSOUND _trans("No Audio Output")
#define BACKEND_ALSA "ALSA"
@@ -75,7 +81,7 @@ struct SConfig
bool bAutomaticStart = false;
bool bBootToPause = false;
int iCPUCore; // Uses the values of PowerPC::CPUCore
PowerPC::CPUCore cpu_core;
bool bJITNoBlockCache = false;
bool bJITNoBlockLinking = false;
@@ -530,7 +530,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
Fifo::Prepare();
// Setup our core, but can't use dynarec if we are compare server
if (core_parameter.iCPUCore != PowerPC::CORE_INTERPRETER &&
if (core_parameter.cpu_core != PowerPC::CPUCore::Interpreter &&
(!core_parameter.bRunCompareServer || core_parameter.bRunCompareClient))
{
PowerPC::SetMode(PowerPC::CoreMode::JIT);
@@ -45,7 +45,7 @@ static bool s_state_system_request_stepping = false;
static bool s_state_cpu_step_instruction = false;
static Common::Event* s_state_cpu_step_instruction_sync = nullptr;
void Init(int cpu_core)
void Init(PowerPC::CPUCore cpu_core)
{
PowerPC::Init(cpu_core);
s_state = State::Stepping;
@@ -9,6 +9,11 @@ namespace Common
class Event;
}
namespace PowerPC
{
enum class CPUCore;
}
namespace CPU
{
enum class State
@@ -19,7 +24,7 @@ enum class State
};
// Init
void Init(int cpu_core);
void Init(PowerPC::CPUCore cpu_core);
// Shutdown
void Shutdown();
@@ -45,7 +45,7 @@ void Init()
DSP::Init(SConfig::GetInstance().bDSPHLE);
DVDInterface::Init();
GPFifo::Init();
CPU::Init(SConfig::GetInstance().iCPUCore);
CPU::Init(SConfig::GetInstance().cpu_core);
SystemTimers::Init();
if (SConfig::GetInstance().bWii)
@@ -12,6 +12,7 @@
#include <mutex>
#include <sstream>
#include <thread>
#include <type_traits>
#include <mbedtls/md5.h>
@@ -35,6 +36,7 @@
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "Core/IOS/USB/Bluetooth/BTEmu.h"
#include "Core/Movie.h"
#include "Core/PowerPC/PowerPC.h"
#include "InputCommon/GCAdapter.h"
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/VideoConfig.h"
@@ -412,7 +414,15 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
packet >> m_current_game;
packet >> g_NetPlaySettings.m_CPUthread;
packet >> g_NetPlaySettings.m_CPUcore;
{
std::underlying_type_t<PowerPC::CPUCore> core;
if (packet >> core)
g_NetPlaySettings.m_CPUcore = static_cast<PowerPC::CPUCore>(core);
else
g_NetPlaySettings.m_CPUcore = PowerPC::CPUCore::CachedInterpreter;
}
packet >> g_NetPlaySettings.m_EnableCheats;
packet >> g_NetPlaySettings.m_SelectedLanguage;
packet >> g_NetPlaySettings.m_OverrideGCLanguage;
@@ -9,10 +9,15 @@
#include "Common/CommonTypes.h"
#include "Core/HW/EXI/EXI_Device.h"
namespace PowerPC
{
enum class CPUCore;
}
struct NetSettings
{
bool m_CPUthread;
int m_CPUcore;
PowerPC::CPUCore m_CPUcore;
bool m_EnableCheats;
int m_SelectedLanguage;
bool m_OverrideGCLanguage;
@@ -11,6 +11,7 @@
#include <mutex>
#include <string>
#include <thread>
#include <type_traits>
#include <unordered_set>
#include <vector>
@@ -815,10 +816,10 @@ bool NetPlayServer::StartGame()
// tell clients to start game
sf::Packet spac;
spac << (MessageId)NP_MSG_START_GAME;
spac << static_cast<MessageId>(NP_MSG_START_GAME);
spac << m_current_game;
spac << m_settings.m_CPUthread;
spac << m_settings.m_CPUcore;
spac << static_cast<std::underlying_type_t<PowerPC::CPUCore>>(m_settings.m_CPUcore);
spac << m_settings.m_EnableCheats;
spac << m_settings.m_SelectedLanguage;
spac << m_settings.m_OverrideGCLanguage;
@@ -832,8 +833,8 @@ bool NetPlayServer::StartGame()
spac << m_settings.m_OCFactor;
spac << m_settings.m_EXIDevice[0];
spac << m_settings.m_EXIDevice[1];
spac << (u32)g_netplay_initial_rtc;
spac << (u32)(g_netplay_initial_rtc >> 32);
spac << static_cast<u32>(g_netplay_initial_rtc);
spac << static_cast<u32>(g_netplay_initial_rtc >> 32);
SendAsyncToClients(std::move(spac));
Oops, something went wrong.

0 comments on commit 6f473b9

Please sign in to comment.