54 lines
1.3 KiB
C
54 lines
1.3 KiB
C
/**
|
|
* Copyright (c) 2021 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "tile.h"
|
|
|
|
tilemap_t * tileMapCreate(tileset_t *tileset) {
|
|
tilemap_t *tilemap = malloc(sizeof(tilemap_t));
|
|
if(tilemap == NULL) return NULL;
|
|
|
|
tilemap->tileset = tileset;
|
|
tilemap->tileDefinitions = calloc(tileset->columns * tileset->rows,
|
|
sizeof(tiledef_t)
|
|
);
|
|
if(!tilemap->tileDefinitions) {
|
|
free(tilemap);
|
|
return NULL;
|
|
}
|
|
|
|
(tilemap->tileDefinitions + 1)->verticeCount = 4;
|
|
(tilemap->tileDefinitions + 1)->indiceCount = 6;
|
|
|
|
(tilemap->tileDefinitions + 2)->verticeCount = 8;
|
|
(tilemap->tileDefinitions + 2)->indiceCount = 36;
|
|
|
|
return tilemap;
|
|
}
|
|
|
|
void tileMapDispose(tilemap_t *tilemap) {
|
|
free(tilemap->tileDefinitions);
|
|
free(tilemap);
|
|
}
|
|
|
|
void tileRender(chunklist_t *list, chunk_t *chunk,
|
|
tile_t *tile, tiledef_t *tileDef, int32_t x, int32_t y, int32_t z
|
|
) {
|
|
if(tile->id == 2) {
|
|
cubeBuffer(chunk->primitive,
|
|
x, y, z,
|
|
1, 1, 1,
|
|
tile->verticeStart, tile->indiceStart
|
|
);
|
|
} else {
|
|
tilesetdiv_t *div = list->tilemap->tileset->divisions + tile->id;
|
|
quadBuffer(chunk->primitive, z,
|
|
x, y, div->x0, div->y0,
|
|
x+1, y+1, div->x1, div->y1,
|
|
tile->verticeStart, tile->indiceStart
|
|
);
|
|
}
|
|
} |