Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
if ! git diff --name-only -z --diff-filter=AM $BASE $HEAD \
| grep -zE '\.(cpp|hpp|c|h)$' \
| grep -zEv 'External/' \
| xargs -0 -r clang-format --dry-run --Werror; then
| xargs -0 -r clang-format-19 --dry-run --Werror; then
echo ""
echo "❌ Formatting issues detected"
exit 1
Expand Down
18 changes: 12 additions & 6 deletions Source/Core/Engine/Engine.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "stdafx.h"

#include "Engine.h"

#include "Util/jsonUtil.h"
#include "Window/Window.h"
#include "frameData.h"
#include "Util/jsonUtil.h"

#include <nlohmann/json.hpp>

namespace {
constexpr std::string_view gConfigFilePath = "../engineConfig.json";
constexpr std::string_view gConfigFilePath = "../engineConfig.json";
}

RF::Engine::Engine(const RF::EngineCreationParams& params) {
Expand All @@ -23,11 +24,16 @@ RF::Engine::Engine(const RF::EngineCreationParams& params) {
mWindow->Init(windowParams);
}

void RF::Engine::Update(const FrameData& frameData) { frameData; }
void RF::Engine::Update(const FrameData& frameData) {
frameData;
}

void RF::Engine::Render(const FrameData& frameData) { frameData; }
void RF::Engine::Render(const FrameData& frameData) {
frameData;
}

void RF::Engine::Shutdown() {}
void RF::Engine::Shutdown() {
}

void RF::Engine::OnResize(const unsigned int width, const unsigned int height) {
mWindow->SetSize(width, height);
Expand Down
51 changes: 26 additions & 25 deletions Source/Core/Engine/Engine.h
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
#pragma once

namespace RF {
struct FrameData;
struct WindowCreationParams;
class Window;
struct FrameData;
struct WindowCreationParams;
class Window;

struct EngineCreationParams {
WNDPROC windowProc = nullptr;
int cmdShow = 0;
HINSTANCE hInstance = nullptr;
};
struct EngineCreationParams {
WNDPROC windowProc = nullptr;
int cmdShow = 0;
HINSTANCE hInstance = nullptr;
};

class Engine {
public:
Engine() = delete;
Engine(const EngineCreationParams& params);
~Engine() = default;
Engine(const Engine&) = delete;
void operator=(const Engine&) = delete;
class Engine {
public:
Engine() = delete;
Engine(const EngineCreationParams& params);
~Engine() = default;
Engine(const Engine&) = delete;
void operator=(const Engine&) = delete;

void Update(const FrameData& frameData);
void Render(const FrameData& frameData);
void Update(const FrameData& frameData);
void Render(const FrameData& frameData);

void Shutdown();
void Shutdown();

void OnResize(const unsigned int width, const unsigned int height);
void OnResize(const unsigned int width, const unsigned int height);

private:
void LoadConfigFile(RF::WindowCreationParams& windowParams);
private:
void LoadConfigFile(RF::WindowCreationParams& windowParams);

std::unique_ptr<Window> mWindow;
std::unique_ptr<Window> mWindow;

std::wstring mAssetsPath;
};
}
std::wstring mAssetsPath;
};
} // namespace RF
38 changes: 17 additions & 21 deletions Source/Core/Engine/Window/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "stdafx.h"

#include "Window.h"

void RF::Window::Init(const WindowCreationParams& params) {
Expand All @@ -9,47 +10,40 @@ void RF::Window::Init(const WindowCreationParams& params) {
mAspectRatio = static_cast<float>(params.width) / static_cast<float>(params.height);

// Initialize the window class
WNDCLASSEX windowClass = { 0 };
WNDCLASSEX windowClass = {0};
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = params.windowProc;
windowClass.hInstance = params.hInstance;
windowClass.hCursor = LoadCursor(nullptr, IDC_ARROW);
windowClass.lpszClassName = mWindowTitle.c_str();
windowClass.hbrBackground = reinterpret_cast<HBRUSH>((COLOR_WINDOW + 2));
//windowClass.hIcon = icon; // TODO in the future
// windowClass.hIcon = icon; // TODO in the future

RegisterClassEx(&windowClass);

RECT windowRect = { 0, 0, static_cast<LONG>(mWidth), static_cast<LONG>(mHeight) };
RECT windowRect = {0, 0, static_cast<LONG>(mWidth), static_cast<LONG>(mHeight)};
AdjustWindowRect(&windowRect, WS_OVERLAPPEDWINDOW, FALSE);

// Create the window
mHWND = CreateWindow(
windowClass.lpszClassName,
mWindowTitle.c_str(),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top,
nullptr, // No parent window
nullptr, // No menus (Maybe for editor in future)
params.hInstance,
params.engine);
mHWND = CreateWindow(windowClass.lpszClassName, mWindowTitle.c_str(), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top,
nullptr, // No parent window
nullptr, // No menus (Maybe for editor in future)
params.hInstance, params.engine);

ShowWindow(mHWND, params.cmdShow);
}

void RF::Window::SetSize(const unsigned int width, const unsigned int height) {
mWidth = width;
mWidth = width;
mHeight = height;

// TODO: Resize event
// TODO: Resize event
}

void RF::Window::SetTitle(const std::wstring& title) {
mWindowTitle = title;
mWindowTitle = title;

ApplyWindowText();
}
Expand All @@ -65,11 +59,13 @@ const std::wstring RF::Window::Title() const {
}

HWND RF::Window::GetHWND() const {
return mHWND;
return mHWND;
}

void RF::Window::SetFullScreen(const bool isFullScreen) { isFullScreen; }
void RF::Window::SetFullScreen(const bool isFullScreen) {
isFullScreen;
}

void RF::Window::ApplyWindowText() {
SetWindowText(mHWND, Title().c_str());
SetWindowText(mHWND, Title().c_str());
}
88 changes: 45 additions & 43 deletions Source/Core/Engine/Window/Window.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
#pragma once

namespace RF {
class Engine;

struct WindowCreationParams {
unsigned int width = 1920;
unsigned int height = 1080;
std::wstring title = L"RuneForge";
bool isFullScreen = false;
bool isResizable = true;

HINSTANCE hInstance = nullptr;
int cmdShow = 0;
RF::Engine* engine = nullptr;
WNDPROC windowProc = nullptr;
};

class Window {
public:
Window() = default;
Window(const Window&) = delete;
void operator=(const Window&) = delete;

void Init(const WindowCreationParams& params);
void SetSize(const unsigned int width, const unsigned int height); // TODO - Vector2ui
//const RF::V2ui Size() const; // TODO - Vector2ui

void SetTitle(const std::wstring& title);
void SetCustomText(const std::wstring& text);
const std::wstring Title() const;

HWND GetHWND() const;

void SetFullScreen(const bool isFullScreen);
private:
void ApplyWindowText();

std::wstring mWindowTitle = {};
std::wstring mCustomText = {};
unsigned int mWidth = {};
unsigned int mHeight = {};
float mAspectRatio = {};
HWND mHWND = {};
};
}
class Engine;

struct WindowCreationParams {
unsigned int width = 1920;
unsigned int height = 1080;
std::wstring title = L"RuneForge";
bool isFullScreen = false;
bool isResizable = true;

HINSTANCE hInstance = nullptr;
int cmdShow = 0;
RF::Engine* engine = nullptr;
WNDPROC windowProc = nullptr;
};

class Window {
public:
Window() = default;
Window(const Window&) = delete;
void operator=(const Window&) = delete;

void Init(const WindowCreationParams& params);
void SetSize(const unsigned int width, const unsigned int height); // TODO - Vector2ui
// const RF::V2ui Size() const; // TODO - Vector2ui

void SetTitle(const std::wstring& title);
void SetCustomText(const std::wstring& text);
const std::wstring Title() const;

HWND GetHWND() const;

void SetFullScreen(const bool isFullScreen);

private:
void ApplyWindowText();

std::wstring mWindowTitle = {};
std::wstring mCustomText = {};
unsigned int mWidth = {};
unsigned int mHeight = {};
float mAspectRatio = {};
HWND mHWND = {};
};
} // namespace RF
11 changes: 6 additions & 5 deletions Source/Core/Engine/frameData.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

namespace RF {
struct FrameData {
float deltaTime = 0.0f;
float totalTime = 0.0f;
};
}
struct FrameData {
float deltaTime = 0.0f;
float totalTime = 0.0f;
};
} // namespace RF
73 changes: 48 additions & 25 deletions Source/Core/Math/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,55 @@
#include <cmath>

