1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | gameState->gameWorld = pushSize(&gameState->worldArena, world); world *gameWorld = gameState->gameWorld; gameWorld->tileMap = pushSize(&gameState->worldArena, tile_map); tile_map *tileMap = gameWorld->tileMap; tileMap->chunkShift = 4; tileMap->chunkMask = (1 << tileMap->chunkShift) - 1; tileMap->chunkDim = (1 << tileMap->chunkShift); tileMap->tileChunkCountX = 128; tileMap->tileChunkCountY = 128; tileMap->tileChunks = pushArray(&gameState->worldArena, tileMap->tileChunkCountX * tileMap->tileChunkCountY, tile_chunk); tileMap->tileSideInMeters = 1.4f; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | real32 screenCenterX = 0.5f * (real32) buffer->width; real32 screenCenterY = 0.5f * (real32) buffer->height; for (int32 i = -10; i < 10; ++i) { for (int32 j = -20; j < 20; ++j) { uint32 column = gameState->playerP.absTileX + j; // <-- this is where the addition = ChunkDim uint32 row = gameState->playerP.absTileY + i; uint32 tileID = getTileValue(tileMap, column, row); // <-- this is where the assert throws, see below if (tileID > 0) { real32 grey = 0.5f; if (tileID == 2) grey = 1.0f; if (row == gameState->playerP.absTileY && column == gameState->playerP.absTileX) grey = 0.0f; real32 centerX = screenCenterX - (metersToPixels * gameState->playerP.tileRelX) + ((real32) j) * tileSideInPixels; real32 centerY = screenCenterY + (metersToPixels * gameState->playerP.tileRelY) - ((real32) i) * tileSideInPixels; real32 minX = centerX - (0.5f * tileSideInPixels); real32 minY = centerY - (0.5f * tileSideInPixels); real32 maxX = centerX + (0.5f * tileSideInPixels); real32 maxY = centerY + (0.5f * tileSideInPixels); drawRectangle(buffer, minX, minY, maxX, maxY, grey, grey, grey); } } } |
1 2 3 4 5 6 | internal uint32 getTileValue(tile_map *tileMap, uint32 absTileX, uint32 absTileY) { tile_chunk_position chunkPos = getChunkPosFor(tileMap, absTileX, absTileY); tile_chunk *tileChunk = getTileChunk(tileMap, chunkPos.tileChunkX, chunkPos.tileChunkY); return getTileValue(tileMap, tileChunk, absTileX, absTileY); } |
1 2 3 4 5 6 7 8 9 | inline uint32 getTileValue(tile_map *tileMap, tile_chunk *tileChunk, uint32 testTileX, uint32 testTileY) { uint32 result = 0; if (tileChunk && tileChunk->tiles) { result = getTileValueUnchecked(tileMap, tileChunk, testTileX, testTileY); } return result; } |
1 2 3 4 5 6 7 | inline uint32 getTileValueUnchecked(tile_map *tileMap, tile_chunk *tileChunk, uint32 tileX, uint32 tileY) { assert(tileChunk); assert(tileX < tileMap->chunkDim); // <-- assertion failed: tileX == tileMap->chunkDim assert(tileY < tileMap->chunkDim); return tileChunk->tiles[(tileY * tileMap->chunkDim) + tileX]; } |
1 2 3 4 5 6 7 | internal uint32 getTileValue(tile_map *tileMap, uint32 absTileX, uint32 absTileY) { tile_chunk_position chunkPos = getChunkPosFor(tileMap, absTileX, absTileY); tile_chunk *tileChunk = getTileChunk(tileMap, chunkPos.tileChunkX, chunkPos.tileChunkY); // return getTileValue(tileMap, tileChunk, absTileX, absTileY); return getTileValue(tileMap, tileChunk, chunkPos.relTileX, chunkPos.relTileY); } |
1 2 3 4 5 6 7 8 9 | for (int32 i = -10; i < 10; ++i) { for (int32 j = -20; j < 20; ++j) { if ( i == 3 && j == 7 ){ /* The value of i and j when the assert triggers. */ __debugbreak(); /* This cause the debugger to stop. */ } /* The rest of the code. */ } } |