Fix chunk bug

This commit is contained in:
Miloslav Ciz 2025-03-25 16:57:59 +01:00
parent cacd5f84a9
commit ca0fc67738
4 changed files with 30 additions and 26 deletions

View file

@ -838,24 +838,30 @@ void _LCR_makeMapChunks(void)
LCR_renderer.chunkStarts[chunkNo] = start;
chunkCorner[0] = (chunkNo & 0x03) * LCR_RENDERER_CHUNK_SIZE_HORIZONTAL;
chunkCorner[1] = ((chunkNo >> 2) & 0x03) * (LCR_RENDERER_CHUNK_SIZE_HORIZONTAL / 2);
chunkCorner[2] = ((chunkNo >> 4) & 0x03) * LCR_RENDERER_CHUNK_SIZE_HORIZONTAL;
chunkCorner[0] =
(chunkNo & 0x03) * LCR_RENDERER_CHUNK_SIZE_HORIZONTAL;
chunkCorner[1] =
((chunkNo >> 2) & 0x03) * (LCR_RENDERER_CHUNK_SIZE_HORIZONTAL / 2);
chunkCorner[2] =
((chunkNo >> 4) & 0x03) * LCR_RENDERER_CHUNK_SIZE_HORIZONTAL;
chunkCorner[0] -= LCR_MAP_SIZE_BLOCKS * LCR_RENDERER_UNIT / 2;
chunkCorner[1] -= LCR_MAP_SIZE_BLOCKS * LCR_RENDERER_UNIT / 4;
chunkCorner[2] -= LCR_MAP_SIZE_BLOCKS * LCR_RENDERER_UNIT / 2;
for (int i = start; i < LCR_renderer.mapModel.triangleCount; ++i)
{
const S3L_Unit *v = LCR_renderer.mapVerts + 3 * tri[0];
if (v[0] >= chunkCorner[0] &&
v[0] < chunkCorner[0] + LCR_RENDERER_CHUNK_SIZE_HORIZONTAL &&
v[0] < chunkCorner[0] + LCR_RENDERER_CHUNK_SIZE_HORIZONTAL +
((chunkNo & 0x03) == 0x03) && // includes last edge
v[1] >= chunkCorner[1] &&
v[1] < chunkCorner[1] + (LCR_RENDERER_CHUNK_SIZE_HORIZONTAL / 2) &&
v[1] < chunkCorner[1] + (LCR_RENDERER_CHUNK_SIZE_HORIZONTAL / 2) +
(((chunkNo >> 2) & 0x03) == 0x03) &&
v[2] >= chunkCorner[2] &&
v[2] < chunkCorner[2] + LCR_RENDERER_CHUNK_SIZE_HORIZONTAL)
v[2] < chunkCorner[2] + LCR_RENDERER_CHUNK_SIZE_HORIZONTAL +
(((chunkNo >> 4) & 0x03) == 0x03))
{
_LCR_rendererSwapMapTris(i,start);
start++;
@ -898,7 +904,7 @@ uint8_t _LCR_buildMapModel(void)
const uint8_t *block = LCR_currentMap.blocks + j * LCR_BLOCK_SIZE;
uint8_t
blockType = block[0],
edgeBits, // bottom, top, left, right, front, bottom
edgeBits, // touching bounds? bottom, top, left, right, front, back
bx, by, bz, // block coords
vx, vy, vz, // vertex coords
vi = 0; // vertex index (0, 1 or 2)
@ -918,16 +924,15 @@ uint8_t _LCR_buildMapModel(void)
for (int i = 0; i < blockShapeByteCount; ++i)
{
if (vi == 0)
edgeBits = (by == 0) |
((by == LCR_MAP_SIZE_BLOCKS - 1) << 1) |
((bx == 0) << 2) |
((bx == LCR_MAP_SIZE_BLOCKS - 1) << 3) |
((bz == 0) << 4) |
((bz == LCR_MAP_SIZE_BLOCKS - 1) << 5);
edgeBits =
(by == 0) | ((by == LCR_MAP_SIZE_BLOCKS - 1) << 1) |
((bx == 0) << 2) | ((bx == LCR_MAP_SIZE_BLOCKS - 1) << 3) |
((bz == 0) << 4) | ((bz == LCR_MAP_SIZE_BLOCKS - 1) << 5);
LCR_decodeMapBlockCoords(blockShapeBytes[i],&vx,&vy,&vz);
edgeBits &= (vy == 0) | ((vy == LCR_BLOCK_SHAPE_COORD_MAX) << 1) |
edgeBits &=
(vy == 0) | ((vy == LCR_BLOCK_SHAPE_COORD_MAX) << 1) |
((vx == 0) << 2) | ((vx == LCR_BLOCK_SHAPE_COORD_MAX) << 3) |
((vz == 0) << 4) | ((vz == LCR_BLOCK_SHAPE_COORD_MAX) << 5);
@ -941,9 +946,9 @@ uint8_t _LCR_buildMapModel(void)
if (vi < 2)
vi++;
else
else // 3 indices => create and add triangle
{
// don't add triangles completely at the floor or ceiling of the map
// don't add triangles completely at the boundary of the map
if (!edgeBits)
{
uint8_t triData;
@ -1246,7 +1251,7 @@ void LCR_rendererMoveCamera(LCR_GameUnit forwRightUpOffset[3],
LCR_renderer.scene.camera.transform.rotation.x +=
(yawPitchOffset[1] * S3L_F) / LCR_GAME_UNIT;
#define CHK(o,c,l) \
if (LCR_renderer.scene.camera.transform.translation.c o l) \
LCR_renderer.scene.camera.transform.translation.c = l;