#ifndef PI
#define PI 3.14159265358979323846f
#define PI 3.14159265358979323846f
#endif

namespace math {

static inline constexpr float TWO_PI = 2.0f * PI;
static inline constexpr float HALF_PI = 0.5f * PI;

static inline constexpr float Deg2Rad(float deg) noexcept { return deg * (PI / 180.0f); }
static inline constexpr float Rad2Deg(float rad) noexcept { return rad * (180.0f / PI); }

template<typename T> static inline constexpr T Square(const T &x) noexcept { return x * x; }
template<typename T> static inline constexpr T Cube(const T &x) noexcept { return x * x * x; }

template<typename T> static inline constexpr const T &Min(const T &a, const T &b) noexcept { return (a < b) ? a : b; }
template<typename T> static inline constexpr const T &Max(const T &a, const T &b) noexcept { return (a > b) ? a : b; }
template<typename T> static inline constexpr const T &Clamp(const T &x, const T &lo, const T &hi) noexcept { return (x < lo) ? lo : (x > hi ? hi : x); }

static inline float WrapDeg(float d) noexcept {
float result = std::fmod(d, 360.0f);
return (result < 0.0f) ? result + 360.0f : result;
}

static inline float WrapRad(float r) noexcept {
float result = std::fmod(r, TWO_PI);
return (result < 0.0f) ? result + TWO_PI : result;
}

}
static inline constexpr float TWO_PI = 2.0f * PI;
static inline constexpr float HALF_PI = 0.5f * PI;

static inline constexpr float Deg2Rad(float deg) noexcept {
return deg * (PI / 180.0f);
}

static inline constexpr float Rad2Deg(float rad) noexcept {
return rad * (180.0f / PI);
}

template <typename T>
static inline constexpr T Square(const T& x) noexcept {
return x * x;
}

template <typename T>
static inline constexpr T Cube(const T& x) noexcept {
return x * x * x;
}

template <typename T>
static inline constexpr const T& Min(const T& a, const T& b) noexcept {
return (a < b) ? a : b;
}

template <typename T>
static inline constexpr const T& Max(const T& a, const T& b) noexcept {
return (a > b) ? a : b;
}

template <typename T>
static inline constexpr const T& Clamp(const T& x, const T& lo, const T& hi) noexcept {
return (x < lo) ? lo : (x > hi ? hi : x);
}

static inline float WrapDeg(float d) noexcept {
float result = std::fmod(d, 360.0f);
return (result < 0.0f) ? result + 360.0f : result;
}

static inline float WrapRad(float r) noexcept {
float result = std::fmod(r, TWO_PI);
return (result < 0.0f) ? result + TWO_PI : result;
}

} // namespace math
Loading