Merge branch 'sdl_platform' of https://github.com/GoaLitiuM/FlaxEngine into GoaLitiuM-sdl_platform
# Conflicts: # Source/Editor/GUI/Dialogs/ColorPickerDialog.cs # Source/Editor/Modules/UIModule.cs
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "CommandLine.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
#include "Engine/Core/Utilities.h"
|
||||
#include "Engine/Core/Types/StringView.h"
|
||||
#include <iostream>
|
||||
|
||||
CommandLine::OptionsData CommandLine::Options;
|
||||
@@ -145,6 +146,12 @@ bool CommandLine::Parse(const Char* cmdLine)
|
||||
PARSE_BOOL_SWITCH("-monolog ", MonoLog);
|
||||
PARSE_BOOL_SWITCH("-mute ", Mute);
|
||||
PARSE_BOOL_SWITCH("-lowdpi ", LowDPI);
|
||||
|
||||
#if PLATFORM_LINUX && PLATFORM_SDL
|
||||
PARSE_BOOL_SWITCH("-wayland ", Wayland);
|
||||
PARSE_BOOL_SWITCH("-x11 ", X11);
|
||||
#endif
|
||||
|
||||
#if USE_EDITOR
|
||||
PARSE_BOOL_SWITCH("-clearcache ", ClearCache);
|
||||
PARSE_BOOL_SWITCH("-clearcooker ", ClearCookerCache);
|
||||
@@ -163,3 +170,63 @@ bool CommandLine::Parse(const Char* cmdLine)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CommandLine::ParseArguments(const StringView& cmdLine, Array<StringAnsi>& arguments)
|
||||
{
|
||||
int32 start = 0;
|
||||
int32 quotesStart = -1;
|
||||
int32 length = cmdLine.Length();
|
||||
for (int32 i = 0; i < length; i++)
|
||||
{
|
||||
if (cmdLine[i] == ' ' && quotesStart == -1)
|
||||
{
|
||||
int32 count = i - start;
|
||||
if (count > 0)
|
||||
arguments.Add(StringAnsi(cmdLine.Substring(start, count)));
|
||||
start = i + 1;
|
||||
}
|
||||
else if (cmdLine[i] == '\"')
|
||||
{
|
||||
if (quotesStart >= 0)
|
||||
{
|
||||
if (i + 1 < length && cmdLine[i + 1] != ' ')
|
||||
{
|
||||
// End quotes are in the middle of the current word,
|
||||
// continue until the end of the current word.
|
||||
}
|
||||
else
|
||||
{
|
||||
int32 offset = 1;
|
||||
if (quotesStart == start && cmdLine[start] == '\"')
|
||||
{
|
||||
// Word starts and ends with quotes, only include the quoted content.
|
||||
quotesStart++;
|
||||
offset--;
|
||||
}
|
||||
else if (quotesStart != start)
|
||||
{
|
||||
// Start quotes in the middle of the word, include the whole word.
|
||||
quotesStart = start;
|
||||
}
|
||||
|
||||
int32 count = i - quotesStart + offset;
|
||||
if (count > 0)
|
||||
arguments.Add(StringAnsi(cmdLine.Substring(quotesStart, count)));
|
||||
start = i + 1;
|
||||
}
|
||||
quotesStart = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
quotesStart = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
const int32 count = length - start;
|
||||
if (count > 0)
|
||||
arguments.Add(StringAnsi(cmdLine.Substring(start, count)));
|
||||
if (quotesStart >= 0)
|
||||
return true; // Missing last closing quote
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "Engine/Core/Types/String.h"
|
||||
#include "Engine/Core/Types/Nullable.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
|
||||
/// <summary>
|
||||
/// Command line options helper.
|
||||
@@ -127,6 +128,20 @@ public:
|
||||
/// </summary>
|
||||
Nullable<bool> LowDPI;
|
||||
|
||||
#if PLATFORM_LINUX && PLATFORM_SDL
|
||||
|
||||
/// <summary>
|
||||
/// -wayland (prefer Wayland over X11 as display server)
|
||||
/// </summary>
|
||||
Nullable<bool> Wayland;
|
||||
|
||||
/// <summary>
|
||||
/// -x11 (prefer X11 over Wayland as display server)
|
||||
/// </summary>
|
||||
Nullable<bool> X11;
|
||||
|
||||
#endif
|
||||
|
||||
#if USE_EDITOR
|
||||
/// <summary>
|
||||
/// -project !path! (Startup project path)
|
||||
@@ -200,4 +215,12 @@ public:
|
||||
/// <param name="cmdLine">The command line.</param>
|
||||
/// <returns>True if failed, otherwise false.</returns>
|
||||
static bool Parse(const Char* cmdLine);
|
||||
|
||||
/// <summary>
|
||||
/// Parses the command line arguments string into string list of arguments.
|
||||
/// </summary>
|
||||
/// <param name="cmdLine">The command line.</param>
|
||||
/// <param name="arguments">The parsed arguments</param>
|
||||
/// <returns>True if failed, otherwise false.</returns>
|
||||
static bool ParseArguments(const StringView& cmdLine, Array<StringAnsi>& arguments);
|
||||
};
|
||||
|
||||
@@ -101,6 +101,8 @@ int32 Engine::Main(const Char* cmdLine)
|
||||
CommandLine::Options.Std = true;
|
||||
#endif
|
||||
|
||||
Platform::SetHighDpiAwarenessEnabled(!CommandLine::Options.LowDPI.IsTrue());
|
||||
|
||||
if (Platform::Init())
|
||||
{
|
||||
Platform::Fatal(TEXT("Cannot init platform."));
|
||||
@@ -110,7 +112,6 @@ int32 Engine::Main(const Char* cmdLine)
|
||||
InitProfilerMemory(cmdLine, 1);
|
||||
#endif
|
||||
|
||||
Platform::SetHighDpiAwarenessEnabled(!CommandLine::Options.LowDPI.IsTrue());
|
||||
Time::StartupTime = DateTime::Now();
|
||||
Globals::StartupFolder = Globals::BinariesFolder = Platform::GetMainDirectory();
|
||||
#if USE_EDITOR
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "Engine/Core/Types/Nullable.h"
|
||||
#include "Engine/Platform/Window.h"
|
||||
#include "Engine/Engine/EngineService.h"
|
||||
#include "Engine/Input/Input.h"
|
||||
#include "Engine/Input/Mouse.h"
|
||||
#if USE_EDITOR
|
||||
#include "Editor/Editor.h"
|
||||
#include "Editor/Managed/ManagedEditor.h"
|
||||
@@ -13,10 +15,14 @@
|
||||
#include "Engine/Engine/Engine.h"
|
||||
#endif
|
||||
|
||||
Nullable<bool> Fullscreen;
|
||||
Nullable<Float2> Size;
|
||||
bool CursorVisible = true;
|
||||
CursorLockMode CursorLock = CursorLockMode::None;
|
||||
namespace
|
||||
{
|
||||
Nullable<bool> Fullscreen;
|
||||
Nullable<Float2> Size;
|
||||
bool CursorVisible = true;
|
||||
CursorLockMode CursorLock = CursorLockMode::None;
|
||||
bool LastGameViewportFocus = false;
|
||||
}
|
||||
|
||||
class ScreenService : public EngineService
|
||||
{
|
||||
@@ -101,9 +107,9 @@ void Screen::SetCursorVisible(const bool value)
|
||||
const auto win = Engine::MainWindow;
|
||||
#endif
|
||||
if (win && Engine::HasGameViewportFocus())
|
||||
{
|
||||
win->SetCursor(value ? CursorType::Default : CursorType::Hidden);
|
||||
}
|
||||
else if (win)
|
||||
win->SetCursor(CursorType::Default);
|
||||
CursorVisible = value;
|
||||
}
|
||||
|
||||
@@ -116,21 +122,31 @@ void Screen::SetCursorLock(CursorLockMode mode)
|
||||
{
|
||||
#if USE_EDITOR
|
||||
const auto win = Editor::Managed->GetGameWindow(true);
|
||||
Rectangle bounds(Editor::Managed->GameViewportToScreen(Float2::Zero), Editor::Managed->GetGameWindowSize());
|
||||
if (win)
|
||||
bounds = Rectangle(win->ScreenToClient(bounds.GetTopLeft()), bounds.Size);
|
||||
#else
|
||||
const auto win = Engine::MainWindow;
|
||||
Rectangle bounds = win != nullptr ? win->GetClientBounds() : Rectangle();
|
||||
#endif
|
||||
if (win && mode == CursorLockMode::Clipped)
|
||||
if (win)
|
||||
{
|
||||
#if USE_EDITOR
|
||||
Rectangle bounds(Editor::Managed->GameViewportToScreen(Float2::Zero), Editor::Managed->GetGameWindowSize());
|
||||
#else
|
||||
Rectangle bounds = win->GetClientBounds();
|
||||
#endif
|
||||
win->StartClippingCursor(bounds);
|
||||
}
|
||||
else if (win && CursorLock == CursorLockMode::Clipped)
|
||||
{
|
||||
win->EndClippingCursor();
|
||||
bool inRelativeMode = Input::Mouse->IsRelative();
|
||||
if (mode == CursorLockMode::Clipped)
|
||||
win->StartClippingCursor(bounds);
|
||||
else if (mode == CursorLockMode::Locked)
|
||||
{
|
||||
// Use mouse clip region to restrict the cursor in one spot
|
||||
win->StartClippingCursor(Rectangle(bounds.GetCenter(), Float2(1, 1)));
|
||||
}
|
||||
else if (CursorLock == CursorLockMode::Locked || CursorLock == CursorLockMode::Clipped)
|
||||
win->EndClippingCursor();
|
||||
|
||||
// Enable relative mode when cursor is restricted
|
||||
if (mode != CursorLockMode::None)
|
||||
Input::Mouse->SetRelativeMode(true, win);
|
||||
else if (mode == CursorLockMode::None && inRelativeMode)
|
||||
Input::Mouse->SetRelativeMode(false, win);
|
||||
}
|
||||
CursorLock = mode;
|
||||
}
|
||||
@@ -190,7 +206,11 @@ void ScreenService::Update()
|
||||
{
|
||||
#if USE_EDITOR
|
||||
// Sync current cursor state in Editor (eg. when viewport focus can change)
|
||||
Screen::SetCursorVisible(CursorVisible);
|
||||
const auto win = Editor::Managed->GetGameWindow(true);
|
||||
bool gameViewportFocus = win && Engine::HasGameViewportFocus();
|
||||
if (gameViewportFocus != LastGameViewportFocus)
|
||||
Screen::SetCursorVisible(CursorVisible);
|
||||
LastGameViewportFocus = gameViewportFocus;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ API_CLASS(Static, Attributes="DebugCommand") class FLAXENGINE_API Time
|
||||
friend class Engine;
|
||||
friend class TimeService;
|
||||
friend class PhysicsSettings;
|
||||
friend Window;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user