From 69d87ab26d5bca40f8c0a23d941b9ea5f58f53d1 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Fri, 27 Dec 2024 09:06:21 +0100 Subject: [PATCH] Rework map string --- assets.h | 58 ++++++++++++++-------------- game.h | 18 +++++++-- map.h | 112 +++++++++++++++++-------------------------------------- 3 files changed, 79 insertions(+), 109 deletions(-) diff --git a/assets.h b/assets.h index 3fc8cce..72a5ea1 100644 --- a/assets.h +++ b/assets.h @@ -18,46 +18,46 @@ static const char *LCR_maps[] = { - "LM;;;0;#*H1k0J" + "0 :*H1k0J" - "#=s0s0 #fd190" // big concrete + ":=s0s0 :fd190" // big concrete - "#+v0n0" - "#+w0o0" - "#!x0n0" + ":+v0n0" + ":+w0o0" + ":!x0n0" - "#=s0B0 #fd910" // concrete wall - "#^s1A0 #fk110" // ramps before wall + ":=s0B0 :fd910" // concrete wall + ":^s1A0 :fk110" // ramps before wall - "#nu0j1 #ly0j1 #AA0j1 " + ":nu0j1 :ly0j1 :AA0j1 " - "#vw0m0" - "#vx0m0J" - "#vw0l0L" - "#vx0l0I" + ":vw0m0" + ":vx0m0J" + ":vw0l0L" + ":vx0l0I" - "#-s0q0" + ":-s0q0" - "#;p0w0L #f5130" // bugs + ":;p0w0L :f5130" // bugs - "#>f0s0 #fd110" // small labyrinth - "#oc0p0 #fd110" - "#=f0s0 #f11d0" - "#=c0p0 #f11d0" + ":>f0s0 :fd110" // small labyrinth + ":oc0p0 :fd110" + ":=f0s0 :f11d0" + ":=c0p0 :f11d0" - "#=C0s1 #fd190" // big dirt - "#=M0s2 #fd190" // big grass - "#=W0s3 #fd190" // big ice + ":=C0s1 :fd190" // big dirt + ":=M0s2 :fd190" // big grass + ":=W0s3 :fd190" // big ice - "#(s0r0" // hill - "#~t1t2 #~u1t2 #~t1u2" // bumps - "#^t0r0 #fq110 " // ramps + ":(s0r0" // hill + ":~t1t2 :~u1t2 :~t1u2" // bumps + ":^t0r0 :fq110 " // ramps - "#}n0l0J #|n1l0J #|n3l0J- #]n4l0J- #=o0l0 #f1510" // loop - "#]n0m0J #|n1m0J #|n3m0J- #]n4m0J- #=o0m0 #f1510" // loop - "#}l0k0L #|l1k0L #|l3k0L- #]l4k0L- #=k0k0 #f1510" - "#]l0j0L #|l1j0L #|l3j0L- #]l4j0L- #=k0j0 #f1510" - "#-k5k0 #f5120" + ":}n0l0J :|n1l0J :|n3l0J- :]n4l0J- :=o0l0 :f1510" // loop + ":]n0m0J :|n1m0J :|n3m0J- :]n4m0J- :=o0m0 :f1510" // loop + ":}l0k0L :|l1k0L :|l3k0L- :]l4k0L- :=k0k0 :f1510" + ":]l0j0L :|l1j0L :|l3j0L- :]l4j0L- :=k0j0 :f1510" + ":-k5k0 :f5120" }; #define LCR_IMAGE_SIZE 64 ///< one-dimension resolution of bitmap image diff --git a/game.h b/game.h index 11ec2ef..53f4aba 100644 --- a/game.h +++ b/game.h @@ -224,14 +224,26 @@ void LCR_gameResetRun(void) LCR_gameSetState(LCR_GAME_STATE_RUN_STARTING); } -void LCR_gameStartRun(const char *mapStr) + + +int aaaa = 0; // tmp +char aaa(void) { - LCR_mapLoadFromStr(mapStr); + return LCR_maps[0][aaaa++]; +} + + + +void LCR_gameStartRun(void) +{ + LCR_mapLoadFromStr(aaa); LCR_rendererLoadMap(); LCR_gameResetRun(); LCR_racingRestart(); } + + void LCR_gameInit(void) { LCR_LOG0("initializing"); @@ -247,7 +259,7 @@ void LCR_gameInit(void) LCR_game.nextRenderFrameTime = 0; LCR_game.nextRacingTickTime = 0; LCR_game.controlMode = LCR_CONTROL_MODE_FREECAM; - LCR_gameStartRun(LCR_maps[0]); + LCR_gameStartRun(); } void LCR_gameEnd(void) diff --git a/map.h b/map.h index d185861..a548f8c 100644 --- a/map.h +++ b/map.h @@ -17,16 +17,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: - - Magic number string: "LM;". - - Until next ';': name. - - Until next ';': description. - - Until next ';': tags. Currently this may contain the following: - - digit N: set the map environment to N. - - Then a series of block strings follows. Blocks may be separated by - characters that aren't '#' (comments may be added this way). Block format + - 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: - #BXYZMT + :BXYZMT where: - B is block type @@ -60,6 +56,8 @@ - last if C7 is set, the block is flipped vertically */ +#define LCR_BLOCK_START_CHAR ':' + #define LCR_BLOCK_TRANSFORM_FLIP_H 0x10 #define LCR_BLOCK_TRANSFORM_ROT_90 0x20 #define LCR_BLOCK_TRANSFORM_ROT_180 0x40 @@ -68,12 +66,6 @@ #define LCR_BLOCK_XYZ_TO_COORD(x,y,z) // ??? -#define LCR_MAP_MAGIC_NUMBER1 'L' -#define LCR_MAP_MAGIC_NUMBER2 'M' -#define LCR_MAP_SEPARATOR ';' - -#define LCR_MAP_MAGIC_NUMBER LCR_MAP_MAGIC_NUMBER1, LCR_MAP_MAGIC_NUMBER2 -#define LCR_MAP_TERMINATOR 0xff #define LCR_MAP_BLOCK(t,x,y,z,m,r) t,(uint8_t) (x | (y << 6)), \ (uint8_t) ((y >> 2) | (z << 4)), \ (uint8_t) ((z >> 4) | (m << 2) | (r)) @@ -361,10 +353,12 @@ int _LCR_mapCharToCoord(char c) return -1; } -uint8_t LCR_mapLoadFromStr(const char *mapStr) +uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void)) { LCR_LOG0("loading map string"); + char c; + uint8_t prevBlock[LCR_BLOCK_SIZE]; prevBlock[0] = LCR_BLOCK_NONE; @@ -375,65 +369,29 @@ uint8_t LCR_mapLoadFromStr(const char *mapStr) LCR_currentMap.blockCount = 0; LCR_currentMap.environment = 0; - if (mapStr[0] != LCR_MAP_MAGIC_NUMBER1 || mapStr[1] != LCR_MAP_MAGIC_NUMBER2 - || mapStr[2] != LCR_MAP_SEPARATOR) + c = getNextCharFunc(); + + if (c < '0' || c > '3') { - LCR_LOG0("bad magic number"); + LCR_LOG0("bad environment char"); return 0; } - mapStr += 3; + LCR_currentMap.environment = c - '0'; - while (*mapStr != LCR_MAP_SEPARATOR) // read map name + while (c) { - if (mapStr[0] == 0) - return 0; - - // TODO - mapStr++; - } - - mapStr++; - - while (*mapStr != LCR_MAP_SEPARATOR) // read map description - { - if (mapStr[0] == 0) - return 0; - - // TODO - mapStr++; - } - - mapStr++; - - while (*mapStr != LCR_MAP_SEPARATOR) // read map tags - { - if (mapStr[0] >= '0' && mapStr[0] <= '9') - LCR_currentMap.environment = mapStr[0] - '0'; - else if (mapStr[0] == 0) - return 0; - - // TODO - mapStr++; - } - - mapStr++; - - while (*mapStr) - { - if (*mapStr == '#') + if (c == LCR_BLOCK_START_CHAR) { - mapStr++; - - uint8_t block = *mapStr; + uint8_t block = getNextCharFunc(); uint8_t trans = 0; uint8_t mat = 0; int coords[3]; for (int i = 0; i < 3; ++i) { - mapStr++; - coords[i] = _LCR_mapCharToCoord(*mapStr); + c = getNextCharFunc(); + coords[i] = _LCR_mapCharToCoord(c); if (coords[i] < 0) { @@ -442,35 +400,36 @@ uint8_t LCR_mapLoadFromStr(const char *mapStr) } } - mapStr++; + c = getNextCharFunc(); - if (*mapStr >= '0' && *mapStr <= '3') - mat = *mapStr - '0'; - else + if (c < '0' || c > '3') { LCR_LOG0("bad material"); return 0; } - - mapStr++; + mat = c - '0'; + while (1) { - if (*mapStr == '|') + c = getNextCharFunc(); + + if (c == '|') trans |= LCR_BLOCK_TRANSFORM_FLIP_H; - else if (*mapStr == '-') + else if (c == '-') trans |= LCR_BLOCK_TRANSFORM_FLIP_V; - else if (*mapStr == 'L') + else if (c == 'L') trans |= LCR_BLOCK_TRANSFORM_ROT_90; - else if (*mapStr == 'I') + else if (c == 'I') trans |= LCR_BLOCK_TRANSFORM_ROT_180; - else if (*mapStr == 'J') + else if (c == 'J') trans |= LCR_BLOCK_TRANSFORM_ROT_270; else break; - - mapStr++; } + + while (c && c != LCR_BLOCK_START_CHAR) + c = getNextCharFunc(); switch (block) { @@ -527,9 +486,8 @@ uint8_t LCR_mapLoadFromStr(const char *mapStr) // TODO: check for invalid blocks? } } - - if (*mapStr != '#') - mapStr++; + else + c = getNextCharFunc(); } LCR_LOG2("clearing map block cache")