change update and init function signatures

main
Brett 2024-04-29 21:42:50 -04:00
parent 16a0fbc7dc
commit 3af6b9c4a0
4 changed files with 71 additions and 50 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
set(BLT_GRAPHICS_VERSION 0.11.4) set(BLT_GRAPHICS_VERSION 0.11.5)
set(BLT_GRAPHICS_TEST_VERSION 0.0.1) set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})

View File

@ -25,7 +25,7 @@ blt::gfx::resource_manager resources;
blt::gfx::batch_renderer_2d renderer_2d(resources); blt::gfx::batch_renderer_2d renderer_2d(resources);
blt::gfx::first_person_camera camera; blt::gfx::first_person_camera camera;
void init(const blt::gfx::window_context& context) void init(const blt::gfx::window_data&)
{ {
using namespace blt::gfx; using namespace blt::gfx;
@ -35,9 +35,9 @@ void init(const blt::gfx::window_context& context)
renderer_2d.create(); renderer_2d.create();
} }
void update(const blt::gfx::window_context& context, std::int32_t width, std::int32_t height) void update(const blt::gfx::window_data& data)
{ {
global_matrices.update_perspectives(width, height, 90, 0.1, 2000); global_matrices.update_perspectives(data.width, data.height, 90, 0.1, 2000);
camera.update(); camera.update();
camera.update_view(global_matrices); camera.update_view(global_matrices);

View File

@ -28,50 +28,63 @@ namespace blt::gfx
struct window_data struct window_data
{ {
std::string title; private:
std::int32_t width; std::function<void(const window_data&)> init;
std::int32_t height; std::function<void(const window_data&)> update;
std::function<void(const window_context&)> init; public:
std::function<void(const window_context&, std::int32_t, std::int32_t)> update; std::string title;
std::int32_t width;
std::int32_t height;
window_context context{}; window_context context{};
std::int32_t sync_interval = 0; std::int32_t sync_interval = 0;
window_data(std::string title, std::function<void(const window_context&)> init, window_data(std::string title, std::function<void(const window_data&)> init, std::function<void(const window_data&)> update,
std::function<void(const window_context&, std::int32_t, std::int32_t)> update, std::int32_t width = 640, std::int32_t width = 640, std::int32_t height = 480):
std::int32_t height = 480): title(std::move(title)), width(width), height(height), init(std::move(init)), update(std::move(update))
title(std::move(title)), width(width), height(height), init(std::move(init)), update(std::move(update)) {}
{}
window_data& setHeight(int32_t new_height) inline void call_init() const
{ {
window_data::height = new_height; init(*this);
return *this; }
}
window_data& setWidth(int32_t new_width) inline void call_update() const
{ {
window_data::width = new_width; update(*this);
return *this; }
}
window_data& setTitle(const std::string& title_str) window_data& setWindowSize(int32_t new_width, int32_t new_height);
{
window_data::title = title_str;
return *this;
}
window_data& setContext(const window_context& ctx) window_data& setHeight(int32_t new_height)
{ {
context = ctx; setWindowSize(width, new_height);
return *this; return *this;
} }
window_data& setSyncInterval(std::int32_t sync) window_data& setWidth(int32_t new_width)
{ {
sync_interval = sync; setWindowSize(new_width, height);
return *this; return *this;
} }
window_data& setTitle(const std::string& title_str)
{
window_data::title = title_str;
return *this;
}
window_data& setContext(const window_context& ctx)
{
context = ctx;
return *this;
}
window_data& setSyncInterval(std::int32_t sync)
{
sync_interval = sync;
return *this;
}
}; };
void init(window_data data); void init(window_data data);

View File

@ -164,7 +164,7 @@ namespace blt::gfx
ImGui::NewFrame(); ImGui::NewFrame();
/* -- Call user update function -- */ /* -- Call user update function -- */
data.update(data.context, window_state.width, window_state.height); data.call_update();
/* -- Render the ImGUI frame -- */ /* -- Render the ImGUI frame -- */
ImGui::Render(); ImGui::Render();
@ -249,7 +249,7 @@ namespace blt::gfx
#endif #endif
/* -- Call User Provided post-window-init function -- */ /* -- Call User Provided post-window-init function -- */
data.init(data.context); data.call_init();
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
/* /*
@ -389,4 +389,12 @@ namespace blt::gfx
{ {
return window_state.inputManager.key_pressed; return window_state.inputManager.key_pressed;
} }
window_data& window_data::setWindowSize(int32_t new_width, int32_t new_height)
{
width = new_width;
height = new_height;
glfwSetWindowSize(window_state.window, width, height);
return *this;
}
} }