Texture loading
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
*/
|
||||
|
||||
#include "tileset.h"
|
||||
#include "display/tileset/tilesetlist.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/string.h"
|
||||
|
||||
void tilesetTileGetUV(
|
||||
const tileset_t *tileset,
|
||||
@@ -23,8 +26,21 @@ void tilesetPositionGetUV(
|
||||
const uint16_t row,
|
||||
vec4 outUV
|
||||
) {
|
||||
assertNotNull(tileset, "Tileset cannot be NULL");
|
||||
assertTrue(column < tileset->columns, "Column index out of bounds");
|
||||
assertTrue(row < tileset->rows, "Row index out of bounds");
|
||||
|
||||
outUV[0] = column * tileset->uv[0];
|
||||
outUV[1] = row * tileset->uv[1];
|
||||
outUV[2] = outUV[0] + tileset->uv[0];
|
||||
outUV[3] = outUV[1] + tileset->uv[1];
|
||||
}
|
||||
|
||||
const tileset_t * tilesetGetByName(const char_t *name) {
|
||||
assertStrLenMin(name, 1, "Tileset name cannot be empty");
|
||||
for(uint32_t i = 0; i < TILESET_LIST_COUNT; i++) {
|
||||
if(stringCompare(TILESET_LIST[i]->name, name) != 0) continue;
|
||||
return TILESET_LIST[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct tileset_s {
|
||||
const char_t *name;
|
||||
const uint16_t tileWidth;
|
||||
const uint16_t tileHeight;
|
||||
const uint16_t tileCount;
|
||||
@@ -18,15 +19,38 @@ typedef struct tileset_s {
|
||||
const char_t *image;
|
||||
} tileset_t;
|
||||
|
||||
/**
|
||||
* Gets the UV coordinates for a tile index in the tileset.
|
||||
*
|
||||
* @param tileset The tileset to get the UV coordinates from.
|
||||
* @param tileIndex The index of the tile to get the UV coordinates for.
|
||||
* @param outUV The output UV coordinates (vec4).
|
||||
*/
|
||||
void tilesetTileGetUV(
|
||||
const tileset_t *tileset,
|
||||
const uint16_t tileIndex,
|
||||
vec4 outUV
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets the UV coordinates for a tile position in the tileset.
|
||||
*
|
||||
* @param tileset The tileset to get the UV coordinates from.
|
||||
* @param column The column of the tile to get the UV coordinates for.
|
||||
* @param row The row of the tile to get the UV coordinates for.
|
||||
* @param outUV The output UV coordinates (vec4).
|
||||
*/
|
||||
void tilesetPositionGetUV(
|
||||
const tileset_t *tileset,
|
||||
const uint16_t column,
|
||||
const uint16_t row,
|
||||
vec4 outUV
|
||||
);
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets a tileset by its name.
|
||||
*
|
||||
* @param name The name of the tileset to get.
|
||||
* @return The tileset with the given name, or NULL if not found.
|
||||
*/
|
||||
const tileset_t* tilesetGetByName(const char_t *name);
|
||||
Reference in New Issue
Block a user