From b8ff068659f700d321eb94f3e244d6ff5841c0e0 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 5 Apr 2021 20:56:37 +1000 Subject: [PATCH] Tile list --- src/engine/world/chunklist.c | 12 +++++++----- src/engine/world/tile.c | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/engine/world/chunklist.c b/src/engine/world/chunklist.c index 068eb3e2..190ba5f8 100644 --- a/src/engine/world/chunklist.c +++ b/src/engine/world/chunklist.c @@ -152,7 +152,8 @@ void chunkListChunkLoad(chunklist_t *list, chunk_t *chunk, int32_t tx, ty, tz, i, count; tilesetdiv_t *div; tileref_t *tiles; - tileref_t tile; + tileref_t tileRef; + tile_t *tile; count = CHUNK_WIDTH * CHUNK_DEPTH * CHUNK_HEIGHT; tiles = calloc(count, sizeof(tileref_t)); @@ -163,10 +164,11 @@ void chunkListChunkLoad(chunklist_t *list, chunk_t *chunk, for(tx = 0; tx < CHUNK_WIDTH; tx++) { for(ty = 0; ty < CHUNK_HEIGHT; ty++) { for(tz = 0; tz < CHUNK_DEPTH; tz++) { - tile = tiles[++i]; - if(tile == TILE_NULL) continue; - div = &list->tilemap->tileset->divisions[tile]; - + tileRef = tiles[++i]; + if(tileRef == TILE_NULL) continue; + div = list->tilemap->tileset->divisions + tileRef; + tile = list->tilemap->tiles + tileRef; + spriteBatchQuad(chunk->batch, -1, tx, ty, tz, 1, 1, div->x0, div->y0, div->x1, div->y1 diff --git a/src/engine/world/tile.c b/src/engine/world/tile.c index 82e32895..783b972e 100644 --- a/src/engine/world/tile.c +++ b/src/engine/world/tile.c @@ -12,7 +12,7 @@ tilemap_t * tileMapCreate(tileset_t *tileset) { if(tilemap == NULL) return NULL; tilemap->tileset = tileset; - tilemap->tiles = malloc(sizeof(tile_t) * tileset->columns * tileset->rows); + tilemap->tiles = calloc(tileset->columns * tileset->rows, sizeof(tile_t)); return tilemap; }