🎉 begin project
This commit is contained in:
commit
8da6ddc689
29 changed files with 1261 additions and 0 deletions
5
Source/Core/CMakeLists.txt
Normal file
5
Source/Core/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
add_module_sources(
|
||||
VUI.cppm
|
||||
Window.cppm
|
||||
WindowManager.cppm
|
||||
)
|
||||
36
Source/Core/VUI.cppm
Normal file
36
Source/Core/VUI.cppm
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
module;
|
||||
#include <cstdint>
|
||||
|
||||
export module VUI:Time;
|
||||
|
||||
import :TimeInternal;
|
||||
|
||||
static uint64_t s_TimerOffset{0};
|
||||
static double s_LastTime{0};
|
||||
static double s_DeltaTime{0};
|
||||
|
||||
namespace VUI {
|
||||
export double GetDeltaTime() { return s_DeltaTime; };
|
||||
export double GetTime() {
|
||||
return static_cast<double>(GetTimerValue() - s_TimerOffset) /
|
||||
static_cast<double>(GetTimerFrequency());
|
||||
};
|
||||
export uint64_t GetTimeNs() {
|
||||
return static_cast<uint64_t>(
|
||||
static_cast<double>(GetTimerValue() - s_TimerOffset) * 1e9 /
|
||||
static_cast<double>(GetTimerFrequency()));
|
||||
}
|
||||
export void SetTime(const uint64_t time) {
|
||||
const auto dTimerValue = static_cast<double>(GetTimerValue());
|
||||
const auto dTime = static_cast<double>(time);
|
||||
const auto dFrequency = static_cast<double>(GetTimerFrequency());
|
||||
s_TimerOffset = static_cast<uint64_t>(dTimerValue - dTime * dFrequency);
|
||||
};
|
||||
export uint64_t GetTimeOffset() { return s_TimerOffset; }
|
||||
|
||||
export void UpdateDeltaTime() {
|
||||
const auto time = GetTime();
|
||||
s_DeltaTime = time - s_LastTime;
|
||||
s_LastTime = time;
|
||||
};
|
||||
} // namespace VUI
|
||||
54
Source/Core/Window.cppm
Normal file
54
Source/Core/Window.cppm
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
module;
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "../PlatformDetection.h"
|
||||
|
||||
export module VUI:Window;
|
||||
|
||||
import :Ref;
|
||||
import :Geometry;
|
||||
import :Input;
|
||||
|
||||
namespace VUI {
|
||||
struct WindowManager;
|
||||
std::uint64_t s_Handle = 0;
|
||||
|
||||
export struct WindowSpecification {
|
||||
uint32_t width{1280};
|
||||
uint32_t height{720};
|
||||
std::string title{"vui"};
|
||||
};
|
||||
|
||||
export struct Window : RefCounted {
|
||||
virtual void pullEvents() = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
virtual void resize(uint32_t width, uint32_t height) = 0;
|
||||
virtual void updateTitle(const std::string &title) = 0;
|
||||
|
||||
bool isOpen() const { return m_IsOpen; }
|
||||
[[nodiscard]] uint32_t getWidth() const { return m_Specification.width; }
|
||||
[[nodiscard]] uint32_t getHeight() const { return m_Specification.height; }
|
||||
[[nodiscard]] std::string getTitle() const { return m_Specification.title; }
|
||||
[[nodiscard]] uint64_t getHandle() const { return m_WindowHandle; }
|
||||
|
||||
protected:
|
||||
static void UpdateKey(uint32_t key, bool isDown);
|
||||
virtual void createWindow() = 0;
|
||||
bool m_IsOpen{false};
|
||||
std::uint64_t m_WindowHandle{0};
|
||||
WindowSpecification m_Specification{};
|
||||
|
||||
UPoint m_WindowPosition{};
|
||||
|
||||
Window() = default;
|
||||
friend Ref;
|
||||
friend WindowManager;
|
||||
};
|
||||
|
||||
void Window::UpdateKey(const uint32_t key, const bool isDown) {
|
||||
Input::UpdateKey(key, isDown);
|
||||
}
|
||||
} // namespace VUI
|
||||
91
Source/Core/WindowManager.cppm
Normal file
91
Source/Core/WindowManager.cppm
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
module;
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
export module VUI:WindowManager;
|
||||
|
||||
import :Window;
|
||||
import :PlatformWindow;
|
||||
import :Time;
|
||||
|
||||
namespace VUI {
|
||||
|
||||
export struct WindowManager {
|
||||
static Ref<Window> Create(uint32_t width, uint32_t height,
|
||||
const std::string &title);
|
||||
static Ref<Window> Create(const WindowSpecification &);
|
||||
static void Manage(const Ref<Window> &window);
|
||||
|
||||
static void Update();
|
||||
static void Close(Ref<Window> &);
|
||||
static void CloseByTitle(const std::string &title);
|
||||
static void CloseAll();
|
||||
static bool HasOpenWindows();
|
||||
|
||||
protected:
|
||||
std::vector<Ref<Window>> m_Windows{};
|
||||
friend Window;
|
||||
};
|
||||
|
||||
static WindowManager s_WindowManager = {};
|
||||
|
||||
Ref<Window> WindowManager::Create(uint32_t width, uint32_t height,
|
||||
const std::string &title) {
|
||||
return Create(WindowSpecification{width, height, title});
|
||||
}
|
||||
|
||||
Ref<Window> WindowManager::Create(const WindowSpecification &specification) {
|
||||
if (GetTimeOffset() == 0)
|
||||
SetTime(0);
|
||||
|
||||
auto window = Windowing::CreateWindowRef();
|
||||
window->m_Specification = specification;
|
||||
window->m_WindowHandle = s_Handle++;
|
||||
window->createWindow();
|
||||
Manage(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
void WindowManager::Manage(const Ref<Window> &window) {
|
||||
s_WindowManager.m_Windows.push_back(window);
|
||||
}
|
||||
|
||||
void WindowManager::Update() {
|
||||
Input::PostFrameUpdate();
|
||||
UpdateDeltaTime();
|
||||
for (auto &window : s_WindowManager.m_Windows) {
|
||||
window->pullEvents();
|
||||
}
|
||||
std::erase_if(s_WindowManager.m_Windows,
|
||||
[](Ref<Window> &window) { return !window->isOpen(); });
|
||||
}
|
||||
|
||||
void WindowManager::Close(Ref<Window> &refWindow) {
|
||||
if (!refWindow)
|
||||
return;
|
||||
refWindow->close();
|
||||
std::erase_if(s_WindowManager.m_Windows, [&refWindow](auto &window) {
|
||||
return !window->isOpen() || window == refWindow;
|
||||
});
|
||||
}
|
||||
void WindowManager::CloseByTitle(const std::string &title) {
|
||||
std::erase_if(s_WindowManager.m_Windows, [&title](Ref<Window> &window) {
|
||||
if (window->getTitle() == title) {
|
||||
window->close();
|
||||
}
|
||||
return !window->isOpen();
|
||||
});
|
||||
}
|
||||
void WindowManager::CloseAll() {
|
||||
for (auto &window : s_WindowManager.m_Windows) {
|
||||
window->close();
|
||||
}
|
||||
s_WindowManager.m_Windows.clear();
|
||||
}
|
||||
bool WindowManager::HasOpenWindows() {
|
||||
return !s_WindowManager.m_Windows.empty();
|
||||
}
|
||||
|
||||
} // namespace VUI
|
||||
Loading…
Add table
Add a link
Reference in a new issue