Fixed up before doing the upgrade to SFML 3.0

This commit is contained in:
Zed A. Shaw 2025-03-27 13:18:41 -04:00
parent 0766a2aacb
commit 2fa68351fc
7 changed files with 143 additions and 37 deletions

View file

@ -1,5 +1,3 @@
#include "imgui.h"
#include "imgui-SFML.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <fmt/core.h>
@ -10,27 +8,11 @@
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Window/Event.hpp>
void ImGui_setup(sf::RenderWindow &window) {
ImGui::SFML::Init(window);
}
void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock, sf::Time &tick) {
ImGui::SFML::Update(window, deltaClock.restart());
// ImGui::ShowDemoWindow();
ImGui::Begin("Clock");
sf::Vector2u size = window.getSize();
ImGui::SetWindowPos(ImVec2(size.x - 150, 0));
ImGui::SetWindowSize(ImVec2(150, 50));
std::string msg = fmt::format("Time: {}\n", tick.asSeconds());
ImGui::Button(msg.c_str());
ImGui::End();
}
#include "dbc.hpp"
void Window_update(sf::RenderWindow &window, sf::Sprite &player) {
window.clear();
window.draw(player);
ImGui::SFML::Render(window);
window.display();
}
@ -73,10 +55,7 @@ void Handle_events(sf::RenderWindow &window, BoxTest &box, sf::Sound &click) {
// is this a main event loop
while (window.pollEvent(event)) {
ImGui::SFML::ProcessEvent(window, event);
switch(event.type) {
case sf::Event::Closed:
fmt::print("Exiting...\n");
window.close();
@ -107,6 +86,8 @@ void Handle_events(sf::RenderWindow &window, BoxTest &box, sf::Sound &click) {
click.play();
}
break;
default:
return; // just here to shutup warnings
}
}
}
@ -126,7 +107,6 @@ sf::Time Update_entities(sf::RenderWindow &window, b2World &world, sf::Clock &cl
player.setPosition(position.x * 100.0f, winSize.y - position.y * 100.0f);
player.setRotation(angle * 180.0f / M_PI);
ImGui_update(window, deltaClock, tick);
Window_update(window, player);
return nextTick;
@ -154,10 +134,9 @@ int main() {
sf::ContextSettings settings;
settings.antialiasingLevel = 8;
sf::RenderWindow window(sf::VideoMode(1920, 1080), "Simple Game Demo", sf::Style::Default, settings);
sf::RenderWindow window(sf::VideoMode(1280, 720), "Simple Game Demo", sf::Style::Default, settings);
window.setFramerateLimit(60);
window.setVerticalSyncEnabled(true);
ImGui_setup(window);
sf::SoundBuffer buffer;
if(!buffer.loadFromFile("click.mp3")) {
@ -183,6 +162,4 @@ int main() {
// preparing for refactoring this into a class or struct for everything
tick = Update_entities(window, world, clock, deltaClock, tick, box, player);
}
ImGui::SFML::Shutdown();
}