Skip to content

Commit

Permalink
Small cleanup + Fix memory base logged as 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Exzap committed Aug 3, 2023
1 parent 3edba96 commit 1baeec1
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 90 deletions.
74 changes: 63 additions & 11 deletions src/Cafe/CafeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,26 @@
#include "Cafe/GameProfile/GameProfile.h"
#include "Cafe/HW/Espresso/Interpreter/PPCInterpreterInternal.h"
#include "Cafe/HW/Espresso/Recompiler/PPCRecompiler.h"
#include "Cafe/HW/Espresso/Debugger/Debugger.h"
#include "Cafe/OS/RPL/rpl_symbol_storage.h"
#include "audio/IAudioAPI.h"
#include "audio/IAudioInputAPI.h"
#include "Cafe/HW/Espresso/Debugger/Debugger.h"

#include "config/ActiveSettings.h"
#include "Cafe/TitleList/GameInfo.h"
#include "util/helpers/SystemException.h"
#include "Cafe/GraphicPack/GraphicPack2.h"

#include "util/helpers/SystemException.h"
#include "Common/cpu_features.h"
#include "input/InputManager.h"

#include "Cafe/CafeSystem.h"
#include "Cafe/TitleList/TitleList.h"
#include "Cafe/TitleList/GameInfo.h"
#include "Cafe/OS/libs/coreinit/coreinit_Alarm.h"
#include "Cafe/OS/libs/snd_core/ax.h"
#include "Cafe/OS/RPL/rpl.h"
#include "Cafe/HW/Latte/Core/Latte.h"

#include "Cafe/Filesystem/FST/FST.h"

#include "Common/FileStream.h"

#include "GamePatch.h"

#include <time.h>
#include "HW/Espresso/Debugger/GDBStub.h"

#include "Cafe/IOSU/legacy/iosu_ioctl.h"
Expand Down Expand Up @@ -70,6 +64,15 @@
// dependency to be removed
#include "gui/guiWrapper.h"

#include <time.h>

#if BOOST_OS_LINUX
#include <sys/sysinfo.h>
#elif BOOST_OS_MACOS
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

std::string _pathToExecutable;
std::string _pathToBaseExecutable;

Expand Down Expand Up @@ -441,17 +444,66 @@ namespace CafeSystem

GameInfo2 sGameInfo_ForegroundTitle;

// initialize all subsystems which are persistent and don't depend on a game running

static void _CheckForWine()
{
#if BOOST_OS_WINDOWS
const HMODULE hmodule = GetModuleHandleA("ntdll.dll");
if (!hmodule)
return;

const auto pwine_get_version = (const char*(__cdecl*)())GetProcAddress(hmodule, "wine_get_version");
if (pwine_get_version)
{
cemuLog_log(LogType::Force, "Wine version: {}", pwine_get_version());
}
#endif
}

void logCPUAndMemoryInfo()
{
std::string cpuName = g_CPUFeatures.GetCPUName();
if (!cpuName.empty())
cemuLog_log(LogType::Force, "CPU: {}", cpuName);
#if BOOST_OS_WINDOWS
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
uint32 memoryInMB = (uint32)(statex.ullTotalPhys / 1024LL / 1024LL);
cemuLog_log(LogType::Force, "RAM: {}MB", memoryInMB);
#elif BOOST_OS_LINUX
struct sysinfo info {};
sysinfo(&info);
cemuLog_log(LogType::Force, "RAM: {}MB", ((static_cast<uint64_t>(info.totalram) * info.mem_unit) / 1024LL / 1024LL));
#elif BOOST_OS_MACOS
int64_t totalRam;
size_t size = sizeof(totalRam);
int result = sysctlbyname("hw.memsize", &totalRam, &size, NULL, 0);
if (result == 0)
cemuLog_log(LogType::Force, "RAM: {}MB", (totalRam / 1024LL / 1024LL));
#endif
}

// initialize all subsystems which are persistent and don't depend on a game running
void Initialize()
{
if (s_initialized)
return;
s_initialized = true;
// init core systems
cemuLog_log(LogType::Force, "------- Init {} -------", BUILD_VERSION_WITH_NAME_STRING);
fsc_init();
memory_init();
cemuLog_log(LogType::Force, "Init Wii U memory space (base: 0x{:016x})", (size_t)memory_base);
PPCCore_init();
RPLLoader_InitState();
cemuLog_log(LogType::Force, "mlc01 path: {}", _pathToUtf8(ActiveSettings::GetMlcPath()));
_CheckForWine();
// CPU and RAM info
logCPUAndMemoryInfo();
cemuLog_log(LogType::Force, "Used CPU extensions: {}", g_CPUFeatures.GetCommaSeparatedExtensionList());
// misc systems
rplSymbolStorage_init();
// allocate memory for all SysAllocators
// must happen before COS module init, but also before iosu::kernel::Initialize()
SysAllocatorContainer::GetInstance().Initialize();
Expand Down
3 changes: 0 additions & 3 deletions src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,6 @@ void OpenGLRenderer::NotifyLatteCommandProcessorIdle()
glFlush();
}


bool IsRunningInWine();

void OpenGLRenderer::GetVendorInformation()
{
// example vendor strings:
Expand Down
1 change: 0 additions & 1 deletion src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ std::vector<VulkanRenderer::DeviceInfo> VulkanRenderer::GetDevices()

}

