From 30c9a55cb5604430035f3719500f0af574803769 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Mon, 16 Dec 2024 20:17:58 +0100 Subject: [PATCH] Fix adding blocks --- TODO.txt | 23 ++++++++++++----------- assets.h | 1 + map.h | 42 ++++++++++++------------------------------ 3 files changed, 25 insertions(+), 41 deletions(-) diff --git a/TODO.txt b/TODO.txt index dca7ca3..7bdfba9 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,17 +1,12 @@ =========== GENERAL ============== -- rework the code for special blocks, we have to literally remember the last - block, not the pointer, now it won't work e.g. if wanting to repeat an - empty block -- allow stopping car rotation in air like in Trackmania -- maybe allow some more air control, like slowing down with brakes, like in TM - sound engine: probably all SFX will be procedurally generated, ok? +- allow slowing down in air like in TM? - music? - probably just make one long track, literally OGG or something, then make that be played by the frontend just ALL the time (maybe with the option in menu to just turn music off) -- simple frontends can just ignore music - allow car to be flipped upside down on start? with start block transform -- map actually in ASCII format? how will humans edit it? - make a simple rendering setting: - will exclude images and only draw solid colors, let's say only 16, so that memory usage is reduced, CPU rendering is relieved, executable is smaller @@ -28,11 +23,6 @@ floor texture? pretty KISS. SKY DOESN'T HAVE TO BE SPHERICALLY MAPPED, it can simply rotate horizontally and shift vertically (camera will never roll) -- not accurate but good enough. <-- YES -- How to visually represent checkpoints (and finish)? - - Could be kind of an arrow made of single tri above the block? - (try how it looks in Blender) - - Probably just a literal block (or pyramid) DRAWN WITH DITHERING and/or - blinking <-- PROBABLY THIS - replay format =========== BUGS ================= @@ -42,8 +32,19 @@ =========== HANDLED ============== +- allow stopping car rotation in air like in Trackmania - drifting: passing some upper threshold on steering force should reduce steering friction until reaching some some lower threshold again probably +- maybe allow some more air control, like slowing down with brakes, like in TM +- map actually in ASCII format? how will humans edit it? +- rework the code for special blocks, we have to literally remember the last + block, not the pointer, now it won't work e.g. if wanting to repeat an + empty block +- How to visually represent checkpoints (and finish)? + - Could be kind of an arrow made of single tri above the block? + (try how it looks in Blender) + - Probably just a literal block (or pyramid) DRAWN WITH DITHERING and/or + blinking <-- PROBABLY THIS - EFFICINT MAP DRAWING: - map will be subdivided into subblocks (probably 16x16x16 or 8x8x8), only nearest subblocks (and possibly only those in viewing direction will be diff --git a/assets.h b/assets.h index f56a5a0..59c89f4 100644 --- a/assets.h +++ b/assets.h @@ -21,6 +21,7 @@ static const char *LCR_maps[] = "LM;;;0;#*H1k0J" "#=s0s0 #fd190" // big concrete + "#=s0B0 #fd910" // concrete wall "#^s1A0 #fk110" // ramps before wall diff --git a/map.h b/map.h index 29abb06..52146ab 100644 --- a/map.h +++ b/map.h @@ -110,8 +110,6 @@ #define LCR_BLOCK_CORNER_CONVEX 'n' #define LCR_BLOCK_CORNER_CONCAVE 'l' - - #define LCR_BLOCK_CHECKPOINT_0 '+' ///< checkpoint, not taken #define LCR_BLOCK_CHECKPOINT_1 '\'' ///< checkpoint, taken @@ -259,14 +257,14 @@ uint8_t *LCR_getMapBlockAtCoordNumber(uint32_t coord) adding LCR_BLOCK_NONE. The function handles sorting the block to the right position. Returns pointer to the block on success, else 0. */ -uint8_t *_LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE]) +void _LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE]) { LCR_LOG2("adding map block"); if (LCR_currentMap.blockCount >= LCR_SETTING_MAP_MAX_BLOCKS) { LCR_LOG0("couldn't add block"); - return 0; + return; } uint32_t coord = LCR_mapBlockGetCoordNumber(block); @@ -277,8 +275,6 @@ uint8_t *_LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE]) insertAt * LCR_BLOCK_SIZE)) insertAt++; - uint8_t *result = LCR_currentMap.blocks + insertAt * LCR_BLOCK_SIZE; - if (block[0] == LCR_BLOCK_NONE) { if (insertAt < LCR_currentMap.blockCount && @@ -286,14 +282,15 @@ uint8_t *_LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE]) insertAt * LCR_BLOCK_SIZE)) { // shift all left (remove the block): - for (uint16_t i = insertAt * LCR_BLOCK_SIZE; - i < LCR_currentMap.blockCount * LCR_BLOCK_SIZE - 1; ++i) - LCR_currentMap.blocks[i] = LCR_currentMap.blocks[i + 1]; + + for (int i = insertAt * LCR_BLOCK_SIZE; + i < (LCR_currentMap.blockCount - 1) * LCR_BLOCK_SIZE; ++i) + LCR_currentMap.blocks[i] = LCR_currentMap.blocks[i + LCR_BLOCK_SIZE]; LCR_currentMap.blockCount--; } - return result; + return; } if (insertAt == LCR_currentMap.blockCount || @@ -315,8 +312,6 @@ uint8_t *_LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE]) for (uint8_t j = 0; j < LCR_BLOCK_SIZE; ++j) LCR_currentMap.blocks[insertAt + j] = block[j]; - - return result; } /** @@ -355,7 +350,8 @@ uint8_t LCR_mapLoadFromStr(const char *mapStr) { LCR_LOG0("loading map string"); - const uint8_t *prevBlock = 0; + uint8_t prevBlock[LCR_BLOCK_SIZE]; + prevBlock[0] = LCR_BLOCK_NONE; for (int i = 0; i < 4; ++i) LCR_currentMap.startPos[i] = 0; @@ -469,12 +465,6 @@ uint8_t LCR_mapLoadFromStr(const char *mapStr) uint8_t x, y, z, mat, transform; uint8_t tmpBlock[LCR_BLOCK_SIZE]; - if (prevBlock == 0 || LCR_currentMap.blockCount == 0) - { - LCR_LOG0("no previous block"); - return 0; - } - mat = LCR_mapBlockGetMaterial(prevBlock); transform = LCR_mapBlockGetTransform(prevBlock); LCR_mapBlockGetCoords(prevBlock,&x,&y,&z); @@ -493,10 +483,7 @@ uint8_t LCR_mapLoadFromStr(const char *mapStr) LCR_makeMapBlock(prevBlock[0],x + i,y + j,z + k,mat,transform, tmpBlock); - prevBlock = _LCR_mapAddBlock(tmpBlock); - - if (!prevBlock) - return 0; + _LCR_mapAddBlock(tmpBlock); } break; @@ -514,15 +501,10 @@ uint8_t LCR_mapLoadFromStr(const char *mapStr) // fall through default: // normal block { - uint8_t tmpBlock[LCR_BLOCK_SIZE]; - LCR_makeMapBlock(block,coords[0],coords[1],coords[2],mat,trans, - tmpBlock); + prevBlock); - prevBlock = _LCR_mapAddBlock(tmpBlock); - - if (prevBlock == 0) - return 0; + _LCR_mapAddBlock(prevBlock); break; }