From 139bb2f9052d7d67c8618366c0976d0f0f76e366 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Mon, 24 Mar 2025 16:24:14 +0100 Subject: [PATCH] Fix some details --- TODO.txt | 2 ++ frontend_sdl.c | 17 +++++++++++++---- game.h | 9 +++++++++ renderer.h | 7 +++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/TODO.txt b/TODO.txt index 0709b16..eb305ff 100644 --- a/TODO.txt +++ b/TODO.txt @@ -61,6 +61,8 @@ =========== BUGS ================= +- sometimes the games prints huge long ass number of newlines, WHY (happens + when driving on accelerator) - immediately after starting the map countdown seems to be lower - the pinch collision test seems to sometimes stop the car e.g. after falling from bigger height or when running into ramp at high speed (or not?) - FIX diff --git a/frontend_sdl.c b/frontend_sdl.c index 05e9931..d62b631 100644 --- a/frontend_sdl.c +++ b/frontend_sdl.c @@ -5,12 +5,15 @@ #define DATA_FILE_NAME "data" -#include "game.h" +#define LCR_LOADING_COMMAND SDL_PumpEvents(); SDL_RenderPresent(renderer); SDL_Window *window; SDL_Renderer *renderer; SDL_Texture *texture; SDL_Surface *screenSurface; + +#include "game.h" + uint16_t screen[LCR_SETTING_RESOLUTION_X * LCR_SETTING_RESOLUTION_Y]; FILE *musicFile = 0; @@ -106,7 +109,7 @@ uint8_t LCR_keyPressed(uint8_t key) void LCR_sleep(uint16_t timeMs) { - usleep(timeMs * 1000); + SDL_Delay(timeMs); } void LCR_drawPixel(unsigned long index, uint16_t color) @@ -221,9 +224,15 @@ int main(int argc, char *argv[]) while (running) { - SDL_PumpEvents(); + SDL_Event event; + + running = 1; + + while (SDL_PollEvent(&event)) + if (event.type == SDL_QUIT) + running = 0; + keyboardState = SDL_GetKeyboardState(NULL); - running = !keyboardState[SDL_SCANCODE_Q]; running &= LCR_gameStep(SDL_GetTicks()); diff --git a/game.h b/game.h index 6a59b85..7f66fef 100644 --- a/game.h +++ b/game.h @@ -167,6 +167,15 @@ uint8_t LCR_gameMusicOn(void); */ uint8_t LCR_gameGetNextAudioSample(void); +/** + This macro may be redefined by frontend to a command that will be periodically + performed during map loading. This exists to prevent making the program seem + unresponsive or being killed by a watchdog. +*/ +#ifndef LCR_LOADING_COMMAND + #define LCR_LOADING_COMMAND ; +#endif + //------------------------------------------------------------------------------ #define LCR_LOG0(s) ; diff --git a/renderer.h b/renderer.h index a5cdebe..091dc1c 100644 --- a/renderer.h +++ b/renderer.h @@ -903,6 +903,13 @@ uint8_t _LCR_buildMapModel(void) vx, vy, vz, // vertex coords vi = 0; // vertex index (0, 1 or 2) +#ifdef LCR_LOADING_COMMAND + if (j % 64 == 0) + { + LCR_LOADING_COMMAND + } +#endif + LCR_mapBlockGetCoords(block,&bx,&by,&bz); LCR_mapGetBlockShape(blockType,LCR_mapBlockGetTransform(block),