From 9d2c6108b1b6f2f5b3393240c637c28ae7c39e34 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Wed, 15 Jan 2025 21:29:38 +0100 Subject: [PATCH] Add map target time --- assets.h | 20 ++++++++++---------- game.h | 53 ++++++++++++++++++++++++++++++++--------------------- map.h | 22 ++++++++++++++++++---- 3 files changed, 60 insertions(+), 35 deletions(-) diff --git a/assets.h b/assets.h index 8380ab5..d513f01 100644 --- a/assets.h +++ b/assets.h @@ -42,7 +42,7 @@ static const char *LCR_texts[] = static const char *LCR_internalResourceFile = "Mtestmap;" - "1 :*H1k0" + "52123 1 :*H1k0" ":=s0s0 :fd190" // big concrete @@ -84,16 +84,16 @@ static const char *LCR_internalResourceFile = ":-k5k0 :f5120" " map end " - "#Mmap2;1 :*H1k0J :,s0s0 :fd190 " + "#Mmap2;4321 1 :*H1k0J :,s0s0 :fd190 " "#Rtestrepl;aaa#Rrepl2;" - "#Mmap3;1 :*H1k0J :,s0s0 :fd190 " - "#Mmap4;1 :*H1k0J :,s0s0 :fd190 " - "#Mmap5;1 :*H1k0J :,s0s0 :fd190 " - "#Mmap6;1 :*H1k0J :,s0s0 :fd190 " - "#Mmap7;1 :*H1k0J :,s0s0 :fd190 " - "#Mmap8;1 :*H1k0J :,s0s0 :fd190 " - "#Mmap9;1 :*H1k0J :,s0s0 :fd190 " - "#Mmap10;1 :*H1k0J :,s0s0 :fd190 " + "#Mmap3;4321 1 :*H1k0J :,s0s0 :fd190 " + "#Mmap4;4321 1 :*H1k0J :,s0s0 :fd190 " + "#Mmap5;4321 1 :*H1k0J :,s0s0 :fd190 " + "#Mmap6;4321 1 :*H1k0J :,s0s0 :fd190 " + "#Mmap7;4321 1 :*H1k0J :,s0s0 :fd190 " + "#Mmap8;4321 1 :*H1k0J :,s0s0 :fd190 " + "#Mmap9;4321 1 :*H1k0J :,s0s0 :fd190 " + "#Mmap10;4321 1 :*H1k0J :,s0s0 :fd190 " ; #define LCR_IMAGE_SIZE 64 ///< one-dimension resolution of bitmap image diff --git a/game.h b/game.h index 2a42d54..20b2fc7 100644 --- a/game.h +++ b/game.h @@ -560,6 +560,31 @@ void LCR_gameEnd(void) LCR_LOG0("ending"); } + + +void LCR_gameTimeToStr(uint32_t timeMS, char *str) +{ + str[9] = 0; + + str[6] = '0' + timeMS % 10; // milliseconds + timeMS /= 10; + str[7] = '0' + timeMS % 10; + timeMS /= 10; + str[8] = '0' + timeMS % 10; + timeMS /= 10; + + str[3] = '0' + (timeMS % 60) / 10; // seconds + str[4] = '0' + timeMS % 10; + str[5] = '\''; + + timeMS = (timeMS / 60) % 100; // minutes + + str[0] = '0' + timeMS / 10; + str[1] = '0' + timeMS % 10; + str[2] = '\''; +} + + void LCR_gameDraw3DView(void) { LCR_GameUnit carTransform[6]; @@ -626,29 +651,15 @@ void LCR_gameDraw3DView(void) LCR_EFFECTIVE_RESOLUTION_Y - LCR_rendererComputeTextHeight(2) - 20,0,2); - val = LCR_game.runTimeMS; - - str[9] = 0; - - str[6] = '0' + val % 10; // milliseconds - val /= 10; - str[7] = '0' + val % 10; - val /= 10; - str[8] = '0' + val % 10; - val /= 10; - - str[3] = '0' + (val % 60) / 10; // seconds - str[4] = '0' + val % 10; - str[5] = '\''; - - val = (val / 60) % 100; // minutes - - str[0] = '0' + val / 10; - str[1] = '0' + val % 10; - str[2] = '\''; + LCR_gameTimeToStr(LCR_game.runTimeMS,str); LCR_rendererDrawText(str,20,LCR_EFFECTIVE_RESOLUTION_Y - - LCR_rendererComputeTextHeight(2) - 20,0,2); + LCR_rendererComputeTextHeight(2) - 45,0,2); + + LCR_gameTimeToStr(LCR_currentMap.targetTime,str); + + LCR_rendererDrawText(str,20,LCR_EFFECTIVE_RESOLUTION_Y - + LCR_rendererComputeTextHeight(2) - 20,0x4208,2); break; } diff --git a/map.h b/map.h index 7387150..7e558e0 100644 --- a/map.h +++ b/map.h @@ -13,10 +13,12 @@ The TEXT format serves for editing maps in human readable format, it more or less corresponds to the binary storage format (below) with some exceptions. It has the following structure: - - Number specifying environment (0, 1, 2, ...) - - A series of block strings. Blocks may be separated by characters that - aren't ':' (comments may be added this way). Block format - is following: + - Target time as a decimal number of milliseconds. + - Non-decimal character. + - Number of environment (0, 1, 2, ...) + - A series of block strings. Blocks may be preceded/followed by characters + that aren't ':' (comments may be added this way). Block format is + following: :BXYZMT @@ -153,6 +155,7 @@ struct uint8_t checkpointCount; uint32_t hash; ///< Hash of the processed binary map. + uint32_t targetTime; char name[LCR_MAP_NAME_MAX_LEN + 1]; } LCR_currentMap; @@ -398,11 +401,22 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name) for (int i = 0; i < 4; ++i) LCR_currentMap.startPos[i] = 0; + LCR_currentMap.targetTime = 0; LCR_currentMap.checkpointCount = 0; LCR_currentMap.blockCount = 0; LCR_currentMap.environment = 0; LCR_currentMap.hash = 0; + while (1) // read target time + { + c = getNextCharFunc(); + + if (c >= '0' && c <= '9') + LCR_currentMap.targetTime = LCR_currentMap.targetTime * 10 + c - '0'; + else + break; + } + c = getNextCharFunc(); if (c < '0' || c > '3')