чување c600bfd13055ee47eb50a3f7c114ce1d6dec5b4d
родитељ 4872820c9b59da8d24ec06e79b84b0ba562058f2
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Tue, 12 Aug 2025 18:49:27 +0200
Add limits.h; fine-tune redrawing, add workaround for MSYS2 bug
Diffstat:
| M | linije.c | | | 26 | ++++++++++++++++---------- |
измењених датотека: 1, додавања: 16(+), брисања: 10(-)
diff --git a/linije.c b/linije.c
@@ -6,6 +6,7 @@
#include <SDL3_image/SDL_image.h>
#include <assert.h>
#include <errno.h>
+#include <limits.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
@@ -881,7 +882,6 @@ handle_event(struct State* state, SDL_Event* event)
case SDL_EVENT_MOUSE_MOTION:
state->mouse.x = event->motion.x;
state->mouse.y = event->motion.y;
- state->redraw = 1;
break;
}
}
@@ -1639,7 +1639,6 @@ step_animation(struct State* state)
"End of path at (%0.0f, %0.0f)",
state->animation.end.x, state->animation.end.y);
state->animation.active = 0;
- state->redraw = 1;
}
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
@@ -1806,7 +1805,7 @@ main(int argc, char** argv)
last_time = SDL_GetTicks();
clock_getcpuclockid(getpid(), &cid);
clock_gettime(cid, &now);
- srandom(now.tv_sec);
+ srandom(now.tv_nsec);
state.selection_start.x = -1;
state.selection_start.y = -1;
@@ -1819,22 +1818,29 @@ main(int argc, char** argv)
current_time = SDL_GetTicks();
if (state.animation.active)
{
- draw(&state);
if (current_time > last_time + 1000 / FPS)
{
+ draw(&state);
step_animation(&state);
last_time = current_time;
}
+ if (!state.animation.active)
+ draw(&state);
}
- else
+ else if (state.redraw)
{
- if (state.redraw)
- {
- draw(&state);
- state.redraw = 0;
- }
+ state.redraw = 0;
+ draw(&state);
}
+/* For some reason, SDL_RenderPresent is not enough for MSYS2/Windoze...
+ * When moving a ball, the state of the screen remains stuck at the next-to-last
+ * cell, until a mouse is moved, then it updates. This is a duct tape fix.
+ */
+#if __WIN32
+ draw(&state);
+#endif
+
while (SDL_PollEvent(&event))
handle_event(&state, &event);
}