Texture loading
All checks were successful
Build Dusk / run-tests (push) Successful in 1m44s
Build Dusk / build-linux (push) Successful in 1m38s
Build Dusk / build-psp (push) Successful in 1m59s
Build Dusk / build-dolphin (push) Successful in 1m59s

This commit is contained in:
2026-02-09 09:29:16 -06:00
parent 592edb90a0
commit 2f5dccc3ef
19 changed files with 590 additions and 103 deletions

View File

@@ -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;
}

View File

@@ -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);