Refactor engine to support double-precision vectors

This commit is contained in:
Wojtek Figat
2022-06-13 00:40:32 +02:00
parent f82e370392
commit a881c90b2e
744 changed files with 19062 additions and 12467 deletions

View File

@@ -81,7 +81,7 @@ X11::Atom xAtomClipboard;
X11::Atom xDnDRequested = 0;
X11::Window xDndSourceWindow = 0;
DragDropEffect xDndResult;
Vector2 xDndPos;
Float2 xDndPos;
int32 xDnDVersion = 0;
int32 SystemDpi = 96;
X11::Cursor Cursors[(int32)CursorType::MAX];
@@ -1185,7 +1185,7 @@ public:
public:
// [Mouse]
void SetMousePosition(const Vector2& newPosition) final override
void SetMousePosition(const Float2& newPosition) final override
{
LinuxPlatform::SetMousePosition(newPosition);
@@ -1457,7 +1457,7 @@ DragDropEffect LinuxWindow::DoDragDrop(const StringView& data)
status = Unreceptive;
else if(version == -1)
status = Unaware;
xDndPos = Vector2((float)event.xmotion.x_root, (float)event.xmotion.y_root);
xDndPos = Float2((float)event.xmotion.x_root, (float)event.xmotion.y_root);
// Update mouse grab
if (status == Unaware)
@@ -2278,7 +2278,7 @@ void LinuxPlatform::Tick()
m.data.l[4] = xAtomXdndActionCopy;
X11::XSendEvent(xDisplay, event.xclient.data.l[0], 0, NoEventMask, (X11::XEvent*)&m);
X11::XFlush(xDisplay);
xDndPos = Vector2((float)(event.xclient.data.l[2] >> 16), (float)(event.xclient.data.l[2] & 0xffff));
xDndPos = Float2((float)(event.xclient.data.l[2] >> 16), (float)(event.xclient.data.l[2] & 0xffff));
window = WindowsManager::GetByNativePtr((void*)event.xany.window);
if (window)
{
@@ -2631,10 +2631,10 @@ void LinuxPlatform::OpenUrl(const StringView& url)
system(cmd);
}
Vector2 LinuxPlatform::GetMousePosition()
Float2 LinuxPlatform::GetMousePosition()
{
if (!xDisplay)
return Vector2::Zero;
return Float2::Zero;
int32 x, y;
uint32 screenCount = (uint32)X11::XScreenCount(xDisplay);
@@ -2648,10 +2648,10 @@ Vector2 LinuxPlatform::GetMousePosition()
break;
}
return Vector2((float)x, (float)y);
return Float2((float)x, (float)y);
}
void LinuxPlatform::SetMousePosition(const Vector2& pos)
void LinuxPlatform::SetMousePosition(const Float2& pos)
{
if (!xDisplay)
return;
@@ -2678,37 +2678,37 @@ void LinuxPlatform::SetMousePosition(const Vector2& pos)
}
}
Vector2 LinuxPlatform::GetDesktopSize()
Float2 LinuxPlatform::GetDesktopSize()
{
if (!xDisplay)
return Vector2::Zero;
return Float2::Zero;
int event, err;
const bool ok = X11::XineramaQueryExtension(xDisplay, &event, &err);
if (!ok)
return Vector2::Zero;
return Float2::Zero;
int count;
int screenIdx = 0;
X11::XineramaScreenInfo* xsi = X11::XineramaQueryScreens(xDisplay, &count);
if (screenIdx >= count)
return Vector2::Zero;
return Float2::Zero;
Vector2 size((float)xsi[screenIdx].width, (float)xsi[screenIdx].height);
Float2 size((float)xsi[screenIdx].width, (float)xsi[screenIdx].height);
X11::XFree(xsi);
return size;
}
Rectangle LinuxPlatform::GetMonitorBounds(const Vector2& screenPos)
Rectangle LinuxPlatform::GetMonitorBounds(const Float2& screenPos)
{
// TODO: do it in a proper way
return Rectangle(Vector2::Zero, GetDesktopSize());
return Rectangle(Float2::Zero, GetDesktopSize());
}
Rectangle LinuxPlatform::GetVirtualDesktopBounds()
{
// TODO: do it in a proper way
return Rectangle(Vector2::Zero, GetDesktopSize());
return Rectangle(Float2::Zero, GetDesktopSize());
}
String LinuxPlatform::GetMainDirectory()

View File

