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

1
.gitignore vendored
View File

@@ -7,6 +7,7 @@ Cache/
Binaries/
Output/
Logs/
Source/*.Gen.*
Source/*.csproj
/Package_*/
!Source/Engine/Debug

View File

@@ -692,10 +692,13 @@ namespace FlaxEditor.Content.GUI
c = char.ToLowerInvariant(c);
for (int i = 0; i < _items.Count; i++)
{
var name = _items[i].ShortName;
var item = _items[i];
var name = item.ShortName;
if (!string.IsNullOrEmpty(name) && char.ToLowerInvariant(name[0]) == c)
{
Select(_items[i]);
Select(item);
if (Parent is Panel panel)
panel.ScrollViewTo(item, true);
break;
}
}

View File

@@ -45,7 +45,7 @@ namespace FlaxEditor.Content
}
/// <inheritdoc />
public override string NewItemName => "Script";
public override string NewItemName => "MyScript";
/// <inheritdoc />
public override bool CanCreate(ContentFolder targetLocation)
@@ -72,6 +72,8 @@ namespace FlaxEditor.Content
// Scripts cannot start with digit.
if (Char.IsDigit(filename[0]))
return false;
if (filename.Equals("Script"))
return false;
return true;
}

View File

@@ -25,6 +25,7 @@ namespace FlaxEditor.GUI.Dialogs
{
private const float ButtonsWidth = 60.0f;
private const float PickerMargin = 6.0f;
private const float EyedropperMargin = 8.0f;
private const float RGBAMargin = 12.0f;
private const float HSVMargin = 0.0f;
private const float ChannelsMargin = 4.0f;
@@ -34,6 +35,7 @@ namespace FlaxEditor.GUI.Dialogs
private Color _value;
private bool _disableEvents;
private bool _useDynamicEditing;
private bool _activeEyedropper;
private ColorValueBox.ColorPickerEvent _onChanged;
private ColorValueBox.ColorPickerClosedEvent _onClosed;
@@ -48,6 +50,7 @@ namespace FlaxEditor.GUI.Dialogs
private TextBox _cHex;
private Button _cCancel;
private Button _cOK;
private Button _cEyedropper;
/// <summary>
/// Gets the selected color.
@@ -192,10 +195,44 @@ namespace FlaxEditor.GUI.Dialogs
};
_cOK.Clicked += OnSubmit;
// Eyedropper button
var style = Style.Current;
_cEyedropper = new Button(_cOK.X - EyedropperMargin, _cHex.Bottom + PickerMargin)
{
TooltipText = "Eyedropper tool to pick a color directly from the screen",
BackgroundBrush = new SpriteBrush(Editor.Instance.Icons.Search32),
BackgroundColor = style.Foreground,
BackgroundColorHighlighted = style.Foreground.RGBMultiplied(0.9f),
BorderColor = Color.Transparent,
BorderColorHighlighted = style.BorderSelected,
Parent = this,
};
_cEyedropper.Clicked += OnEyedropStart;
_cEyedropper.Height = (_cValue.Bottom - _cEyedropper.Y) * 0.5f;
_cEyedropper.Width = _cEyedropper.Height;
_cEyedropper.X -= _cEyedropper.Width;
// Set initial color
SelectedColor = initialValue;
}
private void OnColorPicked(Color32 colorPicked)
{
if (_activeEyedropper)
{
_activeEyedropper = false;
SelectedColor = colorPicked;
ScreenUtilities.PickColorDone -= OnColorPicked;
}
}
private void OnEyedropStart()
{
_activeEyedropper = true;
ScreenUtilities.PickColor();
ScreenUtilities.PickColorDone += OnColorPicked;
}
private void OnRGBAChanged()
{
if (_disableEvents)
@@ -221,6 +258,19 @@ namespace FlaxEditor.GUI.Dialogs
SelectedColor = color;
}
/// <inheritdoc />
public override void Update(float deltaTime)
{
base.Update(deltaTime);
// Update eye dropper tool
if (_activeEyedropper)
{
Float2 mousePosition = Platform.MousePosition;
SelectedColor = ScreenUtilities.GetColorAt(mousePosition);
}
}
/// <inheritdoc />
public override void Draw()
{
@@ -274,6 +324,20 @@ namespace FlaxEditor.GUI.Dialogs
base.OnShow();
}
/// <inheritdoc />
public override bool OnKeyDown(KeyboardKeys key)
{
if (_activeEyedropper && key == KeyboardKeys.Escape)
{
// Cancel eye dropping
_activeEyedropper = false;
ScreenUtilities.PickColorDone -= OnColorPicked;
return true;
}
return base.OnKeyDown(key);
}
/// <inheritdoc />
public override void OnSubmit()
{

View File

@@ -57,6 +57,11 @@ namespace FlaxEditor.GUI.Input
/// </summary>
protected Color _value;
/// <summary>
/// Enables live preview of the selected value from the picker. Otherwise will update the value only when user confirms it on dialog closing.
/// </summary>
public bool UseDynamicEditing = true;
/// <summary>
/// Occurs when value gets changed.
/// </summary>
@@ -143,7 +148,7 @@ namespace FlaxEditor.GUI.Input
base.OnSubmit();
// Show color picker dialog
_currentDialog = ShowPickColorDialog?.Invoke(this, _value, OnColorChanged, OnPickerClosed);
_currentDialog = ShowPickColorDialog?.Invoke(this, _value, OnColorChanged, OnPickerClosed, UseDynamicEditing);
}
private void OnColorChanged(Color color, bool sliding)

