Skip to content

Commit f543241

Browse files
committed
fix: fix a few minor issues with the video render
1 parent 799c909 commit f543241

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

src/graphics/sdl_context.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <SDL.h>
66
#include <SDL_ttf.h>
77
#include <fmt/format.h>
8+
#include <spdlog/spdlog.h>
89

910
#if defined(__CONSOLE__)
1011
#include "helper/console_helpers.hpp"
@@ -21,6 +22,18 @@ SdlContext::SdlContext() {
2122
throw helper::InitializationError{ fmt::format("Failed in initializing sdl: {}", SDL_GetError()) };
2223
}
2324

25+
26+
// when using gdb / lldb to debug and you click something with the mouse, no other application can use the mouse, which is annoying, so not using this feature in debug mode
27+
#if !defined(NDEBUG)
28+
const auto hint_mouse_result = SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
29+
30+
if (hint_mouse_result != SDL_TRUE) {
31+
// this is non fatal, so not returning
32+
spdlog::error("Failed to set the SDL_HINT_MOUSE_AUTO_CAPTURE hint: {}", SDL_GetError());
33+
}
34+
#endif
35+
36+
2437
if (TTF_Init() < 0) {
2538
throw helper::InitializationError{ fmt::format("Failed in initializing sdl ttf: {}", TTF_GetError()) };
2639
}

src/graphics/video_renderer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ std::optional<std::string> VideoRenderer::render(
9494
//TODO: this is just a dummy thing atm, change that
9595
double progress = 0.0;
9696

97-
while (all_games_finished()) {
97+
while (not all_games_finished()) {
9898
progress_callback(progress);
9999

100100
for (const auto& game : m_games) {
101-
game->update();
102-
game->render(*this);
101+
if (not game->is_game_finished()) {
102+
game->update();
103+
game->render(*this);
104+
}
103105
}
104106

105107
backend.add_frame(m_surface.get());

src/graphics/video_renderer_linux.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ std::optional<std::string> VideoRendererBackend::setup(u32 fps, shapes::UPoint s
8080

8181
bool VideoRendererBackend::add_frame(SDL_Surface* surface) {
8282

83-
for (size_t y = surface->h; y > 0; --y) {
84-
if (write(m_decoder->pipe, surface->pixels, surface->h * surface->pitch) < 0) {
85-
spdlog::error("FFMPEG: failed to write into ffmpeg pipe: {}", strerror(errno));
86-
return false;
87-
}
83+
if (write(m_decoder->pipe, surface->pixels, static_cast<size_t>(surface->h) * surface->pitch) < 0) {
84+
spdlog::error("FFMPEG: failed to write into ffmpeg pipe: {}", strerror(errno));
85+
return false;
8886
}
8987
return true;
9088
}

src/helper/clock_source.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ double ManualClock::resume() {
6868

6969

7070
void ManualClock::increment_simulation_step_index() {
71-
m_simulation_step_index++;
71+
++m_simulation_step_index;
7272
}
7373

7474
void ManualClock::set_simulation_step_index(SimulationStep index) {

0 commit comments

Comments
 (0)