Rework map string
This commit is contained in:
parent
85b8b1352d
commit
69d87ab26d
3 changed files with 79 additions and 109 deletions
112
map.h
112
map.h
|
@ -17,16 +17,12 @@
|
|||
The TEXT format serves for editing maps in human readable format, it more or
|
||||
less corresponds to the binary storage format (below) with some exceptions.
|
||||
It has the following structure:
|
||||
- Magic number string: "LM;".
|
||||
- Until next ';': name.
|
||||
- Until next ';': description.
|
||||
- Until next ';': tags. Currently this may contain the following:
|
||||
- digit N: set the map environment to N.
|
||||
- Then a series of block strings follows. Blocks may be separated by
|
||||
characters that aren't '#' (comments may be added this way). Block format
|
||||
- Number specifying environment (0, 1, 2, ...)
|
||||
- A series of block strings. Blocks may be separated by characters that
|
||||
aren't ':' (comments may be added this way). Block format
|
||||
is following:
|
||||
|
||||
#BXYZMT
|
||||
:BXYZMT
|
||||
|
||||
where:
|
||||
- B is block type
|
||||
|
@ -60,6 +56,8 @@
|
|||
- last if C7 is set, the block is flipped vertically
|
||||
*/
|
||||
|
||||
#define LCR_BLOCK_START_CHAR ':'
|
||||
|
||||
#define LCR_BLOCK_TRANSFORM_FLIP_H 0x10
|
||||
#define LCR_BLOCK_TRANSFORM_ROT_90 0x20
|
||||
#define LCR_BLOCK_TRANSFORM_ROT_180 0x40
|
||||
|
@ -68,12 +66,6 @@
|
|||
|
||||
#define LCR_BLOCK_XYZ_TO_COORD(x,y,z) // ???
|
||||
|
||||
#define LCR_MAP_MAGIC_NUMBER1 'L'
|
||||
#define LCR_MAP_MAGIC_NUMBER2 'M'
|
||||
#define LCR_MAP_SEPARATOR ';'
|
||||
|
||||
#define LCR_MAP_MAGIC_NUMBER LCR_MAP_MAGIC_NUMBER1, LCR_MAP_MAGIC_NUMBER2
|
||||
#define LCR_MAP_TERMINATOR 0xff
|
||||
#define LCR_MAP_BLOCK(t,x,y,z,m,r) t,(uint8_t) (x | (y << 6)), \
|
||||
(uint8_t) ((y >> 2) | (z << 4)), \
|
||||
(uint8_t) ((z >> 4) | (m << 2) | (r))
|
||||
|
@ -361,10 +353,12 @@ int _LCR_mapCharToCoord(char c)
|
|||
return -1;
|
||||
}
|
||||
|
||||
uint8_t LCR_mapLoadFromStr(const char *mapStr)
|
||||
uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void))
|
||||
{
|
||||
LCR_LOG0("loading map string");
|
||||
|
||||
char c;
|
||||
|
||||
uint8_t prevBlock[LCR_BLOCK_SIZE];
|
||||
prevBlock[0] = LCR_BLOCK_NONE;
|
||||
|
||||
|
@ -375,65 +369,29 @@ uint8_t LCR_mapLoadFromStr(const char *mapStr)
|
|||
LCR_currentMap.blockCount = 0;
|
||||
LCR_currentMap.environment = 0;
|
||||
|
||||
if (mapStr[0] != LCR_MAP_MAGIC_NUMBER1 || mapStr[1] != LCR_MAP_MAGIC_NUMBER2
|
||||
|| mapStr[2] != LCR_MAP_SEPARATOR)
|
||||
c = getNextCharFunc();
|
||||
|
||||
if (c < '0' || c > '3')
|
||||
{
|
||||
LCR_LOG0("bad magic number");
|
||||
LCR_LOG0("bad environment char");
|
||||
return 0;
|
||||
}
|
||||
|
||||
mapStr += 3;
|
||||
LCR_currentMap.environment = c - '0';
|
||||
|
||||
while (*mapStr != LCR_MAP_SEPARATOR) // read map name
|
||||
while (c)
|
||||
{
|
||||
if (mapStr[0] == 0)
|
||||
return 0;
|
||||
|
||||
// TODO
|
||||
mapStr++;
|
||||
}
|
||||
|
||||
mapStr++;
|
||||
|
||||
while (*mapStr != LCR_MAP_SEPARATOR) // read map description
|
||||
{
|
||||
if (mapStr[0] == 0)
|
||||
return 0;
|
||||
|
||||
// TODO
|
||||
mapStr++;
|
||||
}
|
||||
|
||||
mapStr++;
|
||||
|
||||
while (*mapStr != LCR_MAP_SEPARATOR) // read map tags
|
||||
{
|
||||
if (mapStr[0] >= '0' && mapStr[0] <= '9')
|
||||
LCR_currentMap.environment = mapStr[0] - '0';
|
||||
else if (mapStr[0] == 0)
|
||||
return 0;
|
||||
|
||||
// TODO
|
||||
mapStr++;
|
||||
}
|
||||
|
||||
mapStr++;
|
||||
|
||||
while (*mapStr)
|
||||
{
|
||||
if (*mapStr == '#')
|
||||
if (c == LCR_BLOCK_START_CHAR)
|
||||
{
|
||||
mapStr++;
|
||||
|
||||
uint8_t block = *mapStr;
|
||||
uint8_t block = getNextCharFunc();
|
||||
uint8_t trans = 0;
|
||||
uint8_t mat = 0;
|
||||
int coords[3];
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
mapStr++;
|
||||
coords[i] = _LCR_mapCharToCoord(*mapStr);
|
||||
c = getNextCharFunc();
|
||||
coords[i] = _LCR_mapCharToCoord(c);
|
||||
|
||||
if (coords[i] < 0)
|
||||
{
|
||||
|
@ -442,35 +400,36 @@ uint8_t LCR_mapLoadFromStr(const char *mapStr)
|
|||
}
|
||||
}
|
||||
|
||||
mapStr++;
|
||||
c = getNextCharFunc();
|
||||
|
||||
if (*mapStr >= '0' && *mapStr <= '3')
|
||||
mat = *mapStr - '0';
|
||||
else
|
||||
if (c < '0' || c > '3')
|
||||
{
|
||||
LCR_LOG0("bad material");
|
||||
return 0;
|
||||
}
|
||||
|
||||
mapStr++;
|
||||
|
||||
mat = c - '0';
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (*mapStr == '|')
|
||||
c = getNextCharFunc();
|
||||
|
||||
if (c == '|')
|
||||
trans |= LCR_BLOCK_TRANSFORM_FLIP_H;
|
||||
else if (*mapStr == '-')
|
||||
else if (c == '-')
|
||||
trans |= LCR_BLOCK_TRANSFORM_FLIP_V;
|
||||
else if (*mapStr == 'L')
|
||||
else if (c == 'L')
|
||||
trans |= LCR_BLOCK_TRANSFORM_ROT_90;
|
||||
else if (*mapStr == 'I')
|
||||
else if (c == 'I')
|
||||
trans |= LCR_BLOCK_TRANSFORM_ROT_180;
|
||||
else if (*mapStr == 'J')
|
||||
else if (c == 'J')
|
||||
trans |= LCR_BLOCK_TRANSFORM_ROT_270;
|
||||
else
|
||||
break;
|
||||
|
||||
mapStr++;
|
||||
}
|
||||
|
||||
while (c && c != LCR_BLOCK_START_CHAR)
|
||||
c = getNextCharFunc();
|
||||
|
||||
switch (block)
|
||||
{
|
||||
|
@ -527,9 +486,8 @@ uint8_t LCR_mapLoadFromStr(const char *mapStr)
|
|||
// TODO: check for invalid blocks?
|
||||
}
|
||||
}
|
||||
|
||||
if (*mapStr != '#')
|
||||
mapStr++;
|
||||
else
|
||||
c = getNextCharFunc();
|
||||
}
|
||||
|
||||
LCR_LOG2("clearing map block cache")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue