Add map target time

This commit is contained in:
Miloslav Ciz 2025-01-15 21:29:38 +01:00
parent ea57ecd470
commit 9d2c6108b1
3 changed files with 60 additions and 35 deletions

View file

@ -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

53
game.h
View file

@ -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;
}

22
map.h
View file

@ -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')