Continue ghost

This commit is contained in:
Miloslav Ciz 2025-01-22 00:06:15 +01:00
parent 0a91d5f54e
commit 0b16d64eef
2 changed files with 69 additions and 21 deletions

56
game.h
View file

@ -179,9 +179,7 @@ uint8_t LCR_gameGetNextAudioSample(void);
#define LCR_GAME_STATE_RUN 0x02 #define LCR_GAME_STATE_RUN 0x02
#define LCR_GAME_STATE_RUN_FINISHED 0x03 #define LCR_GAME_STATE_RUN_FINISHED 0x03
#define LCR_GAME_STATE_LOADING_RUN 0x04 #define LCR_GAME_STATE_LOADING 0x04
#define LCR_GAME_STATE_LOADING_REP1 0x05
#define LCR_GAME_STATE_LOADING_REP2 0x06
#define LCR_GAME_STATE_END 0xff #define LCR_GAME_STATE_END 0xff
@ -284,7 +282,7 @@ struct
uint8_t stretch; /**< Stretch of the base sample step, as a bit shift uint8_t stretch; /**< Stretch of the base sample step, as a bit shift
(i.e. 1 means the step will be 2x as long etc.). This (i.e. 1 means the step will be 2x as long etc.). This
is to allow ghosts for even long replays. */ is to allow ghosts for even long replays. */
const uint8_t *currentSample; uint8_t *currentSample;
uint16_t nextSampleIn; uint16_t nextSampleIn;
} ghost; } ghost;
#endif #endif
@ -352,6 +350,12 @@ void LCR_gameResetRun(uint8_t replay)
LCR_game.runTimeMS = 0; LCR_game.runTimeMS = 0;
} }
void LCR_gameGhostReset(void)
{
LCR_game.ghost.currentSample = LCR_game.ghost.samples;
LCR_game.ghost.nextSampleIn = 0;
}
void _LCR_gamePrepareGhost(void) void _LCR_gamePrepareGhost(void)
{ {
LCR_GameUnit carTransform[6]; LCR_GameUnit carTransform[6];
@ -360,6 +364,7 @@ void _LCR_gamePrepareGhost(void)
LCR_gameResetRun(1); LCR_gameResetRun(1);
LCR_game.ghost.stretch = 0; LCR_game.ghost.stretch = 0;
LCR_game.ghost.currentSample = LCR_game.ghost.samples;
while (((int) LCR_replay.achievedTime) > while (((int) LCR_replay.achievedTime) >
(LCR_SETTING_GHOST_STEP << LCR_game.ghost.stretch) * (LCR_SETTING_GHOST_STEP << LCR_game.ghost.stretch) *
@ -375,10 +380,28 @@ void _LCR_gamePrepareGhost(void)
== 0) == 0)
{ {
LCR_racingGetCarTransform(carTransform,carTransform + 3,0); LCR_racingGetCarTransform(carTransform,carTransform + 3,0);
LCR_game.ghost.currentSample[0] = carTransform[0];
LCR_game.ghost.currentSample[1] =
((carTransform[0] >> 8) & 0x01) |
(carTransform[1] << 1);
LCR_game.ghost.currentSample[2] =
((carTransform[1] >> 7) & 0x03) |
(carTransform[2] << 2);
LCR_game.ghost.currentSample[3] =
((carTransform[2] >> 6) & 0x0f) |
(carTransform[3] << 4);
LCR_game.ghost.currentSample[4] =
(carTransform[4] >> 4) |
(carTransform[5] << 4);
LCR_game.ghost.currentSample += LCR_GHOST_SAMPLE_SIZE;
} }
LCR_racingStep(0); LCR_racingStep(0);
} }
LCR_gameGhostReset();
} }
LCR_GameUnit LCR_carSpeedKMH(void) LCR_GameUnit LCR_carSpeedKMH(void)
@ -742,14 +765,6 @@ void LCR_gameTimeToStr(uint32_t timeMS, char *str)
str[2] = '\''; str[2] = '\'';
} }
int _LCR_gameIsLoading(void)
{
return
(LCR_game.state == LCR_GAME_STATE_LOADING_RUN) ||
(LCR_game.state == LCR_GAME_STATE_LOADING_REP1) ||
(LCR_game.state == LCR_GAME_STATE_LOADING_REP2);
}
void LCR_gameDraw3DView(void) void LCR_gameDraw3DView(void)
{ {
LCR_GameUnit carTransform[6]; LCR_GameUnit carTransform[6];
@ -951,7 +966,7 @@ void LCR_gameHandleInput(void)
case 1: case 1:
LCR_gameLoadMap(LCR_game.dataFile.firstItemIndex + LCR_gameLoadMap(LCR_game.dataFile.firstItemIndex +
LCR_game.menu.selectedItem); LCR_game.menu.selectedItem);
LCR_gameSetState(LCR_GAME_STATE_LOADING_RUN); LCR_gameSetState(LCR_GAME_STATE_LOADING);
break; break;
case 2: case 2:
@ -969,8 +984,7 @@ void LCR_gameHandleInput(void)
LCR_LOG1("couldn't load replay map"); LCR_LOG1("couldn't load replay map");
} }
else else
LCR_gameSetState(LCR_game.menu.selectedTab == 2 ? LCR_gameSetState(LCR_GAME_STATE_LOADING);
LCR_GAME_STATE_LOADING_REP1 : LCR_GAME_STATE_LOADING_REP2);
break; break;
} }
@ -1063,17 +1077,16 @@ uint8_t LCR_gameStep(uint32_t time)
LCR_game.keyStates[i] = LCR_keyPressed(i) ? LCR_game.keyStates[i] = LCR_keyPressed(i) ?
(LCR_game.keyStates[i] < 255 ? LCR_game.keyStates[i] + 1 : 255) : 0; (LCR_game.keyStates[i] < 255 ? LCR_game.keyStates[i] + 1 : 255) : 0;
if (_LCR_gameIsLoading()) if (LCR_game.state == LCR_GAME_STATE_LOADING)
{ {
LCR_rendererLoadMap(); LCR_rendererLoadMap();
if (LCR_game.state == LCR_GAME_STATE_LOADING_REP2) if (LCR_game.menu.selectedTab == 3)
{ {
_LCR_gamePrepareGhost(); _LCR_gamePrepareGhost();
} }
LCR_gameResetRun( LCR_gameResetRun(LCR_game.menu.selectedTab == 2);
LCR_game.state == LCR_GAME_STATE_LOADING_REP1);
} }
LCR_gameHandleInput(); LCR_gameHandleInput();
@ -1144,7 +1157,8 @@ LCR_replayOutputStr(_LCR_gameDataCharWrite);
while (time >= LCR_game.nextRenderFrameTime) while (time >= LCR_game.nextRenderFrameTime)
LCR_game.nextRenderFrameTime += 1000 / LCR_SETTING_FPS; LCR_game.nextRenderFrameTime += 1000 / LCR_SETTING_FPS;
if ((LCR_game.state == LCR_GAME_STATE_MENU) || _LCR_gameIsLoading()) if ((LCR_game.state == LCR_GAME_STATE_MENU) ||
LCR_game.state == LCR_GAME_STATE_LOADING)
LCR_rendererDrawMenu(LCR_texts[LCR_TEXTS_TABS LCR_rendererDrawMenu(LCR_texts[LCR_TEXTS_TABS
+ LCR_game.menu.selectedTab],LCR_game.menu.itemNamePtrs, + LCR_game.menu.selectedTab],LCR_game.menu.itemNamePtrs,
LCR_game.menu.itemCount + 1,LCR_game.menu.selectedItem); LCR_game.menu.itemCount + 1,LCR_game.menu.selectedItem);
@ -1157,7 +1171,7 @@ LCR_replayOutputStr(_LCR_gameDataCharWrite);
sleep = tmp < sleep ? tmp : sleep; sleep = tmp < sleep ? tmp : sleep;
} }
if (_LCR_gameIsLoading()) if (LCR_game.state == LCR_GAME_STATE_LOADING)
{ {
// show the "loading" screen // show the "loading" screen

View file

@ -115,11 +115,31 @@ struct
with color stored in this variable. */ with color stored in this variable. */
} LCR_renderer; } LCR_renderer;
void _LCR_rendererSetModelTransofmr(S3L_Model3D *model,
LCR_GameUnit position[3], LCR_GameUnit rotation[3])
{
model->transform.translation.x =
(position[0] * LCR_RENDERER_UNIT) / LCR_GAME_UNIT;
model->transform.translation.y =
(position[1] * LCR_RENDERER_UNIT) / LCR_GAME_UNIT;
model->transform.translation.z =
(position[2] * LCR_RENDERER_UNIT) / LCR_GAME_UNIT;
model->transform.rotation.x = S3L_wrap((rotation[0] *
S3L_F) / LCR_GAME_UNIT,S3L_F);
model->transform.rotation.y = S3L_wrap((rotation[1] *
S3L_F) / LCR_GAME_UNIT,S3L_F);
model->transform.rotation.z = S3L_wrap((rotation[2] *
S3L_F) / LCR_GAME_UNIT,S3L_F);
}
void LCR_rendererSetCarTransform(LCR_GameUnit position[3], void LCR_rendererSetCarTransform(LCR_GameUnit position[3],
LCR_GameUnit rotation[3]) LCR_GameUnit rotation[3])
{ {
LCR_LOG2("setting car transform"); LCR_LOG2("setting car transform");
_LCR_rendererSetModelTransofmr(LCR_renderer.carModel,position,rotation);
/*
LCR_renderer.carModel->transform.translation.x = LCR_renderer.carModel->transform.translation.x =
(position[0] * LCR_RENDERER_UNIT) / LCR_GAME_UNIT; (position[0] * LCR_RENDERER_UNIT) / LCR_GAME_UNIT;
LCR_renderer.carModel->transform.translation.y = LCR_renderer.carModel->transform.translation.y =
@ -133,6 +153,15 @@ void LCR_rendererSetCarTransform(LCR_GameUnit position[3],
S3L_F) / LCR_GAME_UNIT,S3L_F); S3L_F) / LCR_GAME_UNIT,S3L_F);
LCR_renderer.carModel->transform.rotation.z = S3L_wrap((rotation[2] * LCR_renderer.carModel->transform.rotation.z = S3L_wrap((rotation[2] *
S3L_F) / LCR_GAME_UNIT,S3L_F); S3L_F) / LCR_GAME_UNIT,S3L_F);
*/
}
void LCR_rendererSetGhostTransform(LCR_GameUnit position[3],
LCR_GameUnit rotation[3])
{
LCR_LOG2("setting ghost transform");
_LCR_rendererSetModelTransofmr(LCR_renderer.ghostModel,position,rotation);
} }
void LCR_rendererSetCarVisibility(uint8_t visible) void LCR_rendererSetCarVisibility(uint8_t visible)
@ -140,6 +169,11 @@ void LCR_rendererSetCarVisibility(uint8_t visible)
LCR_renderer.carModel->config.visible = visible; LCR_renderer.carModel->config.visible = visible;
} }
void LCR_rendererSetGhostVisibility(uint8_t visible)
{
LCR_renderer.ghostModel->config.visible = visible;
}
void _LCR_rendererDrawFontPixel(int x, int y, uint16_t color) void _LCR_rendererDrawFontPixel(int x, int y, uint16_t color)
{ {
#if LCR_FONT_PIXEL_SIZE == 1 #if LCR_FONT_PIXEL_SIZE == 1