View File

@@ -30,7 +30,7 @@ namespace FlaxEditor.Surface.Elements
{
ParentNode = parentNode;
Archetype = archetype;
UseDynamicEditing = false;
ParentNode.ValuesChanged += OnNodeValuesChanged;
}

View File

@@ -0,0 +1,130 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#include "ScreenUtilities.h"
#include "Engine/Core/Math/Vector2.h"
#include "Engine/Core/Delegate.h"
#include "Engine/Core/Log.h"
#include "Engine/Profiler/ProfilerCPU.h"
Delegate<Color32> ScreenUtilities::PickColorDone;
#if PLATFORM_WINDOWS
#include <Windows.h>
#pragma comment(lib, "Gdi32.lib")
static HHOOK MouseCallbackHook;
LRESULT CALLBACK OnScreenUtilsMouseCallback(_In_ int nCode, _In_ WPARAM wParam, _In_ LPARAM lParam)
{
if (nCode >= 0 && wParam == WM_LBUTTONDOWN)
{
UnhookWindowsHookEx(MouseCallbackHook);
// Push event with the picked color
const Float2 cursorPos = Platform::GetMousePosition();
const Color32 colorPicked = ScreenUtilities::GetColorAt(cursorPos);
ScreenUtilities::PickColorDone(colorPicked);
return 1;
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
Color32 ScreenUtilities::GetColorAt(const Float2& pos)
{
PROFILE_CPU();
HDC deviceContext = GetDC(NULL);
COLORREF color = GetPixel(deviceContext, (int)pos.X, (int)pos.Y);
ReleaseDC(NULL, deviceContext);
return Color32(GetRValue(color), GetGValue(color), GetBValue(color), 255);
}
void ScreenUtilities::PickColor()
{
MouseCallbackHook = SetWindowsHookEx(WH_MOUSE_LL, OnScreenUtilsMouseCallback, NULL, NULL);
if (MouseCallbackHook == NULL)
{
LOG(Warning, "Failed to set mouse hook.");
LOG(Warning, "Error: {0}", GetLastError());
}
}
#elif PLATFORM_LINUX
#include "Engine/Platform/Linux/LinuxPlatform.h"
#include "Engine/Platform/Linux/IncludeX11.h"
Color32 ScreenUtilities::GetColorAt(const Float2& pos)
{
X11::XColor color;
X11::Display* display = (X11::Display*) LinuxPlatform::GetXDisplay();
int defaultScreen = X11::XDefaultScreen(display);
X11::XImage* image;
image = X11::XGetImage(display, X11::XRootWindow(display, defaultScreen), x, y, 1, 1, AllPlanes, XYPixmap);
color.pixel = XGetPixel(image, 0, 0);
X11::XFree(image);
X11::XQueryColor(display, X11::XDefaultColormap(display, defaultScreen), &color);
Color32 outputColor;
outputColor.R = color.red / 256;
outputColor.G = color.green / 256;
outputColor.B = color.blue / 256;
return outputColor;
}
void OnScreenUtilsXEventCallback(void* eventPtr)
{
X11::XEvent* event = (X11::XEvent*) eventPtr;
X11::Display* display = (X11::Display*)LinuxPlatform::GetXDisplay();
if (event->type == ButtonPress)
{
const Float2 cursorPos = Platform::GetMousePosition();
const Color32 colorPicked = ScreenUtilities::GetColorAt(cursorPos);
X11::XUngrabPointer(display, CurrentTime);
ScreenUtilities::PickColorDone(colorPicked);
LinuxPlatform::xEventRecieved.Unbind(OnScreenUtilsXEventCallback);
}
}
void ScreenUtilities::PickColor()
{
PROFILE_CPU();
X11::Display* display = (X11::Display*) LinuxPlatform::GetXDisplay();
X11::Window rootWindow = X11::XRootWindow(display, X11::XDefaultScreen(display));
X11::Cursor cursor = XCreateFontCursor(display, 130);
int grabbedPointer = X11::XGrabPointer(display, rootWindow, 0, ButtonPressMask, GrabModeAsync, GrabModeAsync, rootWindow, cursor, CurrentTime);
if (grabbedPointer != GrabSuccess)
{
LOG(Error, "Failed to grab cursor for events.");
X11::XFreeCursor(display, cursor);
return;
}
X11::XFreeCursor(display, cursor);
LinuxPlatform::xEventRecieved.Bind(OnScreenUtilsXEventCallback);
}
#elif PLATFORM_MAC
#include <Cocoa/Cocoa.h>
#include <AppKit/AppKit.h>
Color32 ScreenUtilities::GetColorAt(const Float2& pos)
{
// TODO: implement ScreenUtilities for macOS
return { 0, 0, 0, 255 };
}
void ScreenUtilities::PickColor()
{
// This is what C# calls to start the color picking sequence
// This should stop mouse clicks from working for one click, and that click is on the selected color
// There is a class called NSColorSample that might implement that for you, but maybe not.
}
#endif

View File

@@ -0,0 +1,33 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Types/BaseTypes.h"
#include "Engine/Core/Math/Color32.h"
#include "Engine/Core/Math/Vector2.h"
#include "Engine/Core/Delegate.h"
/// <summary>
/// Platform-dependent screen utilities.
/// </summary>
API_CLASS(Static) class FLAXENGINE_API ScreenUtilities
{
DECLARE_SCRIPTING_TYPE_MINIMAL(ScreenUtilities);
/// <summary>
/// Gets the pixel color at the specified coordinates.
/// </summary>
/// <param name="pos">Screen-space coordinate to read.</param>
/// <returns>Pixel color at the specified coordinates.</returns>
API_FUNCTION() static Color32 GetColorAt(const Float2& pos);
/// <summary>
/// Starts async color picking. Color will be returned through PickColorDone event when the actions ends (user selected the final color with a mouse). When action is active, GetColorAt can be used to read the current value.
/// </summary>
API_FUNCTION() static void PickColor();
/// <summary>
/// Called when PickColor action is finished.
/// </summary>
API_EVENT() static Delegate<Color32> PickColorDone;
};

View File

@@ -612,7 +612,16 @@ namespace FlaxEditor.Windows
/// <param name="files">The files paths to import.</param>
public void Paste(string[] files)
{
Editor.ContentImporting.Import(files, CurrentViewFolder);
var importFiles = new List<string>();
foreach (var sourcePath in files)
{
var item = Editor.ContentDatabase.Find(sourcePath);
if (item != null)
Editor.ContentDatabase.Copy(item, Path.Combine(CurrentViewFolder.Path, item.FileName));
else
importFiles.Add(sourcePath);
}
Editor.ContentImporting.Import(importFiles, CurrentViewFolder);
}
/// <summary>

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#include "ObjectsRemovalService.h"
#include "Utilities.h"
#include "Collections/Dictionary.h"
#include "Engine/Engine/Time.h"
#include "Engine/Engine/EngineService.h"
@@ -8,6 +9,11 @@
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Scripting/ScriptingObject.h"
const Char* BytesSizesData[] = { TEXT("b"), TEXT("Kb"), TEXT("Mb"), TEXT("Gb"), TEXT("Tb"), TEXT("Pb"), TEXT("Eb"), TEXT("Zb"), TEXT("Yb") };
const Char* HertzSizesData[] = { TEXT("Hz"), TEXT("KHz"), TEXT("MHz"), TEXT("GHz"), TEXT("THz"), TEXT("PHz"), TEXT("EHz"), TEXT("ZHz"), TEXT("YHz") };
Span<const Char*> Utilities::Private::BytesSizes(BytesSizesData, ARRAY_COUNT(BytesSizesData));
Span<const Char*> Utilities::Private::HertzSizes(HertzSizesData, ARRAY_COUNT(HertzSizesData));
namespace ObjectsRemovalServiceImpl
{
CriticalSection PoolLocker;

View File

@@ -4,12 +4,19 @@
#include "Types/BaseTypes.h"
#include "Types/String.h"
#include "Types/Span.h"
#if _MSC_VER && PLATFORM_SIMD_SSE4_2
#include <intrin.h>
#endif
namespace Utilities
{
struct Private
{
static FLAXENGINE_API Span<const Char*> BytesSizes;
static FLAXENGINE_API Span<const Char*> HertzSizes;
};
// Round floating point value up to 1 decimal place
template<typename T>
FORCE_INLINE T RoundTo1DecimalPlace(T value)
@@ -31,20 +38,41 @@ namespace Utilities
return (T)round((double)value * 1000.0) / (T)1000;
}
// Converts units to the best fitting human-readable denominator
// @param units Units count
// @param divider Amount of units required for the next size
// @param sizes Array with human-readable sizes to convert from
// @return The best fitting string of the units
template<typename T>
String UnitsToText(T units, int32 divider, const Span<const Char*> sizes)
{
if (sizes.Length() == 0)
return String::Format(TEXT("{0}"), units);
int32 i = 0;
double dblSUnits = static_cast<double>(units);
for (; static_cast<uint64>(units / static_cast<double>(divider)) > 0; i++, units /= divider)
dblSUnits = units / static_cast<double>(divider);
if (i >= sizes.Length())
i = 0;
return String::Format(TEXT("{0} {1}"), RoundTo2DecimalPlaces(dblSUnits), sizes[i]);
}
// Converts size of the file (in bytes) to the best fitting string
// @param bytes Size of the file in bytes
// @return The best fitting string of the file size
template<typename T>
String BytesToText(T bytes)
{
static const Char* sizes[] = { TEXT("B"), TEXT("KB"), TEXT("MB"), TEXT("GB"), TEXT("TB") };
uint64 i = 0;
double dblSByte = static_cast<double>(bytes);
for (; static_cast<uint64>(bytes / 1024.0) > 0; i++, bytes /= 1024)
dblSByte = bytes / 1024.0;
if (i >= ARRAY_COUNT(sizes))
return String::Empty;
return String::Format(TEXT("{0} {1}"), RoundTo2DecimalPlaces(dblSByte), sizes[i]);
return UnitsToText(bytes, 1024, Private::BytesSizes);
}
// Converts hertz to the best fitting string
// @param hertz Hertz for convertion
// @return The best fitting string
template<typename T>
String HertzToText(T hertz)
{
return UnitsToText(hertz, 1000, Private::HertzSizes);
}
// Returns the amount of set bits in 32-bit integer.

View File

@@ -114,7 +114,15 @@ GPUDevice* GPUDeviceDX11::Create()
// Create DXGI factory
#if PLATFORM_WINDOWS
IDXGIFactory1* dxgiFactory;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
IDXGIFactory6* dxgiFactory6;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory6));
if (hr == S_OK)
dxgiFactory = dxgiFactory6;
else
{
dxgiFactory6 = nullptr;
hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
}
#else
IDXGIFactory2* dxgiFactory;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
@@ -126,16 +134,17 @@ GPUDevice* GPUDeviceDX11::Create()
}
// Enumerate the DXGIFactory's adapters
int32 selectedAdapterIndex = -1;
Array<GPUAdapterDX> adapters;
IDXGIAdapter* tmpAdapter;
for (uint32 index = 0; dxgiFactory->EnumAdapters(index, &tmpAdapter) != DXGI_ERROR_NOT_FOUND; index++)
IDXGIAdapter* tempAdapter;
for (uint32 index = 0; dxgiFactory->EnumAdapters(index, &tempAdapter) != DXGI_ERROR_NOT_FOUND; index++)
{
GPUAdapterDX adapter;
if (tmpAdapter && TryCreateDevice(tmpAdapter, maxAllowedFeatureLevel, &adapter.MaxFeatureLevel))
if (tempAdapter && TryCreateDevice(tempAdapter, maxAllowedFeatureLevel, &adapter.MaxFeatureLevel))
{
adapter.Index = index;
VALIDATE_DIRECTX_RESULT(tmpAdapter->GetDesc(&adapter.Description));
uint32 outputs = RenderToolsDX::CountAdapterOutputs(tmpAdapter);
VALIDATE_DIRECTX_RESULT(tempAdapter->GetDesc(&adapter.Description));
uint32 outputs = RenderToolsDX::CountAdapterOutputs(tempAdapter);
LOG(Info, "Adapter {1}: '{0}', DirectX {2}", adapter.Description.Description, index, RenderToolsDX::GetFeatureLevelString(adapter.MaxFeatureLevel));
LOG(Info, " Dedicated Video Memory: {0}, Dedicated System Memory: {1}, Shared System Memory: {2}, Output(s): {3}", Utilities::BytesToText(adapter.Description.DedicatedVideoMemory), Utilities::BytesToText(adapter.Description.DedicatedSystemMemory), Utilities::BytesToText(adapter.Description.SharedSystemMemory), outputs);
@@ -143,14 +152,41 @@ GPUDevice* GPUDeviceDX11::Create()
adapters.Add(adapter);
}
}
#if PLATFORM_WINDOWS
// Find the best performing adapter and prefer using it instead of the first device
const auto gpuPreference = DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE;
if (dxgiFactory6 != nullptr && selectedAdapterIndex == -1)
{
if (dxgiFactory6->EnumAdapterByGpuPreference(0, gpuPreference, IID_PPV_ARGS(&tempAdapter)) != DXGI_ERROR_NOT_FOUND)
{
GPUAdapterDX adapter;
if (tempAdapter && TryCreateDevice(tempAdapter, maxAllowedFeatureLevel, &adapter.MaxFeatureLevel))
{
DXGI_ADAPTER_DESC desc;
VALIDATE_DIRECTX_RESULT(tempAdapter->GetDesc(&desc));
for (int i = 0; i < adapters.Count(); i++)
{
if (adapters[i].Description.AdapterLuid.LowPart == desc.AdapterLuid.LowPart &&
adapters[i].Description.AdapterLuid.HighPart == desc.AdapterLuid.HighPart)
{
selectedAdapterIndex = i;
break;
}
}
}
}
}
#endif
// Select the adapter to use
if (adapters.Count() == 0)
if (selectedAdapterIndex < 0)
selectedAdapterIndex = 0;
if (adapters.Count() == 0 || selectedAdapterIndex >= adapters.Count())
{
LOG(Error, "Failed to find valid DirectX adapter!");
return nullptr;
}
GPUAdapterDX selectedAdapter = adapters[0];
GPUAdapterDX selectedAdapter = adapters[selectedAdapterIndex];
uint32 vendorId = 0;
if (CommandLine::Options.NVIDIA)
vendorId = GPU_VENDOR_ID_NVIDIA;
@@ -185,6 +221,15 @@ GPUDevice* GPUDeviceDX11::Create()
Delete(device);
return nullptr;
}
#if PLATFORM_WINDOWS
if (dxgiFactory6 != nullptr)
dxgiFactory6->Release();
else
#endif
{
dxgiFactory->Release();
}
return device;
}

