Optimize a bit

This commit is contained in:
Miloslav Ciz 2024-08-02 00:05:03 +02:00
parent 2241b4d635
commit 880ae3c805
6 changed files with 120 additions and 25 deletions

57
map.h
View file

@ -82,12 +82,12 @@
#define LCR_BLOCK_RAMP_CURVED_SHORT 0x08
#define LCR_BLOCK_RAMP_CURVED_WALL 0x09
#define LCR_BLOCK_FULL_ACCEL 0x40
#define LCR_BLOCK_FULL_STICKER 0x60
#define LCR_BLOCK_FULL_ACCEL 0x20
#define LCR_BLOCK_FULL_STICKER 0x30
#define LCR_BLOCK_CHECKPOINT_0 0x10 ///< checkpoint, not taken
#define LCR_BLOCK_CHECKPOINT_1 0x11 ///< checkpoint, taken
#define LCR_BLOCK_FINISH 0x12 ///< finish
#define LCR_BLOCK_CHECKPOINT_0 0x40 ///< checkpoint, not taken
#define LCR_BLOCK_CHECKPOINT_1 0x41 ///< checkpoint, taken
#define LCR_BLOCK_FINISH 0x42 ///< finish
// special blocks:
#define LCR_BLOCK_NONE 0x80 /**< no block, can be used e.g to make
@ -130,6 +130,15 @@ static const uint8_t *LCR_maps[LCR_MAP_COUNT] =
LCR_map0
};
void LCR_makeMapBlock(uint8_t type, uint8_t x, uint8_t y, uint8_t z,
uint8_t material, uint8_t transform, uint8_t block[LCR_BLOCK_SIZE])
{
block[0] = type;
block[1] = x | (y << 6);
block[2] = (y >> 2) | (z << 4);
block[3] = (z >> 4) | (material << 2) | transform;
}
void LCR_mapBlockGetCoords(const uint8_t block[LCR_BLOCK_SIZE],
uint8_t *x, uint8_t *y, uint8_t *z)
{
@ -273,8 +282,42 @@ uint8_t LCR_mapLoad(const uint8_t *map)
while (*map != LCR_MAP_TERMINATOR)
{
if (!_LCR_mapAddBlock(map))
return 0;
switch (*map)
{
case LCR_BLOCK_CUBOID_FILL:
{
const uint8_t *prevBlock = map - LCR_BLOCK_SIZE;
uint8_t x, y, z, w, h, d, mat, transform;
uint8_t tmpBlock[LCR_BLOCK_SIZE];
if (LCR_currentMap.blockCount == 0 || (prevBlock[0] & 0x80))
return 0;
mat = LCR_mapBlockGetMaterial(prevBlock);
transform = LCR_mapBlockGetTransform(prevBlock);
LCR_mapBlockGetCoords(prevBlock,&x,&y,&z);
LCR_mapBlockGetCoords(map,&w,&h,&d);
for (uint8_t k = 0; k < d; ++k)
for (uint8_t j = 0; j < h; ++j)
for (uint8_t i = 0; i < w; ++i)
{
LCR_makeMapBlock(prevBlock[0],x + i,y + j,z + k,mat,transform,
tmpBlock);
if (!_LCR_mapAddBlock(tmpBlock))
return 0;
}
break;
}
default:
if (!_LCR_mapAddBlock(map)) // normal block
return 0;
break;
}
map += 4;
}