Merge remote-tracking branch 'origin/1.10' into sdl_platform

# Conflicts:
#	Source/Editor/GUI/ContextMenu/ContextMenuBase.cs
#	Source/Engine/Platform/Linux/LinuxPlatform.cpp
This commit is contained in:
2025-03-09 13:16:25 +02:00
594 changed files with 19183 additions and 15772 deletions

View File

@@ -8,6 +8,7 @@
#include "Engine/Core/Log.h"
#include "Engine/Core/Types/Guid.h"
#include "Engine/Core/Types/String.h"
#include "Engine/Core/Types/Version.h"
#include "Engine/Core/Collections/HashFunctions.h"
#include "Engine/Core/Collections/Array.h"
#include "Engine/Core/Collections/Dictionary.h"
@@ -19,6 +20,7 @@
#include "Engine/Platform/MemoryStats.h"
#include "Engine/Platform/StringUtils.h"
#include "Engine/Platform/MessageBox.h"
#include "Engine/Platform/File.h"
#include "Engine/Platform/WindowsManager.h"
#include "Engine/Platform/CreateProcessSettings.h"
#include "Engine/Platform/Clipboard.h"
@@ -57,6 +59,7 @@
CPUInfo UnixCpu;
int ClockSource;
uint64 ProgramSizeMemory;
Guid DeviceId;
String UserLocale, ComputerName, HomeDir;
byte MacAddress[6];
@@ -659,7 +662,7 @@ DialogResult MessageBox::Show(Window* parent, const StringView& text, const Stri
DialogResult MessageBox::ShowFallback(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon)
#endif
{
if (CommandLine::Options.Headless)
if (CommandLine::Options.Headless.IsTrue())
return DialogResult::None;
// Setup for simple popup
@@ -1341,7 +1344,33 @@ namespace Impl
X11::XQueryPointer(display, w, &wtmp, &child, &tmp, &tmp, &tmp, &tmp, &utmp);
return FindAppWindow(display, child);
}
#endif
Dictionary<String, String> LoadConfigFile(StringView path)
{
Dictionary<String, String> results;
String data;
File::ReadAllText(path, data);
Array<String> lines, parts;
data.Split('\n', lines);
for (String& line : lines)
{
line = line.TrimTrailing();
if (line.StartsWith('#'))
continue; // Skip comments
line.Split('=', parts);
if (parts.Count() == 2)
{
String key = parts[0].TrimTrailing();
String value = parts[1].TrimTrailing();
if (key.StartsWith('\"'))
key = key.Substring(1, key.Length() - 2);
if (value.StartsWith('\"'))
value = value.Substring(1, value.Length() - 2);
results[key] = value;
}
}
return results;
}
}
#if !PLATFORM_SDL
@@ -1384,7 +1413,7 @@ public:
DragDropEffect Window::DoDragDrop(const StringView& data)
{
if (CommandLine::Options.Headless)
if (CommandLine::Options.Headless.IsTrue())
return DragDropEffect::None;
auto cursorWrong = X11::XCreateFontCursor(xDisplay, 54);
auto cursorTransient = X11::XCreateFontCursor(xDisplay, 24);
@@ -1689,7 +1718,7 @@ void LinuxClipboard::Clear()
void LinuxClipboard::SetText(const StringView& text)
{
if (CommandLine::Options.Headless)
if (CommandLine::Options.Headless.IsTrue())
return;
auto mainWindow = Engine::MainWindow;
if (!mainWindow)
@@ -1711,7 +1740,7 @@ void LinuxClipboard::SetFiles(const Array<String>& files)
String LinuxClipboard::GetText()
{
if (CommandLine::Options.Headless)
if (CommandLine::Options.Headless.IsTrue())
return String::Empty;
String result;
auto mainWindow = Engine::MainWindow;
@@ -1786,32 +1815,25 @@ CPUInfo LinuxPlatform::GetCPUInfo()
MemoryStats LinuxPlatform::GetMemoryStats()
{
// Get memory usage
const uint64 pageSize = getpagesize();
const uint64 totalPages = get_phys_pages();
const uint64 availablePages = get_avphys_pages();
// Fill result data
MemoryStats result;
result.TotalPhysicalMemory = totalPages * pageSize;
result.UsedPhysicalMemory = (totalPages - availablePages) * pageSize;
result.TotalVirtualMemory = result.TotalPhysicalMemory;
result.UsedVirtualMemory = result.UsedPhysicalMemory;
result.ProgramSizeMemory = ProgramSizeMemory;
return result;
}
ProcessMemoryStats LinuxPlatform::GetProcessMemoryStats()
{
// Get memory usage
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
// Fill result data
ProcessMemoryStats result;
result.UsedPhysicalMemory = usage.ru_maxrss;
result.UsedVirtualMemory = result.UsedPhysicalMemory;
return result;
}
@@ -1943,6 +1965,9 @@ bool LinuxPlatform::Init()
ClockSource = CLOCK_MONOTONIC;
}
// Estimate program size by checking physical memory usage on start
ProgramSizeMemory = Platform::GetProcessMemoryStats().UsedPhysicalMemory;
// Set info about the CPU
cpu_set_t cpus;
CPU_ZERO(&cpus);
@@ -2081,28 +2106,6 @@ bool LinuxPlatform::Init()
UnixGetMacAddress(MacAddress);
// Generate unique device ID
{
DeviceId = Guid::Empty;
// A - Computer Name and User Name
uint32 hash = GetHash(Platform::GetComputerName());
CombineHash(hash, GetHash(Platform::GetUserName()));
DeviceId.A = hash;
// B - MAC address
hash = MacAddress[0];
for (uint32 i = 0; i < 6; i++)
CombineHash(hash, MacAddress[i]);
DeviceId.B = hash;
// C - memory
DeviceId.C = (uint32)Platform::GetMemoryStats().TotalPhysicalMemory;
// D - cpuid
DeviceId.D = (uint32)UnixCpu.ClockSpeed * UnixCpu.LogicalProcessorCount * UnixCpu.ProcessorCoreCount * UnixCpu.CacheLineSize;
}
#if !PLATFORM_SDL
// Get user locale string
setlocale(LC_ALL, "");
@@ -2132,9 +2135,30 @@ bool LinuxPlatform::Init()
Platform::MemoryClear(Cursors, sizeof(Cursors));
Platform::MemoryClear(CursorsImg, sizeof(CursorsImg));
// Generate unique device ID
{
DeviceId = Guid::Empty;
// A - Computer Name and User Name
uint32 hash = GetHash(Platform::GetComputerName());
CombineHash(hash, GetHash(Platform::GetUserName()));
DeviceId.A = hash;
// B - MAC address
hash = MacAddress[0];
for (uint32 i = 0; i < 6; i++)
CombineHash(hash, MacAddress[i]);
DeviceId.B = hash;
// C - memory
DeviceId.C = (uint32)Platform::GetMemoryStats().TotalPhysicalMemory;
// D - cpuid
DeviceId.D = (uint32)UnixCpu.ClockSpeed * UnixCpu.LogicalProcessorCount * UnixCpu.ProcessorCoreCount * UnixCpu.CacheLineSize;
}
// Skip setup if running in headless mode (X11 might not be available on servers)
if (CommandLine::Options.Headless)
if (CommandLine::Options.Headless.IsTrue())
return false;
#if PLATFORM_SDL
xDisplay = X11::XOpenDisplay(nullptr);
@@ -2678,6 +2702,25 @@ void LinuxPlatform::Exit()
#endif
}
String LinuxPlatform::GetSystemName()
{
Dictionary<String, String> configs = Impl::LoadConfigFile(TEXT("/etc/os-release"));
String str;
if (configs.TryGet(TEXT("NAME"), str))
return str;
return TEXT("Linux");
}
Version LinuxPlatform::GetSystemVersion()
{
Dictionary<String, String> configs = Impl::LoadConfigFile(TEXT("/etc/os-release"));
String str;
Version version;
if (configs.TryGet(TEXT("VERSION_ID"), str) && !Version::Parse(str, &version))
return version;
return Version(0, 0);
}
#if !PLATFORM_SDL
int32 LinuxPlatform::GetDpi()
{