initial commit
This commit is contained in:
55
src/application/application.cpp
Executable file
55
src/application/application.cpp
Executable file
@@ -0,0 +1,55 @@
|
||||
#include "application.hpp"
|
||||
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace VE
|
||||
{
|
||||
application::application(std::string app_name) : m_glfw{ std::make_unique<glfw>() }
|
||||
{
|
||||
m_glfw->init(app_name);
|
||||
m_glfw->set_event_fn(VE_EVENT_FN);
|
||||
|
||||
m_gui = std::make_unique<gui>(m_glfw);
|
||||
}
|
||||
|
||||
void application::run()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glClearColor(0.07f, 0.13f, 0.17f, 1.0f);
|
||||
glViewport(0, 0, m_glfw->width(), m_glfw->height());
|
||||
|
||||
while(!glfwWindowShouldClose(m_glfw->get_win()))
|
||||
{
|
||||
m_glfw->clear();
|
||||
|
||||
m_gui->begin_frame();
|
||||
for (auto l : m_layers_stack) l->render();
|
||||
m_gui->end_frame();
|
||||
|
||||
m_glfw->update();
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<glfw>& application::get_glfw()
|
||||
{
|
||||
return m_glfw;
|
||||
}
|
||||
|
||||
void application::attach_layers()
|
||||
{
|
||||
for (auto l : m_layers_stack) l->on_attach();
|
||||
}
|
||||
|
||||
void application::set_event_fn()
|
||||
{
|
||||
for (const auto l : m_layers_stack) l->set_event_fn(VE_EVENT_FN);
|
||||
}
|
||||
|
||||
void application::on_event(event& e)
|
||||
{
|
||||
if (e.is_parallele)
|
||||
for (auto l : m_layers_stack) auto future = std::async(std::launch::async, [&]() { l->on_event(e); });
|
||||
else
|
||||
for (auto l : m_layers_stack) l->on_event(e);
|
||||
}
|
||||
}
|
||||
42
src/application/application.hpp
Executable file
42
src/application/application.hpp
Executable file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "glfw/glfw.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
#include "layer/layer.hpp"
|
||||
|
||||
namespace VE
|
||||
{
|
||||
class application
|
||||
{
|
||||
public:
|
||||
application(std::string app_name);
|
||||
virtual ~application() = default;
|
||||
|
||||
private:
|
||||
std::unique_ptr<glfw> m_glfw;
|
||||
std::unique_ptr<gui> m_gui;
|
||||
layers_stack<layer> m_layers_stack;
|
||||
|
||||
public:
|
||||
void run();
|
||||
std::unique_ptr<glfw>& get_glfw();
|
||||
|
||||
public:
|
||||
template<typename... Args>
|
||||
void push_layer(Args*... args)
|
||||
{
|
||||
(m_layers_stack.push_back(args), ...);
|
||||
attach_layers();
|
||||
set_event_fn();
|
||||
}
|
||||
|
||||
private:
|
||||
void clear();
|
||||
void attach_layers();
|
||||
void set_event_fn();
|
||||
void on_event(event& e);
|
||||
};
|
||||
|
||||
// реализация см. в проекте
|
||||
application& create();
|
||||
}
|
||||
Reference in New Issue
Block a user