@@ -120,16 +120,16 @@ public:
static bool GetHasFocus();
static bool CanOpenUrl(const StringView& url);
static void OpenUrl(const StringView& url);
static Vector2 GetMousePosition();
static void SetMousePosition(const Vector2& pos);
static Rectangle GetMonitorBounds(const Vector2& screenPos);
static Vector2 GetDesktopSize();
static Rectangle GetVirtualDesktopBounds();
static String GetMainDirectory();
static String GetExecutableFilePath();
static Guid GetUniqueDeviceId();
static Float2 GetMousePosition();
static void SetMousePosition(const Float2& pos);
static Rectangle GetMonitorBounds(const Float2& screenPos);
static Float2 GetDesktopSize();
static Rectangle GetVirtualDesktopBounds();
static String GetMainDirectory();
static String GetExecutableFilePath();
static Guid GetUniqueDeviceId();
static String GetWorkingDirectory();
static bool SetWorkingDirectory(const String& path);
static bool SetWorkingDirectory(const String& path);
static Window* CreateWindow(const CreateWindowSettings& settings);
static bool GetEnvironmentVariable(const String& name, String& value);
static bool SetEnvironmentVariable(const String& name, const String& value);

View File

@@ -10,7 +10,7 @@
#include "Engine/Core/Log.h"
#include "Engine/Core/Math/Math.h"
#include "Engine/Core/Math/Color32.h"
#include "Engine/Core/Math/Int2.h"
#include "Engine/Core/Math/Vector2.h"
#include "Engine/Core/Collections/Array.h"
#include "Engine/Core/Collections/Dictionary.h"
#include "Engine/Utilities/StringConverter.h"
@@ -53,7 +53,7 @@ LinuxWindow::LinuxWindow(const CreateWindowSettings& settings)
// Cache data
int32 width = Math::TruncToInt(settings.Size.X);
int32 height = Math::TruncToInt(settings.Size.Y);
_clientSize = Vector2((float)width, (float)height);
_clientSize = Float2((float)width, (float)height);
int32 x = 0, y = 0;
switch (settings.StartPosition)
{
@@ -67,7 +67,7 @@ LinuxWindow::LinuxWindow(const CreateWindowSettings& settings)
break;
case WindowStartPosition::CenterScreen:
{
Vector2 desktopSize = Platform::GetDesktopSize();
Float2 desktopSize = Platform::GetDesktopSize();
x = Math::TruncToInt((desktopSize.X - _clientSize.X) * 0.5f);
y = Math::TruncToInt((desktopSize.Y - _clientSize.Y) * 0.5f);
}
@@ -365,13 +365,13 @@ void LinuxWindow::SetClientBounds(const Rectangle& clientArea)
X11::XSetNormalHints(display, window, &hints);
}
_clientSize = Vector2((float)width, (float)height);
_clientSize = Float2((float)width, (float)height);
X11::XResizeWindow(display, window, width, height);
X11::XMoveWindow(display, window, x, y);
X11::XFlush(display);
}
void LinuxWindow::SetPosition(const Vector2& position)
void LinuxWindow::SetPosition(const Float2& position)
{
int32 x = Math::TruncToInt(position.X);
int32 y = Math::TruncToInt(position.Y);
@@ -382,7 +382,7 @@ void LinuxWindow::SetPosition(const Vector2& position)
X11::XFlush(display);
}
void LinuxWindow::SetClientPosition(const Vector2& position)
void LinuxWindow::SetClientPosition(const Float2& position)
{
int32 x = Math::TruncToInt(position.X);
int32 y = Math::TruncToInt(position.Y);
@@ -395,32 +395,32 @@ void LinuxWindow::SetClientPosition(const Vector2& position)
X11::XFlush(display);
}
Vector2 LinuxWindow::GetPosition() const
Float2 LinuxWindow::GetPosition() const
{
LINUX_WINDOW_PROLOG;
if (!display)
return Vector2::Zero;
return Float2::Zero;
X11::XWindowAttributes xwa;
X11::XGetWindowAttributes(display, window, &xwa);
return Vector2((float)xwa.x, (float)xwa.y);
return Float2((float)xwa.x, (float)xwa.y);
}
Vector2 LinuxWindow::GetSize() const
Float2 LinuxWindow::GetSize() const
{
LINUX_WINDOW_PROLOG;
if (!display)
return _clientSize;
X11::XWindowAttributes xwa;
X11::XGetWindowAttributes(display, window, &xwa);
return Vector2((float)(xwa.width + xwa.border_width), (float)(xwa.height + xwa.border_width));
return Float2((float)(xwa.width + xwa.border_width), (float)(xwa.height + xwa.border_width));
}
Vector2 LinuxWindow::GetClientSize() const
Float2 LinuxWindow::GetClientSize() const
{
return _clientSize;
}
Vector2 LinuxWindow::ScreenToClient(const Vector2& screenPos) const
Float2 LinuxWindow::ScreenToClient(const Float2& screenPos) const
{
LINUX_WINDOW_PROLOG;
if (!display)
@@ -428,10 +428,10 @@ Vector2 LinuxWindow::ScreenToClient(const Vector2& screenPos) const
int32 x, y;
X11::Window child;
X11::XTranslateCoordinates(display, X11_DefaultRootWindow(display), window, (int32)screenPos.X, (int32)screenPos.Y, &x, &y, &child);
return Vector2((float)x, (float)y);
return Float2((float)x, (float)y);
}
Vector2 LinuxWindow::ClientToScreen(const Vector2& clientPos) const
Float2 LinuxWindow::ClientToScreen(const Float2& clientPos) const
{
LINUX_WINDOW_PROLOG;
if (!display)
@@ -439,7 +439,7 @@ Vector2 LinuxWindow::ClientToScreen(const Vector2& clientPos) const
int32 x, y;
X11::Window child;
X11::XTranslateCoordinates(display, window, X11_DefaultRootWindow(display), (int32)clientPos.X, (int32)clientPos.Y, &x, &y, &child);
return Vector2((float)x, (float)y);
return Float2((float)x, (float)y);
}
void LinuxWindow::FlashWindow()
@@ -513,7 +513,7 @@ void LinuxWindow::CheckForWindowResize()
X11::XGetWindowAttributes(display, window, &xwa);
const int32 width = xwa.width;
const int32 height = xwa.height;
const Vector2 clientSize((float)width, (float)height);
const Float2 clientSize((float)width, (float)height);
// Check if window size has been changed
if (clientSize != _clientSize && width > 0 && height > 0)
@@ -564,7 +564,7 @@ void LinuxWindow::OnButtonPress(void* event)
{
auto buttonEvent = (X11::XButtonPressedEvent*)event;
Vector2 mousePos((float)buttonEvent->x, (float)buttonEvent->y);
Float2 mousePos((float)buttonEvent->x, (float)buttonEvent->y);
MouseButton mouseButton;
switch (buttonEvent->button)
{
@@ -602,7 +602,7 @@ void LinuxWindow::OnButtonPress(void* event)
void LinuxWindow::OnButtonRelease(void* event)
{
auto buttonEvent = (X11::XButtonReleasedEvent*)event;
Vector2 mousePos((float)buttonEvent->x, (float)buttonEvent->y);
Float2 mousePos((float)buttonEvent->x, (float)buttonEvent->y);
switch (buttonEvent->button)
{
case Button1:
@@ -628,7 +628,7 @@ void LinuxWindow::OnButtonRelease(void* event)
void LinuxWindow::OnMotionNotify(void* event)
{
auto motionEvent = (X11::XMotionEvent*)event;
Vector2 mousePos((float)motionEvent->x, (float)motionEvent->y);
Float2 mousePos((float)motionEvent->x, (float)motionEvent->y);
Input::Mouse->OnMouseMove(ClientToScreen(mousePos), this);
}
@@ -641,7 +641,7 @@ void LinuxWindow::OnLeaveNotify(void* event)
void LinuxWindow::OnConfigureNotify(void* event)
{
auto configureEvent = (X11::XConfigureEvent*)event;
const Vector2 clientSize((float)configureEvent->width, (float)configureEvent->height);
const Float2 clientSize((float)configureEvent->width, (float)configureEvent->height);
if (clientSize != _clientSize)
{
_clientSize = clientSize;
@@ -847,7 +847,7 @@ void LinuxWindow::SetIcon(TextureData& icon)
{
for (int32 x = 0; x < icon.Width; x++)
{
const Vector2 uv((float)x / icon.Width, (float)y / icon.Height);
const Float2 uv((float)x / icon.Width, (float)y / icon.Height);
Color color = TextureTool::SampleLinear(sampler, uv, iconData->Data.Get(), iconSize, iconData->RowPitch);
*(mipData + y * icon.Width + x) = Color32(color);
}
@@ -891,7 +891,7 @@ void LinuxWindow::SetIcon(TextureData& icon)
{
for (int32 x = 0; x < newWidth; x++)
{
const Vector2 uv((float)x / newWidth, (float)y / newHeight);
const Float2 uv((float)x / newWidth, (float)y / newHeight);
Color color = TextureTool::SampleLinear(sampler, uv, iconData->Data.Get(), iconSize, iconData->RowPitch);
*(mipData + y * newWidth + x) = Color32(color);
}

View File

@@ -76,13 +76,13 @@ public:
bool IsForegroundWindow() const override;
void BringToFront(bool force = false) override;
void SetClientBounds(const Rectangle& clientArea) override;
void SetPosition(const Vector2& position) override;
void SetClientPosition(const Vector2& position) override;
Vector2 GetPosition() const override;
Vector2 GetSize() const override;
Vector2 GetClientSize() const override;
Vector2 ScreenToClient(const Vector2& screenPos) const override;
Vector2 ClientToScreen(const Vector2& clientPos) const override;
void SetPosition(const Float2& position) override;
void SetClientPosition(const Float2& position) override;
Float2 GetPosition() const override;
Float2 GetSize() const override;
Float2 GetClientSize() const override;
Float2 ScreenToClient(const Float2& screenPos) const override;
Float2 ClientToScreen(const Float2& clientPos) const override;
void FlashWindow() override;
float GetOpacity() const override;
void SetOpacity(float opacity) override;