Skip to content

Commit

Permalink
v1.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Klemmbaustein committed Jul 12, 2024
1 parent 1324b83 commit 777e59d
Show file tree
Hide file tree
Showing 72 changed files with 757 additions and 653 deletions.
17 changes: 17 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions EngineSource/Engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="CSharp\CSharpUICanvas.cpp" />
<ClCompile Include="Engine\AppWindow.cpp" />
<ClCompile Include="Engine\Subsystem\BackgroundTask.cpp" />
<ClCompile Include="Engine\Gamepad.cpp" />
<ClCompile Include="Engine\Subsystem\InputSubsystem.cpp" />
Expand All @@ -34,6 +35,8 @@
<ClCompile Include="Objects\Components\PhysicsComponent.cpp" />
<ClCompile Include="Rendering\RenderSubsystem\OcclusionCulling.cpp" />
<ClCompile Include="Rendering\RenderSubsystem\RenderSubsystem.cpp" />
<ClInclude Include="Engine\AppWindow.h" />
<ClInclude Include="Engine\LaunchArgs.h" />
<ClInclude Include="Rendering\RenderSubsystem\RenderSubsystem.h" />
<ClCompile Include="UI\Debug\ConsoleAutoComplete.cpp" />
<ClCompile Include="UI\EditorUI\AssetBrowser.cpp" />
Expand Down Expand Up @@ -98,7 +101,7 @@
<ClCompile Include="Rendering\Mesh\Model.cpp" />
<ClCompile Include="Rendering\Mesh\ModelGenerator.cpp" />
<ClCompile Include="Rendering\Particle.cpp" />
<ClCompile Include="Rendering\Renderable.cpp" />
<ClCompile Include="Rendering\Drawable.cpp" />
<ClCompile Include="Rendering\Shader.cpp" />
<ClCompile Include="Rendering\Texture\Cubemap.cpp" />
<ClCompile Include="Rendering\Texture\Material.cpp" />
Expand Down Expand Up @@ -229,7 +232,7 @@
<ClInclude Include="Rendering\Mesh\Model.h" />
<ClInclude Include="Rendering\Mesh\ModelGenerator.h" />
<ClInclude Include="Rendering\Particle.h" />
<ClInclude Include="Rendering\Renderable.h" />
<ClInclude Include="Rendering\Drawable.h" />
<ClInclude Include="Rendering\Shader.h" />
<ClInclude Include="Rendering\Texture\Cubemap.h" />
<ClInclude Include="Rendering\Texture\Material.h" />
Expand Down
174 changes: 174 additions & 0 deletions EngineSource/Engine/AppWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#if !SERVER
#include "AppWindow.h"
#include <SDL.h>
#include "Subsystem/CSharpInterop.h"
#include "EngineProperties.h"
#include "Stats.h"
#include <Rendering/Graphics.h>
#include <iostream>
#include <GL/glew.h>
#include <Engine/EngineError.h>

// 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
80 changes: 80 additions & 0 deletions EngineSource/Engine/AppWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#if !SERVER
#pragma once
#include <string>
#include <Math/Vector.h>

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
Loading

0 comments on commit 777e59d

Please sign in to comment.