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

@@ -175,7 +175,7 @@ Window* GameBase::CreateMainWindow()
settings.AllowMaximize = true;
settings.AllowMinimize = true;
settings.Size = Platform::GetDesktopSize();
settings.Position = Vector2::Zero;
settings.Position = Float2::Zero;
Game::InitMainWindowSettings(settings);
@@ -249,8 +249,8 @@ void GameBaseImpl::OnPostRender(GPUContext* context, RenderContext& renderContex
const float height = imageArea.GetWidth() / aspectRatio;
imageArea.Location.Y += (imageArea.GetHeight() - height) * 0.5f;
imageArea.Size.Y = height;
imageArea.Location = Vector2::Ceil(imageArea.Location);
imageArea.Size = Vector2::Ceil(imageArea.Size);
imageArea.Location = Float2::Ceil(imageArea.Location);
imageArea.Size = Float2::Ceil(imageArea.Size);
// Draw
Render2D::Begin(GPUDevice::Instance->GetMainContext(), renderContext.Task->GetOutputView(), nullptr, viewport);

View File

@@ -37,14 +37,13 @@ void LinuxGame::InitMainWindowSettings(CreateWindowSettings& settings)
windowMode == GameWindowMode::Fullscreen)
{
settings.Size = Platform::GetDesktopSize();
settings.Position = Vector2::Zero;
settings.Position = Float2::Zero;
}
// Not fullscreen - put window in the middle of the screen
else if (windowMode == GameWindowMode::Windowed ||
windowMode == GameWindowMode::Borderless)
// Not fullscreen - put window in the middle of the screen
else if (windowMode == GameWindowMode::Windowed || windowMode == GameWindowMode::Borderless)
{
settings.Size = Vector2((float)platformSettings->ScreenWidth, (float)platformSettings->ScreenHeight);
settings.Position = (Platform::GetDesktopSize() - settings.Size) / 2;
settings.Size = Float2((float)platformSettings->ScreenWidth, (float)platformSettings->ScreenHeight);
settings.Position = (Platform::GetDesktopSize() - settings.Size) * 0.5f;
}
// Windowed mode

View File

@@ -28,13 +28,13 @@ void MacGame::InitMainWindowSettings(CreateWindowSettings& settings)
if (windowMode == GameWindowMode::FullscreenBorderless || windowMode == GameWindowMode::Fullscreen)
{
settings.Size = Platform::GetDesktopSize();
settings.Position = Vector2::Zero;
settings.Position = Float2::Zero;
}
// Not fullscreen - put window in the middle of the screen
else if (windowMode == GameWindowMode::Windowed || windowMode == GameWindowMode::Borderless)
{
settings.Size = Vector2((float)platformSettings->ScreenWidth, (float)platformSettings->ScreenHeight);
settings.Position = (Platform::GetDesktopSize() - settings.Size) / 2;
settings.Size = Float2((float)platformSettings->ScreenWidth, (float)platformSettings->ScreenHeight);
settings.Position = (Platform::GetDesktopSize() - settings.Size) * 0.5f;
}
// Windowed mode

View File

@@ -13,7 +13,7 @@
#endif
Nullable<bool> Fullscreen;
Nullable<Vector2> Size;
Nullable<Float2> Size;
static CursorLockMode CursorLock = CursorLockMode::None;
class ScreenService : public EngineService
@@ -45,17 +45,17 @@ void Screen::SetIsFullscreen(bool value)
Fullscreen = value;
}
Vector2 Screen::GetSize()
Float2 Screen::GetSize()
{
#if USE_EDITOR
return Editor::Managed->GetGameWindowSize();
#else
auto win = Engine::MainWindow;
return win ? win->GetClientSize() : Vector2::Zero;
return win ? win->GetClientSize() : Float2::Zero;
#endif
}
void Screen::SetSize(const Vector2& value)
void Screen::SetSize(const Float2& value)
{
if (value.X <= 0 || value.Y <= 0)
{
@@ -66,23 +66,23 @@ void Screen::SetSize(const Vector2& value)
Size = value;
}
Vector2 Screen::ScreenToGameViewport(const Vector2& screenPos)
Float2 Screen::ScreenToGameViewport(const Float2& screenPos)
{
#if USE_EDITOR
return Editor::Managed->ScreenToGameViewport(screenPos);
#else
auto win = Engine::MainWindow;
return win ? win->ScreenToClient(screenPos) : Vector2::Minimum;
return win ? win->ScreenToClient(screenPos) : Float2::Minimum;
#endif
}
Vector2 Screen::GameViewportToScreen(const Vector2& viewportPos)
Float2 Screen::GameViewportToScreen(const Float2& viewportPos)
{
#if USE_EDITOR
return Editor::Managed->GameViewportToScreen(viewportPos);
#else
auto win = Engine::MainWindow;
return win ? win->ClientToScreen(viewportPos) : Vector2::Minimum;
return win ? win->ClientToScreen(viewportPos) : Float2::Minimum;
#endif
}

View File

@@ -32,21 +32,21 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Screen);
/// Gets the window size.
/// </summary>
/// <returns>The value</returns>
API_PROPERTY() static Vector2 GetSize();
API_PROPERTY() static Float2 GetSize();
/// <summary>
/// Converts the screen-space position to the game viewport position.
/// </summary>
/// <param name="screenPos">The screen-space position.</param>
/// <returns>The game viewport position.</returns>
API_FUNCTION() static Vector2 ScreenToGameViewport(const Vector2& screenPos);
API_FUNCTION() static Float2 ScreenToGameViewport(const Float2& screenPos);
/// <summary>
/// Converts the game viewport position to the screen-space position.
/// </summary>
/// <param name="viewportPos">The game viewport position.</param>
/// <returns>The screen-space position.</returns>
API_FUNCTION() static Vector2 GameViewportToScreen(const Vector2& viewportPos);
API_FUNCTION() static Float2 GameViewportToScreen(const Float2& viewportPos);
/// <summary>
/// Sets the window size.
@@ -55,7 +55,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Screen);
/// Resizing may not happen immediately. It will be performed before next frame rendering.
/// </remarks>
/// <param name="value">The value.</param>
API_PROPERTY() static void SetSize(const Vector2& value);
API_PROPERTY() static void SetSize(const Float2& value);
/// <summary>
/// Gets the cursor visible flag.

View File

@@ -28,14 +28,13 @@ void WindowsGame::InitMainWindowSettings(CreateWindowSettings& settings)
windowMode == GameWindowMode::Fullscreen)
{
settings.Size = Platform::GetDesktopSize();
settings.Position = Vector2::Zero;
settings.Position = Float2::Zero;
}
// Not fullscreen - put window in the middle of the screen
else if (windowMode == GameWindowMode::Windowed ||
windowMode == GameWindowMode::Borderless)
// Not fullscreen - put window in the middle of the screen
else if (windowMode == GameWindowMode::Windowed || windowMode == GameWindowMode::Borderless)
{
settings.Size = Vector2((float)platformSettings->ScreenWidth, (float)platformSettings->ScreenHeight);
settings.Position = (Platform::GetDesktopSize() - settings.Size) / 2;
settings.Size = Float2((float)platformSettings->ScreenWidth, (float)platformSettings->ScreenHeight);
settings.Position = (Platform::GetDesktopSize() - settings.Size) * 0.5f;
}
// Windowed mode