bool IsRunningInWine();
void VulkanRenderer::DetermineVendor()
{
VkPhysicalDeviceProperties2 properties{};
Expand Down
14 changes: 4 additions & 10 deletions src/gui/GameUpdateWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ std::string _GetTitleIdTypeStr(TitleId titleId)
return "Unknown";
}

bool IsRunningInWine();

bool GameUpdateWindow::ParseUpdate(const fs::path& metaPath)
{
m_title_info = TitleInfo(metaPath);
Expand Down Expand Up @@ -130,15 +128,11 @@ bool GameUpdateWindow::ParseUpdate(const fs::path& metaPath)
}
}

// checking size is buggy on Wine (on Steam Deck this would return values too small to install bigger updates) - we therefore skip this step
if(!IsRunningInWine())
const fs::space_info targetSpace = fs::space(ActiveSettings::GetMlcPath());
if (targetSpace.free <= m_required_size)
{
const fs::space_info targetSpace = fs::space(ActiveSettings::GetMlcPath());
if (targetSpace.free <= m_required_size)
{
auto string = wxStringFormat(_("Not enough space available.\nRequired: {0} MB\nAvailable: {1} MB"), L"%lld %lld", (m_required_size / 1024 / 1024), (targetSpace.free / 1024 / 1024));
throw std::runtime_error(string);
}
auto string = wxStringFormat(_("Not enough space available.\nRequired: {0} MB\nAvailable: {1} MB"), L"%lld %lld", (m_required_size / 1024 / 1024), (targetSpace.free / 1024 / 1024));
throw std::runtime_error(string);
}

return true;
Expand Down
65 changes: 0 additions & 65 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "util/crypto/aes128.h"
#include "gui/MainWindow.h"
#include "Cafe/OS/RPL/rpl.h"
#include "Cafe/OS/RPL/rpl_symbol_storage.h"
#include "Cafe/OS/libs/gx2/GX2.h"
#include "Cafe/OS/libs/coreinit/coreinit_Thread.h"
#include "Cafe/HW/Latte/Core/LatteOverlay.h"
Expand Down Expand Up @@ -60,66 +59,6 @@ std::atomic_bool g_isGPUInitFinished = false;

std::wstring executablePath;

void logCPUAndMemoryInfo()
{
std::string cpuName = g_CPUFeatures.GetCPUName();
if (!cpuName.empty())
cemuLog_log(LogType::Force, "CPU: {}", cpuName);

#if BOOST_OS_WINDOWS
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
uint32 memoryInMB = (uint32)(statex.ullTotalPhys / 1024LL / 1024LL);
cemuLog_log(LogType::Force, "RAM: {}MB", memoryInMB);
#elif BOOST_OS_LINUX
struct sysinfo info {};
sysinfo(&info);
cemuLog_log(LogType::Force, "RAM: {}MB", ((static_cast<uint64_t>(info.totalram) * info.mem_unit) / 1024LL / 1024LL));
#elif BOOST_OS_MACOS
int64_t totalRam;
size_t size = sizeof(totalRam);
int result = sysctlbyname("hw.memsize", &totalRam, &size, NULL, 0);
if (result == 0)
cemuLog_log(LogType::Force, "RAM: {}MB", (totalRam / 1024LL / 1024LL));
#endif
}

bool g_running_in_wine = false;
bool IsRunningInWine()
{
return g_running_in_wine;
}

void checkForWine()
{
#if BOOST_OS_WINDOWS
const HMODULE hmodule = GetModuleHandleA("ntdll.dll");
if (!hmodule)
return;

const auto pwine_get_version = (const char*(__cdecl*)())GetProcAddress(hmodule, "wine_get_version");
if (pwine_get_version)
{
g_running_in_wine = true;
cemuLog_log(LogType::Force, "Wine version: {}", pwine_get_version());
}
#else
g_running_in_wine = false;
#endif
}

void infoLog_cemuStartup()
{
cemuLog_log(LogType::Force, "------- Init {} -------", BUILD_VERSION_WITH_NAME_STRING);
cemuLog_log(LogType::Force, "Init Wii U memory space (base: 0x{:016x})", (size_t)memory_base);
cemuLog_log(LogType::Force, "mlc01 path: {}", _pathToUtf8(ActiveSettings::GetMlcPath()));
checkForWine();
// CPU and RAM info
logCPUAndMemoryInfo();
cemuLog_log(LogType::Force, "Used CPU extensions: {}", g_CPUFeatures.GetCommaSeparatedExtensionList());
}

// some implementations of _putenv dont copy the string and instead only store a pointer
// thus we use a helper to keep a permanent copy
std::vector<std::string*> sPutEnvMap;
Expand Down Expand Up @@ -189,16 +128,12 @@ void CemuCommonInit()
g_config.Load();
if (NetworkConfig::XMLExists())
n_config.Load();
// symbol storage
rplSymbolStorage_init();
// parallelize expensive init code
std::future<int> futureInitAudioAPI = std::async(std::launch::async, []{ IAudioAPI::InitializeStatic(); IAudioInputAPI::InitializeStatic(); return 0; });
std::future<int> futureInitGraphicPacks = std::async(std::launch::async, []{ GraphicPack2::LoadAll(); return 0; });
InputManager::instance().load();
futureInitAudioAPI.wait();
futureInitGraphicPacks.wait();
// log Cemu startup info
infoLog_cemuStartup();
// init Cafe system
CafeSystem::Initialize();
// init title list
Expand Down

0 comments on commit 1baeec1

Please sign in to comment.