A bit more source refactoring.

master
Zed A. Shaw 2 months ago
parent cc3bb171e1
commit 152d4cf037
  1. 4
      gui.cpp
  2. 2
      meson.build
  3. 24
      sfmlbackend.cpp
  4. 4
      sfmlbackend.hpp
  5. 12
      xmake.lua

@ -8,7 +8,7 @@
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <fstream> #include <fstream>
#include "sfmlgui.hpp" #include "sfmlbackend.hpp"
#include "builder.hpp" #include "builder.hpp"
using std::string, std::vector; using std::string, std::vector;
@ -52,7 +52,7 @@ void GUI::output(const string msg) {
} }
int GUI::main_loop(GameEngine &game, Builder &builder) { int GUI::main_loop(GameEngine &game, Builder &builder) {
auto gui = SFMLGui(game); auto gui = SFMLBackend(game);
gui.startup(); gui.startup();

@ -32,7 +32,7 @@ executable('escape_turings_tarpit',
'gui.cpp', 'gui.cpp',
'watcher.cpp', 'watcher.cpp',
'builder.cpp', 'builder.cpp',
'sfmlgui.cpp', 'sfmlbackend.cpp',
'escape_turings_tarpit.cpp'], 'escape_turings_tarpit.cpp'],
dependencies: dependencies) dependencies: dependencies)

@ -9,17 +9,17 @@
#include <SFML/Graphics/Text.hpp> #include <SFML/Graphics/Text.hpp>
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <SFML/Window/Event.hpp> #include <SFML/Window/Event.hpp>
#include "sfmlgui.hpp" #include "sfmlbackend.hpp"
using namespace ImGui; using namespace ImGui;
using std::string; using std::string;
void SFMLGui::ImGui_setup() { void SFMLBackend::ImGui_setup() {
bool res = SFML::Init(window); bool res = SFML::Init(window);
fmt::println("IMGUI returned {}", res); fmt::println("IMGUI returned {}", res);
} }
void SFMLGui::ImGui_update() { void SFMLBackend::ImGui_update() {
sf::Vector2u size = window.getSize(); sf::Vector2u size = window.getSize();
SFML::Update(window, deltaClock.restart()); SFML::Update(window, deltaClock.restart());
@ -38,14 +38,14 @@ void SFMLGui::ImGui_update() {
End(); End();
} }
void SFMLGui::Window_update() { void SFMLBackend::Window_update() {
if(show_build_log) { if(show_build_log) {
SFML::Render(window); SFML::Render(window);
} }
window.display(); window.display();
} }
void SFMLGui::handle_events() { void SFMLBackend::handle_events() {
sf::Event event; sf::Event event;
// is this a main event loop // is this a main event loop
@ -87,7 +87,7 @@ sf::Vector2f translate(int x, int y) {
} }
void SFMLGui::write_text(int x, int y, string content) { void SFMLBackend::write_text(int x, int y, string content) {
sf::Vector2f position = translate(x,y); sf::Vector2f position = translate(x,y);
sf::Text text; sf::Text text;
text.setFont(font); text.setFont(font);
@ -98,7 +98,7 @@ void SFMLGui::write_text(int x, int y, string content) {
window.draw(text); window.draw(text);
} }
void SFMLGui::update_entities() { void SFMLBackend::update_entities() {
window.clear(); window.clear();
sf::RectangleShape face_box(translate(X_ROWS/4, Y_LINES/2)); sf::RectangleShape face_box(translate(X_ROWS/4, Y_LINES/2));
@ -135,19 +135,19 @@ void SFMLGui::update_entities() {
show_build_log = window_active_out; show_build_log = window_active_out;
} }
SFMLGui::SFMLGui(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings), game(g) SFMLBackend::SFMLBackend(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings), game(g)
{ {
} }
void SFMLGui::update_log(std::vector<string> &lines) { void SFMLBackend::update_log(std::vector<string> &lines) {
log.clear(); log.clear();
for(string &line : lines) { for(string &line : lines) {
log.push_back(line); log.push_back(line);
} }
} }
void SFMLGui::startup() { void SFMLBackend::startup() {
fmt::print("Setting up a window for you...\n"); fmt::print("Setting up a window for you...\n");
settings.antialiasingLevel = 8; settings.antialiasingLevel = 8;
@ -162,10 +162,10 @@ void SFMLGui::startup() {
ImGui_setup(); ImGui_setup();
} }
bool SFMLGui::is_open() { bool SFMLBackend::is_open() {
return window.isOpen(); return window.isOpen();
} }
void SFMLGui::shutdown() { void SFMLBackend::shutdown() {
SFML::Shutdown(); SFML::Shutdown();
} }

@ -15,7 +15,7 @@ constexpr int TEXT_SIZE = 48;
constexpr int Y_LINES = 23; constexpr int Y_LINES = 23;
constexpr int X_ROWS = 48; constexpr int X_ROWS = 48;
class SFMLGui { class SFMLBackend {
sf::ContextSettings settings; sf::ContextSettings settings;
sf::RenderWindow window; sf::RenderWindow window;
sf::Clock clock; sf::Clock clock;
@ -30,7 +30,7 @@ class SFMLGui {
std::vector<string> log; std::vector<string> log;
public: public:
SFMLGui(GameEngine &g); SFMLBackend(GameEngine &g);
void startup(); void startup();

@ -1,12 +0,0 @@
add_requires(
"efsw",
"fmt",
{configs = {cxflags = "-DFMT_HEADER_ONLY"}})
target("watchgit")
set_kind("binary")
add_files("watchgit.cpp")
set_languages("c++20")
add_packages(
"fmt",
"efsw")
Loading…
Cancel
Save