feat: exposed more internal state to defs.h
This commit is contained in:
parent
e880ded96f
commit
438d633a78
14
src/defs.h
14
src/defs.h
|
|
@ -1,10 +1,13 @@
|
||||||
#ifndef LLCS_DEFS_H
|
#ifndef LLCS_DEFS_H
|
||||||
#define LLCS_DEFS_H
|
#define LLCS_DEFS_H
|
||||||
|
|
||||||
#include <optional>
|
#include "SFML/Graphics/View.hpp"
|
||||||
#include <SFML/System/String.hpp>
|
|
||||||
#include <SFML/Window/VideoMode.hpp>
|
|
||||||
#include <SFML/Graphics/RenderStates.hpp>
|
#include <SFML/Graphics/RenderStates.hpp>
|
||||||
|
#include <SFML/Graphics/RenderWindow.hpp>
|
||||||
|
#include <SFML/System/String.hpp>
|
||||||
|
#include <SFML/System/Time.hpp>
|
||||||
|
#include <SFML/Window/VideoMode.hpp>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
struct AppConfig {
|
struct AppConfig {
|
||||||
sf::String window_title{ "UNNAMED WINDOW" };
|
sf::String window_title{ "UNNAMED WINDOW" };
|
||||||
|
|
@ -14,4 +17,9 @@ struct AppConfig {
|
||||||
std::optional<int> frame_rate_limit{std::nullopt};
|
std::optional<int> frame_rate_limit{std::nullopt};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern AppConfig const &get_application_configuration();
|
||||||
|
extern sf::Time const &get_delta_time();
|
||||||
|
extern sf::RenderWindow const &get_window();
|
||||||
|
extern void set_render_view(sf::View const &view);
|
||||||
|
|
||||||
#endif // !LLCS_DEFS_H
|
#endif // !LLCS_DEFS_H
|
||||||
|
|
|
||||||
54
src/main.cpp
54
src/main.cpp
|
|
@ -5,7 +5,8 @@
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
static sf::RenderWindow window{};
|
static sf::RenderWindow window{};
|
||||||
static sf::Clock deltaClock{};
|
static sf::Clock delta_clock{};
|
||||||
|
static sf::Time delta_time{};
|
||||||
static AppConfig cfg{};
|
static AppConfig cfg{};
|
||||||
static sf::View view{};
|
static sf::View view{};
|
||||||
|
|
||||||
|
|
@ -26,16 +27,35 @@ void initialize_imgui() {
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void handle_input_event(sf::Event const &evt);
|
||||||
|
extern void handle_window_event(sf::Event const &evt);
|
||||||
|
|
||||||
void poll_events() {
|
void poll_events() {
|
||||||
while (std::optional const event{ window.pollEvent() })
|
while (std::optional const event{ window.pollEvent() })
|
||||||
{
|
{
|
||||||
ImGui::SFML::ProcessEvent(window, *event);
|
ImGui::SFML::ProcessEvent(window, *event);
|
||||||
// "close requested" event: we close the window
|
|
||||||
if (event->is<sf::Event::Closed>()) {
|
if (event->is<sf::Event::Closed>()) {
|
||||||
window.close();
|
window.close();
|
||||||
} else if (sf::Event::Resized const *resized{ event->getIf<sf::Event::Resized>()}) {
|
} else if (event->is<sf::Event::JoystickButtonPressed>() || event->is<sf::Event::JoystickButtonReleased>()) {
|
||||||
view.setSize({ static_cast<float>(resized->size.x), static_cast<float>(resized->size.y) });
|
handle_input_event(*event);
|
||||||
window.setView(view);
|
} else if (event->is<sf::Event::JoystickMoved>()) {
|
||||||
|
handle_input_event(*event);
|
||||||
|
} else if (event->is<sf::Event::JoystickConnected>() || event->is<sf::Event::JoystickDisconnected>()) {
|
||||||
|
handle_input_event(*event);
|
||||||
|
} else if (event->is<sf::Event::KeyPressed>() || event->is<sf::Event::KeyReleased>()) {
|
||||||
|
handle_input_event(*event);
|
||||||
|
} else if (event->is<sf::Event::TouchBegan>() || event->is<sf::Event::TouchEnded>()) {
|
||||||
|
handle_input_event(*event);
|
||||||
|
} else if (event->is<sf::Event::TouchMoved>()) {
|
||||||
|
handle_input_event(*event);
|
||||||
|
} else if (event->is<sf::Event::MouseButtonPressed>() || event->is<sf::Event::MouseButtonReleased>()) {
|
||||||
|
handle_input_event(*event);
|
||||||
|
} else if (event->is<sf::Event::MouseMoved>() || event->is<sf::Event::MouseMovedRaw>()) {
|
||||||
|
handle_input_event(*event);
|
||||||
|
} else if (event->is<sf::Event::FocusGained>() || event->is<sf::Event::FocusLost>()) {
|
||||||
|
handle_window_event(*event);
|
||||||
|
} else if (event->is<sf::Event::Resized>()) {
|
||||||
|
handle_window_event(*event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -45,6 +65,7 @@ extern void loop(double delta);
|
||||||
extern void draw_scene(sf::RenderTarget &target, sf::RenderStates const &states);
|
extern void draw_scene(sf::RenderTarget &target, sf::RenderStates const &states);
|
||||||
extern void draw_main_menu_bar(void);
|
extern void draw_main_menu_bar(void);
|
||||||
extern void draw_gui(void);
|
extern void draw_gui(void);
|
||||||
|
extern void shutdown(void);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
initialize_window();
|
initialize_window();
|
||||||
|
|
@ -54,9 +75,9 @@ int main() {
|
||||||
// Event Polling
|
// Event Polling
|
||||||
poll_events();
|
poll_events();
|
||||||
// Update
|
// Update
|
||||||
sf::Time const deltaTime{ deltaClock.restart() };
|
delta_time = delta_clock.restart();
|
||||||
ImGui::SFML::Update(window, deltaTime);
|
ImGui::SFML::Update(window, delta_time);
|
||||||
loop(deltaTime.asSeconds());
|
loop(delta_time.asSeconds());
|
||||||
if(ImGui::BeginMainMenuBar()) {
|
if(ImGui::BeginMainMenuBar()) {
|
||||||
draw_main_menu_bar();
|
draw_main_menu_bar();
|
||||||
ImGui::EndMainMenuBar();
|
ImGui::EndMainMenuBar();
|
||||||
|
|
@ -68,6 +89,23 @@ int main() {
|
||||||
ImGui::SFML::Render(window);
|
ImGui::SFML::Render(window);
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
shutdown();
|
||||||
ImGui::SFML::Shutdown();
|
ImGui::SFML::Shutdown();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppConfig const &get_application_configuration() {
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Time const &get_delta_time() {
|
||||||
|
return delta_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::RenderWindow const &get_window() {
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_render_view(sf::View const &view) {
|
||||||
|
window.setView(view);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue