Clean a little

This commit is contained in:
Miloslav Ciz 2025-01-08 00:10:27 +01:00
parent 302bac10e6
commit 402867e73b
3 changed files with 64 additions and 62 deletions

95
game.h
View file

@ -203,17 +203,18 @@ struct
during a single frame, hold number of
frames for which the key has been
continuously held. */
uint32_t runTimeMS; /**< Current time of the run */
uint32_t runTimeMS;
struct
{
uint8_t selectedTab;
uint8_t selectedItem;
uint8_t itemCount;
char itemNames[LCR_MENU_MAX_ITEMS][LCR_MENU_STRING_SIZE];
const char *itemNamePtrs[LCR_MENU_MAX_ITEMS]; ///< helper array
} menu;
// TODO: make menu struct?
uint8_t menuSelectedTab;
uint8_t menuSelectedItem;
char menuItemNames[LCR_MENU_MAX_ITEMS][LCR_MENU_STRING_SIZE];
uint8_t menuItemCount;
const char *menuItemNamePointers[LCR_MENU_MAX_ITEMS]; ///< helper array
struct
{
@ -398,21 +399,19 @@ void LCR_gameStartRun(unsigned int mapIndex)
void LCR_gameEraseMenuItemNames(void)
{
for (int i = 0; i < LCR_MENU_MAX_ITEMS; ++i)
for (int j = 0; j < LCR_MENU_STRING_SIZE; ++j)
LCR_game.menuItemNames[i][j] = 0;
LCR_game.menuItemCount = 0;
LCR_game.menu.itemNames[i][j] = 0;
LCR_game.menu.itemCount = 0;
}
void LCR_gameSetMenuItemStr(uint8_t item, const char *str, char replaceChar)
{
for (int i = 0; i < LCR_MENU_STRING_SIZE - 1; ++i)
{
LCR_game.menuItemNames[item][i] = str[i] == '$' ? replaceChar : str[i];
LCR_game.menuItemNames[item][i + 1] = 0;
LCR_game.menu.itemNames[item][i] = str[i] == '$' ? replaceChar : str[i];
LCR_game.menu.itemNames[item][i + 1] = 0;
}
}
@ -426,7 +425,7 @@ void LCR_gameLoadMainMenuItems(void)
LCR_gameSetMenuItemStr(i,LCR_texts[4 + i],replaceChar);
}
LCR_game.menuItemCount = 4;
LCR_game.menu.itemCount = 4;
}
void LCR_gameInit(void)
@ -444,10 +443,10 @@ void LCR_gameInit(void)
LCR_game.resourceFile.state = 0;
for (int i = 0; i < LCR_MENU_MAX_ITEMS; ++i)
LCR_game.menuItemNamePointers[i] = LCR_game.menuItemNames[i];
LCR_game.menu.itemNamePtrs[i] = LCR_game.menu.itemNames[i];
LCR_game.menuSelectedTab = 0;
LCR_game.menuSelectedItem = 0;
LCR_game.menu.selectedTab = 0;
LCR_game.menu.selectedItem = 0;
LCR_game.frame = 0;
LCR_game.musicOn = 1;
@ -516,13 +515,13 @@ void LCR_gameLoadResourceFileChunk(unsigned int startIndex, char magicNumber)
state >= 1 + LCR_MENU_STRING_SIZE - 1)
{
state = 255;
LCR_game.menuItemCount++;
LCR_game.menu.itemCount++;
if (LCR_game.menuItemCount >= LCR_RESOURCE_ITEM_CHUNK)
if (LCR_game.menu.itemCount >= LCR_RESOURCE_ITEM_CHUNK)
break;
}
else
LCR_game.menuItemNames[LCR_game.menuItemCount][state - 1] = c;
LCR_game.menu.itemNames[LCR_game.menu.itemCount][state - 1] = c;
state++;
}
@ -562,7 +561,7 @@ void LCR_gameDraw3DView(void)
LCR_racingGetWheelSteer() * 2);
#endif
LCR_rendererDraw();
LCR_rendererDraw3D();
#if LCR_SETTING_DEBUG_PHYSICS_DRAW
LCR_GameUnit camTr[7];
@ -644,34 +643,34 @@ void LCR_gameHandleInput(void)
if (LCR_game.keyStates[LCR_KEY_RIGHT] == 1)
{
LCR_LOG1("menu tab right");
LCR_game.menuSelectedTab =
(LCR_game.menuSelectedTab + 1) % LCR_MENU_TABS;
tabSwitchedTo = LCR_game.menuSelectedTab;
LCR_game.menuSelectedItem = 0;
LCR_game.menu.selectedTab =
(LCR_game.menu.selectedTab + 1) % LCR_MENU_TABS;
tabSwitchedTo = LCR_game.menu.selectedTab;
LCR_game.menu.selectedItem = 0;
LCR_audioPlaySound(LCR_SOUND_CLICK);
}
else if (LCR_game.keyStates[LCR_KEY_LEFT] == 1)
{
LCR_LOG1("menu tab left");
LCR_game.menuSelectedTab =
(LCR_game.menuSelectedTab + LCR_MENU_TABS - 1) % LCR_MENU_TABS;
tabSwitchedTo = LCR_game.menuSelectedTab;
LCR_game.menuSelectedItem = 0;
LCR_game.menu.selectedTab =
(LCR_game.menu.selectedTab + LCR_MENU_TABS - 1) % LCR_MENU_TABS;
tabSwitchedTo = LCR_game.menu.selectedTab;
LCR_game.menu.selectedItem = 0;
LCR_audioPlaySound(LCR_SOUND_CLICK);
}
else if (LCR_game.keyStates[LCR_KEY_UP] == 1)
{
LCR_LOG1("menu item up");
if (LCR_game.menuSelectedItem != 0)
if (LCR_game.menu.selectedItem != 0)
{
LCR_game.menuSelectedItem--;
LCR_game.menu.selectedItem--;
LCR_audioPlaySound(LCR_SOUND_CLICK);
}
else if (LCR_game.menuSelectedTab != 0 &&
else if (LCR_game.menu.selectedTab != 0 &&
LCR_game.resourceFile.firstItemIndex != 0)
{
LCR_game.menuSelectedItem = LCR_RESOURCE_ITEM_CHUNK - 1;
LCR_game.menu.selectedItem = LCR_RESOURCE_ITEM_CHUNK - 1;
LCR_audioPlaySound(LCR_SOUND_CLICK);
scrolled = -1;
}
@ -680,23 +679,23 @@ void LCR_gameHandleInput(void)
{
LCR_LOG1("menu item down");
if (LCR_game.menuSelectedTab == 0)
if (LCR_game.menu.selectedTab == 0)
{
if (LCR_game.menuSelectedItem < 4)
if (LCR_game.menu.selectedItem < 4)
{
LCR_game.menuSelectedItem++;
LCR_game.menu.selectedItem++;
LCR_audioPlaySound(LCR_SOUND_CLICK);
}
}
else if (LCR_game.menuSelectedItem < LCR_game.menuItemCount - 1)
else if (LCR_game.menu.selectedItem < LCR_game.menu.itemCount - 1)
{
LCR_game.menuSelectedItem++;
LCR_game.menu.selectedItem++;
LCR_audioPlaySound(LCR_SOUND_CLICK);
}
else if (LCR_game.resourceFile.firstItemIndex +
LCR_RESOURCE_ITEM_CHUNK < LCR_game.resourceFile.itemsTotal)
{
LCR_game.menuSelectedItem = 0;
LCR_game.menu.selectedItem = 0;
LCR_audioPlaySound(LCR_SOUND_CLICK);
scrolled = 1;
}
@ -711,10 +710,10 @@ void LCR_gameHandleInput(void)
LCR_LOG1("menu confirm");
LCR_audioPlaySound(LCR_SOUND_CLICK);
switch (LCR_game.menuSelectedTab)
switch (LCR_game.menu.selectedTab)
{
case 0:
switch (LCR_game.menuSelectedItem)
switch (LCR_game.menu.selectedItem)
{
case 0:
LCR_game.cameraMode = (LCR_game.cameraMode + 1) % 4;
@ -743,7 +742,7 @@ void LCR_gameHandleInput(void)
case 1:
LCR_gameStartRun(
LCR_game.resourceFile.firstItemIndex + LCR_game.menuSelectedItem);
LCR_game.resourceFile.firstItemIndex + LCR_game.menu.selectedItem);
break;
default: break;
@ -769,7 +768,7 @@ void LCR_gameHandleInput(void)
{
LCR_LOG1("menu open");
LCR_gameSetState(LCR_GAME_STATE_MENU);
LCR_game.menuSelectedItem = 0;
LCR_game.menu.selectedItem = 0;
}
else if (LCR_game.cameraMode == LCR_CAMERA_MODE_FREE)
{
@ -817,7 +816,7 @@ void LCR_gameHandleInput(void)
LCR_gameLoadResourceFileChunk(
(tabSwitchedTo > 0) ? 0 : (LCR_game.resourceFile.firstItemIndex +
scrolled * LCR_RESOURCE_ITEM_CHUNK),
LCR_game.menuSelectedTab == 1 ? 'M' : 'R');
LCR_game.menu.selectedTab == 1 ? 'M' : 'R');
}
uint8_t LCR_gameStep(uint32_t time)
@ -907,9 +906,9 @@ uint8_t LCR_gameStep(uint32_t time)
if (LCR_game.state == LCR_GAME_STATE_MENU ||
LCR_game.state == LCR_GAME_STATE_LOADING_MAP)
LCR_rendererDrawMenu(LCR_texts[LCR_game.menuSelectedTab],
LCR_game.menuItemNamePointers,LCR_game.menuItemCount + 1,
LCR_game.menuSelectedItem);
LCR_rendererDrawMenu(LCR_texts[LCR_game.menu.selectedTab],
LCR_game.menu.itemNamePtrs,LCR_game.menu.itemCount + 1,
LCR_game.menu.selectedItem);
else
LCR_gameDraw3DView();
}

View file

@ -809,7 +809,7 @@ int _LCR_racingCarShapeOK(void)
*/
uint32_t LCR_racingStep(unsigned int input)
{
LCR_LOG2("racing step start");
LCR_LOG2("racing step (start)");
uint32_t result = 0;
TPE_Vec3 carForw, carRight, carUp, carVel;
@ -1043,9 +1043,9 @@ uint32_t LCR_racingStep(unsigned int input)
LCR_racing.fanForce = 0;
}
LCR_LOG2("gonna step physics engine");
LCR_LOG2("stepping physics (start)");
TPE_worldStep(&(LCR_racing.physicsWorld));
LCR_LOG2("stepping physics engine done");
LCR_LOG2("stepping physics (end)");
int speedDiff =
TPE_abs(LCR_racing.carSpeeds[0]) -
@ -1204,7 +1204,7 @@ uint32_t LCR_racingStep(unsigned int input)
LCR_racing.tick += LCR_racing.tick < 0xffffffff; // disallow overflow
LCR_LOG2("racing step end");
LCR_LOG2("racing step (end)");
return result;
}
@ -1213,7 +1213,7 @@ void LCR_physicsDebugDraw(LCR_GameUnit camPos[3], LCR_GameUnit camRot[2],
LCR_GameUnit camFov)
{
#if LCR_SETTING_DEBUG_PHYSICS_DRAW
LCR_LOG2("drawing physics debug overlay");
LCR_LOG2("drawing physics debug");
TPE_Vec3 cPos, cRot, cView;

View file

@ -1745,6 +1745,8 @@ void LCR_rendererDrawMenu(const char *tabName,const char **items,
int i = 0;
uint16_t effect = LCR_renderer.frame >> 1;
LCR_LOG2("drawing menu");
while (i < stripHeight * LCR_EFFECTIVE_RESOLUTION_X)
{
LCR_drawPixel(i,0x8ddc
@ -1818,7 +1820,9 @@ void LCR_rendererDrawMenu(const char *tabName,const char **items,
LCR_renderer.frame++;
}
// TODO: what is this function even doing?
/**
Resets camera rotation and places it behind the car.
*/
void LCR_rendererCameraReset(void)
{
LCR_renderer.scene.camera.transform.translation =
@ -1844,7 +1848,7 @@ void LCR_rendererSetWheelState(LCR_GameUnit rotation, LCR_GameUnit steer)
#endif
}
void LCR_rendererDraw(void)
void LCR_rendererDraw3D(void)
{
LCR_LOG2("rendering frame (start)");
@ -1871,7 +1875,7 @@ void LCR_rendererDraw(void)
LCR_drawLevelFloor();
LCR_rendererDrawLOD();
LCR_LOG2("gonna render 3D scene");
LCR_LOG2("3D rendering (start)");
#if LCR_SETTING_POTATO_GRAPHICS
/* in potato mode we render twice so that car is always in front of the
@ -1897,10 +1901,9 @@ void LCR_rendererDraw(void)
S3L_drawScene(LCR_renderer.scene);
#endif
LCR_LOG2("rendering 3D scene done");
LCR_renderer.frame++;
LCR_LOG2("3D rendering (end)");
LCR_LOG2("rendering frame (end)");
}