initial commit
All checks were successful
Build (Arch Linux) / build (push) Successful in 3m10s

This commit is contained in:
2025-04-16 01:58:29 +01:00
commit a8d8b9b9ab
116 changed files with 106633 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
#pragma once
#include <cstdint>
#include <memory>
#include <string>
namespace kuiper
{
class engine;
struct application_spec {
std::u8string name = u8"Kuiper Engine Application";
std::uint32_t width = 640;
std::uint32_t height = 480;
bool fullscreen = false;
};
class application {
public:
application(const application_spec& app_spec = application_spec())
: m_app_spec(app_spec) {};
virtual ~application() = default;
public:
virtual void initialise(kuiper::engine* engine) = 0;
virtual void shutdown() = 0;
virtual void pre_render(float dt) = 0;
virtual void render(float dt) = 0;
virtual void post_render(float dt) = 0;
inline const application_spec& get_app_spec() {
return m_app_spec;
}
private:
application_spec m_app_spec = application_spec();
};
/// This function must be implement by the user,
/// defining & creating the application which will be run by the Kuiper engine.
/// Consider this function your application's entrypoint, you can perform initialisation that must
/// occur before your application starts here.
/// NOTE: This function is expected to return a *unique* pointer to the application, to be owned by the engine.
/// Don't store a copy of this pointer to use later as there are no guarantees to whether the pointer is valid.
std::unique_ptr<application> create_application(int argc, char* argv[]);
} // namespace kuiper

82
include/core/engine.hpp Normal file
View File

@@ -0,0 +1,82 @@
#pragma once
#include "cli/cli.hpp"
#include "components/camera.hpp"
#include "core/application.hpp"
#include "graphics/opengl/framebuffer.hpp"
#include "platform/glfw/glfw_window.hpp"
#include "renderer/gl_renderer.hpp"
#include "resources/resource_manager.hpp"
#include <flecs.h>
#include <expected>
#include <memory>
#include <system_error>
#include <vector>
namespace kuiper
{
struct engine_metrics {
float rendering_time = 0.0f;
gl::renderer_metrics renderer_metrics {};
};
class engine {
public:
engine(std::unique_ptr<application>&& app);
~engine();
engine(const engine& other) = delete;
engine& operator=(const engine& other) = delete;
engine(engine&& other) noexcept = delete;
engine& operator=(engine&& other) noexcept = delete;
/// Initialise core engine subsystems
static std::expected<void, std::error_code> initialise(const cli& cli_args) noexcept;
void start();
public:
std::shared_ptr<glfw_window> window() noexcept {
return m_window;
}
engine_metrics metrics() const noexcept {
return m_metrics;
}
flecs::world& world() noexcept {
return m_world;
}
resource_manager& resources() noexcept {
return m_resources;
}
void add_render_target(const gl::framebuffer::s_ptr& target) noexcept;
void remove_render_target(const gl::framebuffer::s_ptr& target) noexcept;
/// Only draw to render targets added with `add_render_target()`
void disable_default_framebuffer() noexcept;
/// Draw to default framebuffer as well as any additional render targets
void enable_default_framebuffer() noexcept;
void set_render_camera(const glm::vec3& pos, const component::camera_props& cam_props) noexcept;
private:
std::unique_ptr<application> m_application {nullptr};
std::shared_ptr<glfw_window> m_window {nullptr};
engine_metrics m_metrics {};
std::vector<gl::framebuffer::s_ptr> m_render_targets {};
bool m_render_to_default {true};
glm::vec3 m_cam_pos {};
component::camera_props m_cam_props {};
resource_manager m_resources {};
flecs::world m_world {};
};
// Some assumptions that I make
static_assert(sizeof(char8_t) == sizeof(char));
} // namespace kuiper

View File

@@ -0,0 +1,15 @@
#pragma once
#if defined(_WIN32)
// TODO: Windows entrypoint
#else
/// Standard C entrypoint
int main(int argc, char** argv);
#endif
namespace kuiper
{
/// Actual entrypoint, as far as the engine is concerned.
/// Once we reach the real entrypoint, `WinMain` should've converted any UTF-16 wchar strings into UTF-8 C-style strings
int entrypoint(int argc, char** argv);
} // namespace kuiper

21
include/core/io.hpp Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <filesystem>
#include <span>
#include <string>
#include <vector>
namespace kuiper
{
class io {
public:
static std::string read_text_file(const std::filesystem::path& path) noexcept;
static std::filesystem::path get_home_dir() noexcept;
};
} // namespace kuiper