Handle start position
This commit is contained in:
parent
34293981b0
commit
beda272f18
4 changed files with 146 additions and 162 deletions
61
map.h
61
map.h
|
@ -104,7 +104,7 @@ struct
|
|||
{
|
||||
uint16_t blockCount;
|
||||
uint8_t blocks[LCR_SETTING_MAP_MAX_BLOCKS * LCR_BLOCK_SIZE];
|
||||
uint32_t startPos;
|
||||
uint8_t startPos[4]; ///< Initial position and rotation.
|
||||
|
||||
uint8_t environment;
|
||||
|
||||
|
@ -227,6 +227,8 @@ uint8_t *LCR_getMapBlockAtCoordNumber(uint32_t coord)
|
|||
*/
|
||||
uint8_t _LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE])
|
||||
{
|
||||
LCR_LOG2("adding map block");
|
||||
|
||||
if (LCR_currentMap.blockCount >= LCR_SETTING_MAP_MAX_BLOCKS)
|
||||
return 0;
|
||||
|
||||
|
@ -283,7 +285,11 @@ uint8_t _LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE])
|
|||
*/
|
||||
uint8_t LCR_mapLoad(const uint8_t *map)
|
||||
{
|
||||
LCR_currentMap.startPos = 0;
|
||||
LCR_LOG0("loading map")
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
LCR_currentMap.startPos[i] = 0;
|
||||
|
||||
LCR_currentMap.blockCount = 0;
|
||||
|
||||
if (map[0] != LCR_MAP_MAGIC_NUMBER1 || map[1] != LCR_MAP_MAGIC_NUMBER2)
|
||||
|
@ -348,6 +354,15 @@ uint8_t LCR_mapLoad(const uint8_t *map)
|
|||
break;
|
||||
}
|
||||
|
||||
case LCR_BLOCK_START:
|
||||
LCR_mapBlockGetCoords(map,
|
||||
LCR_currentMap.startPos,
|
||||
LCR_currentMap.startPos + 1,
|
||||
LCR_currentMap.startPos + 2);
|
||||
|
||||
LCR_currentMap.startPos[3] = LCR_mapBlockGetTransform(map) & 0x60;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!_LCR_mapAddBlock(map)) // normal block
|
||||
return 0;
|
||||
|
@ -355,16 +370,10 @@ uint8_t LCR_mapLoad(const uint8_t *map)
|
|||
break;
|
||||
}
|
||||
|
||||
map += 4;
|
||||
map += LCR_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
// process and remove special blocks:
|
||||
|
||||
// TODO
|
||||
|
||||
// sort the blocks (for fast searching):
|
||||
|
||||
// TODO
|
||||
|
||||
LCR_LOG2("map loaded")
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -447,8 +456,9 @@ void _LCR_addBlockShapeByte(uint8_t *bytes, uint8_t *byteCount,
|
|||
*byteCount += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Macro that transforms coordinates according to block transformation.
|
||||
*/
|
||||
#define LCR_TRANSFORM_COORDS(trans,cx,cy,cz,maxXZ,maxY)\
|
||||
if (trans & LCR_BLOCK_TRANSFORM_FLIP_H) cx = maxXZ - cx;\
|
||||
if (trans & 0x20) { /* for both 90 and 270 */ \
|
||||
|
@ -460,8 +470,6 @@ void _LCR_addBlockShapeByte(uint8_t *bytes, uint8_t *byteCount,
|
|||
if (trans & LCR_BLOCK_TRANSFORM_FLIP_V) \
|
||||
cy = maxY - cy;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Gets a shape of given map block type as a 3D model composed of triangles. The
|
||||
model is returned as an array of byte triplets (triangles), with each byte
|
||||
|
@ -584,28 +592,7 @@ void LCR_mapGetBlockShape(uint8_t blockType, uint8_t transform,
|
|||
|
||||
_LCR_decodeMapBlockCoords(bytes[i],&x,&y,&z);
|
||||
|
||||
LCR_TRANSFORM_COORDS(transform,x,y,z,6,4)
|
||||
|
||||
/*
|
||||
if (transform & LCR_BLOCK_TRANSFORM_FLIP_H)
|
||||
x = 6 - x;
|
||||
|
||||
if (transform & 0x20) // for both 90 and 270
|
||||
{
|
||||
tmp = z;
|
||||
z = x;
|
||||
x = 6 - tmp;
|
||||
}
|
||||
|
||||
if (transform & 0x40) // for both 180 and 270
|
||||
{
|
||||
x = 6 - x;
|
||||
z = 6 - z;
|
||||
}
|
||||
|
||||
if (transform & LCR_BLOCK_TRANSFORM_FLIP_V)
|
||||
y = 4 - y;
|
||||
*/
|
||||
LCR_TRANSFORM_COORDS(transform,x,y,z,6,4)
|
||||
|
||||
bytes[i] = _LCR_encodeMapBlockCoords(x,y,z);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue