Merge remote-tracking branch 'origin/master' into 1.6

This commit is contained in:
Wojtek Figat
2023-05-28 16:34:38 +02:00
38 changed files with 503 additions and 124 deletions

View File

@@ -5,6 +5,7 @@
#include "Engine/Platform/MemoryStats.h"
#include "Engine/Platform/MessageBox.h"
#include "Engine/Platform/FileSystem.h"
#include "Engine/Platform/Window.h"
#include "Engine/Platform/User.h"
#include "Engine/Core/Log.h"
#include "Engine/Core/Types/DateTime.h"
@@ -157,7 +158,7 @@ void PlatformBase::LogInfo()
LOG(Info, "CPU package count: {0}, Core count: {1}, Logical processors: {2}", cpuInfo.ProcessorPackageCount, cpuInfo.ProcessorCoreCount, cpuInfo.LogicalProcessorCount);
LOG(Info, "CPU Page size: {0}, cache line size: {1} bytes", Utilities::BytesToText(cpuInfo.PageSize), cpuInfo.CacheLineSize);
LOG(Info, "L1 cache: {0}, L2 cache: {1}, L3 cache: {2}", Utilities::BytesToText(cpuInfo.L1CacheSize), Utilities::BytesToText(cpuInfo.L2CacheSize), Utilities::BytesToText(cpuInfo.L3CacheSize));
LOG(Info, "Clock speed: {0} GHz", Utilities::RoundTo2DecimalPlaces(cpuInfo.ClockSpeed * 1e-9f));
LOG(Info, "Clock speed: {0}", Utilities::HertzToText(cpuInfo.ClockSpeed));
const MemoryStats memStats = Platform::GetMemoryStats();
LOG(Info, "Physical Memory: {0} total, {1} used ({2}%)", Utilities::BytesToText(memStats.TotalPhysicalMemory), Utilities::BytesToText(memStats.UsedPhysicalMemory), Utilities::RoundTo2DecimalPlaces((float)memStats.UsedPhysicalMemory * 100.0f / (float)memStats.TotalPhysicalMemory));
@@ -520,6 +521,21 @@ void PlatformBase::CreateGuid(Guid& result)
result = Guid(dateThingHigh, randomThing | (sequentialThing << 16), cyclesThing, dateThingLow);
}
Float2 PlatformBase::GetMousePosition()
{
const Window* win = Engine::MainWindow;
if (win)
return win->ClientToScreen(win->GetMousePosition());
return Float2::Minimum;
}
void PlatformBase::SetMousePosition(const Float2& position)
{
const Window* win = Engine::MainWindow;
if (win)
win->SetMousePosition(win->ScreenToClient(position));
}
Rectangle PlatformBase::GetMonitorBounds(const Float2& screenPos)
{
return Rectangle(Float2::Zero, Platform::GetDesktopSize());

View File

@@ -651,6 +651,18 @@ public:
API_FUNCTION() static void OpenUrl(const StringView& url) = delete;
public:
/// <summary>
/// Gets the mouse cursor position in screen-space coordinates.
/// </summary>
/// <returns>Mouse cursor coordinates.</returns>
API_PROPERTY() static Float2 GetMousePosition();
/// <summary>
/// Sets the mouse cursor position in screen-space coordinates.
/// </summary>
/// <param name="position">Cursor position to set.</param>
API_PROPERTY() static void SetMousePosition(const Float2& position);
/// <summary>
/// Gets the origin position and size of the monitor at the given screen-space location.
/// </summary>

View File

@@ -89,6 +89,7 @@ X11::Cursor Cursors[(int32)CursorType::MAX];
X11::XcursorImage* CursorsImg[(int32)CursorType::MAX];
Dictionary<StringAnsi, X11::KeyCode> KeyNameMap;
Array<KeyboardKeys> KeyCodeMap;
Delegate<void*> LinuxPlatform::xEventRecieved;
// Message boxes configuration
#define LINUX_DIALOG_MIN_BUTTON_WIDTH 64
@@ -2232,10 +2233,12 @@ void LinuxPlatform::Tick()
{
X11::XEvent event;
X11::XNextEvent(xDisplay, &event);
if (X11::XFilterEvent(&event, 0))
continue;
// External event handling
xEventRecieved(&event);
LinuxWindow* window;
switch (event.type)
{
@@ -2640,10 +2643,8 @@ Float2 LinuxPlatform::GetMousePosition()
{
if (!xDisplay)
return Float2::Zero;
int32 x, y;
int32 x = 0, y = 0;
uint32 screenCount = (uint32)X11::XScreenCount(xDisplay);
for (uint32 i = 0; i < screenCount; i++)
{
X11::Window outRoot, outChild;
@@ -2652,7 +2653,6 @@ Float2 LinuxPlatform::GetMousePosition()
if (X11::XQueryPointer(xDisplay, X11::XRootWindow(xDisplay, i), &outRoot, &outChild, &x, &y, &childX, &childY, &mask))
break;
}
return Float2((float)x, (float)y);
}

View File

@@ -33,6 +33,11 @@ public:
/// <returns>The user home directory.</returns>
static const String& GetHomeDirectory();
/// <summary>
/// An event that is fired when an XEvent is received during platform tick.
/// </summary>
static Delegate<void*> xEventRecieved;
public:
// [UnixPlatform]

View File

@@ -158,27 +158,6 @@ void UWPPlatform::OpenUrl(const StringView& url)
// TODO: add support for OpenUrl on UWP
}
Float2 UWPPlatform::GetMousePosition()
{
// Use the main window
auto win = Engine::MainWindow;
if (win)
{
return win->ClientToScreen(win->GetMousePosition());
}
return Float2::Minimum;
}
void UWPPlatform::SetMousePosition(const Float2& pos)
{
// Use the main window
auto win = Engine::MainWindow;
if (win)
{
win->SetMousePosition(win->ScreenToClient(pos));
}
}
Float2 UWPPlatform::GetDesktopSize()
{
Float2 result;

View File

@@ -37,8 +37,6 @@ public:
static bool GetHasFocus();
static bool CanOpenUrl(const StringView& url);
static void OpenUrl(const StringView& url);
static Float2 GetMousePosition();
static void SetMousePosition(const Float2& pos);
static Float2 GetDesktopSize();
static Window* CreateWindow(const CreateWindowSettings& settings);
static void* LoadLibrary(const Char* filename);

View File

@@ -109,7 +109,7 @@ public:
static void CreateGuid(Guid& result);
static String GetMainDirectory();
static String GetExecutableFilePath();
static struct Guid GetUniqueDeviceId();
static Guid GetUniqueDeviceId();
static String GetWorkingDirectory();
static bool SetWorkingDirectory(const String& path);
static void FreeLibrary(void* handle);

View File

@@ -830,6 +830,18 @@ void WindowsPlatform::OpenUrl(const StringView& url)
::ShellExecuteW(nullptr, TEXT("open"), *url, nullptr, nullptr, SW_SHOWNORMAL);
}
Float2 WindowsPlatform::GetMousePosition()
{
POINT cursorPos;
GetCursorPos(&cursorPos);
return Float2((float)cursorPos.x, (float)cursorPos.y);
}
void WindowsPlatform::SetMousePosition(const Float2& pos)
{
::SetCursorPos((int)pos.X, (int)pos.Y);
}
struct GetMonitorBoundsData
{
Float2 Pos;

View File

@@ -71,6 +71,8 @@ public:
static bool GetHasFocus();
static bool CanOpenUrl(const StringView& url);
static void OpenUrl(const StringView& url);
static Float2 GetMousePosition();
static void SetMousePosition(const Float2& pos);
static Rectangle GetMonitorBounds(const Float2& screenPos);
static Float2 GetDesktopSize();
static Rectangle GetVirtualDesktopBounds();