From 777e59d64034e31b261e77fbdc328b0c57e4f976 Mon Sep 17 00:00:00 2001 From: Klemmbaustein Date: Fri, 12 Jul 2024 18:35:09 +0200 Subject: [PATCH] v1.13.0 --- CHANGES.md | 17 ++ EngineSource/Engine.vcxproj | 7 +- EngineSource/Engine/AppWindow.cpp | 174 ++++++++++++ EngineSource/Engine/AppWindow.h | 80 ++++++ EngineSource/Engine/Application.cpp | 257 +++--------------- EngineSource/Engine/Application.h | 70 +---- EngineSource/Engine/EngineError.cpp | 5 +- EngineSource/Engine/EngineProperties.h | 2 +- EngineSource/Engine/File/Assets.cpp | 2 +- EngineSource/Engine/Gamepad.cpp | 14 +- EngineSource/Engine/Gamepad.h | 2 +- EngineSource/Engine/LaunchArgs.cpp | 27 +- EngineSource/Engine/LaunchArgs.h | 9 + EngineSource/Engine/Stats.cpp | 10 +- EngineSource/Engine/Stats.h | 19 +- .../Engine/Subsystem/CSharpInterop.cpp | 7 + EngineSource/Engine/Subsystem/Console.cpp | 132 +++++---- .../Engine/Subsystem/InputSubsystem.cpp | 9 +- .../Engine/Subsystem/PhysicsSubsystem.cpp | 5 + EngineSource/Engine/Subsystem/Subsystem.cpp | 7 + EngineSource/Rendering/BillboardSprite.h | 4 +- .../{Renderable.cpp => Drawable.cpp} | 44 ++- .../Rendering/{Renderable.h => Drawable.h} | 10 +- EngineSource/Rendering/Framebuffer.cpp | 13 +- EngineSource/Rendering/Framebuffer.h | 6 +- EngineSource/Rendering/Graphics.h | 2 +- EngineSource/Rendering/Mesh/InstancedModel.h | 2 +- EngineSource/Rendering/Mesh/Mesh.h | 2 +- EngineSource/Rendering/Mesh/Model.h | 4 +- EngineSource/Rendering/Particle.cpp | 2 +- .../RenderSubsystem/BakedLighting.cpp | 1 + .../Rendering/RenderSubsystem/Bloom.cpp | 37 +-- .../Rendering/RenderSubsystem/Bloom.h | 4 +- .../Rendering/RenderSubsystem/CSM.cpp | 21 +- EngineSource/Rendering/RenderSubsystem/CSM.h | 8 +- .../RenderSubsystem/OcclusionCulling.cpp | 3 +- .../Rendering/RenderSubsystem/PostProcess.cpp | 4 +- .../RenderSubsystem/RenderSubsystem.cpp | 61 ++++- .../RenderSubsystem/RenderSubsystem.h | 6 +- .../Rendering/RenderSubsystem/SSAO.cpp | 1 + EngineSource/Rendering/Texture/Material.cpp | 2 +- EngineSource/Rendering/Texture/Texture.cpp | 127 ++++----- EngineSource/Rendering/Texture/Texture.h | 12 +- EngineSource/UI/Debug/DebugUI.cpp | 8 +- EngineSource/UI/EditorUI/ContextMenu.cpp | 1 - EngineSource/UI/EditorUI/EditorDropdown.cpp | 3 +- EngineSource/UI/EditorUI/EditorPanel.cpp | 11 +- EngineSource/UI/EditorUI/EditorPanel.h | 1 + EngineSource/UI/EditorUI/EditorUI.cpp | 12 +- EngineSource/UI/EditorUI/ItemBrowser.cpp | 11 +- EngineSource/UI/EditorUI/LogUI.cpp | 7 +- .../UI/EditorUI/Popups/AboutWindow.cpp | 14 +- EngineSource/UI/EditorUI/Popups/BakeMenu.cpp | 1 - .../UI/EditorUI/Popups/ClassCreator.cpp | 2 - .../UI/EditorUI/Popups/ColorPicker.cpp | 4 +- .../UI/EditorUI/Popups/EditorPopup.cpp | 7 +- EngineSource/UI/EditorUI/Popups/RenameBox.cpp | 1 - EngineSource/UI/EditorUI/SerializePanel.cpp | 5 +- EngineSource/UI/EditorUI/SettingsPanel.cpp | 3 +- EngineSource/UI/EditorUI/SettingsPanel.h | 3 +- EngineSource/UI/EditorUI/StatusBar.cpp | 5 +- EngineSource/UI/EditorUI/Tabs/CubemapTab.cpp | 1 - EngineSource/UI/EditorUI/Tabs/MaterialTab.cpp | 28 +- EngineSource/UI/EditorUI/Tabs/MeshTab.cpp | 14 +- .../UI/EditorUI/Tabs/ParticleEditorTab.cpp | 9 +- EngineSource/UI/EditorUI/Toolbar.cpp | 3 +- EngineSource/UI/EditorUI/UIVectorField.cpp | 9 +- EngineSource/UI/EditorUI/Viewport.cpp | 7 +- EngineSource/UI/UIBackground.cpp | 2 +- EngineSource/UI/UIBackground.h | 5 +- EngineSource/UI/UIDropdown.cpp | 1 - EngineSource/UI/UIScrollBox.cpp | 1 - 72 files changed, 757 insertions(+), 653 deletions(-) create mode 100644 EngineSource/Engine/AppWindow.cpp create mode 100644 EngineSource/Engine/AppWindow.h create mode 100644 EngineSource/Engine/LaunchArgs.h rename EngineSource/Rendering/{Renderable.cpp => Drawable.cpp} (88%) rename EngineSource/Rendering/{Renderable.h => Drawable.h} (83%) diff --git a/CHANGES.md b/CHANGES.md index e4340f13..a940c618 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,22 @@ # Changes +## Version 1.13.0 + +### Changes + +- Moved all window functions from `Application::` to `Window::` in `AppWindow.h`. +- Moved many functions from `Application.cpp` into other files. +- Code cleanup. +- Renamed Renderable to Drawable. + +### Fixes + +- Fixed a crash related to saving editor panel layouts. +- Fixed some incorrect padding. +- Removed all `UIBox::SetPadding(0)` calls because they're unnecessary after 1.11.0. +- Fixed `OS::GetMemUsage()` returning incorrect values on Linux. +- Fixed spamming empty console commands when using some Linux terminals. + ## Version 1.12.0 ### Changes diff --git a/EngineSource/Engine.vcxproj b/EngineSource/Engine.vcxproj index 9b383962..207d8a72 100644 --- a/EngineSource/Engine.vcxproj +++ b/EngineSource/Engine.vcxproj @@ -20,6 +20,7 @@ + @@ -34,6 +35,8 @@ + + @@ -98,7 +101,7 @@ - + @@ -229,7 +232,7 @@ - + diff --git a/EngineSource/Engine/AppWindow.cpp b/EngineSource/Engine/AppWindow.cpp new file mode 100644 index 00000000..68ad19f3 --- /dev/null +++ b/EngineSource/Engine/AppWindow.cpp @@ -0,0 +1,174 @@ +#if !SERVER +#include "AppWindow.h" +#include +#include "Subsystem/CSharpInterop.h" +#include "EngineProperties.h" +#include "Stats.h" +#include +#include +#include +#include + +// TODO: Multiple windows? + +SDL_Window* Window::SDLWindow = nullptr; +SDL_GLContext OpenGLContext = nullptr; + +static std::string ToAppTitle(std::string Name) +{ + std::string ApplicationTitle = Name; +#if EDITOR + ApplicationTitle.append(" Editor, v" + std::string(VERSION_STRING)); +#endif +#if ENGINE_CSHARP && !RELEASE + if (CSharpInterop::GetUseCSharp()) + { + ApplicationTitle.append(" (C#)"); + } +#endif + +#if !RELEASE && !EDITOR + { + ApplicationTitle.append(" (Debug)"); + } +#endif + return ApplicationTitle; +} + +void Window::SetCursorPosition(Vector2 NewPos) +{ +#if SERVER + return; +#endif + Vector2 Size = Window::GetWindowSize(); + Vector2 TranslatedPos = Vector2(((NewPos.X + 1) / 2) * Size.X, (((NewPos.Y) + 1) / 2) * Size.Y); + TranslatedPos.Y = Size.Y - TranslatedPos.Y; + SDL_WarpMouseInWindow(SDLWindow, (int)TranslatedPos.X, (int)TranslatedPos.Y); +} + +Vector2 Window::GetCursorPosition() +{ + int x; + int y; + SDL_GetMouseState(&x, &y); + Vector2 Size = Window::GetWindowSize(); + return Vector2((x / Size.X - 0.5f) * 2, 1 - (y / Size.Y * 2)); +} + +void Window::InitWindow(std::string WindowTitle) +{ + ENGINE_ASSERT(!SDLWindow, "Window::InitWindow has been called but the window already exists."); + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + int flags = SDL_WINDOW_OPENGL; + // Set Window resolution to the screens resolution * 0.75 + SDL_DisplayMode DM; + SDL_GetCurrentDisplayMode(0, &DM); + Graphics::WindowResolution = Vector2((float)DM.w, (float)DM.h) / 1.5f; + Graphics::RenderResolution = Graphics::WindowResolution; + SDLWindow = SDL_CreateWindow(ToAppTitle(WindowTitle).c_str(), + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + (int)Graphics::WindowResolution.X, (int)Graphics::WindowResolution.Y, + flags); + + OpenGLContext = SDL_GL_CreateContext(SDLWindow); + SDL_SetWindowResizable(SDLWindow, SDL_TRUE); + + std::cout << "- Starting GLEW - "; + auto GlewStatus = glewContextInit(); + if (GlewStatus != GLEW_OK) + { + std::cout << "GLEW Init Error:\n" << glewGetErrorString(GlewStatus); + SDL_DestroyWindow(SDLWindow); + std::cout << "\nPress Enter to continue"; + std::cin.get(); + exit(1); + } + if (!glewIsSupported(OPENGL_MIN_REQUIRED_VERSION)) + { + SDL_DestroyWindow(SDLWindow); + std::cout << std::string("OpenGL version "); + std::cout << (const char*)glGetString(GL_VERSION); + std::cout << std::string(" is not supported. Minimum: ") + OPENGL_MIN_REQUIRED_VERSION << std::endl; + std::cout << "Press enter to continue"; + std::cin.get(); + std::cout << std::endl; + exit(1); + } + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + std::cout << "GLEW started (No error)" << std::endl; +} + +void Window::DestroyWindow() +{ + ENGINE_ASSERT(SDLWindow, "Window::DestroyWindow() has been called but the window doesn't exist."); + SDL_DestroyWindow(SDLWindow); + SDL_GL_DeleteContext(OpenGLContext); +} + +void Window::SetWindowTitle(std::string NewTitle) +{ + SDL_SetWindowTitle(SDLWindow, ToAppTitle(NewTitle).c_str()); +} + +void Window::Minimize() +{ + SDL_MinimizeWindow(SDLWindow); +} + +bool Window::WindowHasFocus() +{ +#if SERVER + return false; +#endif + return SDL_GetKeyboardFocus() == SDLWindow || Stats::Time <= 1; +} + +void Window::SetFullScreen(bool NewFullScreen) +{ +#if EDITOR + if (NewFullScreen) + { + SDL_MaximizeWindow(SDLWindow); + } + else + { + SDL_RestoreWindow(SDLWindow); + } +#else + if (NewFullScreen) SDL_SetWindowFullscreen(SDLWindow, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP); + else SDL_SetWindowFullscreen(SDLWindow, SDL_WINDOW_OPENGL); + int w, h; + SDL_GetWindowSize(SDLWindow, &w, &h); + Graphics::SetWindowResolution(Vector2((float)w, (float)h)); +#endif +} +bool Window::GetFullScreen() +{ +#if EDITOR + auto Flag = SDL_GetWindowFlags(SDLWindow); + auto IsFullScreen = Flag & SDL_WINDOW_MAXIMIZED; +#else + auto Flag = SDL_GetWindowFlags(SDLWindow); + auto IsFullScreen = Flag & SDL_WINDOW_FULLSCREEN; +#endif + return IsFullScreen; +} + +Vector2 Window::GetWindowSize() +{ +#if SERVER + return 0; +#endif + int w, h; + SDL_GetWindowSize(SDLWindow, &w, &h); + return Vector2((float)w, (float)h); +} + +#endif \ No newline at end of file diff --git a/EngineSource/Engine/AppWindow.h b/EngineSource/Engine/AppWindow.h new file mode 100644 index 00000000..9d5e9d7e --- /dev/null +++ b/EngineSource/Engine/AppWindow.h @@ -0,0 +1,80 @@ +#if !SERVER +#pragma once +#include +#include + +struct SDL_Window; + +namespace Window +{ + void InitWindow(std::string WindowTitle); + void DestroyWindow(); + + void SetWindowTitle(std::string NewTitle); + + /** + * @brief + * Minimizes the application window. + */ + void Minimize(); + + extern SDL_Window* SDLWindow; + + /** + * @brief + * A function that returns true if the application window has mouse focus. + * + * @return + * true if the window has mouse focus, false if not. + */ + bool WindowHasFocus(); + + /** + * @brief + * Enables/disables full screen mode. + * + * For full screen, SDL_WINDOW_FULLSCREEN_DESKTOP is used. + * + * @param NewFullScreen + * If true, the application window will be set to full screen. If false, the window will be in windowed mode. + */ + void SetFullScreen(bool NewFullScreen); + + /** + * @brief + * A function that returns true if full screen is enabled. + * @return + * + * true if full screen is enabled, false if not. + */ + bool GetFullScreen(); + + /** + * @brief + * Returns the size of the application window in pixels. + */ + Vector2 GetWindowSize(); + + /** + * @brief + * Sets the mouse cursors position to the given position. + * + * Expects coordinates from -1, -1 (bottom left corner of the window) to 1, 1 (top right corner of the window) + * + * @param NewPos + * The new position of the cursor. + */ + void SetCursorPosition(Vector2 NewPos); + + /** + * @brief + * Returns the position of the mouse cursor. + * + * The position will be in the format: -1, -1 (bottom left corner of the window) to 1, 1 (top right corner of the window) + * + * @return + * The current position of the cursor. + */ + Vector2 GetCursorPosition(); +} +#endif \ No newline at end of file diff --git a/EngineSource/Engine/Application.cpp b/EngineSource/Engine/Application.cpp index 0c29c8c2..390d7b5a 100644 --- a/EngineSource/Engine/Application.cpp +++ b/EngineSource/Engine/Application.cpp @@ -1,4 +1,3 @@ -// Engine includes #define SDL_MAIN_HANDLED #include #include @@ -8,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -26,81 +27,33 @@ #include #include #include +#include #include #include #include -// Library includes #include #include -// STL includes #include #include #include -#include - -static Vector2 GetMousePosition() -{ -#if SERVER - return 0; -#endif - int x; - int y; - SDL_GetMouseState(&x, &y); - Vector2 Size = Application::GetWindowSize(); - return Vector2((x / Size.X - 0.5f) * 2, 1 - (y / Size.Y * 2)); -} - -static std::string ToAppTitle(std::string Name) -{ - std::string ApplicationTitle = Name; -#if EDITOR - ApplicationTitle.append(" Editor, v" + std::string(VERSION_STRING)); -#endif -#if ENGINE_CSHARP && !RELEASE - if (CSharpInterop::GetUseCSharp()) - { - ApplicationTitle.append(" (C#)"); - } -#endif - if (EngineDebug && !IsInEditor) - { - ApplicationTitle.append(" (Debug)"); - } - return ApplicationTitle; -} namespace Application { std::string StartupSceneOverride; bool ShowStartupInfo = true; - SDL_Window* Window = nullptr; bool ShouldClose = false; - bool WindowHasFocus() - { -#if SERVER - return false; -#endif - return SDL_GetKeyboardFocus() == Window || Stats::Time <= 1; - } - void Quit() { ShouldClose = true; } - void Minimize() - { -#if SERVER - return; -#endif - SDL_MinimizeWindow(Window); - } + std::set ButtonEvents; #if EDITOR EditorUI* EditorInstance = nullptr; @@ -122,64 +75,6 @@ namespace Application { Time = SDL_GetPerformanceCounter(); } - void SetFullScreen(bool NewFullScreen) - { -#if !SERVER -#if EDITOR - if (NewFullScreen) - { - SDL_MaximizeWindow(Window); - } - else - { - SDL_RestoreWindow(Window); - } -#else - if (NewFullScreen) SDL_SetWindowFullscreen(Window, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP); - else SDL_SetWindowFullscreen(Window, SDL_WINDOW_OPENGL); - int w, h; - SDL_GetWindowSize(Window, &w, &h); - Graphics::SetWindowResolution(Vector2((float)w, (float)h)); -#endif -#endif - } - bool GetFullScreen() - { -#if SERVER - return false; -#endif -#if EDITOR - auto flag = SDL_GetWindowFlags(Window); - auto is_fullscreen = flag & SDL_WINDOW_MAXIMIZED; -#else - auto flag = SDL_GetWindowFlags(Window); - auto is_fullscreen = flag & SDL_WINDOW_FULLSCREEN; -#endif - return is_fullscreen; - } - void SetCursorPosition(Vector2 NewPos) - { -#if SERVER - return; -#endif - Vector2 Size = GetWindowSize(); - Vector2 TranslatedPos = Vector2(((NewPos.X + 1) / 2) * Size.X, (((NewPos.Y) + 1) / 2) * Size.Y); - TranslatedPos.Y = Size.Y - TranslatedPos.Y; - SDL_WarpMouseInWindow(Window, (int)TranslatedPos.X, (int)TranslatedPos.Y); - } - Vector2 GetCursorPosition() - { - return GetMousePosition(); - } - Vector2 GetWindowSize() - { -#if SERVER - return 0; -#endif - int w, h; - SDL_GetWindowSize(Window, &w, &h); - return Vector2((float)w, (float)h); - } std::string EditorPath; void SetEditorPath(std::string NewEditorPath) @@ -191,37 +86,8 @@ namespace Application { return EditorPath; } - float LogicTime = 0, RenderTime = 0, SyncTime = 0; - size_t FrameCount = 0; -#if !SERVER -#endif -} - -namespace LaunchArgs -{ - void EvaluateLaunchArguments(std::vector Arguments); -} - -static void GLAPIENTRY MessageCallback( - GLenum source, - GLenum type, - GLuint id, - GLenum severity, - GLsizei length, - const GLchar* message, - const void* userParam -) -{ - if (type == GL_DEBUG_TYPE_ERROR - || type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR - || type == GL_DEBUG_TYPE_PORTABILITY) - { - Log::Print(std::string(message) + " - " + Stats::EngineStatus, Log::LogColor::Red); - SDL_Delay(5); - } } - static void UpdateObjects() { Stats::EngineStatus = "Updating objects"; @@ -244,6 +110,7 @@ static void ApplicationLoop() UpdateObjects(); float LogicTime = LogicTimer.Get(); + const Application::Timer RenderTimer; #if !SERVER Stats::EngineStatus = "Rendering (Framebuffer)"; @@ -254,6 +121,7 @@ static void ApplicationLoop() UIBox::UpdateUI(); UIBox::DrawAllUIElements(); float RenderTime = RenderTimer.Get(); + #if !EDITOR && !RELEASE if (!Debug::DebugUI::CurrentDebugUI) { @@ -262,18 +130,19 @@ static void ApplicationLoop() #endif PostProcess::PostProcessSystem->Draw(); #endif + const Application::Timer SwapTimer; #if !SERVER SDL_GL_SetSwapInterval(0 - Graphics::VSync); - SDL_GL_SwapWindow(Application::Window); + SDL_GL_SwapWindow(Window::SDLWindow); #endif #if !SERVER - Application::RenderTime = RenderTime; + Stats::RenderTime = RenderTime; #endif - Application::LogicTime = LogicTime; - Application::SyncTime = SwapTimer.Get(); - Application::FrameCount++; + Stats::LogicTime = LogicTime; + Stats::SyncTime = SwapTimer.Get(); + Stats::FrameCount++; Stats::DeltaTime = FrameTimer.Get(); Stats::DeltaTime *= Stats::TimeMultiplier; @@ -282,14 +151,18 @@ static void ApplicationLoop() Stats::DrawCalls = 0u; #if EDITOR - if (!Application::WindowHasFocus()) + // Slow down the editor if it doesn't have focus. + // This saves performance. + if (!Window::WindowHasFocus()) { SDL_Delay(100 - (Uint32)(Stats::DeltaTime * 1000)); } #endif #if SERVER + if (Networking::GetTickDelta() > Stats::DeltaTime) { + // Sleep to maintain a constant update rate on a server float SleepDelay = Networking::GetTickDelta() - Stats::DeltaTime; std::this_thread::sleep_for(std::chrono::microseconds(Uint32(1000.0f * 1000.0f * SleepDelay))); @@ -300,15 +173,19 @@ static void ApplicationLoop() Stats::Time += Stats::DeltaTime; } -static void CreateWindow() +static void InitSDL() { std::cout << "Starting..." << std::endl; std::cout << "- Starting SDL2 - "; + #if !SERVER int SDLReturnValue = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK); #else + // A server only needs SDL_INIT_EVENTS. + // SDL still needs to be initialized for SDL_net. int SDLReturnValue = SDL_Init(SDL_INIT_EVENTS); #endif + if (SDLReturnValue != 0) { std::cout << "Could not start SDL2 (" << SDL_GetError() << ")\n"; @@ -318,54 +195,6 @@ static void CreateWindow() { std::cout << "SDL2 started (No error)\n"; } -#if !SERVER - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - int flags = SDL_WINDOW_OPENGL; - // Set Window resolution to the screens resolution * 0.75 - SDL_DisplayMode DM; - SDL_GetCurrentDisplayMode(0, &DM); - Graphics::WindowResolution = Vector2((float)DM.w, (float)DM.h) / 1.5f; - Graphics::RenderResolution = Graphics::WindowResolution; - Application::Window = SDL_CreateWindow(ToAppTitle(Project::ProjectName).c_str(), - SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - (int)Graphics::WindowResolution.X, (int)Graphics::WindowResolution.Y, - flags); - - SDL_GL_CreateContext(Application::Window); - SDL_SetWindowResizable(Application::Window, SDL_TRUE); - - std::cout << "- Starting GLEW - "; - auto GlewStatus = glewContextInit(); - if (GlewStatus != GLEW_OK) - { - std::cout << "GLEW Init Error:\n" << glewGetErrorString(GlewStatus); - SDL_DestroyWindow(Application::Window); - std::cout << "\nPress Enter to continue"; - std::cin.get(); - exit(1); - } - if (!glewIsSupported(OPENGL_MIN_REQUIRED_VERSION)) - { - SDL_DestroyWindow(Application::Window); - std::cout << std::string("OpenGL version "); - std::cout << (const char*)glGetString(GL_VERSION); - std::cout << std::string(" is not supported. Minimum: ") + OPENGL_MIN_REQUIRED_VERSION << std::endl; - std::cout << "Press enter to continue"; - std::cin.get(); - std::cout << std::endl; - exit(1); - } - glEnable(GL_DEBUG_OUTPUT); - glDebugMessageCallback(MessageCallback, 0); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - std::cout << "GLEW started (No error)" << std::endl; -#endif } int Application::Initialize(int argc, char** argv) @@ -374,11 +203,13 @@ int Application::Initialize(int argc, char** argv) OS::SetConsoleWindowVisible(true); Assets::ScanForAssets(); Application::EditorPath = std::filesystem::current_path().u8string(); - - CreateWindow(); - Error::Init(); + InitSDL(); +#if !SERVER + Window::InitWindow(Project::ProjectName); +#endif + Subsystem::Load(new LogSubsystem()); Subsystem::Load(new Console()); Subsystem::Load(new PhysicsSubsystem()); @@ -395,38 +226,24 @@ int Application::Initialize(int argc, char** argv) } #endif - if (argc > 1) - { - std::vector LaunchArguments; - for (size_t i = 1; i < argc; i++) - { - LaunchArguments.push_back(argv[i]); - } - LaunchArgs::EvaluateLaunchArguments(LaunchArguments); - } + // Evaluating launch args depends on some subsystems (LogSubsystem, Console, Scene...), so these can't be evaluated before here. + LaunchArgs::Evaluate(argc, argv); + #if ENGINE_CSHARP Subsystem::Load(new CSharpInterop()); - -#if ENGINE_NO_SOURCE - SDL_SetWindowTitle(Window, ToAppTitle( - CSharpInterop::StaticCall( - CSharpInterop::CSharpSystem->LoadCSharpFunction("GetNameInternally", "Engine", "StringDelegate") - ) - ).c_str()); -#endif #endif #if !SERVER UIBox::InitUI(); - RenderSubsystem::LoadRenderSubsystems(); - - Console::ConsoleSystem->RegisterCommand(Console::Command("show_collision", CollisionVisualize::Activate, {})); - Console::ConsoleSystem->RegisterCommand(Console::Command("hide_collision", CollisionVisualize::Deactivate, {})); + Subsystem::Load(new RenderSubsystem()); #endif std::string Startup = Project::GetStartupScene(); + + // Application::StartupSceneOverride is set mostly by launch args. (-scene xyz) + // Some projects might still depend on GetStartupScene always being called, which is why it's alwayys called here. if (!Application::StartupSceneOverride.empty()) { Startup = Application::StartupSceneOverride; @@ -451,8 +268,12 @@ int Application::Initialize(int argc, char** argv) { ApplicationLoop(); } - Subsystem::DestroyAll(); +#if !SERVER OS::SetConsoleWindowVisible(true); + Window::DestroyWindow(); +#endif + + Subsystem::DestroyAll(); exit(0); } diff --git a/EngineSource/Engine/Application.h b/EngineSource/Engine/Application.h index d054e404..9ddade84 100644 --- a/EngineSource/Engine/Application.h +++ b/EngineSource/Engine/Application.h @@ -8,8 +8,6 @@ class EditorUI; #include #include -struct SDL_Window; - /** * @file * @brief @@ -22,87 +20,21 @@ struct SDL_Window; */ namespace Application { - extern size_t FrameCount; - extern std::string StartupSceneOverride; - /** - * @brief - * A function that returns true if the application window has mouse focus. - * - * @return - * true if the window has mouse focus, false if not. - */ - bool WindowHasFocus(); - extern bool ShowStartupInfo; int Initialize(int argc, char** argv); - extern float LogicTime, RenderTime, SyncTime; - extern SDL_Window* Window; - /** * @brief - * Deinitializes the engine, quits the application. + * DeInitializes the engine, quits the application. * * If in the editor, this will call EditorUI::OnQuit(). */ void Quit(); - /** - * @brief - * Minimizes the application window. - */ - void Minimize(); - - /** - * @brief - * Enables/disables full screen mode. - * - * For full screen, SDL_WINDOW_FULLSCREEN_DESKTOP is used. - * - * @param NewFullScreen - * If true, the application window will be set to full screen. If false, the window will be in windowed mode. - */ - void SetFullScreen(bool NewFullScreen); - - /** - * @brief - * A function that returns true if full screen is enabled. - * @return - * - * true if full screen is enabled, false if not. - */ - bool GetFullScreen(); - - /** - * @brief - * Sets the mouse cursors position to the given position. - * - * Expects coordinates from -1, -1 (bottom left corner of the window) to 1, 1 (top right corner of the window) - * - * @param NewPos - * The new position of the cursor. - */ - void SetCursorPosition(Vector2 NewPos); - - /** - * @brief - * Returns the position of the mouse cursor. - * - * The position will be in the format: -1, -1 (bottom left corner of the window) to 1, 1 (top right corner of the window) - * - * @return - * The current position of the cursor. - */ - Vector2 GetCursorPosition(); - /** - * @brief - * Returns the size of the application window in pixels. - */ - Vector2 GetWindowSize(); #if EDITOR /** * @brief diff --git a/EngineSource/Engine/EngineError.cpp b/EngineSource/Engine/EngineError.cpp index f4969766..7d2bb074 100644 --- a/EngineSource/Engine/EngineError.cpp +++ b/EngineSource/Engine/EngineError.cpp @@ -13,6 +13,7 @@ #if __cpp_lib_stacktrace >= 202011L #include #endif +#include "AppWindow.h" std::map SignalTypes = { @@ -52,8 +53,10 @@ void Error::Init() void Error::AssertFailure(std::string Name, std::string Position) { +#if !SERVER OS::SetConsoleWindowVisible(true); - SDL_DestroyWindow(Application::Window); + Window::DestroyWindow(); +#endif Log::Print("[Error]: ------------------------------------[Error]------------------------------------", Log::LogColor::Red); Log::PrintMultiLine(Name, Log::LogColor::Red, "[Error]: "); Log::Print("[Error]: " + Position, Log::LogColor::Red); diff --git a/EngineSource/Engine/EngineProperties.h b/EngineSource/Engine/EngineProperties.h index 0c2b49ed..c74df7b6 100644 --- a/EngineSource/Engine/EngineProperties.h +++ b/EngineSource/Engine/EngineProperties.h @@ -16,7 +16,7 @@ namespace Project void OnLaunch(); extern const char* ProjectName; } -#define VERSION_STRING "1.12.0" +#define VERSION_STRING "1.13.0" #define OPENGL_MIN_REQUIRED_VERSION "GL_VERSION_4_2" /** diff --git a/EngineSource/Engine/File/Assets.cpp b/EngineSource/Engine/File/Assets.cpp index 59f4ed4d..fb282f50 100644 --- a/EngineSource/Engine/File/Assets.cpp +++ b/EngineSource/Engine/File/Assets.cpp @@ -35,7 +35,7 @@ namespace Assets { std::string Path = entry.path().string(); #if _WIN32 // Replace all backslashes with forward slashes for consistency. - for (auto& i : Path) + for (char& i : Path) { if (i == '\\') { diff --git a/EngineSource/Engine/Gamepad.cpp b/EngineSource/Engine/Gamepad.cpp index d8c8906b..5fd3ab89 100644 --- a/EngineSource/Engine/Gamepad.cpp +++ b/EngineSource/Engine/Gamepad.cpp @@ -5,6 +5,7 @@ #include #include #include "Application.h" +#include "AppWindow.h" std::unordered_map Input::Gamepads; Vector2 GetHatState(Uint8 hat); @@ -15,6 +16,7 @@ Input::GamepadType Input::GetGamepadType(Gamepad* From) void Input::AddGamepad(int32_t ID) { +#if !SERVER SDL_Joystick* New = SDL_JoystickOpen(ID); int32_t NewID = SDL_JoystickInstanceID(New); Log::Print(StrUtil::Format("Connected device '%s' with ID %i.", SDL_JoystickName(New), NewID)); @@ -30,6 +32,7 @@ void Input::AddGamepad(int32_t ID) g.Buttons = new bool[GAMEPAD_MAX](); Gamepads.insert(std::pair(NewID, g)); } +#endif } void Input::GamepadUpdate() @@ -38,7 +41,8 @@ void Input::GamepadUpdate() void Input::HandleGamepadEvent(void* EventPtr) { - if (!Application::WindowHasFocus()) +#if !SERVER + if (!Window::WindowHasFocus()) { return; } @@ -108,13 +112,13 @@ void Input::HandleGamepadEvent(void* EventPtr) } break; } - //Log::Print(Gamepads[e->jdevice.which].LeftStickPosition.ToString()); - //Log::Print(StrUtil::Format("%u\t%s\t%u\t%s", timestamp, eventType.c_str(), index, otherData.c_str())); +#endif } Vector2 GetHatState(Uint8 hat) { - switch (hat) +#if !SERVER + switch (hat) { case SDL_HAT_LEFTUP: return Vector2(-1, 1); @@ -147,6 +151,8 @@ Vector2 GetHatState(Uint8 hat) return Vector2(0); break; } +#endif + return 0; } Input::Gamepad::Gamepad() diff --git a/EngineSource/Engine/Gamepad.h b/EngineSource/Engine/Gamepad.h index 69b38611..946aeff6 100644 --- a/EngineSource/Engine/Gamepad.h +++ b/EngineSource/Engine/Gamepad.h @@ -75,4 +75,4 @@ namespace Input void GamepadUpdate(); void HandleGamepadEvent(void* EventPtr); -} \ No newline at end of file +} diff --git a/EngineSource/Engine/LaunchArgs.cpp b/EngineSource/Engine/LaunchArgs.cpp index b56fc458..a0b1d0c4 100644 --- a/EngineSource/Engine/LaunchArgs.cpp +++ b/EngineSource/Engine/LaunchArgs.cpp @@ -8,6 +8,8 @@ #include #include #include +#include "AppWindow.h" +#include "LaunchArgs.h" namespace LaunchArgs { @@ -24,7 +26,7 @@ namespace LaunchArgs { if (AdditionalArgs.size() != 1) { - Log::Print("Unexpected or missing arguments in -loadscene", Log::LogColor::Yellow); + Log::Print("Unexpected or missing arguments in -scene", Log::LogColor::Yellow); return; } Application::StartupSceneOverride = AdditionalArgs[0]; @@ -52,11 +54,13 @@ namespace LaunchArgs exit(0); } +#if !SERVER static void FullScreen(std::vector AdditionalArgs) { if (AdditionalArgs.size()) Log::Print("Unexpected arguments in -fullscreen", Log::LogColor::Yellow); - Application::SetFullScreen(true); + Window::SetFullScreen(true); } +#endif static void NoStartupInfo(std::vector AdditionalArgs) { @@ -98,7 +102,9 @@ namespace LaunchArgs std::pair("novsync", &NoVSync), std::pair("wireframe", &Wireframe), std::pair("version", &GetVersion), +#if !SERVER std::pair("fullscreen", &FullScreen), +#endif std::pair("nostartupinfo", &NoStartupInfo), std::pair("connect", &Connect), std::pair("verbose", &LogVerbose), @@ -111,11 +117,22 @@ namespace LaunchArgs }), #endif }; - void EvaluateLaunchArguments(std::vector Arguments) + + void LaunchArgs::Evaluate(int argc, char** argv) + { + std::vector Args; + for (size_t i = 1; i < argc; i++) + { + Args.push_back(argv[i]); + } + EvaluateVector(Args); + } + + void EvaluateVector(std::vector Args) { std::vector CommandArguments; std::string CurrentCommand; - for (const std::string& arg : Arguments) + for (const std::string& arg : Args) { if (arg[0] == '-') { @@ -130,7 +147,7 @@ namespace LaunchArgs CommandArguments.clear(); CurrentCommand = arg; } - else if(!CurrentCommand.empty()) + else if (!CurrentCommand.empty()) { CommandArguments.push_back(arg); } diff --git a/EngineSource/Engine/LaunchArgs.h b/EngineSource/Engine/LaunchArgs.h new file mode 100644 index 00000000..24ddceb2 --- /dev/null +++ b/EngineSource/Engine/LaunchArgs.h @@ -0,0 +1,9 @@ +#pragma once +#include +#include + +namespace LaunchArgs +{ + void Evaluate(int argc, char** argv); + void EvaluateVector(std::vector Args); +} \ No newline at end of file diff --git a/EngineSource/Engine/Stats.cpp b/EngineSource/Engine/Stats.cpp index e06e72f6..9d470e4c 100644 --- a/EngineSource/Engine/Stats.cpp +++ b/EngineSource/Engine/Stats.cpp @@ -2,26 +2,24 @@ #include #include "EngineProperties.h" -namespace Engine -{ - std::string VersionString = VERSION_STRING + std::string(IS_IN_EDITOR ? "-Editor" : "-Build"); -} - const bool IsInEditor = IS_IN_EDITOR; const bool EngineDebug = ENGINE_DEBUG; namespace Stats { + std::string VersionString = VERSION_STRING + std::string(IS_IN_EDITOR ? "-Editor" : "-Build"); float DeltaTime; float FPS; float TimeMultiplier = 1; unsigned int DrawCalls = 0; float Time = 0; std::string EngineStatus; + float LogicTime = 0, RenderTime = 0, SyncTime = 0; + size_t FrameCount = 0; } namespace Editor { bool IsInSubscene = false; -} \ No newline at end of file +} diff --git a/EngineSource/Engine/Stats.h b/EngineSource/Engine/Stats.h index 06184b97..c1fdc099 100644 --- a/EngineSource/Engine/Stats.h +++ b/EngineSource/Engine/Stats.h @@ -7,26 +7,17 @@ namespace Stats extern float FPS; extern float TimeMultiplier; extern unsigned int DrawCalls; -} - -namespace Stats -{ extern float Time; -} - -namespace Editor -{ - extern bool IsInSubscene; -} + extern std::string EngineStatus; -namespace Engine -{ + extern size_t FrameCount; + extern float LogicTime, RenderTime, SyncTime; extern std::string VersionString; } -namespace Stats +namespace Editor { - extern std::string EngineStatus; + extern bool IsInSubscene; } const extern bool IsInEditor; diff --git a/EngineSource/Engine/Subsystem/CSharpInterop.cpp b/EngineSource/Engine/Subsystem/CSharpInterop.cpp index 0fa28306..77e7b868 100644 --- a/EngineSource/Engine/Subsystem/CSharpInterop.cpp +++ b/EngineSource/Engine/Subsystem/CSharpInterop.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -289,6 +290,12 @@ CSharpInterop::CSharpInterop() LoadAssembly(); NativeFunctions::RegisterNativeFunctions(); + +#if ENGINE_NO_SOURCE && !SERVER + Window::SetWindowTitle(CSharpInterop::StaticCall( + CSharpInterop::CSharpSystem->LoadCSharpFunction("GetNameInternally", "Engine", "StringDelegate") + )); +#endif } void CSharpInterop::Update() diff --git a/EngineSource/Engine/Subsystem/Console.cpp b/EngineSource/Engine/Subsystem/Console.cpp index 038c10bc..a995779d 100644 --- a/EngineSource/Engine/Subsystem/Console.cpp +++ b/EngineSource/Engine/Subsystem/Console.cpp @@ -18,6 +18,7 @@ #if __linux__ #include #endif +#include Console* Console::ConsoleSystem = nullptr; #if _WIN32 @@ -117,18 +118,18 @@ Console::Console() { ConsoleSystem = this; Name = "Console"; - RegisterCommand(Command("echo", - []() { - ConsoleSystem->Print(ConsoleSystem->CommandArgs()[0]); + RegisterCommand(Command("echo", [this]() + { + Print(CommandArgs()[0]); }, { Console::Command::Argument("msg", NativeType::String) })); - RegisterCommand(Command("version", - []() { - ConsoleSystem->Print(std::string(VERSION_STRING) + (IS_IN_EDITOR ? "-Editor (" : " (") + std::string(Project::ProjectName) + ")"); + RegisterCommand(Command("version", [this]() + { + Print(std::string(VERSION_STRING) + (IS_IN_EDITOR ? "-Editor (" : " (") + std::string(Project::ProjectName) + ")"); }, {})); RegisterCommand(Command("info", - []() { + [this]() { void (*InfoPrintTypes[4])() = { []() { @@ -162,61 +163,61 @@ Console::Console() #endif } }; - if (!ConsoleSystem->CommandArgs().size()) + if (!CommandArgs().size()) { - ConsoleSystem->Print("-----------------------------------[Info]-------------------------------------"); + Print("-----------------------------------[Info]-------------------------------------"); InfoPrintTypes[0](); InfoPrintTypes[1](); InfoPrintTypes[2](); InfoPrintTypes[3](); - ConsoleSystem->Print("------------------------------------------------------------------------------"); + Print("------------------------------------------------------------------------------"); return; } if (ConsoleSystem->CommandArgs()[0] == "version") { - ConsoleSystem->Print("-----------------------------------[Info]-------------------------------------"); + Print("-----------------------------------[Info]-------------------------------------"); InfoPrintTypes[0](); - ConsoleSystem->Print("------------------------------------------------------------------------------"); + Print("------------------------------------------------------------------------------"); return; } - if (ConsoleSystem->CommandArgs()[0] == "graphics") + if (CommandArgs()[0] == "graphics") { - ConsoleSystem->Print("-----------------------------------[Info]-------------------------------------"); + Print("-----------------------------------[Info]-------------------------------------"); InfoPrintTypes[1](); - ConsoleSystem->Print("------------------------------------------------------------------------------"); + Print("------------------------------------------------------------------------------"); return; } if (ConsoleSystem->CommandArgs()[0] == "sound") { - ConsoleSystem->Print("-----------------------------------[Info]-------------------------------------"); + Print("-----------------------------------[Info]-------------------------------------"); InfoPrintTypes[2](); - ConsoleSystem->Print("------------------------------------------------------------------------------"); + Print("------------------------------------------------------------------------------"); return; } - if (ConsoleSystem->CommandArgs()[0] == "csharp") + if (CommandArgs()[0] == "csharp") { - ConsoleSystem->Print("-----------------------------------[Info]-------------------------------------"); + Print("-----------------------------------[Info]-------------------------------------"); InfoPrintTypes[3](); - ConsoleSystem->Print("------------------------------------------------------------------------------"); + Print("------------------------------------------------------------------------------"); return; } - ConsoleSystem->Print("Unknown info topic: " + ConsoleSystem->CommandArgs()[0], ErrorLevel::Error); - ConsoleSystem->Print("Topics are: version, graphics, sound.", ErrorLevel::Error); + Print("Unknown info topic: " + ConsoleSystem->CommandArgs()[0], ErrorLevel::Error); + Print("Topics are: version, graphics, sound.", ErrorLevel::Error); }, { Command::Argument("info_type", NativeType::String, true) })); - RegisterCommand(Command("list_pack", - []() { + RegisterCommand(Command("list_pack", [this]() + { std::string Pack = ConsoleSystem->CommandArgs()[0]; auto Result = Pack::GetPackContents(Pack); if (Result.size()) { - ConsoleSystem->Print("Content of .pack file: " + Pack + ": "); - ConsoleSystem->Print("------------------------------------------------------------------------------"); + Print("Content of .pack file: " + Pack + ": "); + Print("------------------------------------------------------------------------------"); } else { - ConsoleSystem->Print("Pack File is emtpy"); + Print("Pack File is emtpy"); return; } for (size_t i = 0; i < Result.size(); i += 2) @@ -227,97 +228,92 @@ Console::Console() LogString.resize(35, ' '); LogString.append(Result[i + 1].FileName + " (" + std::to_string(Result[i + 1].Content.size()) + " bytes)"); } - ConsoleSystem->Print(LogString); + Print(LogString); } }, { Command::Argument("pack_file", NativeType::String) })); - RegisterCommand(Command("open", []() { - if (std::filesystem::exists(Assets::GetAsset(ConsoleSystem->CommandArgs()[0] + +".jscn"))) + RegisterCommand(Command("open", [this]() + { + if (std::filesystem::exists(Assets::GetAsset(CommandArgs()[0] + +".jscn"))) { - Scene::LoadNewScene(Assets::GetAsset(ConsoleSystem->CommandArgs()[0] + ".jscn")); + Scene::LoadNewScene(Assets::GetAsset(CommandArgs()[0] + ".jscn")); } else { - ConsoleSystem->Print("Could not find scene \"" + ConsoleSystem->CommandArgs()[0] + "\"", ErrorLevel::Error); + Print("Could not find scene \"" + CommandArgs()[0] + "\"", ErrorLevel::Error); } }, { Command::Argument("scene", NativeType::String) })); - RegisterCommand(Command("help", []() { - std::string CommandString = ConsoleSystem->CommandArgs()[0]; - if (ConsoleSystem->Commands.contains(CommandString)) + RegisterCommand(Command("help", [this]() { - auto& FoundCommand = ConsoleSystem->Commands[CommandString]; - ConsoleSystem->Print("Help about " + CommandString + ": "); - ConsoleSystem->PrintArguments(FoundCommand.Arguments); - return; - } - ConsoleSystem->Print("Help: " + CommandString + " is not a registered command.", ErrorLevel::Error); + std::string CommandString = ConsoleSystem->CommandArgs()[0]; + if (Commands.contains(CommandString)) + { + auto& FoundCommand = ConsoleSystem->Commands[CommandString]; + Print("Help about " + CommandString + ": "); + PrintArguments(FoundCommand.Arguments); + return; + } + Print("Help: " + CommandString + " is not a registered command.", ErrorLevel::Error); }, { Command::Argument("command", NativeType::String) })); - RegisterCommand(Command("get_commands", []() { - for (auto& i : ConsoleSystem->Commands) + RegisterCommand(Command("get_commands", [this]() { - ConsoleSystem->Print(i.first); - ConsoleSystem->PrintArguments(i.second.Arguments); - } + for (auto& i : ConsoleSystem->Commands) + { + Print(i.first); + PrintArguments(i.second.Arguments); + } }, {})); RegisterCommand(Command("exit", Application::Quit, {})); - RegisterCommand(Command("stats", []() + RegisterCommand(Command("stats", [this]() { - ConsoleSystem->Print("FPS: " + std::to_string(1.f / Stats::DeltaTime) + ", Delta: " + std::to_string(Stats::DeltaTime)); - ConsoleSystem->Print("DrawCalls: " + std::to_string(Stats::DrawCalls)); + Print("FPS: " + std::to_string(1.f / Stats::DeltaTime) + ", Delta: " + std::to_string(Stats::DeltaTime)); + Print("DrawCalls: " + std::to_string(Stats::DrawCalls)); }, {})); - RegisterCommand(Command("locate", []() + RegisterCommand(Command("locate", [this]() { Application::Timer t; - std::string FoundFile = Assets::GetAsset(ConsoleSystem->CommandArgs()[0]); + std::string FoundFile = Assets::GetAsset(CommandArgs()[0]); float Duration = t.Get(); if (FoundFile.empty()) { FoundFile = "Not found"; } - std::string LogMessage = ConsoleSystem->CommandArgs()[0] + " -> " + FoundFile; - if (ConsoleSystem->CommandArgs().size() > 1 && ConsoleSystem->CommandArgs()[1] != "0") + std::string LogMessage = CommandArgs()[0] + " -> " + FoundFile; + if (CommandArgs().size() > 1 && CommandArgs()[1] != "0") { LogMessage.append(" (" + std::to_string(Duration) + " seconds)"); } - ConsoleSystem->Print(LogMessage); + Print(LogMessage); }, { Command::Argument("file", NativeType::String), Command::Argument("print_search_time", NativeType::Bool, true) })); - RegisterCommand(Command("asset_dump", []() + RegisterCommand(Command("asset_dump", [this]() { for (auto& i : Assets::Assets) { - ConsoleSystem->Print(i.Filepath + " - " + i.Name); + Print(i.Filepath + " - " + i.Name); } }, { })); - RegisterCommand(Command("get_class", []() + RegisterCommand(Command("get_class", [this]() { for (const auto& i : Objects::ObjectTypes) { - if (i.Name == ConsoleSystem->CommandArgs()[0]) + if (i.Name == CommandArgs()[0]) { - ConsoleSystem->Print(Objects::GetCategoryFromID(i.ID) + "/" + i.Name); + Print(Objects::GetCategoryFromID(i.ID) + "/" + i.Name); return; } } - ConsoleSystem->Print("Could not find class " + ConsoleSystem->CommandArgs()[0], ErrorLevel::Error); + Print("Could not find class " + CommandArgs()[0], ErrorLevel::Error); }, { Command::Argument("objectName", NativeType::String) })); - RegisterConVar(Variable("wireframe", NativeType::Bool, &Graphics::IsWireframe, nullptr)); - RegisterConVar(Variable("vignette", NativeType::Float, &Graphics::Vignette, nullptr)); - RegisterConVar(Variable("vsync", NativeType::Bool, &Graphics::VSync, nullptr)); - RegisterConVar(Variable("timescale", NativeType::Float, &Stats::TimeMultiplier, nullptr)); - RegisterConVar(Variable("resolution_scale", NativeType::Float, &Graphics::ResolutionScale, []() - { - Graphics::SetWindowResolution(Application::GetWindowSize()); - })); RegisterCommand(Command("crash", []() { diff --git a/EngineSource/Engine/Subsystem/InputSubsystem.cpp b/EngineSource/Engine/Subsystem/InputSubsystem.cpp index 804bd444..f7080412 100644 --- a/EngineSource/Engine/Subsystem/InputSubsystem.cpp +++ b/EngineSource/Engine/Subsystem/InputSubsystem.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace Input { @@ -53,11 +54,11 @@ void InputSubsystem::Update() Input::MouseMovement = Vector2(); PollInput(); - if (Input::CursorVisible || !Application::WindowHasFocus()) + if (Input::CursorVisible || !Window::WindowHasFocus()) { SDL_SetRelativeMouseMode(SDL_FALSE); Input::MouseMovement = 0; - Input::MouseLocation = Application::GetCursorPosition(); + Input::MouseLocation = Window::GetCursorPosition(); } else { @@ -172,7 +173,7 @@ void InputSubsystem::PollInput() TextInput::PollForText = false; break; case SDLK_F11: - Application::SetFullScreen(!Application::GetFullScreen()); + Window::SetFullScreen(!Window::GetFullScreen()); break; case SDLK_c: if (TextInput::PollForText && (SDL_GetModState() & KMOD_CTRL)) @@ -219,7 +220,7 @@ void InputSubsystem::PollInput() if (Event.window.event == SDL_WINDOWEVENT_RESIZED) { int w, h; - SDL_GetWindowSize(Application::Window, &w, &h); + SDL_GetWindowSize(Window::SDLWindow, &w, &h); Graphics::SetWindowResolution(Vector2((float)w, (float)h)); } } diff --git a/EngineSource/Engine/Subsystem/PhysicsSubsystem.cpp b/EngineSource/Engine/Subsystem/PhysicsSubsystem.cpp index 944705ce..07528006 100644 --- a/EngineSource/Engine/Subsystem/PhysicsSubsystem.cpp +++ b/EngineSource/Engine/Subsystem/PhysicsSubsystem.cpp @@ -1,6 +1,7 @@ #include "PhysicsSubsystem.h" #include #include +#include "Console.h" PhysicsSubsystem* PhysicsSubsystem::PhysicsSystem = nullptr; @@ -11,6 +12,10 @@ PhysicsSubsystem::PhysicsSubsystem() Physics::Init(); +#if !SERVER + Console::ConsoleSystem->RegisterCommand(Console::Command("show_collision", CollisionVisualize::Activate, {})); + Console::ConsoleSystem->RegisterCommand(Console::Command("hide_collision", CollisionVisualize::Deactivate, {})); +#endif } void PhysicsSubsystem::Update() diff --git a/EngineSource/Engine/Subsystem/Subsystem.cpp b/EngineSource/Engine/Subsystem/Subsystem.cpp index 6de23c05..baa3766c 100644 --- a/EngineSource/Engine/Subsystem/Subsystem.cpp +++ b/EngineSource/Engine/Subsystem/Subsystem.cpp @@ -83,6 +83,13 @@ Subsystem* Subsystem::GetSubsystemByName(std::string Name) return System; } } + for (Subsystem* System : LoadedSystems) + { + if (System->SystemType == Name && System->Name == nullptr) + { + return System; + } + } return nullptr; } diff --git a/EngineSource/Rendering/BillboardSprite.h b/EngineSource/Rendering/BillboardSprite.h index c650e9dd..32eb55d4 100644 --- a/EngineSource/Rendering/BillboardSprite.h +++ b/EngineSource/Rendering/BillboardSprite.h @@ -1,11 +1,11 @@ #pragma once -#include +#include class Camera; class FramebufferObject; struct VertexBuffer; -class BillboardSprite : public Renderable +class BillboardSprite : public Drawable { public: diff --git a/EngineSource/Rendering/Renderable.cpp b/EngineSource/Rendering/Drawable.cpp similarity index 88% rename from EngineSource/Rendering/Renderable.cpp rename to EngineSource/Rendering/Drawable.cpp index 497f56d4..cfbcb78a 100644 --- a/EngineSource/Rendering/Renderable.cpp +++ b/EngineSource/Rendering/Drawable.cpp @@ -1,4 +1,4 @@ -#include "Renderable.h" +#include "Drawable.h" #include #include #include @@ -19,7 +19,7 @@ Graphics::Sun FullbrightSun = .AmbientColor = 1, }; -void Renderable::ApplyDefaultUniformsToShader(Shader* ShaderToApply, bool MainFramebuffer) +void Drawable::ApplyDefaultUniformsToShader(Shader* ShaderToApply, bool MainFramebuffer) { #if !SERVER ShaderToApply->Bind(); @@ -244,6 +244,13 @@ void ObjectRenderContext::LoadUniform(Material::Param u) #endif } +void ObjectRenderContext::LoadTexture(std::string UniformName, Texture::TextureType TextureID) +{ + DeleteUniform(UniformName); + + Uniforms.push_back(Uniform(UniformName, NativeType::GL_Texture, new unsigned int(TextureID))); +} + void ObjectRenderContext::Unload() { #if !SERVER @@ -279,3 +286,36 @@ void ObjectRenderContext::Unload() Mat = Material(); #endif } + +bool ObjectRenderContext::DeleteUniform(std::string Name) +{ + for (size_t i = 0; i < Uniforms.size(); i++) + { + if (Uniforms[i].Name != Name) + { + continue; + } + switch (Uniforms[i].NativeType) + { + case NativeType::Int: + case NativeType::Bool: + delete (int*)Uniforms[i].Content; + break; + case NativeType::Vector3Color: + case NativeType::Vector3Rotation: + case NativeType::Vector3: + delete (Vector3*)Uniforms[i].Content; + break; + case NativeType::Float: + delete (float*)Uniforms[i].Content; + break; + case NativeType::GL_Texture: + delete (unsigned int*)Uniforms[i].Content; + break; + default: + break; + } + return true; + } + return false; +} diff --git a/EngineSource/Rendering/Renderable.h b/EngineSource/Rendering/Drawable.h similarity index 83% rename from EngineSource/Rendering/Renderable.h rename to EngineSource/Rendering/Drawable.h index 092994aa..95935129 100644 --- a/EngineSource/Rendering/Renderable.h +++ b/EngineSource/Rendering/Drawable.h @@ -2,6 +2,7 @@ #include #include #include +#include struct ObjectRenderContext { @@ -27,23 +28,26 @@ struct ObjectRenderContext Material Mat; void LoadUniform(Material::Param u); + void LoadTexture(std::string TextureName, Texture::TextureType TextureID); void Unload(); + bool DeleteUniform(std::string Name); + protected: Shader* ContextShader = nullptr; std::vector Uniforms; }; -class Renderable +class Drawable { public: virtual void Render(Camera* WorldCamera, bool MainFrameBuffer, bool TransparencyPass) = 0; virtual void SimpleRender(Shader* UsedShader) = 0; - Renderable() + Drawable() { }; - virtual ~Renderable() + virtual ~Drawable() { }; diff --git a/EngineSource/Rendering/Framebuffer.cpp b/EngineSource/Rendering/Framebuffer.cpp index 95146451..630ae362 100644 --- a/EngineSource/Rendering/Framebuffer.cpp +++ b/EngineSource/Rendering/Framebuffer.cpp @@ -13,6 +13,7 @@ #include #include #include +#include FramebufferObject::FramebufferObject() { @@ -58,7 +59,7 @@ void FramebufferObject::ReInit() } } -void FramebufferObject::UseWith(Renderable* r) +void FramebufferObject::UseWith(Drawable* r) { Renderables.push_back(r); } @@ -75,7 +76,7 @@ void FramebufferObject::Draw() #if EDITOR - if (!Application::WindowHasFocus()) + if (!Window::WindowHasFocus()) { return; } @@ -143,7 +144,7 @@ void FramebufferObject::Draw() Vector2 BufferResolution = UseMainWindowResolution ? Graphics::RenderResolution : CustomFramebufferResolution; glViewport(0, 0, (int)BufferResolution.X, (int)BufferResolution.Y); - const auto LightSpaceMatrices = CSM::getLightSpaceMatrices(FramebufferCamera); + const auto LightSpaceMatrices = CSM::GetLightSpaceMatrices(FramebufferCamera); std::vector DrawnLights; DrawnLights.reserve(std::min(size_t(8), Lights.size())); @@ -172,7 +173,7 @@ void FramebufferObject::Draw() for (auto& s : ShaderManager::Shaders) { - Renderable::ApplyDefaultUniformsToShader(s.second.UsedShader, this == Graphics::MainFramebuffer); + Drawable::ApplyDefaultUniformsToShader(s.second.UsedShader, this == Graphics::MainFramebuffer); CSM::BindLightSpaceMatricesToShader(LightSpaceMatrices, s.second.UsedShader); for (int i = 0; i < Graphics::MAX_LIGHTS; i++) @@ -278,8 +279,8 @@ void FramebufferObject::AddEditorGrid() void FramebufferObject::ClearContent(bool Full) { - std::vector Remaining; - for (Renderable* r : Renderables) + std::vector Remaining; + for (Drawable* r : Renderables) { if (r->DestroyOnUnload || Full) { diff --git a/EngineSource/Rendering/Framebuffer.h b/EngineSource/Rendering/Framebuffer.h index d0219c41..119f684d 100644 --- a/EngineSource/Rendering/Framebuffer.h +++ b/EngineSource/Rendering/Framebuffer.h @@ -1,7 +1,7 @@ #if !SERVER #pragma once #include -#include +#include #include #include @@ -42,13 +42,13 @@ class FramebufferObject void ClearContent(bool Full = false); Camera* FramebufferCamera = nullptr; void ReInit(); - void UseWith(Renderable* r); + void UseWith(Drawable* r); std::vector ParticleEmitters; Framebuffer* GetBuffer(); std::string ReflectionCubemapName; std::string PreviousReflectionCubemapName; unsigned int ReflectionCubemap = 0; - std::vector Renderables; + std::vector Renderables; void Draw(); diff --git a/EngineSource/Rendering/Graphics.h b/EngineSource/Rendering/Graphics.h index cce06742..c8bb3320 100644 --- a/EngineSource/Rendering/Graphics.h +++ b/EngineSource/Rendering/Graphics.h @@ -2,7 +2,7 @@ #include #include -class Renderable; +class Drawable; class UICanvas; class Camera; struct Shader; diff --git a/EngineSource/Rendering/Mesh/InstancedModel.h b/EngineSource/Rendering/Mesh/InstancedModel.h index 48bf0104..2f38046e 100644 --- a/EngineSource/Rendering/Mesh/InstancedModel.h +++ b/EngineSource/Rendering/Mesh/InstancedModel.h @@ -2,7 +2,7 @@ #pragma once #include #include -class InstancedModel : public Renderable +class InstancedModel : public Drawable { public: InstancedModel(std::string Filename); diff --git a/EngineSource/Rendering/Mesh/Mesh.h b/EngineSource/Rendering/Mesh/Mesh.h index bd28d2cc..0f0f5b41 100644 --- a/EngineSource/Rendering/Mesh/Mesh.h +++ b/EngineSource/Rendering/Mesh/Mesh.h @@ -4,7 +4,7 @@ #include "Rendering/Shader.h" #include "Rendering/VertexBuffer.h" #include -#include +#include class Mesh { diff --git a/EngineSource/Rendering/Mesh/Model.h b/EngineSource/Rendering/Mesh/Model.h index df0789b4..636e8984 100644 --- a/EngineSource/Rendering/Mesh/Model.h +++ b/EngineSource/Rendering/Mesh/Model.h @@ -3,7 +3,7 @@ #include #include "Rendering/Camera/Camera.h" #include "Math/Collision/CollisionBox.h" -#include +#include #include #include #include @@ -11,7 +11,7 @@ #if !SERVER class Mesh; -class Model : public Renderable +class Model : public Drawable { public: Model(std::string Filename); diff --git a/EngineSource/Rendering/Particle.cpp b/EngineSource/Rendering/Particle.cpp index 774d780f..b723272b 100644 --- a/EngineSource/Rendering/Particle.cpp +++ b/EngineSource/Rendering/Particle.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include struct Uniform { diff --git a/EngineSource/Rendering/RenderSubsystem/BakedLighting.cpp b/EngineSource/Rendering/RenderSubsystem/BakedLighting.cpp index 7d57c25e..9d6d4b6b 100644 --- a/EngineSource/Rendering/RenderSubsystem/BakedLighting.cpp +++ b/EngineSource/Rendering/RenderSubsystem/BakedLighting.cpp @@ -467,6 +467,7 @@ float BakedLighting::GetBakeProgress() #endif BakedLighting::BakedLighting() + : RenderSubsystem(true) { Name = "LightMap"; BakeSystem = this; diff --git a/EngineSource/Rendering/RenderSubsystem/Bloom.cpp b/EngineSource/Rendering/RenderSubsystem/Bloom.cpp index 8670f9b5..3fa4cd5e 100644 --- a/EngineSource/Rendering/RenderSubsystem/Bloom.cpp +++ b/EngineSource/Rendering/RenderSubsystem/Bloom.cpp @@ -10,8 +10,8 @@ float Bloom::BloomResolutionMultiplier = 0.15f; int Bloom::BloomShape = 2; Shader* Bloom::BloomShader = nullptr; -unsigned int Bloom::pingpongFBO[2]; -unsigned int Bloom::pingpongBuffer[2]; +unsigned int Bloom::PingPongFBO[2]; +unsigned int Bloom::PingPongBuffer[2]; unsigned int Bloom::BlurFramebuffer(unsigned int buf) { @@ -24,16 +24,16 @@ unsigned int Bloom::BlurFramebuffer(unsigned int buf) bool horizontal = true, first_iteration = true; unsigned int amount = 15u; BloomShader->Bind(); - glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]); + glBindFramebuffer(GL_FRAMEBUFFER, PingPongFBO[horizontal]); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUniform1i(glGetUniformLocation(BloomShader->GetShaderID(), "FullScreen"), 1); for (unsigned int i = 0; i < amount; i++) { - glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]); + glBindFramebuffer(GL_FRAMEBUFFER, PingPongFBO[horizontal]); glUniform1i(glGetUniformLocation(BloomShader->GetShaderID(), "horizontal"), (i % (unsigned int)BloomShape) != 0); glActiveTexture(GL_TEXTURE0); glBindTexture( - GL_TEXTURE_2D, first_iteration ? buf : pingpongBuffer[!horizontal] + GL_TEXTURE_2D, first_iteration ? buf : PingPongBuffer[!horizontal] ); glDrawArrays(GL_TRIANGLES, 0, 3); horizontal = !horizontal; @@ -44,19 +44,20 @@ unsigned int Bloom::BlurFramebuffer(unsigned int buf) glViewport(0, 0, (unsigned int)Graphics::WindowResolution.X, (unsigned int)Graphics::WindowResolution.Y); } - return pingpongBuffer[1]; + return PingPongBuffer[1]; } Bloom::Bloom() + : RenderSubsystem(true) { Name = "Bloom"; BloomShader = new Shader("Shaders/Internal/postprocess.vert", "Shaders/Internal/bloom.frag"); - glGenFramebuffers(2, pingpongFBO); - glGenTextures(2, pingpongBuffer); + glGenFramebuffers(2, PingPongFBO); + glGenTextures(2, PingPongBuffer); for (unsigned int i = 0; i < 2; i++) { - glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[i]); - glBindTexture(GL_TEXTURE_2D, pingpongBuffer[i]); + glBindFramebuffer(GL_FRAMEBUFFER, PingPongFBO[i]); + glBindTexture(GL_TEXTURE_2D, PingPongBuffer[i]); glTexImage2D( GL_TEXTURE_2D, 0, @@ -73,7 +74,7 @@ Bloom::Bloom() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glFramebufferTexture2D( - GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pingpongBuffer[i], 0 + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, PingPongBuffer[i], 0 ); } Console::ConsoleSystem->RegisterConVar(Console::Variable("bloom", NativeType::Bool, &Graphics::Bloom, nullptr)); @@ -82,14 +83,14 @@ Bloom::Bloom() void Bloom::OnRendererResized() { - glDeleteFramebuffers(2, pingpongFBO); - glDeleteTextures(2, pingpongBuffer); - glGenFramebuffers(2, pingpongFBO); - glGenTextures(2, pingpongBuffer); + glDeleteFramebuffers(2, PingPongFBO); + glDeleteTextures(2, PingPongBuffer); + glGenFramebuffers(2, PingPongFBO); + glGenTextures(2, PingPongBuffer); for (unsigned int i = 0; i < 2; i++) { - glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[i]); - glBindTexture(GL_TEXTURE_2D, pingpongBuffer[i]); + glBindFramebuffer(GL_FRAMEBUFFER, PingPongFBO[i]); + glBindTexture(GL_TEXTURE_2D, PingPongBuffer[i]); glTexImage2D( GL_TEXTURE_2D, 0, @@ -106,7 +107,7 @@ void Bloom::OnRendererResized() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glFramebufferTexture2D( - GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pingpongBuffer[i], 0 + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, PingPongBuffer[i], 0 ); } } diff --git a/EngineSource/Rendering/RenderSubsystem/Bloom.h b/EngineSource/Rendering/RenderSubsystem/Bloom.h index 87396e5d..829b9ccd 100644 --- a/EngineSource/Rendering/RenderSubsystem/Bloom.h +++ b/EngineSource/Rendering/RenderSubsystem/Bloom.h @@ -12,8 +12,8 @@ class Bloom : public RenderSubsystem private: static Shader* BloomShader; - static unsigned int pingpongFBO[2]; - static unsigned int pingpongBuffer[2]; + static unsigned int PingPongFBO[2]; + static unsigned int PingPongBuffer[2]; static float BloomResolutionMultiplier; static int BloomShape; }; \ No newline at end of file diff --git a/EngineSource/Rendering/RenderSubsystem/CSM.cpp b/EngineSource/Rendering/RenderSubsystem/CSM.cpp index 2908f4a9..d0e2b5d9 100644 --- a/EngineSource/Rendering/RenderSubsystem/CSM.cpp +++ b/EngineSource/Rendering/RenderSubsystem/CSM.cpp @@ -18,7 +18,7 @@ unsigned int CSM::ShadowMaps = 0; unsigned int CSM::matricesUBO = 0; Shader* CSM::ShadowShader = nullptr; -std::vector CSM::getFrustumCornersWorldSpace(const glm::mat4& projview) +std::vector CSM::GetFrustumCornersWorldSpace(const glm::mat4& projview) { const auto inv = glm::inverse(projview); @@ -45,7 +45,7 @@ void CSM::UpdateMatricesUBO(Camera* From) { return; } - const auto LightSpaceMatrices = getLightSpaceMatrices(From); + const auto LightSpaceMatrices = GetLightSpaceMatrices(From); glBindBuffer(GL_UNIFORM_BUFFER, matricesUBO); for (size_t i = 0; i < LightSpaceMatrices.size(); ++i) @@ -68,12 +68,13 @@ void CSM::BindLightSpaceMatricesToShader(const std::vector& Matrices, } } -std::vector CSM::getFrustumCornersWorldSpace(const glm::mat4& proj, const glm::mat4& view) +std::vector CSM::GetFrustumCornersWorldSpace(const glm::mat4& proj, const glm::mat4& view) { - return getFrustumCornersWorldSpace(proj * view); + return GetFrustumCornersWorldSpace(proj * view); } CSM::CSM() + : RenderSubsystem(true) { Name = "Shadows"; ShadowShader = new Shader("Shaders/Internal/shadow.vert", "Shaders/Internal/shadow.frag", "Shaders/Internal/shadow.geom"); @@ -142,13 +143,13 @@ void CSM::ReInit() } } -glm::mat4 CSM::getLightSpaceMatrix(const float nearPlane, const float farPlane, Camera* From) +glm::mat4 CSM::GetLightSpaceMatrix(const float nearPlane, const float farPlane, Camera* From) { const auto proj = glm::perspective( From->FOV, (float)Graphics::WindowResolution.X / (float)Graphics::WindowResolution.Y, nearPlane, farPlane); - const auto corners = getFrustumCornersWorldSpace(proj, From->getView()); + const auto corners = GetFrustumCornersWorldSpace(proj, From->getView()); glm::vec3 center = glm::vec3(0, 0, 0); for (const auto& v : corners) @@ -211,22 +212,22 @@ glm::mat4 CSM::getLightSpaceMatrix(const float nearPlane, const float farPlane, return lightProjection * lightView; } -std::vector CSM::getLightSpaceMatrices(Camera* From) +std::vector CSM::GetLightSpaceMatrices(Camera* From) { std::vector ret; for (size_t i = 0; i < shadowCascadeLevels.size() + 1; ++i) { if (i == 0) { - ret.push_back(getLightSpaceMatrix(0.1f * CSMDistance, shadowCascadeLevels[i] * CSMDistance, From)); + ret.push_back(GetLightSpaceMatrix(0.1f * CSMDistance, shadowCascadeLevels[i] * CSMDistance, From)); } else if (i < shadowCascadeLevels.size()) { - ret.push_back(getLightSpaceMatrix(shadowCascadeLevels[i - 1] * CSMDistance, shadowCascadeLevels[i] * CSMDistance, From)); + ret.push_back(GetLightSpaceMatrix(shadowCascadeLevels[i - 1] * CSMDistance, shadowCascadeLevels[i] * CSMDistance, From)); } else { - ret.push_back(getLightSpaceMatrix(shadowCascadeLevels[i - 1] * CSMDistance, cameraFarPlane * CSMDistance, From)); + ret.push_back(GetLightSpaceMatrix(shadowCascadeLevels[i - 1] * CSMDistance, cameraFarPlane * CSMDistance, From)); } } return ret; diff --git a/EngineSource/Rendering/RenderSubsystem/CSM.h b/EngineSource/Rendering/RenderSubsystem/CSM.h index 3b5e0171..270333ab 100644 --- a/EngineSource/Rendering/RenderSubsystem/CSM.h +++ b/EngineSource/Rendering/RenderSubsystem/CSM.h @@ -24,17 +24,17 @@ class CSM : public RenderSubsystem static Shader* ShadowShader; - static std::vector getFrustumCornersWorldSpace(const glm::mat4& projview); + static std::vector GetFrustumCornersWorldSpace(const glm::mat4& projview); static void UpdateMatricesUBO(Camera* From); static void BindLightSpaceMatricesToShader(const std::vector& Matrices, Shader* ShaderToBind); - static std::vector getFrustumCornersWorldSpace(const glm::mat4& proj, const glm::mat4& view); + static std::vector GetFrustumCornersWorldSpace(const glm::mat4& proj, const glm::mat4& view); CSM(); static void ReInit(); - static glm::mat4 getLightSpaceMatrix(const float nearPlane, const float farPlane, Camera* From); + static glm::mat4 GetLightSpaceMatrix(const float nearPlane, const float farPlane, Camera* From); - static std::vector getLightSpaceMatrices(Camera* From); + static std::vector GetLightSpaceMatrices(Camera* From); }; #endif \ No newline at end of file diff --git a/EngineSource/Rendering/RenderSubsystem/OcclusionCulling.cpp b/EngineSource/Rendering/RenderSubsystem/OcclusionCulling.cpp index a93132a2..02ca3425 100644 --- a/EngineSource/Rendering/RenderSubsystem/OcclusionCulling.cpp +++ b/EngineSource/Rendering/RenderSubsystem/OcclusionCulling.cpp @@ -8,6 +8,7 @@ OcclusionCulling::OcclusionCulling() + : RenderSubsystem(true) { Name = "Occlude"; @@ -30,7 +31,7 @@ bool OcclusionCulling::RenderOccluded(Model* m, size_t i, FramebufferObject* Buf } if ((m->Size.extents * m->ModelTransform.Scale).Length() > 500.0f - || (!m->IsOcclusionCulled && i != Application::FrameCount % Buffer->Renderables.size()) + || (!m->IsOcclusionCulled && i != Stats::FrameCount % Buffer->Renderables.size()) || !m->ShouldCull) { m->Render(Buffer->FramebufferCamera, Buffer == Graphics::MainFramebuffer, false); diff --git a/EngineSource/Rendering/RenderSubsystem/PostProcess.cpp b/EngineSource/Rendering/RenderSubsystem/PostProcess.cpp index e379a484..ba644f31 100644 --- a/EngineSource/Rendering/RenderSubsystem/PostProcess.cpp +++ b/EngineSource/Rendering/RenderSubsystem/PostProcess.cpp @@ -12,6 +12,7 @@ #include #include #include +#include std::vector PostProcess::AllEffects; PostProcess* PostProcess::PostProcessSystem = nullptr; @@ -104,6 +105,7 @@ void PostProcess::Effect::UpdateSize() } PostProcess::PostProcess() + : RenderSubsystem(true) { Name = "PostProcess"; PostProcessSystem = this; @@ -161,7 +163,7 @@ void PostProcess::Draw() #if !SERVER bool ShouldSkip3D = false; #if EDITOR - if (!Application::WindowHasFocus()) + if (!Window::WindowHasFocus()) { ShouldSkip3D = true; } diff --git a/EngineSource/Rendering/RenderSubsystem/RenderSubsystem.cpp b/EngineSource/Rendering/RenderSubsystem/RenderSubsystem.cpp index 07997ff3..50e75b05 100644 --- a/EngineSource/Rendering/RenderSubsystem/RenderSubsystem.cpp +++ b/EngineSource/Rendering/RenderSubsystem/RenderSubsystem.cpp @@ -1,5 +1,6 @@ #if !SERVER #include "RenderSubsystem.h" +#include #include #include #include @@ -7,10 +8,58 @@ #include #include #include +#include +#include +#include -RenderSubsystem::RenderSubsystem() +static void GLAPIENTRY MessageCallback( + GLenum source, + GLenum type, + GLuint id, + GLenum severity, + GLsizei length, + const GLchar* message, + const void* userParam +) +{ + if (type == GL_DEBUG_TYPE_ERROR + || type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR + || type == GL_DEBUG_TYPE_PORTABILITY) + { + Subsystem::GetSubsystemByName("Renderer")->Print(std::string(message) + " - " + Stats::EngineStatus, Subsystem::ErrorLevel::Error); + } +} + +RenderSubsystem::RenderSubsystem(bool IsDerived) { SystemType = "Renderer"; + + if (!IsDerived) + { + glEnable(GL_DEBUG_OUTPUT); + glDebugMessageCallback(MessageCallback, 0); + Subsystem::Load(new Graphics()); + Subsystem::Load(new Bloom()); + Subsystem::Load(new CSM()); + Subsystem::Load(new OcclusionCulling()); + Subsystem::Load(new SSAO()); + Subsystem::Load(new PostProcess()); + Subsystem::Load(new BakedLighting()); + + Console::ConsoleSystem->RegisterConVar(Console::Variable("wireframe", NativeType::Bool, &Graphics::IsWireframe, nullptr)); + Console::ConsoleSystem->RegisterConVar(Console::Variable("vignette", NativeType::Float, &Graphics::Vignette, nullptr)); + Console::ConsoleSystem->RegisterConVar(Console::Variable("vsync", NativeType::Bool, &Graphics::VSync, nullptr)); + Console::ConsoleSystem->RegisterConVar(Console::Variable("timescale", NativeType::Float, &Stats::TimeMultiplier, nullptr)); + Console::ConsoleSystem->RegisterConVar(Console::Variable("resolution_scale", NativeType::Float, &Graphics::ResolutionScale, []() + { + Graphics::SetWindowResolution(Window::GetWindowSize()); + })); + } +} + +RenderSubsystem::~RenderSubsystem() +{ + glDisable(GL_DEBUG_OUTPUT); } void RenderSubsystem::OnRendererResized() @@ -28,14 +77,4 @@ void RenderSubsystem::ResizeAll() } } -void RenderSubsystem::LoadRenderSubsystems() -{ - Subsystem::Load(new Graphics()); - Subsystem::Load(new Bloom()); - Subsystem::Load(new CSM()); - Subsystem::Load(new OcclusionCulling()); - Subsystem::Load(new SSAO()); - Subsystem::Load(new PostProcess()); - Subsystem::Load(new BakedLighting()); -} #endif \ No newline at end of file diff --git a/EngineSource/Rendering/RenderSubsystem/RenderSubsystem.h b/EngineSource/Rendering/RenderSubsystem/RenderSubsystem.h index 4df1b836..c9471394 100644 --- a/EngineSource/Rendering/RenderSubsystem/RenderSubsystem.h +++ b/EngineSource/Rendering/RenderSubsystem/RenderSubsystem.h @@ -4,10 +4,10 @@ class RenderSubsystem : public Subsystem { public: - RenderSubsystem(); + RenderSubsystem(bool IsDerived = false); + ~RenderSubsystem(); + virtual void OnRendererResized(); static void ResizeAll(); - - static void LoadRenderSubsystems(); }; \ No newline at end of file diff --git a/EngineSource/Rendering/RenderSubsystem/SSAO.cpp b/EngineSource/Rendering/RenderSubsystem/SSAO.cpp index 8d9e2fb7..a9db3cf1 100644 --- a/EngineSource/Rendering/RenderSubsystem/SSAO.cpp +++ b/EngineSource/Rendering/RenderSubsystem/SSAO.cpp @@ -28,6 +28,7 @@ namespace SSAO_Impl } SSAO::SSAO() + : RenderSubsystem(true) { using namespace SSAO_Impl; std::default_random_engine ssaoRandom; diff --git a/EngineSource/Rendering/Texture/Material.cpp b/EngineSource/Rendering/Texture/Material.cpp index 56fbd900..c894508b 100644 --- a/EngineSource/Rendering/Texture/Material.cpp +++ b/EngineSource/Rendering/Texture/Material.cpp @@ -153,7 +153,7 @@ void Material::SaveMaterialFile(std::string Path, Material m) void Material::ReloadMaterial(std::string MaterialPath) { Material NewMaterial = LoadMaterialFile(MaterialPath); - for (Renderable* m : Graphics::MainFramebuffer->Renderables) + for (Drawable* m : Graphics::MainFramebuffer->Renderables) { Model* RenderableModel = dynamic_cast(m); if (RenderableModel) diff --git a/EngineSource/Rendering/Texture/Texture.cpp b/EngineSource/Rendering/Texture/Texture.cpp index d4f873a8..fe39c8c2 100644 --- a/EngineSource/Rendering/Texture/Texture.cpp +++ b/EngineSource/Rendering/Texture/Texture.cpp @@ -16,6 +16,7 @@ namespace Texture { std::vector Textures; + // Deprecated for SaveData::Field objects. TextureInfo ParseTextureInfoString(std::string TextureInfoString) { TextureInfo T; @@ -53,7 +54,7 @@ namespace Texture return TextureInfo.File + ";" + std::to_string((int)TextureInfo.Filtering) + ";" + std::to_string((int)TextureInfo.Wrap) + ";"; } - unsigned int LoadTexture(std::string File, TextureFiltering Filtering, TextureWrap Wrap) + TextureType LoadTexture(std::string File, TextureFiltering Filtering, TextureWrap Wrap) { std::string TextureInternalString = File + "_" + std::to_string((int)Filtering) + "_" + std::to_string((int)Wrap); for (Texture& t : Textures) @@ -64,76 +65,68 @@ namespace Texture return t.TextureID; } } - try + std::string TextureFile = File; + if (!std::filesystem::exists(TextureFile)) { - std::string TextureFile = File; - if (!std::filesystem::exists(TextureFile)) - { - TextureFile = Assets::GetAsset(File + ".png"); - } - - if (!std::filesystem::exists(TextureFile)) - { - return 0; - } + TextureFile = Assets::GetAsset(File + ".png"); + } - int TextureWidth = 0; - int TextureHeigth = 0; - int BitsPerPixel = 0; - stbi_set_flip_vertically_on_load(true); - auto TextureBuffer = stbi_load(TextureFile.c_str(), &TextureWidth, &TextureHeigth, &BitsPerPixel, 4); - GLuint TextureID; - glGenTextures(1, &TextureID); - glBindTexture(GL_TEXTURE_2D, TextureID); - - int FilterMode = GL_NEAREST; - int WrapMode = GL_REPEAT; - switch (Filtering) - { - case TextureFiltering::Linear: - FilterMode = GL_LINEAR; - break; - default: - break; - } - switch (Wrap) - { - case TextureWrap::Clamp: - WrapMode = GL_CLAMP_TO_EDGE; - break; - case TextureWrap::Border: - WrapMode = GL_CLAMP_TO_BORDER; - break; - default: - break; - } + if (!std::filesystem::exists(TextureFile)) + { + return 0; + } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FilterMode); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, FilterMode); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, WrapMode); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, WrapMode); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TextureWidth, TextureHeigth, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureBuffer); + int TextureWidth = 0; + int TextureHeight = 0; + int BitsPerPixel = 0; + stbi_set_flip_vertically_on_load(true); + auto TextureBuffer = stbi_load(TextureFile.c_str(), &TextureWidth, &TextureHeight, &BitsPerPixel, 4); + GLuint TextureID; + glGenTextures(1, &TextureID); + glBindTexture(GL_TEXTURE_2D, TextureID); - Textures.push_back(Texture(TextureID, 1, TextureInternalString)); - if (TextureBuffer) - { - stbi_image_free(TextureBuffer); - } - return TextureID; + int FilterMode = GL_NEAREST; + int WrapMode = GL_REPEAT; + switch (Filtering) + { + case TextureFiltering::Linear: + FilterMode = GL_LINEAR; + break; + default: + break; } - catch (std::exception& e) + switch (Wrap) { - Log::Print(std::string("Error loading Texture: ") + e.what(), Vector3(0.7f, 0.f, 0.f)); - return 0; + case TextureWrap::Clamp: + WrapMode = GL_CLAMP_TO_EDGE; + break; + case TextureWrap::Border: + WrapMode = GL_CLAMP_TO_BORDER; + break; + default: + break; + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FilterMode); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, FilterMode); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, WrapMode); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, WrapMode); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TextureWidth, TextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureBuffer); + + Textures.push_back(Texture(TextureID, 1, TextureInternalString)); + if (TextureBuffer) + { + stbi_image_free(TextureBuffer); } + return TextureID; } - unsigned int LoadTexture(TextureInfo T) + TextureType LoadTexture(TextureInfo T) { return LoadTexture(T.File, T.Filtering, T.Wrap); } - unsigned int CreateTexture(TextureData T) + TextureType CreateTexture(TextureData T) { unsigned int TextureID; glGenTextures(1, &TextureID); @@ -148,7 +141,7 @@ namespace Texture return TextureID; } - unsigned int LoadCubemapTexture(std::vector Files) + TextureType LoadCubemapTexture(std::vector Files) { std::vector IsJPEG = { false, false, false, false, false, false }; for (int i = 0; i < Files.size(); i++) @@ -171,15 +164,15 @@ namespace Texture continue; } } - unsigned int textureID; - glGenTextures(1, &textureID); - glBindTexture(GL_TEXTURE_CUBE_MAP, textureID); + TextureType TextureID; + glGenTextures(1, &TextureID); + glBindTexture(GL_TEXTURE_CUBE_MAP, TextureID); int width = 0, height = 0, nrChannels; - for (unsigned int i = 0; i < Files.size(); i++) + for (size_t i = 0; i < Files.size(); i++) { int newWidth, newHeight; - unsigned char* data = stbi_load(Files[i].c_str(), &newWidth, &newHeight, &nrChannels, 0); + uint8_t* data = stbi_load(Files[i].c_str(), &newWidth, &newHeight, &nrChannels, 0); if (width == 0) { width = newWidth; @@ -195,7 +188,7 @@ namespace Texture if (data) { int format = nrChannels == 3 ? GL_RGB : GL_RGBA; - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + GLenum(i), 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data ); stbi_image_free(data); @@ -210,10 +203,10 @@ namespace Texture glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - return textureID; + return TextureID; } - void UnloadTexture(unsigned int TextureID) + void UnloadTexture(TextureType TextureID) { for (int i = 0; i < Textures.size(); i++) { diff --git a/EngineSource/Rendering/Texture/Texture.h b/EngineSource/Rendering/Texture/Texture.h index b9769ef2..9617cd3e 100644 --- a/EngineSource/Rendering/Texture/Texture.h +++ b/EngineSource/Rendering/Texture/Texture.h @@ -3,6 +3,8 @@ namespace Texture { + typedef unsigned int TextureType; + struct Texture { unsigned int TextureID = 0; @@ -50,11 +52,11 @@ namespace Texture TextureInfo ParseTextureInfoString(std::string TextureInfoString); std::string CreateTextureInfoString(TextureInfo TextureInfo); - unsigned int LoadTexture(std::string File, TextureFiltering Filtering = TextureFiltering::Nearest, TextureWrap Wrap = TextureWrap::Clamp); - unsigned int LoadTexture(TextureInfo T); - unsigned int CreateTexture(TextureData T); + TextureType LoadTexture(std::string File, TextureFiltering Filtering = TextureFiltering::Nearest, TextureWrap Wrap = TextureWrap::Clamp); + TextureType LoadTexture(TextureInfo T); + TextureType CreateTexture(TextureData T); - unsigned int LoadCubemapTexture(std::vector Files); + TextureType LoadCubemapTexture(std::vector Files); - void UnloadTexture(unsigned int TextureID); + void UnloadTexture(TextureType TextureID); } \ No newline at end of file diff --git a/EngineSource/UI/Debug/DebugUI.cpp b/EngineSource/UI/Debug/DebugUI.cpp index f80473c2..5bde1400 100644 --- a/EngineSource/UI/Debug/DebugUI.cpp +++ b/EngineSource/UI/Debug/DebugUI.cpp @@ -157,9 +157,9 @@ void DebugUI::Tick() DebugTexts[1]->SetText("Delta: " + std::to_string(1000 / FPS) + "ms"); std::string DeltaString; - DeltaString.append(std::to_string((int)(Application::LogicTime / Stats::DeltaTime * 100.f)) + "% Log "); - DeltaString.append(std::to_string((int)(Application::RenderTime / Stats::DeltaTime * 100.f)) + "% Rend "); - DeltaString.append(std::to_string((int)(Application::SyncTime / Stats::DeltaTime * 100.f)) + "% Buf"); + DeltaString.append(std::to_string((int)(Stats::LogicTime / Stats::DeltaTime * 100.f)) + "% Log "); + DeltaString.append(std::to_string((int)(Stats::RenderTime / Stats::DeltaTime * 100.f)) + "% Rend "); + DeltaString.append(std::to_string((int)(Stats::SyncTime / Stats::DeltaTime * 100.f)) + "% Buf"); DebugTexts[2]->SetText(DeltaString); DebugTexts[3]->SetText("DrawCalls: " + std::to_string(Stats::DrawCalls)); @@ -231,7 +231,7 @@ void DebugUI::GenerateLog() { str.append(" (x" + std::to_string(LogMessages[i].Amount + 1) + ")"); } - LogBackground->AddChild((new UIText(0.5f, LogMessages[i].Color, str, Text))->SetPadding(0)); + LogBackground->AddChild(new UIText(0.5f, LogMessages[i].Color, str, Text)); } } #endif \ No newline at end of file diff --git a/EngineSource/UI/EditorUI/ContextMenu.cpp b/EngineSource/UI/EditorUI/ContextMenu.cpp index 95e17f29..2bef2b52 100644 --- a/EngineSource/UI/EditorUI/ContextMenu.cpp +++ b/EngineSource/UI/EditorUI/ContextMenu.cpp @@ -20,7 +20,6 @@ ContextMenu::ContextMenu(EditorPanel* Parent, bool IsScene) : EditorPanel(Parent { IsObject = !IsScene; BackgroundBox = new UIScrollBox(UIBox::Orientation::Vertical, 0, true); - BackgroundBox->SetPadding(0); PanelMainBackground->AddChild(BackgroundBox); } diff --git a/EngineSource/UI/EditorUI/EditorDropdown.cpp b/EngineSource/UI/EditorUI/EditorDropdown.cpp index 2c5b571e..aceb8721 100644 --- a/EngineSource/UI/EditorUI/EditorDropdown.cpp +++ b/EngineSource/UI/EditorUI/EditorDropdown.cpp @@ -19,8 +19,7 @@ EditorDropdown::EditorDropdown(std::vector Menu, Vector2 Position) Root = new UIBox(UIBox::Orientation::Vertical, Position); auto Background = new UIBackground(UIBox::Orientation::Vertical, 0, Vector3::Lerp(EditorUI::UIColors[0], EditorUI::UIColors[2], 0.5f), 0); Root->AddChild(Background - ->SetMinSize(Vector2(0.15f, 0)) - ->SetPadding(0)); + ->SetMinSize(Vector2(0.15f, 0))); for (size_t i = 0; i < Menu.size(); i++) { diff --git a/EngineSource/UI/EditorUI/EditorPanel.cpp b/EngineSource/UI/EditorUI/EditorPanel.cpp index 1ddda27b..a73c3190 100644 --- a/EngineSource/UI/EditorUI/EditorPanel.cpp +++ b/EngineSource/UI/EditorUI/EditorPanel.cpp @@ -109,10 +109,8 @@ EditorPanel::EditorPanel(EditorPanel* NewParent, std::string Name, std::string C PanelMainBackground = new UIBackground(UIBox::Orientation::Vertical, 0, EditorUI::UIColors[0], 1); TabList = new UIBackground(UIBox::Orientation::Horizontal, 0, EditorUI::UIColors[0] * 0.75, Vector2(1, 0.04f)); PanelMainBackground - ->SetPadding(0) ->SetBorder(UIBox::BorderType::DarkenedEdge, 0.15f); - PanelMainBackground->AddChild(TabList - ->SetPadding(0)); + PanelMainBackground->AddChild(TabList); PanelMainBackground->HasMouseCollision = true; TabList->HasMouseCollision = true; if (Parent) @@ -448,15 +446,13 @@ void EditorPanel::AddTabButton(bool Selected, int Index, std::string Name, bool 0, Selected ? EditorUI::UIColors[2] : EditorUI::UIColors[0] * 0.75f, Vector2(0.02f, 2.0f / Graphics::WindowResolution.Y))) - ->SetTryFill(true) - ->SetPadding(0)) + ->SetTryFill(true)) ->AddChild(HorizontalBox ->AddChild((new UIText(0.45f, EditorUI::UIColors[2], Name, EditorUI::Text)) ->SetPaddingSizeMode(UIBox::SizeMode::AspectRelative) ->SetPadding(0.005f)))); HorizontalBox ->SetMaxSize(Vector2(2, 0.04f)) - ->SetPadding(0) ->SetVerticalAlign(UIBox::Align::Centered); if (Closable) { @@ -700,7 +696,7 @@ void EditorPanel::UpdateTabs() EditorPanel::~EditorPanel() { - ClearParent(false); + ClearParent(ClearParentOnDestruct); if (Parent) { for (size_t i = 0; i < Parent->Children.size(); i++) @@ -719,6 +715,7 @@ EditorPanel::~EditorPanel() while (Children.size()) { // Children will put themselves out of the Children array. + Children[0]->ClearParentOnDestruct = false; delete Children[0]; } delete PanelMainBackground; diff --git a/EngineSource/UI/EditorUI/EditorPanel.h b/EngineSource/UI/EditorUI/EditorPanel.h index 9e385ecd..1e725c65 100644 --- a/EngineSource/UI/EditorUI/EditorPanel.h +++ b/EngineSource/UI/EditorUI/EditorPanel.h @@ -21,6 +21,7 @@ class EditorPanel : public UICanvas void AddTabButton(bool Selected, int Index, std::string Name, bool Closable); static void HandleDrag(); bool TickPanelInternal(); + bool ClearParentOnDestruct = true; public: bool UpdatePanelLayout = false; std::string ClassName; diff --git a/EngineSource/UI/EditorUI/EditorUI.cpp b/EngineSource/UI/EditorUI/EditorUI.cpp index 0df780d3..b4567a72 100644 --- a/EngineSource/UI/EditorUI/EditorUI.cpp +++ b/EngineSource/UI/EditorUI/EditorUI.cpp @@ -349,20 +349,20 @@ void EditorUI::SetUseLightMode(bool NewLightMode) { if (dynamic_cast(i)) { - dynamic_cast(i)->SetColor(Editor::ReplaceWithNewUIColor(dynamic_cast(i)->GetColor())); + static_cast(i)->SetColor(Editor::ReplaceWithNewUIColor(static_cast(i)->GetColor())); } if (dynamic_cast(i)) { - dynamic_cast(i)->SetColor(Editor::ReplaceWithNewUIColor(dynamic_cast(i)->GetColor())); + static_cast(i)->SetColor(Editor::ReplaceWithNewUIColor(static_cast(i)->GetColor())); } if (dynamic_cast(i)) { - dynamic_cast(i)->SetColor(Editor::ReplaceWithNewUIColor(dynamic_cast(i)->GetColor())); + static_cast(i)->SetColor(Editor::ReplaceWithNewUIColor(static_cast(i)->GetColor())); } if (dynamic_cast(i)) { - dynamic_cast(i)->SetColor(Editor::ReplaceWithNewUIColor(dynamic_cast(i)->GetTextColor())); - dynamic_cast(i)->SetTextColor(Editor::ReplaceWithNewUIColor(dynamic_cast(i)->GetTextColor())); + static_cast(i)->SetColor(Editor::ReplaceWithNewUIColor(static_cast(i)->GetTextColor())); + static_cast(i)->SetTextColor(Editor::ReplaceWithNewUIColor(static_cast(i)->GetTextColor())); } } std::swap(Application::EditorInstance->UIColors, Editor::NewUIColors); @@ -530,7 +530,7 @@ void EditorUI::Update() #ifdef ENGINE_CSHARP if (Editor::CanHotreload == true) { - Application::EditorInstance->Print("Finished building assembly. HotReloading .dll file.", Subsystem::ErrorLevel::Info); + Print("Finished building assembly. HotReloading .dll file.", Subsystem::ErrorLevel::Info); CSharpInterop::CSharpSystem->ReloadCSharpAssembly(); for (UICanvas* c : Graphics::UIToRender) { diff --git a/EngineSource/UI/EditorUI/ItemBrowser.cpp b/EngineSource/UI/EditorUI/ItemBrowser.cpp index bbc1f6e8..37211b58 100644 --- a/EngineSource/UI/EditorUI/ItemBrowser.cpp +++ b/EngineSource/UI/EditorUI/ItemBrowser.cpp @@ -19,8 +19,7 @@ ItemBrowser::ItemBrowser(EditorPanel* Parent, std::string Name, std::string Clas PanelMainBackground->AddChild(TopBox ->SetMinSize(Vector2(0, 0.1f)) ->SetVerticalAlign(UIBox::Align::Centered) - ->SetTryFill(true) - ->SetPadding(0)); + ->SetTryFill(true)); SeparatorLine = new UIBackground(UIBox::Orientation::Horizontal, 0, EditorUI::UIColors[0] * 0.75f, Vector2(0, 6.0f / Graphics::WindowResolution.Y)); @@ -31,8 +30,7 @@ ItemBrowser::ItemBrowser(EditorPanel* Parent, std::string Name, std::string Clas BrowserScrollBox = new UIScrollBox(UIBox::Orientation::Vertical, 0, true); BrowserScrollBox->SetMinSize(PanelMainBackground->GetMinSize() - Vector2(0.004f / Graphics::AspectRatio, TabList->GetMinSize().Y - 0.1f)); - PanelMainBackground->AddChild(BrowserScrollBox - ->SetPadding(0)); + PanelMainBackground->AddChild(BrowserScrollBox); } void ItemBrowser::OnResized() @@ -241,7 +239,7 @@ void ItemBrowser::GenerateAssetList() for (int i = 0; i < (int)LoadedItems.size() / SlotsPerRow + 1; i++) { UIBox* New = (new UIBox(UIBox::Orientation::Horizontal, 0)) - ->SetPadding(0); + ; HorizontalBoxes.push_back(New); BrowserScrollBox->AddChild(New); } @@ -276,7 +274,8 @@ void ItemBrowser::GenerateAssetList() if (LoadedItems.empty()) { HorizontalBoxes[0]->AddChild((new UIText(0.45f, EditorUI::UIColors[2], EmptyText, EditorUI::Text)) - ->SetWrapEnabled(true, Scale.X * 1.2f, UIBox::SizeMode::ScreenRelative)); + ->SetWrapEnabled(true, Scale.X * 2.0f - 0.1f, UIBox::SizeMode::ScreenRelative) + ->SetPadding(0.01f)); } } diff --git a/EngineSource/UI/EditorUI/LogUI.cpp b/EngineSource/UI/EditorUI/LogUI.cpp index 2ed46040..de50f7f8 100644 --- a/EngineSource/UI/EditorUI/LogUI.cpp +++ b/EngineSource/UI/EditorUI/LogUI.cpp @@ -34,14 +34,13 @@ LogUI::LogUI(EditorPanel* Parent) : EditorPanel(Parent, "Console", "log") LogScrollBox = new UIScrollBox(UIBox::Orientation::Vertical, 0, true); LogPrompt = new UITextField(0, EditorUI::UIColors[1] * 0.5f, this, 0, EditorUI::MonoText); LogPrompt->HintText = "Console"; - PanelMainBackground->AddChild((new UIBackground(UIBox::Orientation::Vertical, 0, EditorUI::UIColors[1] * 0.99f, 0)) + PanelMainBackground->AddChild((new UIBackground(UIBox::Orientation::Vertical, 0, EditorUI::UIColors[1], 0)) ->SetPadding(0.02f) ->AddChild(LogScrollBox ->SetScrollSpeed(4) ->SetPadding(0, 0, 0.01f, 0)) ->AddChild(LogPrompt ->SetTextSize(0.45f) - ->SetPadding(0) ->SetTryFill(true))); AutoComplete = new Debug::ConsoleAutoComplete(EditorUI::MonoText, 0.425f); @@ -49,11 +48,9 @@ LogUI::LogUI(EditorPanel* Parent) : EditorPanel(Parent, "Console", "log") CommandsBackground = new UIBackground(UIBox::Orientation::Vertical, 0, 0, Vector2(1, 0)); CommandHighlightScrollBox = new UIScrollBox(UIBox::Orientation::Vertical, 0, true); CommandHighlightScrollBox - ->SetTryFill(true) - ->SetPadding(0); + ->SetTryFill(true); CommandsBackground ->SetOpacity(0.95f) - ->SetPadding(0) ->AddChild(CommandHighlightScrollBox); UpdateLogBoxSize(); diff --git a/EngineSource/UI/EditorUI/Popups/AboutWindow.cpp b/EngineSource/UI/EditorUI/Popups/AboutWindow.cpp index c25bf6da..a897555b 100644 --- a/EngineSource/UI/EditorUI/Popups/AboutWindow.cpp +++ b/EngineSource/UI/EditorUI/Popups/AboutWindow.cpp @@ -31,7 +31,6 @@ AboutWindow::AboutWindow() : EditorPopup(0, Vector2(0.5f, 0.6f), "About") ContentBox = new UIBox(UIBox::Orientation::Vertical, 0); ContentBox - ->SetPadding(0) ->SetMinSize(0.3f); PopupBackground->AddChild(ContentBox); @@ -42,13 +41,11 @@ AboutWindow::AboutWindow() : EditorPopup(0, Vector2(0.5f, 0.6f), "About") #endif ContentBox->AddChild((new UIBox(UIBox::Orientation::Horizontal, 0)) - ->SetPadding(0) ->AddChild((new UIBackground(UIBox::Orientation::Horizontal, 0, 1, 0.1f)) ->SetUseTexture(true, EditorUI::Textures[15]) ->SetPadding(0.01f) ->SetSizeMode(UIBox::SizeMode::AspectRelative)) - ->AddChild((new UIBox(UIBox::Orientation::Vertical, 0)) - ->SetPadding(0) + ->AddChild((new UIBox(UIBox::Orientation::Vertical, 0)) ->AddChild((new UIText(0.5f, EditorUI::UIColors[2], "Klemmgine Editor v" + std::string(VERSION_STRING), EditorUI::Text)) ->SetPadding(0.005f)) ->AddChild((new UIText(0.4f, EditorUI::UIColors[2], " For " + OsString, EditorUI::Text)) @@ -72,8 +69,7 @@ AboutWindow::AboutWindow() : EditorPopup(0, Vector2(0.5f, 0.6f), "About") )); UIScrollBox* CreditsBox = new UIScrollBox(UIBox::Orientation::Vertical, 0, true); - ContentBox->AddChild(CreditsBox - ->SetPadding(0)); + ContentBox->AddChild(CreditsBox); int ButtonIndex = 1; @@ -83,8 +79,7 @@ AboutWindow::AboutWindow() : EditorPopup(0, Vector2(0.5f, 0.6f), "About") ->SetPadding(i.second.empty() ? 0.02f : 0.005f, 0.005f, i.second.empty() ? 0.005f : 0.02f, 0.005f)); UIBox* ButtonsBox = new UIBox(UIBox::Orientation::Horizontal, 0); - CreditsBox->AddChild(ButtonsBox - ->SetPadding(0)); + CreditsBox->AddChild(ButtonsBox); for (auto& entry : i.second) { @@ -97,8 +92,7 @@ AboutWindow::AboutWindow() : EditorPopup(0, Vector2(0.5f, 0.6f), "About") if (i.second.empty()) { - ButtonsBox->AddChild((new UIBackground(UIBox::Orientation::Horizontal, 0, EditorUI::UIColors[2], Vector2(0.5f, 0.003f))) - ->SetPadding(0)); + ButtonsBox->AddChild((new UIBackground(UIBox::Orientation::Horizontal, 0, EditorUI::UIColors[2], Vector2(0.5f, 0.003f)))); } } CreditsBox->SetMinSize(Vector2(0.5f, 0.365f)); diff --git a/EngineSource/UI/EditorUI/Popups/BakeMenu.cpp b/EngineSource/UI/EditorUI/Popups/BakeMenu.cpp index c0f77fee..e13b31f9 100644 --- a/EngineSource/UI/EditorUI/Popups/BakeMenu.cpp +++ b/EngineSource/UI/EditorUI/Popups/BakeMenu.cpp @@ -136,7 +136,6 @@ void BakeMenu::StartBake() LogScrollBox = new UIScrollBox(UIBox::Orientation::Vertical, 0, true); LogScrollBox->SetMinSize(Vector2(0.45f, 0.35f)); LogScrollBox->SetMaxSize(Vector2(0.45f, 0.35f)); - LogScrollBox->SetPadding(0); PopupBackground->AddChild((new UIBackground(UIBox::Orientation::Horizontal, 0, EditorUI::UIColors[1], 0)) ->SetPadding(0.01f, 0.01f, 0.02f, 0.01f) diff --git a/EngineSource/UI/EditorUI/Popups/ClassCreator.cpp b/EngineSource/UI/EditorUI/Popups/ClassCreator.cpp index 0e37d029..6494b0ee 100644 --- a/EngineSource/UI/EditorUI/Popups/ClassCreator.cpp +++ b/EngineSource/UI/EditorUI/Popups/ClassCreator.cpp @@ -36,7 +36,6 @@ ClassCreator::ClassCreator() : EditorPopup(0, 0.3f, "Create class") ->SetPadding(0.02f)); PopupBackground->AddChild((new UIBox(UIBox::Orientation::Horizontal, 0)) - ->SetPadding(0) ->AddChild((new UIText(0.4f, EditorUI::UIColors[2], "Path: ", EditorUI::Text)) ->SetTextWidthOverride(0.06f) ->SetPadding(0.01f, 0.01f, 0.02f, 0)) @@ -47,7 +46,6 @@ ClassCreator::ClassCreator() : EditorPopup(0, 0.3f, "Create class") ->SetMinSize(Vector2(0.15f, 0.01f)))); PopupBackground->AddChild((new UIBox(UIBox::Orientation::Horizontal, 0)) - ->SetPadding(0) ->AddChild((new UIText(0.4f, EditorUI::UIColors[2], "Name: ", EditorUI::Text)) ->SetTextWidthOverride(0.06f) ->SetPadding(0.01f, 0.01f, 0.02f, 0)) diff --git a/EngineSource/UI/EditorUI/Popups/ColorPicker.cpp b/EngineSource/UI/EditorUI/Popups/ColorPicker.cpp index 93026670..772f6826 100644 --- a/EngineSource/UI/EditorUI/Popups/ColorPicker.cpp +++ b/EngineSource/UI/EditorUI/Popups/ColorPicker.cpp @@ -132,9 +132,7 @@ ColorPicker::ColorPicker(UIVectorField* Color) ColorPickerBackgrounds[2]->SetPadding(0.01f, 0.01f, 0.01f, 0.01f); RGBBox = new UIBox(UIBox::Orientation::Vertical, 0); - RGBBox->SetPadding(0); auto PreviewBox = new UIBox(UIBox::Orientation::Vertical, 0); - PreviewBox->SetPadding(0); PreviewBox->AddChild(RGBBox); PreviewBox->AddChild(ColorPickerBackgrounds[2]); PickerBackground->AddChild(ColorPickerBackgrounds[0]); @@ -248,7 +246,7 @@ void ColorPicker::GenerateRGBDisplay() ->SetBorder(UIBox::BorderType::Rounded, 0.5f); RGBTexts[i]->SetText(EditorUI::ToShortString(SelectedColor[(int)i])); RGBBox->AddChild((new UIBox(UIBox::Orientation::Horizontal, 0)) - ->SetPadding(0) + ->AddChild((new UIText(0.4f, EditorUI::UIColors[2], xyz[i], EditorUI::Text)) ->SetPadding(0.015f, 0.015f, 0.01f, 0.005f)) ->AddChild(RGBTexts[i] diff --git a/EngineSource/UI/EditorUI/Popups/EditorPopup.cpp b/EngineSource/UI/EditorUI/Popups/EditorPopup.cpp index 5b966491..8817fd01 100644 --- a/EngineSource/UI/EditorUI/Popups/EditorPopup.cpp +++ b/EngineSource/UI/EditorUI/Popups/EditorPopup.cpp @@ -54,16 +54,13 @@ EditorPopup::EditorPopup(Vector2 Position, Vector2 Scale, std::string Name) RootBox ->AddChild(TitleBackground ->SetVerticalAlign(UIBox::Align::Centered) - ->SetPadding(0) ->AddChild((new UIText(0.5f, EditorUI::UIColors[2], Name, EditorUI::Text)) ->SetPadding(0, 0, 0.01f, 0.01f))) ->AddChild(PopupBackground ->SetBorder(UIBox::BorderType::DarkenedEdge, 0.2f) - ->SetMinSize(Scale - Vector2(0, 0.1f)) - ->SetPadding(0)) + ->SetMinSize(Scale - Vector2(0, 0.1f))) ->AddChild(OptionsList - ->SetHorizontalAlign(UIBox::Align::Reverse) - ->SetPadding(0)); + ->SetHorizontalAlign(UIBox::Align::Reverse)); RootBox->HasMouseCollision = true; TitleBackground->HasMouseCollision = true; diff --git a/EngineSource/UI/EditorUI/Popups/RenameBox.cpp b/EngineSource/UI/EditorUI/Popups/RenameBox.cpp index 82faf388..78e03391 100644 --- a/EngineSource/UI/EditorUI/Popups/RenameBox.cpp +++ b/EngineSource/UI/EditorUI/Popups/RenameBox.cpp @@ -20,7 +20,6 @@ RenameBox::RenameBox(std::string FileToRename) PopupBackground->AddChild((new UIText(0.4f, EditorUI::UIColors[2], "From: " + FileUtil::GetFileNameFromPath(FileToRename), EditorUI::Text)) ->SetPadding(0.02f)); PopupBackground->AddChild((new UIBox(UIBox::Orientation::Horizontal, 0)) - ->SetPadding(0) ->AddChild((new UIText(0.4f, EditorUI::UIColors[2], "To: ", EditorUI::Text)) ->SetPadding(0.01f, 0.01f, 0.02f, 0)) ->AddChild(InputField diff --git a/EngineSource/UI/EditorUI/SerializePanel.cpp b/EngineSource/UI/EditorUI/SerializePanel.cpp index 1458ce7f..dbcaea40 100644 --- a/EngineSource/UI/EditorUI/SerializePanel.cpp +++ b/EngineSource/UI/EditorUI/SerializePanel.cpp @@ -11,10 +11,13 @@ #include #include #include +#include std::string Editor::SerializePanel::GetLayoutPrefFilePath() { - return Application::GetEditorPath() + "/EditorContent/Config/EditorLayout"; + std::string EditorPath = Application::GetEditorPath(); + StrUtil::ReplaceChar(EditorPath, '\\', "/"); + return EditorPath + "/EditorContent/Config/EditorLayout"; } SaveData::Field Editor::SerializePanel::SerializeLayout(EditorPanel* Target) diff --git a/EngineSource/UI/EditorUI/SettingsPanel.cpp b/EngineSource/UI/EditorUI/SettingsPanel.cpp index c243c7cd..e9d6cf31 100644 --- a/EngineSource/UI/EditorUI/SettingsPanel.cpp +++ b/EngineSource/UI/EditorUI/SettingsPanel.cpp @@ -244,8 +244,7 @@ SettingsPanel::SettingsPanel(EditorPanel* Parent) : EditorPanel(Parent, "Setting { CanBeClosed = true; HorizontalBox = new UIBox(UIBox::Orientation::Horizontal, 0); - PanelMainBackground->AddChild(HorizontalBox - ->SetPadding(0)); + PanelMainBackground->AddChild(HorizontalBox); GenerateUI(); Load(); diff --git a/EngineSource/UI/EditorUI/SettingsPanel.h b/EngineSource/UI/EditorUI/SettingsPanel.h index ed26b4d4..de04eda7 100644 --- a/EngineSource/UI/EditorUI/SettingsPanel.h +++ b/EngineSource/UI/EditorUI/SettingsPanel.h @@ -7,6 +7,7 @@ #include #include #include +#include /** * @brief @@ -76,7 +77,7 @@ class SettingsPanel : public EditorPanel { if (Stats::Time == 0) { - Application::SetFullScreen(std::stoi(NewValue)); + Window::SetFullScreen(std::stoi(NewValue)); } }), } diff --git a/EngineSource/UI/EditorUI/StatusBar.cpp b/EngineSource/UI/EditorUI/StatusBar.cpp index 32e9153e..fcf59916 100644 --- a/EngineSource/UI/EditorUI/StatusBar.cpp +++ b/EngineSource/UI/EditorUI/StatusBar.cpp @@ -121,10 +121,8 @@ StatusBar::StatusBar() BarBoxes[1] = new UIBox(UIBox::Orientation::Horizontal, 0); StatusBackground = new UIBackground(UIBox::Orientation::Horizontal, Vector2(-1, 0.95f), 1, Vector2(2, 0.05f)); StatusBackground->AddChild(BarBoxes[0] - ->SetPadding(0) ->SetMinSize(Vector2(1, 0))); StatusBackground->AddChild(BarBoxes[1] - ->SetPadding(0) ->SetHorizontalAlign(UIBox::Align::Reverse) ->SetMinSize(Vector2(1, 0))); @@ -174,8 +172,7 @@ void StatusBar::GenerateMenuBarDropdown(int ButtonIndex) MenuBarDropdown->SetMinSize(Vector2(0.0f, 0.5f)); MenuBarButtons[ButtonIndex]->SetColor(EditorUI::UIColors[0] * 1.5f); auto Background = new UIBackground(UIBox::Orientation::Vertical, 0, Vector3::Lerp(EditorUI::UIColors[0], EditorUI::UIColors[2], 0.5f), 0); - MenuBarDropdown->AddChild(Background - ->SetPadding(0)); + MenuBarDropdown->AddChild(Background); int it = 0; for (auto& i : MenuBarItems[ButtonIndex].Entries) { diff --git a/EngineSource/UI/EditorUI/Tabs/CubemapTab.cpp b/EngineSource/UI/EditorUI/Tabs/CubemapTab.cpp index ac2c6561..1adafbb0 100644 --- a/EngineSource/UI/EditorUI/Tabs/CubemapTab.cpp +++ b/EngineSource/UI/EditorUI/Tabs/CubemapTab.cpp @@ -109,7 +109,6 @@ void CubemapTab::Generate() UITextField* text = new UITextField(0, 0.2f, this, 0, Renderer); text->SetText(SaveFile->GetField(Cubenames[i]).Value); text->SetMinSize(Vector2(0.2f, 0.05f)); - text->SetPadding(0); text->SetBorder(UIBox::BorderType::Rounded, 0.5f); SideFields.push_back(text); CubemapSidesBox->AddChild((new UIBox(false, 0)) diff --git a/EngineSource/UI/EditorUI/Tabs/MaterialTab.cpp b/EngineSource/UI/EditorUI/Tabs/MaterialTab.cpp index 9c1c7db4..7b456986 100644 --- a/EngineSource/UI/EditorUI/Tabs/MaterialTab.cpp +++ b/EngineSource/UI/EditorUI/Tabs/MaterialTab.cpp @@ -95,15 +95,12 @@ void MaterialTab::OnButtonClicked(int Index) MaterialTab::MaterialTab(EditorPanel* Parent, std::string File) : EditorTab(Parent, "Material", File) { auto RowBox = new UIBox(UIBox::Orientation::Horizontal, 0); - PanelMainBackground->AddChild(RowBox - ->SetPadding(0)); + PanelMainBackground->AddChild(RowBox); Rows[0] = new UIScrollBox(UIBox::Orientation::Vertical, 0, true); - RowBox->AddChild(Rows[0] - ->SetPadding(0)); + RowBox->AddChild(Rows[0]); Rows[1] = new UIBackground(UIBox::Orientation::Vertical, 0, EditorUI::UIColors[0] * 0.75f); - RowBox->AddChild(Rows[1] - ->SetPadding(0)); + RowBox->AddChild(Rows[1]); if (!PreviewBuffer) @@ -330,22 +327,15 @@ void MaterialTab::GenerateUI() ->SetPadding(0, 0.02f, 0, 0) }; - ParamBox->AddChild((new UIBox(UIBox::Orientation::Vertical, 0)) - ->SetPadding(0) - ->AddChild((new UIBox(UIBox::Orientation::Horizontal, 0)) - ->SetPadding(0) + ParamBox->AddChild((new UIBox(UIBox::Orientation::Vertical, 0)) + ->AddChild((new UIBox(UIBox::Orientation::Horizontal, 0)) ->AddChild(NewField)) ->AddChild((new UIBox(UIBox::Orientation::Horizontal, 0)) - ->SetPadding(0) ->AddChild((new UIBox(UIBox::Orientation::Vertical, 0)) - ->SetPadding(0) - ->AddChild((new UIText(0.35f, EditorUI::UIColors[2] * 0.75f, "Filtering:", EditorUI::Text)) - ->SetPadding(0)) + ->AddChild(new UIText(0.35f, EditorUI::UIColors[2] * 0.75f, "Filtering:", EditorUI::Text)) ->AddChild(TextureSelectionBoxes[0])) ->AddChild((new UIBox(UIBox::Orientation::Vertical, 0)) - ->SetPadding(0) - ->AddChild((new UIText(0.35f, EditorUI::UIColors[2] * 0.75f, "Wrap:", EditorUI::Text)) - ->SetPadding(0)) + ->AddChild(new UIText(0.35f, EditorUI::UIColors[2] * 0.75f, "Wrap:", EditorUI::Text)) ->AddChild(TextureSelectionBoxes[1])))); TextBox->SetMinSize(Vector2(DescriptionSize, 0.15f)); @@ -389,7 +379,7 @@ void MaterialTab::GenerateMaterialProperties() PreviewWindow = new UIBackground(UIBox::Orientation::Vertical, 0, 1, 0.25f); auto ScrollBox = new UIScrollBox(UIBox::Orientation::Vertical, 0, true); Rows[1]->AddChild(ScrollBox - ->SetPadding(0) + ->SetMaxSize(Rows[1]->GetMinSize()) ->SetMinSize(Rows[1]->GetMinSize())); @@ -436,7 +426,7 @@ void MaterialTab::GenerateMaterialProperties() ->SetPadding(0.01f, 0.00, 0.02f, 0.02f) ->AddChild((new UIText(0.5f, EditorUI::UIColors[2], i.first, EditorUI::Text)) ->SetTextWidthOverride(0.15f) - ->SetPadding(0)) + ) ->AddChild(NewField)); } } diff --git a/EngineSource/UI/EditorUI/Tabs/MeshTab.cpp b/EngineSource/UI/EditorUI/Tabs/MeshTab.cpp index 388a1398..0db02fbe 100644 --- a/EngineSource/UI/EditorUI/Tabs/MeshTab.cpp +++ b/EngineSource/UI/EditorUI/Tabs/MeshTab.cpp @@ -41,24 +41,19 @@ MeshTab::MeshTab(EditorPanel* Parent, std::string File) : EditorTab(Parent, "Mod } auto RowBox = new UIBox(UIBox::Orientation::Horizontal, 0); RowBox->SetVerticalAlign(UIBox::Align::Default); - PanelMainBackground->AddChild(RowBox - ->SetPadding(0)); + PanelMainBackground->AddChild(RowBox); PreviewWindow = new UIBackground(UIBox::Orientation::Horizontal, 0, 1, 0.5f); Rows[0] = new UIScrollBox(UIBox::Orientation::Vertical, 0, true); RowBox->AddChild((new UIBackground(UIBox::Orientation::Horizontal, 0, EditorUI::UIColors[0] * 0.75)) - ->SetPadding(0) - ->AddChild(Rows[0] - ->SetPadding(0))); + ->AddChild(Rows[0])); Rows[0]->AddChild(PreviewWindow); PreviewWindow->SetBorder(UIBox::BorderType::Rounded, 1); Rows[1] = new UIScrollBox(UIBox::Orientation::Vertical, 0, true); RowBox->AddChild((new UIBox(UIBox::Orientation::Vertical, 0)) - ->SetPadding(0) - ->AddChild(Rows[1] - ->SetPadding(0))); + ->AddChild(Rows[1])); } void MeshTab::Tick() @@ -182,8 +177,7 @@ void MeshTab::Generate() ->SetVerticalAlign(UIBox::Align::Centered) ->AddChild((new UIText(0.5f, EditorUI::UIColors[2], "Material " + std::to_string(MaterialIndex++) + ": ", EditorUI::Text)) ->SetPadding(0, 0, 0, 0)) - ->AddChild(NewTextInput - ->SetPadding(0))); + ->AddChild(NewTextInput)); MaterialTextFields.push_back(NewTextInput); } } diff --git a/EngineSource/UI/EditorUI/Tabs/ParticleEditorTab.cpp b/EngineSource/UI/EditorUI/Tabs/ParticleEditorTab.cpp index d97cacdd..90ccfc15 100644 --- a/EngineSource/UI/EditorUI/Tabs/ParticleEditorTab.cpp +++ b/EngineSource/UI/EditorUI/Tabs/ParticleEditorTab.cpp @@ -118,11 +118,8 @@ ParticleEditorTab::ParticleEditorTab(EditorPanel* Parent, std::string File) : Ed PreviewBackground = new UIBackground(UIBox::Orientation::Horizontal, 0, 1, 0.275f); PanelMainBackground->AddChild((new UIBox(UIBox::Orientation::Horizontal, 0)) - ->SetPadding(0) - ->AddChild(ChildBox - ->SetPadding(0)) - ->AddChild(SideBar - ->SetPadding(0) + ->AddChild(ChildBox) + ->AddChild(SideBar ->AddChild(PreviewBackground ->SetPadding(0.02f, 0, 0, 0)) ->AddChild((new UIButton(UIBox::Orientation::Horizontal, 0, EditorUI::UIColors[2], this, -1)) @@ -219,13 +216,11 @@ void ParticleEditorTab::Generate() { UIBackground* ElementBackground = new UIBackground(UIBackground::Orientation::Vertical, 0, EditorUI::UIColors[0] * 0.75); ElementBackground->AddChild((new UIBox(UIBox::Orientation::Horizontal, 0)) - ->SetPadding(0) ->AddChild((new UIText(0.5f, EditorUI::UIColors[2], "Element " + std::to_string(it) + ":", EditorUI::Text)) ->SetTextWidthOverride(std::min(0.25f, Scale.X - 0.1f)) ->SetPadding(0.01f, 0, 0.01f, 0)) ->AddChild((new UIButton(UIBox::Orientation::Horizontal, 0, EditorUI::UIColors[2], this, it * 100 + 99)) ->SetUseTexture(true, EditorUI::Textures[4]) - ->SetPadding(0) ->SetSizeMode(UIBox::SizeMode::AspectRelative) ->SetMinSize(0.04f))); diff --git a/EngineSource/UI/EditorUI/Toolbar.cpp b/EngineSource/UI/EditorUI/Toolbar.cpp index 9b61432d..681f142d 100644 --- a/EngineSource/UI/EditorUI/Toolbar.cpp +++ b/EngineSource/UI/EditorUI/Toolbar.cpp @@ -137,8 +137,7 @@ Toolbar::Toolbar(EditorPanel* Parent) : EditorPanel(Parent, "Toolbar", "toolbar" ButtonsBox = new UIBox(UIBox::Orientation::Horizontal, 0); PanelMainBackground->AddChild(ButtonsBox - ->SetVerticalAlign(UIBox::Align::Centered) - ->SetPadding(0)); + ->SetVerticalAlign(UIBox::Align::Centered)); GenerateButtons(); } diff --git a/EngineSource/UI/EditorUI/UIVectorField.cpp b/EngineSource/UI/EditorUI/UIVectorField.cpp index f40bd1c6..010b36ca 100644 --- a/EngineSource/UI/EditorUI/UIVectorField.cpp +++ b/EngineSource/UI/EditorUI/UIVectorField.cpp @@ -114,14 +114,13 @@ void UIVectorField::Generate() }; DeleteChildren(); FieldBox = new UIBox(UIBox::Orientation::Horizontal, 0); - FieldBox->SetPadding(0); AddChild(FieldBox); float ElementSize = Size / 3.0f - 0.015f; for (int i = 0; i < 3; i++) { auto NewItemColor = new UIBackground(UIBox::Orientation::Vertical, 0, Colors[i], 0); NewItemColor - ->SetPadding(0) + ->SetVerticalAlign(UIBox::Align::Centered) ->SetHorizontalAlign(UIBox::Align::Centered) ->SetMinSize(Vector2(0.015f, 0.04f)) @@ -132,7 +131,6 @@ void UIVectorField::Generate() FieldBox->AddChild(NewItemColor); NewItemColor->AddChild(ItemName); NewTextField->HintText = DimensionStrings[(int)NativeType][i]; - NewTextField->SetPadding(0); NewTextField->SetTextColor(EditorUI::UIColors[2]); NewTextField->SetMinSize(Vector2(ElementSize, 0.04f)); NewTextField->SetMaxSize(Vector2(ElementSize, 0.04f)); @@ -152,13 +150,12 @@ void UIVectorField::Generate() ->SetHorizontalAlign(UIBox::Align::Centered) ->SetVerticalAlign(UIBox::Align::Centered); ColorText = new UIText(0.35f, std::max(Value.Length(), 0.0f) < 0.2f ? 1.0f : 0.0f, "Color picker", Renderer); - ColorDisplay->AddChild(ColorText->SetPadding(0)); + ColorDisplay->AddChild(ColorText); AddChild(ColorDisplay); ColorDisplay ->SetMinSize(Vector2(Size, 0.03f)) ->SetBorder(BorderType::Rounded, 0.25f) - ->SetTryFill(true) - ->SetPadding(0); + ->SetTryFill(true); } } diff --git a/EngineSource/UI/EditorUI/Viewport.cpp b/EngineSource/UI/EditorUI/Viewport.cpp index 3c4aad02..231d618f 100644 --- a/EngineSource/UI/EditorUI/Viewport.cpp +++ b/EngineSource/UI/EditorUI/Viewport.cpp @@ -23,6 +23,7 @@ #include "ContextMenu.h" #include #include +#include Viewport* Viewport::ViewportInstance = nullptr; @@ -160,7 +161,7 @@ void Viewport::ClearSelectedObjects() void Viewport::OnItemDropped(DroppedItem Item) { - Vector2 RelativeMouseLocation = Application::GetCursorPosition() - (Position + (Scale * 0.5)); + Vector2 RelativeMouseLocation = Window::GetCursorPosition() - (Position + (Scale * 0.5)); Vector3 Direction = Graphics::MainCamera->ForwardVectorFromScreenPosition(RelativeMouseLocation.X, RelativeMouseLocation.Y); Vector3 Point = (Direction * 100.0f) + Graphics::MainCamera->Position; @@ -325,7 +326,7 @@ void Viewport::Tick() SetName(EditorUI::ChangedScene ? "Viewport*" : "Viewport"); - Vector2 RelativeMouseLocation = Application::GetCursorPosition() - (Position + (Scale * 0.5)); + Vector2 RelativeMouseLocation = Window::GetCursorPosition() - (Position + (Scale * 0.5)); Vector3 Rotation = Graphics::MainCamera->ForwardVectorFromScreenPosition(RelativeMouseLocation.X, RelativeMouseLocation.Y); if (UI::HoveredBox == PanelMainBackground && !Dragging) @@ -357,7 +358,7 @@ void Viewport::Tick() } if (ViewportLock && !Input::IsRMBDown) { - Application::SetCursorPosition(InitialMousePosition); + Window::SetCursorPosition(InitialMousePosition); ViewportLock = false; } if (Input::IsLMBDown && !PressedLMB) diff --git a/EngineSource/UI/UIBackground.cpp b/EngineSource/UI/UIBackground.cpp index 897d30d1..120cfbd3 100644 --- a/EngineSource/UI/UIBackground.cpp +++ b/EngineSource/UI/UIBackground.cpp @@ -100,7 +100,7 @@ void UIBackground::SetInvertTextureCoordinates(bool Invert) MakeGLBuffers(Invert); } -UIBackground* UIBackground::SetUseTexture(bool UseTexture, unsigned int TextureID) +UIBackground* UIBackground::SetUseTexture(bool UseTexture, Texture::TextureType TextureID) { if (this->TextureMode != (UseTexture ? 1 : 0) || TextureID != this->TextureID) { diff --git a/EngineSource/UI/UIBackground.h b/EngineSource/UI/UIBackground.h index f8efca47..e34569d1 100644 --- a/EngineSource/UI/UIBackground.h +++ b/EngineSource/UI/UIBackground.h @@ -2,6 +2,7 @@ #pragma once #include #include +#include struct Shader; @@ -20,7 +21,7 @@ class UIBackground : public UIBox void MakeGLBuffers(bool InvertTextureCoordinates = false); // 0 = none, 1 = texture, 2 texture that should be unloaded with the box uint8_t TextureMode = 0; - unsigned int TextureID = 0; + Texture::TextureType TextureID = 0; protected: Shader* BackgroundShader = nullptr; Vector3 Color; @@ -35,7 +36,7 @@ class UIBackground : public UIBox Vector3 GetColor() const; bool GetUseTexture() const; void SetInvertTextureCoordinates(bool Invert); - UIBackground* SetUseTexture(bool UseTexture, unsigned int TextureID = 0); + UIBackground* SetUseTexture(bool UseTexture, Texture::TextureType TextureID = 0); UIBackground* SetUseTexture(bool UseTexture, std::string TextureName); UIBackground(Orientation BoxOrientation, Vector2 Position, Vector3 Color, Vector2 MinScale = Vector2(0), Shader* UsedShader = Graphics::UIShader); virtual ~UIBackground(); diff --git a/EngineSource/UI/UIDropdown.cpp b/EngineSource/UI/UIDropdown.cpp index ae62e5b0..3d441bb8 100644 --- a/EngineSource/UI/UIDropdown.cpp +++ b/EngineSource/UI/UIDropdown.cpp @@ -73,7 +73,6 @@ void UIDropdown::GenerateOptions() for (size_t i = 0; i < Options.size(); i++) { UIButton* NewButton = new UIButton(UIBox::Orientation::Horizontal, 0, Vector3::Lerp(DropdownColor, Color, (i == SelectedIndex) ? 0.5f : 0), nullptr, (int)i); - NewButton->SetPadding(0); NewButton->SetMinSize(Vector2(Size, 0)); NewButton->ParentOverride = this; NewButton->CurrentScrollObject = this->CurrentScrollObject; diff --git a/EngineSource/UI/UIScrollBox.cpp b/EngineSource/UI/UIScrollBox.cpp index d34ac429..caa7bd64 100644 --- a/EngineSource/UI/UIScrollBox.cpp +++ b/EngineSource/UI/UIScrollBox.cpp @@ -71,7 +71,6 @@ UIScrollBox* UIScrollBox::SetDisplayScrollBar(bool NewDisplay) #endif ScrollBarBackground->AddChild(ScrollBar); ScrollBar->SetBorder(UIBox::BorderType::Rounded, 0.25); - ScrollBar->SetPadding(0); } else if (ScrollBar) {