Skip to content

Commit

Permalink
Add ImGui::SFML library
Browse files Browse the repository at this point in the history
  • Loading branch information
Smertig committed Oct 12, 2020
1 parent a3edfaa commit 5fe0fec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
1 change: 1 addition & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class AmongUsReplayerConan(ConanFile):

requires = [
"sfml/2.5.1@bincrafters/stable",
"imgui-sfml/2.1@bincrafters/stable",
"fmt/7.0.3",
"nlohmann_json/3.9.1"
]
Expand Down
48 changes: 33 additions & 15 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <replay/replay.hpp>
#include <util/platform.hpp>

#include <imgui-SFML.h>
#include <imgui.h>
#include <fmt/format.h>

#include <optional>
Expand Down Expand Up @@ -42,6 +44,8 @@ int main(int argc, char** argv) {
sf::RenderWindow window(sf::VideoMode::getFullscreenModes().front(), platform::get_app_fullname());
window.setVerticalSyncEnabled(true);

ImGui::SFML::Init(window);

// Prepare map and camera
scene::map m(r.get_map_id());
scene::camera camera(window);
Expand All @@ -57,7 +61,26 @@ int main(int argc, char** argv) {
int current_time = 0;

while (window.isOpen()) {
current_time += deltaClock.restart().asMilliseconds() * 3;
const auto dt = deltaClock.restart();

current_time += dt.asMilliseconds() * 3;

// Process events
sf::Event event{};
while (window.pollEvent(event)) {
ImGui::SFML::ProcessEvent(event);

if (!ImGui::GetIO().WantCaptureMouse) {
camera.process_event(event);
}

if (event.type == sf::Event::Closed) {
window.close();
}
}

// Update
ImGui::SFML::Update(window, dt);

if (r.is_meeting(current_time)) {
for (const auto& [id, info] : r.get_players()) {
Expand All @@ -72,20 +95,6 @@ int main(int argc, char** argv) {
}
}

window.clear();
window.setView(camera.view());
m.draw(window, sf::Transform::Identity);
window.display();

sf::Event event{};
while (window.pollEvent(event)) {
camera.process_event(event);

if (event.type == sf::Event::Closed) {
window.close();
}
}

if (current_time >= r.get_duration()) {
if (platform::msgbox_ask("End of round. Restart?")) {
current_time = 0;
Expand All @@ -95,8 +104,17 @@ int main(int argc, char** argv) {
window.close();
}
}

// Render
window.clear();
window.setView(camera.view());
m.draw(window, sf::Transform::Identity);
ImGui::SFML::Render(window);
window.display();
}

ImGui::SFML::Shutdown();

return 0;
}
catch (std::exception& e) {
Expand Down

0 comments on commit 5fe0fec

Please sign in to comment.