From 614741f6e8126ec7f30ac3ca67534e1c9d4bac04 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Wed, 8 Jan 2025 21:28:01 +0100 Subject: [PATCH] Clean a bit --- assets.h | 8 ++++++-- audio.h | 26 +++++++------------------- constants.h | 5 +++++ game.h | 22 ++++++---------------- renderer.h | 9 ++++++--- settings.h | 6 ++++++ 6 files changed, 36 insertions(+), 40 deletions(-) diff --git a/assets.h b/assets.h index b324d48..cf11b5f 100644 --- a/assets.h +++ b/assets.h @@ -18,19 +18,23 @@ static const char *LCR_texts[] = { - // menu tabs: +#define LCR_TEXTS_VERSION 0 + "0.5d", // version string + +#define LCR_TEXTS_TABS 1 "main menu", "play map", "view repl", "play repl", - // main menu items: +#define LCR_TEXTS_MAIN_MENU 5 "camera: $", "music: $", "sound: $", "save repl", "exit", +#define LCR_TEXTS_LOADING 10 "loading" }; diff --git a/audio.h b/audio.h index 33179a2..7085859 100644 --- a/audio.h +++ b/audio.h @@ -13,7 +13,6 @@ #define LCR_AUDIO_CRASH_LEN 2048 - struct { uint32_t frame; @@ -21,20 +20,12 @@ struct uint8_t soundPlayed; uint16_t soundPlayedFrame; uint32_t noise; - -uint8_t crashSample; - - -int engineIntensity; -int engineOsc; -int engineInc; - - + uint8_t crashSample; + int engineIntensity; + int engineOsc; + int engineInc; } LCR_audio; - - - void LCR_audioInit(void) { LCR_LOG0("initializing audio"); @@ -123,9 +114,7 @@ uint8_t LCR_audioGetNextSample(void) LCR_audio.soundPlayedFrame++; else if (LCR_audio.engineIntensity) { - LCR_audio.engineOsc += - LCR_audio.engineInc ? - (((_LCR_audioNoise() % 256) < + LCR_audio.engineOsc += LCR_audio.engineInc ? (((_LCR_audioNoise() % 256) < (10 + LCR_audio.engineIntensity))) : -31; if (LCR_audio.engineInc && LCR_audio.engineOsc > @@ -134,9 +123,8 @@ uint8_t LCR_audioGetNextSample(void) else if ((!LCR_audio.engineInc) && LCR_audio.engineOsc < 10) LCR_audio.engineInc = 1; - result += - LCR_audio.engineIntensity < 20 ? - LCR_audio.engineOsc / 2 : LCR_audio.engineOsc; + result += LCR_audio.engineIntensity < 20 ? + LCR_audio.engineOsc / 2 : LCR_audio.engineOsc; } LCR_audio.frame++; diff --git a/constants.h b/constants.h index c1d144b..0cdd2ca 100644 --- a/constants.h +++ b/constants.h @@ -36,4 +36,9 @@ #define LCR_RESOURCE_FILE_SEPARATOR '#' #define LCR_RESOURCE_FILE_SEPARATOR2 ';' +#define LCR_MENU_MAX_ITEMS 9 // don't change +#define LCR_RESOURCE_ITEM_CHUNK (LCR_MENU_MAX_ITEMS - 1) +#define LCR_MENU_TABS 4 +#define LCR_MENU_STRING_SIZE 16 + #endif diff --git a/game.h b/game.h index d45df51..e596a26 100644 --- a/game.h +++ b/game.h @@ -180,14 +180,6 @@ uint8_t LCR_gameGetNextAudioSample(void); #define LCR_GAME_STATE_LOADING_MAP 0x04 #define LCR_GAME_STATE_END 0xff -// TODO: move to consts? -#define LCR_MENU_MAX_ITEMS 9 // don't change -#define LCR_RESOURCE_ITEM_CHUNK (LCR_MENU_MAX_ITEMS - 1) -#define LCR_MENU_TABS 4 -#define LCR_MENU_STRING_SIZE 16 - - - struct { uint8_t state; @@ -214,8 +206,6 @@ struct const char *itemNamePtrs[LCR_MENU_MAX_ITEMS]; ///< helper array } menu; - // TODO: make menu struct? - struct { int state; ///< -1 if reading external res. f., else pos. @@ -422,7 +412,7 @@ void LCR_gameLoadMainMenuItems(void) char replaceChar = i == 0 ? '0' + LCR_game.cameraMode : (i == 1 ? '0' + LCR_game.musicOn : ('0' + LCR_audio.on)); - LCR_gameSetMenuItemStr(i,LCR_texts[4 + i],replaceChar); + LCR_gameSetMenuItemStr(i,LCR_texts[LCR_TEXTS_MAIN_MENU + i],replaceChar); } LCR_game.menu.itemCount = 4; @@ -907,9 +897,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.menu.selectedTab], - LCR_game.menu.itemNamePtrs,LCR_game.menu.itemCount + 1, - LCR_game.menu.selectedItem); + LCR_rendererDrawMenu(LCR_texts[LCR_TEXTS_TABS + + LCR_game.menu.selectedTab],LCR_game.menu.itemNamePtrs, + LCR_game.menu.itemCount + 1,LCR_game.menu.selectedItem); else LCR_gameDraw3DView(); } @@ -930,9 +920,9 @@ uint8_t LCR_gameStep(uint32_t time) LCR_EFFECTIVE_RESOLUTION_Y - 2 * LCR_EFFECTIVE_RESOLUTION_Y / 3, 0xffff,0); - LCR_rendererDrawText(LCR_texts[9], + LCR_rendererDrawText(LCR_texts[LCR_TEXTS_LOADING], (LCR_EFFECTIVE_RESOLUTION_X - - LCR_rendererComputeTextWidth(LCR_texts[9],4)) / 2, + LCR_rendererComputeTextWidth(LCR_texts[LCR_TEXTS_LOADING],4)) / 2, (LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(4)) / 2,0x0000,4); } diff --git a/renderer.h b/renderer.h index 3687cdf..e1d2813 100644 --- a/renderer.h +++ b/renderer.h @@ -1444,7 +1444,7 @@ S3L_Unit _LCR_rendererSmoothRot(S3L_Unit angleOld, S3L_Unit angleNew, /** Loads the map models with 8 chunks that are nearest to a certain point - towards which camera is looking. + towards which the camera is looking. */ void _LCR_rendererLoadMapChunks(void) { @@ -1787,7 +1787,9 @@ void LCR_rendererDrawMenu(const char *tabName,const char **items, LCR_IMAGE_SIZE * (stripHeight / LCR_IMAGE_SIZE)) / 2,0, stripHeight / LCR_IMAGE_SIZE,0xffff); #endif - + + LCR_rendererDrawText(LCR_texts[LCR_TEXTS_VERSION],5,5,0xffff,2); + LCR_renderer.frame++; } @@ -1837,7 +1839,8 @@ void LCR_rendererDraw3D(void) _LCR_rendererAnimateCar(); #endif - _LCR_rendererLoadMapChunks(); // TODO: call only once in a while? + if (LCR_renderer.frame % LCR_SETTING_MAP_CHUNK_RELOAD_INTERVAL == 0) + _LCR_rendererLoadMapChunks(); LCR_rendererDrawSky(LCR_currentMap.environment, LCR_renderer.scene.camera.transform.rotation.y, diff --git a/settings.h b/settings.h index 0ada35d..62ed9a9 100644 --- a/settings.h +++ b/settings.h @@ -187,4 +187,10 @@ #define LCR_SETTING_COUNTDOWN_SECONDS 1 // for release make 3 #endif +#ifndef LCR_SETTING_MAP_CHUNK_RELOAD_INTERVAL + /** Interval in rendering frames of reloading map chunks, should ideally be + kept a power of two, can't be 0. */ + #define LCR_SETTING_MAP_CHUNK_RELOAD_INTERVAL 16 +#endif + #endif // guard