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)
set(BLT_GRAPHICS_VERSION 0.11.4)
set(BLT_GRAPHICS_VERSION 0.11.5)
set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
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::first_person_camera camera;
void init(const blt::gfx::window_context& context)
void init(const blt::gfx::window_data&)
{
using namespace blt::gfx;
@ -35,9 +35,9 @@ void init(const blt::gfx::window_context& context)
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_view(global_matrices);

View File

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

View File

@ -164,7 +164,7 @@ namespace blt::gfx
ImGui::NewFrame();
/* -- Call user update function -- */
data.update(data.context, window_state.width, window_state.height);
data.call_update();
/* -- Render the ImGUI frame -- */
ImGui::Render();
@ -249,7 +249,7 @@ namespace blt::gfx
#endif
/* -- Call User Provided post-window-init function -- */
data.init(data.context);
data.call_init();
#ifdef __EMSCRIPTEN__
/*
@ -389,4 +389,12 @@ namespace blt::gfx
{
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;
}
}