Fix bug, add input display

This commit is contained in:
Miloslav Ciz 2025-05-28 22:05:50 +02:00
parent 19a2aff2cc
commit 0bbbc26f2a
5 changed files with 41 additions and 11 deletions

View file

@ -2,7 +2,6 @@ fuck issue trackers :D
=========== GENERAL ============== =========== GENERAL ==============
- add display of inputs on the screen (option in setting? arg?)
- frontends: - frontends:
- auto test frontend, with no I/O, that will just internally run a series of - auto test frontend, with no I/O, that will just internally run a series of
inputs and check if the output is as expected inputs and check if the output is as expected
@ -44,6 +43,8 @@ fuck issue trackers :D
=========== HANDLED ============== =========== HANDLED ==============
- should drifting make a sound? NO NEED - should drifting make a sound? NO NEED
- add display of inputs on the screen (option in setting? arg?)
- viewing replay during countdown bugs!
- sometimes after restart the timer shows not 0:0:0, but something like 0:0:033 - sometimes after restart the timer shows not 0:0:0, but something like 0:0:033
- doxygen documentation - doxygen documentation
- immediately after starting the map countdown seems to be lower (seems to - immediately after starting the map countdown seems to be lower (seems to

31
game.h
View file

@ -482,6 +482,7 @@ void LCR_gameResetRun(uint8_t replay, uint8_t ghost)
LCR_LOG0("resetting run"); LCR_LOG0("resetting run");
LCR_mapReset(); LCR_mapReset();
LCR_racingRestart(replay); LCR_racingRestart(replay);
LCR_rendererUnmarkCPs(); LCR_rendererUnmarkCPs();
LCR_racingGetCarTransform(carTransform,carTransform + 3,0); LCR_racingGetCarTransform(carTransform,carTransform + 3,0);
@ -833,6 +834,7 @@ uint8_t LCR_gameLoadMap(unsigned int mapIndex)
result = LCR_mapLoadFromStr(LCR_gameGetNextDataStrChar,name); result = LCR_mapLoadFromStr(LCR_gameGetNextDataStrChar,name);
LCR_game.mapBeaten = LCR_mapIsBeaten(LCR_currentMap.name); LCR_game.mapBeaten = LCR_mapIsBeaten(LCR_currentMap.name);
return result; return result;
} }
@ -1228,9 +1230,12 @@ void LCR_gameDraw3DView(void)
{ {
LCR_GameUnit carTransform[6]; LCR_GameUnit carTransform[6];
LCR_GameUnit physicsInterpolationParam = LCR_GAME_UNIT - LCR_GameUnit physicsInterpolationParam =
((LCR_game.nextRacingTickTime - LCR_game.time) * LCR_GAME_UNIT) !(LCR_racing.playingReplay && LCR_replayHasFinished()) ?
/ LCR_RACING_TICK_MS; LCR_GAME_UNIT -
((LCR_game.nextRacingTickTime - LCR_game.time) * LCR_GAME_UNIT)
/ LCR_RACING_TICK_MS
: LCR_GAME_UNIT / 2;
LCR_racingGetCarTransform(carTransform,carTransform + 3, LCR_racingGetCarTransform(carTransform,carTransform + 3,
physicsInterpolationParam); physicsInterpolationParam);
@ -1285,6 +1290,19 @@ void LCR_gameDraw3DView(void)
LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(_FONT_SIZE) - LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(_FONT_SIZE) -
LCR_GUI_GAP,0,_FONT_SIZE); LCR_GUI_GAP,0,_FONT_SIZE);
#if LCR_SETTING_DISPLAY_INPUTS
str[0] = (LCR_racing.currentInputs & LCR_RACING_INPUT_LEFT) ? 'L' : '.';
str[1] = (LCR_racing.currentInputs & LCR_RACING_INPUT_BACK) ? 'D' : '.';
str[2] = (LCR_racing.currentInputs & LCR_RACING_INPUT_FORW) ? 'U' : '.';
str[3] = (LCR_racing.currentInputs & LCR_RACING_INPUT_RIGHT) ? 'R' : '.';
str[4] = 0;
LCR_rendererDrawText(str,LCR_EFFECTIVE_RESOLUTION_X -
LCR_rendererComputeTextWidth(str,_FONT_SIZE) - LCR_GUI_GAP,
LCR_EFFECTIVE_RESOLUTION_Y - 2 *
(LCR_rendererComputeTextHeight(_FONT_SIZE) + LCR_GUI_GAP),0,_FONT_SIZE);
#endif
LCR_gameTimeToStr(LCR_game.runTime,str); LCR_gameTimeToStr(LCR_game.runTime,str);
if (LCR_game.state != LCR_GAME_STATE_RUN_FINISHED) if (LCR_game.state != LCR_GAME_STATE_RUN_FINISHED)
@ -1622,9 +1640,10 @@ uint8_t LCR_gameStep(uint32_t time)
else else
{ {
LCR_gameHandleInput(); LCR_gameHandleInput();
int paused = LCR_game.state == LCR_GAME_STATE_MENU || int paused =
LCR_game.state == LCR_GAME_STATE_RUN_STARTING; LCR_game.state != LCR_GAME_STATE_RUN &&
LCR_game.state != LCR_GAME_STATE_RUN_FINISHED;
// handle simulation: // handle simulation:
while (time >= LCR_game.nextRacingTickTime) while (time >= LCR_game.nextRacingTickTime)

4
map.h
View file

@ -392,10 +392,10 @@ void _LCR_mapComputeHash(void)
LCR_currentMap.hash = 11 + LCR_currentMap.environment; LCR_currentMap.hash = 11 + LCR_currentMap.environment;
for (int i = 0; i < LCR_currentMap.blockCount * LCR_BLOCK_SIZE + 4; ++i) for (int i = 0; i < 4 + LCR_currentMap.blockCount * LCR_BLOCK_SIZE; ++i)
{ {
LCR_currentMap.hash = LCR_currentMap.hash * 101 + *data; LCR_currentMap.hash = LCR_currentMap.hash * 101 + *data;
data = i != 3 ? data + 1 : LCR_currentMap.blocks; data = (i != 3) ? data + 1 : LCR_currentMap.blocks;
} }
LCR_currentMap.hash *= 251; LCR_currentMap.hash *= 251;

View file

@ -134,6 +134,7 @@ struct
LCR_GameUnit carSpeeds[2]; /**< Signed speed in game units per tick (negative LCR_GameUnit carSpeeds[2]; /**< Signed speed in game units per tick (negative
if backwards) and its previous value. */ if backwards) and its previous value. */
uint8_t currentInputs; ///< Current input state (from player or replay).
uint8_t groundMaterial; ///< Material currently under car wheels. uint8_t groundMaterial; ///< Material currently under car wheels.
@ -251,8 +252,8 @@ void LCR_replayOutputStr(void (*printChar)(char))
the memory they point to will be filled with the map hash and name hash. the memory they point to will be filled with the map hash and name hash.
Returns 1 on success, else 0. Returns 1 on success, else 0.
*/ */
int LCR_replayLoadFromStr(char (*nextChar)(void), int LCR_replayLoadFromStr(char (*nextChar)(void), uint32_t *mapHash,
uint32_t *mapHash, uint16_t *nameHash) uint16_t *nameHash)
{ {
char c; char c;
@ -964,6 +965,7 @@ void LCR_racingRestart(uint8_t replay)
LCR_racing.carSpeeds[1] = 0; LCR_racing.carSpeeds[1] = 0;
LCR_racing.carDrifting = 0; LCR_racing.carDrifting = 0;
LCR_racing.crashState = 0; LCR_racing.crashState = 0;
LCR_racing.currentInputs = 0;
// make the car body: // make the car body:
TPE_makeCenterRectFull(LCR_racing.carJoints, TPE_makeCenterRectFull(LCR_racing.carJoints,
@ -1192,6 +1194,8 @@ uint32_t LCR_racingStep(unsigned int input)
LCR_replayRecordEvent(LCR_racing.tick,input); LCR_replayRecordEvent(LCR_racing.tick,input);
} }
LCR_racing.currentInputs = input;
carForw = TPE_vec3Normalized(TPE_vec3Plus( carForw = TPE_vec3Normalized(TPE_vec3Plus(
TPE_vec3Minus(LCR_racing.carBody.joints[0].position, TPE_vec3Minus(LCR_racing.carBody.joints[0].position,
LCR_racing.carBody.joints[2].position), LCR_racing.carBody.joints[2].position),

View file

@ -92,9 +92,15 @@
#endif #endif
#ifndef LCR_SETTING_LOD_COLOR #ifndef LCR_SETTING_LOD_COLOR
/** RGB565 color of LOD blocks in the distance. */
#define LCR_SETTING_LOD_COLOR 0x4229 #define LCR_SETTING_LOD_COLOR 0x4229
#endif #endif
#ifndef LCR_SETTING_DISPLAY_INPUTS
/** Whether to display current inputs on the screen. */
#define LCR_SETTING_DISPLAY_INPUTS 1
#endif
#ifndef LCR_SETTING_CAR_ANIMATION_SUBDIVIDE #ifndef LCR_SETTING_CAR_ANIMATION_SUBDIVIDE
/** How many frames will be used to complete whole animation of the car model. /** How many frames will be used to complete whole animation of the car model.
0 turns off car animation completely (may be faster and smaller), 1 turns on 0 turns off car animation completely (may be faster and smaller), 1 turns on