Start block collisions
This commit is contained in:
parent
c0aa81e79e
commit
e068b02b9f
5 changed files with 159 additions and 11 deletions
47
map.h
47
map.h
|
@ -163,6 +163,13 @@ uint32_t LCR_mapBlockGetCoordNumber(const uint8_t block[LCR_BLOCK_SIZE])
|
|||
((((uint32_t) block[3]) & 0x3) << 16);
|
||||
}
|
||||
|
||||
uint32_t LCR_mapBlockCoordsToCoordNumber(uint8_t x, uint8_t y, uint8_t z)
|
||||
{
|
||||
uint8_t b[LCR_BLOCK_SIZE];
|
||||
LCR_makeMapBlock(0,x,y,z,0,0,b);
|
||||
return LCR_mapBlockGetCoordNumber(b);
|
||||
}
|
||||
|
||||
uint8_t *LCR_getMapBlockAtCoordNumber(uint32_t coord)
|
||||
{
|
||||
// binary search the block:
|
||||
|
@ -339,12 +346,44 @@ uint8_t LCR_mapLoad(const uint8_t *map)
|
|||
}
|
||||
|
||||
/**
|
||||
Gets a pointer to a map block of the currently loaded map at given
|
||||
coordinates. If there is no block at given coordinates, 0 is returned.
|
||||
Same as LCR_mapGetBlockAt, but allows to specify start and end block of the
|
||||
of the search to make it faster.
|
||||
*/
|
||||
const uint8_t *LCR_mapGetBlockAt(uint8_t x, uint8_t y, uint8_t z)
|
||||
int LCR_mapGetBlockAtFast(uint8_t x, uint8_t y, uint8_t z,
|
||||
int start, int end)
|
||||
{
|
||||
return 0;
|
||||
// binary search (the blocks are sorted)
|
||||
|
||||
uint32_t n = LCR_mapBlockCoordsToCoordNumber(x,y,z);
|
||||
|
||||
while (start <= end)
|
||||
{
|
||||
int m = (start + end) / 2;
|
||||
|
||||
uint32_t n2 = LCR_mapBlockGetCoordNumber(
|
||||
LCR_currentMap.blocks + m * LCR_BLOCK_SIZE);
|
||||
|
||||
if (n2 < n)
|
||||
start = m + 1;
|
||||
else if (n2 > n)
|
||||
end = m - 1;
|
||||
else
|
||||
return m;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
Gets an index to a map block of the currently loaded map at given
|
||||
coordinates. If there is no block at given coordinates, -1 is returned.
|
||||
*/
|
||||
int LCR_mapGetBlockAt(uint8_t x, uint8_t y, uint8_t z)
|
||||
{
|
||||
if (LCR_currentMap.blockCount == 0)
|
||||
return -1;
|
||||
|
||||
return LCR_mapGetBlockAtFast(x,y,z,0,LCR_currentMap.blockCount - 1);
|
||||
}
|
||||
|
||||
uint8_t _LCR_encodeMapBlockCoords(uint8_t x, uint8_t y, uint8_t z)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue