Fix adding blocks
This commit is contained in:
parent
9fc88a91af
commit
30c9a55cb5
3 changed files with 25 additions and 41 deletions
42
map.h
42
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue