Add getblockat function

This commit is contained in:
Miloslav Ciz 2023-08-08 16:17:51 +02:00
parent e2d12804d2
commit e678c68b66
3 changed files with 45 additions and 0 deletions

View file

@ -23,6 +23,10 @@
- possibility to turn off textures completely - possibility to turn off textures completely
- how to map textures to blocks? - how to map textures to blocks?
- figured out nice procedural mapping in Blender :) - figured out nice procedural mapping in Blender :)
- PROBABLY LIKE THIS:
- background textures: 128x128 with image-specific 256 color palette,
pixel access shouldn't be as time critical here
- other textures 64x64 with direct 565 values stored
- Rendering: two pass: 1st pass renders the scaled down background (possibly not - Rendering: two pass: 1st pass renders the scaled down background (possibly not
rendering floor, can be just pure green for "grass") to prevent overflows, rendering floor, can be just pure green for "grass") to prevent overflows,
second pass renders the tracks (or the nearest part of it). second pass renders the tracks (or the nearest part of it).

8
main.c
View file

@ -9,5 +9,13 @@ int main(void)
LCR_debugPrintCurrentMap(); LCR_debugPrintCurrentMap();
uint8_t *b = LCR_getMapBlockAtCoordNumber(0);
if (!b)
printf("NO!\n");
else
printf("%d\n",(b - LCR_currentMap.blocks) / 4);
return 0; return 0;
} }

33
map.h
View file

@ -16,6 +16,7 @@
The STORAGE map format is binary and consists of the following values: The STORAGE map format is binary and consists of the following values:
- 76, 77 (for "LM", magic number) - 76, 77 (for "LM", magic number)
- one byte recording the map environment
- ASCII map name - ASCII map name
- 10 (separator) - 10 (separator)
- ASCII comment - ASCII comment
@ -95,6 +96,8 @@ struct
uint8_t blocks[LCR_SETTING_MAP_MAX_SIZE * 4]; uint8_t blocks[LCR_SETTING_MAP_MAX_SIZE * 4];
uint32_t startPos; uint32_t startPos;
uint8_t environment;
// TODO: name, desc? possibly as a single '\n' separated string? // TODO: name, desc? possibly as a single '\n' separated string?
} LCR_currentMap; } LCR_currentMap;
@ -132,6 +135,32 @@ uint32_t LCR_mapBlockGetCoordNumber(const uint8_t block[4])
((((uint32_t) block[3]) & 0x3) << 16); ((((uint32_t) block[3]) & 0x3) << 16);
} }
uint8_t *LCR_getMapBlockAtCoordNumber(uint32_t coord)
{
// binary search the block:
uint16_t a = 0, b = LCR_currentMap.blockCount - 1;
while (b >= a)
{
uint16_t mid = (a + b) / 2;
uint8_t *block = LCR_currentMap.blocks + mid * 4;
uint32_t coord2 =
LCR_mapBlockGetCoordNumber(block);
if (coord2 == coord)
return block;
else if (coord2 > coord)
b = mid - 1;
else
a = mid + 1;
}
return 0;
}
/** /**
Adds given block to current map, including possibly deleting a block by Adds given block to current map, including possibly deleting a block by
adding LCR_BLOCK_NONE. The function handles sorting the block to the right adding LCR_BLOCK_NONE. The function handles sorting the block to the right
@ -213,6 +242,10 @@ uint8_t LCR_mapLoad(const uint8_t *map)
map++; map++;
LCR_currentMap.environment = *map;
map++;
while (*map != LCR_MAP_TERMINATOR) while (*map != LCR_MAP_TERMINATOR)
{ {
if (!_LCR_mapAddBlock(map)) if (!_LCR_mapAddBlock(map))