View File

@@ -89,7 +89,15 @@ GPUDevice* GPUDeviceDX12::Create()
// Create DXGI factory (CreateDXGIFactory2 is supported on Windows 8.1 or newer)
IDXGIFactory4* dxgiFactory;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
IDXGIFactory6* dxgiFactory6;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory6));
if (hr == S_OK)
dxgiFactory = dxgiFactory6;
else
{
dxgiFactory6 = nullptr;
hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
}
if (hr != S_OK)
{
LOG(Error, "Cannot create DXGI adapter. Error code: {0:x}.", hr);
@@ -97,6 +105,7 @@ GPUDevice* GPUDeviceDX12::Create()
}
// Enumerate the DXGIFactory's adapters
int32 selectedAdapterIndex = -1;
Array<GPUAdapterDX> adapters;
IDXGIAdapter* tempAdapter;
for (uint32 index = 0; dxgiFactory->EnumAdapters(index, &tempAdapter) != DXGI_ERROR_NOT_FOUND; index++)
@@ -118,13 +127,39 @@ GPUDevice* GPUDeviceDX12::Create()
}
}
// Find the best performing adapter and prefer using it instead of the first device
const auto gpuPreference = DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE;
if (dxgiFactory6 != nullptr && selectedAdapterIndex == -1)
{
if (dxgiFactory6->EnumAdapterByGpuPreference(0, gpuPreference, IID_PPV_ARGS(&tempAdapter)) != DXGI_ERROR_NOT_FOUND)
{
GPUAdapterDX adapter;
if (tempAdapter && CheckDX12Support(tempAdapter))
{
DXGI_ADAPTER_DESC desc;
VALIDATE_DIRECTX_RESULT(tempAdapter->GetDesc(&desc));
for (int i = 0; i < adapters.Count(); i++)
{
if (adapters[i].Description.AdapterLuid.LowPart == desc.AdapterLuid.LowPart &&
adapters[i].Description.AdapterLuid.HighPart == desc.AdapterLuid.HighPart)
{
selectedAdapterIndex = i;
break;
}
}
}
}
}
// Select the adapter to use
if (adapters.Count() == 0)
if (selectedAdapterIndex < 0)
selectedAdapterIndex = 0;
if (adapters.Count() == 0 || selectedAdapterIndex >= adapters.Count())
{
LOG(Error, "Failed to find valid DirectX adapter!");
return nullptr;
}
GPUAdapterDX selectedAdapter = adapters[0];
GPUAdapterDX selectedAdapter = adapters[selectedAdapterIndex];
uint32 vendorId = 0;
if (CommandLine::Options.NVIDIA)
vendorId = GPU_VENDOR_ID_NVIDIA;
@@ -167,6 +202,15 @@ GPUDevice* GPUDeviceDX12::Create()
return nullptr;
}
#if !(PLATFORM_XBOX_SCARLETT || PLATFORM_XBOX_ONE)
if (dxgiFactory6 != nullptr)
dxgiFactory6->Release();
else
#endif
{
dxgiFactory->Release();
}
return device;
}

View File

@@ -40,9 +40,11 @@ typedef IGraphicsUnknown IDXGISwapChain3;
#include <d3d11_1.h>
#include <dxgi1_3.h>
#include <dxgi1_5.h>
#include <dxgi1_6.h>
#endif
#if GRAPHICS_API_DIRECTX12
#include <dxgi1_5.h>
#include <dxgi1_6.h>
#endif
#pragma comment(lib, "DXGI.lib")

View File

@@ -1155,6 +1155,7 @@ GPUDevice* GPUDeviceVulkan::Create()
#endif
// Enumerate all GPU devices and pick one
int32 selectedAdapterIndex = -1;
uint32 gpuCount = 0;
VALIDATE_VULKAN_RESULT(vkEnumeratePhysicalDevices(Instance, &gpuCount, nullptr));
if (gpuCount <= 0)
@@ -1187,6 +1188,9 @@ GPUDevice* GPUDeviceVulkan::Create()
break;
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
type = TEXT("Discrete GPU");
// Select the first discrete GPU device
if (selectedAdapterIndex == -1)
selectedAdapterIndex = gpuIndex;
break;
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
type = TEXT("Virtual GPU");
@@ -1203,12 +1207,13 @@ GPUDevice* GPUDeviceVulkan::Create()
}
// Select the adapter to use
if (adapters.Count() == 0)
if (selectedAdapterIndex < 0)
selectedAdapterIndex = 0;
if (adapters.Count() == 0 || selectedAdapterIndex >= adapters.Count())
{
LOG(Error, "Failed to find valid Vulkan adapter!");
return nullptr;
}
int32 selectedAdapter = 0;
uint32 vendorId = 0;
if (CommandLine::Options.NVIDIA)
vendorId = GPU_VENDOR_ID_NVIDIA;
@@ -1222,15 +1227,15 @@ GPUDevice* GPUDeviceVulkan::Create()
{
if (adapters[i].GetVendorId() == vendorId)
{
selectedAdapter = i;
selectedAdapterIndex = i;
break;
}
}
}
ASSERT(selectedAdapter != -1 && adapters[selectedAdapter].IsValid());
ASSERT(adapters[selectedAdapterIndex].IsValid());
// Create device
auto device = New<GPUDeviceVulkan>(ShaderProfile::Vulkan_SM5, New<GPUAdapterVulkan>(adapters[selectedAdapter]));
auto device = New<GPUDeviceVulkan>(ShaderProfile::Vulkan_SM5, New<GPUAdapterVulkan>(adapters[selectedAdapterIndex]));
if (device->Init())
{
LOG(Warning, "Graphics Device init failed");

View File

@@ -26,9 +26,8 @@ protected:
public:
/// <summary>
/// Gets the text entered during the current frame.
/// Gets the text entered during the current frame (Unicode format).
/// </summary>
/// <returns>The input text (Unicode).</returns>
API_PROPERTY() StringView GetInputText() const
{
return StringView(_state.InputText, _state.InputTextLength);

View File

@@ -58,7 +58,6 @@ public:
/// <summary>
/// Gets the position of the mouse in the screen-space coordinates.
/// </summary>
/// <returns>The mouse position</returns>
API_PROPERTY() FORCE_INLINE Float2 GetPosition() const
{
return _state.MousePosition;
@@ -72,7 +71,6 @@ public:
/// <summary>
/// Gets the delta position of the mouse in the screen-space coordinates.
/// </summary>
/// <returns>The mouse position delta</returns>
API_PROPERTY() FORCE_INLINE Float2 GetPositionDelta() const
{
return _state.MousePosition - _prevState.MousePosition;
@@ -81,7 +79,6 @@ public:
/// <summary>
/// Gets the mouse wheel change during the last frame.
/// </summary>
/// <returns>Mouse wheel value delta</returns>
API_PROPERTY() FORCE_INLINE float GetScrollDelta() const
{
return _state.MouseWheelDelta;

View File

@@ -13,22 +13,27 @@ API_INTERFACE(Namespace = "FlaxEngine.Networking") class FLAXENGINE_API INetwork
DECLARE_SCRIPTING_TYPE_MINIMAL(INetworkObject);
public:
/// <summary>
/// Event called when network objects gets spawned.
/// Event called when network object gets spawned.
/// </summary>
API_FUNCTION() virtual void OnNetworkSpawn() = 0;
API_FUNCTION() virtual void OnNetworkSpawn() {};
/// <summary>
/// Event called when network objects gets despawned.
/// Event called when network object gets despawned.
/// </summary>
API_FUNCTION() virtual void OnNetworkDespawn() = 0;
API_FUNCTION() virtual void OnNetworkDespawn() {};
/// <summary>
/// Event called before network object gets replicated (before reading data).
/// </summary>
API_FUNCTION() virtual void OnNetworkSerialize() = 0;
API_FUNCTION() virtual void OnNetworkSerialize() {};
/// <summary>
/// Event called when network objects gets replicated (after reading data).
/// Event called when network object gets replicated (after reading data).
/// </summary>
API_FUNCTION() virtual void OnNetworkDeserialize() = 0;
API_FUNCTION() virtual void OnNetworkDeserialize() {};
/// <summary>
/// Event called when network object gets synced (called only once upon initial sync).
/// </summary>
API_FUNCTION() virtual void OnNetworkSync() {};
};

View File

@@ -109,12 +109,14 @@ struct NetworkReplicatedObject
uint32 LastOwnerFrame = 0;
NetworkObjectRole Role;
uint8 Spawned : 1;
uint8 Synced : 1;
DataContainer<uint32> TargetClientIds;
INetworkObject* AsNetworkObject;
NetworkReplicatedObject()
{
Spawned = 0;
Synced = 0;
}
bool operator==(const NetworkReplicatedObject& other) const
@@ -637,7 +639,14 @@ void InvokeObjectReplication(NetworkReplicatedObject& item, uint32 ownerFrame, b
}
if (item.AsNetworkObject)
{
item.AsNetworkObject->OnNetworkDeserialize();
if (!item.Synced)
{
item.Synced = true;
item.AsNetworkObject->OnNetworkSync();
}
}
// Speed up replication of client-owned objects to other clients from server to reduce lag (data has to go from client to server and then to other clients)
if (NetworkManager::IsServer())

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();

View File

@@ -10,7 +10,6 @@
#include "Engine/Graphics/GPUResourceProperty.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUSwapChain.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Threading/ThreadPoolTask.h"
#include "Engine/Engine/Globals.h"
#if COMPILE_WITH_TEXTURE_TOOL

View File

@@ -1,12 +0,0 @@
// This code was auto-generated. Do not modify it.
#include "Engine/Scripting/BinaryModule.h"
#include "FlaxEngine.Gen.h"
StaticallyLinkedBinaryModuleInitializer StaticallyLinkedBinaryModuleFlaxEngine(GetBinaryModuleFlaxEngine);
extern "C" BinaryModule* GetBinaryModuleFlaxEngine()
{
static NativeBinaryModule module("FlaxEngine");
return &module;
}

View File

@@ -1,19 +0,0 @@
// This code was auto-generated. Do not modify it.
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("FlaxEngine")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Flax")]
[assembly: AssemblyProduct("FlaxEngine")]
[assembly: AssemblyCopyright("Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("b8442186-4a70-7c85-704a-857c68060f38")]
[assembly: AssemblyVersion("1.6.6340")]
[assembly: AssemblyFileVersion("1.6.6340")]
[assembly: DisableRuntimeMarshalling]

View File

@@ -1,15 +0,0 @@
// This code was auto-generated. Do not modify it.
#pragma once
#define FLAXENGINE_NAME "FlaxEngine"
#define FLAXENGINE_VERSION Version(1, 6, 6340)
#define FLAXENGINE_VERSION_TEXT "1.6.6340"
#define FLAXENGINE_VERSION_MAJOR 1
#define FLAXENGINE_VERSION_MINOR 6
#define FLAXENGINE_VERSION_BUILD 6340
#define FLAXENGINE_COMPANY "Flax"
#define FLAXENGINE_COPYRIGHT "Copyright (c) 2012-2023 Wojciech Figat. All rights reserved."
class BinaryModule;
extern "C" FLAXENGINE_API BinaryModule* GetBinaryModuleFlaxEngine();

View File

@@ -369,10 +369,7 @@ static int64_t SetupHwTimer()
#endif
}
#endif
#else
static int64_t SetupHwTimer()
{
#endif
return Profiler::GetTime();
}
#else
@@ -4786,4 +4783,4 @@ TRACY_API void ___tracy_shutdown_profiler( void )
#endif
#endif
#endif

View File

@@ -157,6 +157,11 @@ namespace Flax.Build.NativeCpp
/// </summary>
public readonly List<string> IncludePaths = new List<string>();
/// <summary>
/// The collection of custom arguments to pass to the compilator.
/// </summary>
public readonly HashSet<string> CustomArgs = new HashSet<string>();
/// <inheritdoc />
public object Clone()
{
@@ -183,6 +188,7 @@ namespace Flax.Build.NativeCpp
};
clone.PreprocessorDefinitions.AddRange(PreprocessorDefinitions);
clone.IncludePaths.AddRange(IncludePaths);
clone.CustomArgs.AddRange(CustomArgs);
return clone;
}
}

View File

@@ -106,6 +106,11 @@ namespace Flax.Build.NativeCpp
/// </summary>
public readonly List<string> LibraryPaths = new List<string>();
/// <summary>
/// The collection of custom arguments to pass to the linker.
/// </summary>
public readonly HashSet<string> CustomArgs = new HashSet<string>();
/// <inheritdoc />
public object Clone()
{
@@ -127,6 +132,7 @@ namespace Flax.Build.NativeCpp
clone.DocumentationFiles.AddRange(DocumentationFiles);
clone.InputLibraries.AddRange(InputLibraries);
clone.LibraryPaths.AddRange(LibraryPaths);
clone.CustomArgs.AddRange(CustomArgs);
return clone;
}
}

View File

@@ -96,6 +96,7 @@ namespace Flax.Build.Platforms
// Setup arguments shared by all source files
var commonArgs = new List<string>();
commonArgs.AddRange(options.CompileEnv.CustomArgs);
{
commonArgs.Add("-c");
commonArgs.Add("-fmessage-length=0");
@@ -235,6 +236,7 @@ namespace Flax.Build.Platforms
// Setup arguments
var args = new List<string>();
args.AddRange(options.LinkEnv.CustomArgs);
{
args.Add(string.Format("-o \"{0}\"", outputFilePath));
AddArgsCommon(options, args);

View File

@@ -325,6 +325,7 @@ namespace Flax.Build.Platforms
// Setup arguments shared by all source files
var commonArgs = new List<string>();
commonArgs.AddRange(options.CompileEnv.CustomArgs);
SetupCompileCppFilesArgs(graph, options, commonArgs, outputPath);
{
commonArgs.Add("-c");
@@ -511,6 +512,7 @@ namespace Flax.Build.Platforms
// Setup arguments
var args = new List<string>();
args.AddRange(options.LinkEnv.CustomArgs);
{
args.Add(string.Format("-o \"{0}\"", outputFilePath));

View File

@@ -428,6 +428,7 @@ namespace Flax.Build.Platforms
// Setup arguments shared by all source files
var commonArgs = new List<string>();
commonArgs.AddRange(options.CompileEnv.CustomArgs);
SetupCompileCppFilesArgs(graph, options, commonArgs);
{
// Suppress Startup Banner
@@ -669,6 +670,7 @@ namespace Flax.Build.Platforms
// Setup arguments
var args = new List<string>();
args.AddRange(options.LinkEnv.CustomArgs);
SetupLinkFilesArgs(graph, options, args);
{
// Suppress startup banner