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 ==============
- add display of inputs on the screen (option in setting? arg?)
- frontends:
- auto test frontend, with no I/O, that will just internally run a series of
inputs and check if the output is as expected
@ -44,6 +43,8 @@ fuck issue trackers :D
=========== HANDLED ==============
- 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
- doxygen documentation
- 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_mapReset();
LCR_racingRestart(replay);
LCR_rendererUnmarkCPs();
LCR_racingGetCarTransform(carTransform,carTransform + 3,0);
@ -833,6 +834,7 @@ uint8_t LCR_gameLoadMap(unsigned int mapIndex)
result = LCR_mapLoadFromStr(LCR_gameGetNextDataStrChar,name);
LCR_game.mapBeaten = LCR_mapIsBeaten(LCR_currentMap.name);
return result;
}
@ -1228,9 +1230,12 @@ void LCR_gameDraw3DView(void)
{
LCR_GameUnit carTransform[6];
LCR_GameUnit physicsInterpolationParam = LCR_GAME_UNIT -
((LCR_game.nextRacingTickTime - LCR_game.time) * LCR_GAME_UNIT)
/ LCR_RACING_TICK_MS;
LCR_GameUnit physicsInterpolationParam =
!(LCR_racing.playingReplay && LCR_replayHasFinished()) ?
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,
physicsInterpolationParam);
@ -1285,6 +1290,19 @@ void LCR_gameDraw3DView(void)
LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(_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);
if (LCR_game.state != LCR_GAME_STATE_RUN_FINISHED)
@ -1622,9 +1640,10 @@ uint8_t LCR_gameStep(uint32_t time)
else
{
LCR_gameHandleInput();
int paused = LCR_game.state == LCR_GAME_STATE_MENU ||
LCR_game.state == LCR_GAME_STATE_RUN_STARTING;
int paused =
LCR_game.state != LCR_GAME_STATE_RUN &&
LCR_game.state != LCR_GAME_STATE_RUN_FINISHED;
// handle simulation:
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;
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;
data = i != 3 ? data + 1 : LCR_currentMap.blocks;
data = (i != 3) ? data + 1 : LCR_currentMap.blocks;
}
LCR_currentMap.hash *= 251;

View file

@ -134,6 +134,7 @@ struct
LCR_GameUnit carSpeeds[2]; /**< Signed speed in game units per tick (negative
if backwards) and its previous value. */
uint8_t currentInputs; ///< Current input state (from player or replay).
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.
Returns 1 on success, else 0.
*/
int LCR_replayLoadFromStr(char (*nextChar)(void),
uint32_t *mapHash, uint16_t *nameHash)
int LCR_replayLoadFromStr(char (*nextChar)(void), uint32_t *mapHash,
uint16_t *nameHash)
{
char c;
@ -964,6 +965,7 @@ void LCR_racingRestart(uint8_t replay)
LCR_racing.carSpeeds[1] = 0;
LCR_racing.carDrifting = 0;
LCR_racing.crashState = 0;
LCR_racing.currentInputs = 0;
// make the car body:
TPE_makeCenterRectFull(LCR_racing.carJoints,
@ -1192,6 +1194,8 @@ uint32_t LCR_racingStep(unsigned int input)
LCR_replayRecordEvent(LCR_racing.tick,input);
}
LCR_racing.currentInputs = input;
carForw = TPE_vec3Normalized(TPE_vec3Plus(
TPE_vec3Minus(LCR_racing.carBody.joints[0].position,
LCR_racing.carBody.joints[2].position),

View file

@ -92,9 +92,15 @@
#endif
#ifndef LCR_SETTING_LOD_COLOR
/** RGB565 color of LOD blocks in the distance. */
#define LCR_SETTING_LOD_COLOR 0x4229
#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
/** 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