diff options
author | kdx <kikoodx@paranoici.org> | 2023-06-23 08:48:23 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-06-23 08:48:23 +0200 |
commit | b3ad8b4d238c7fbf9581e849cbcd532c4d70094a (patch) | |
tree | b6d951995414918d972314b57d18b724b3c0e0ac | |
parent | dfc0ced3ad485a19aab7ce492fca0408b0d06c49 (diff) | |
download | hmle-b3ad8b4d238c7fbf9581e849cbcd532c4d70094a.tar.gz |
compute tileset size
-rw-r--r-- | src/tileset.c | 11 | ||||
-rw-r--r-- | src/tileset.h | 2 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/tileset.c b/src/tileset.c index 32f46a4..53a723d 100644 --- a/src/tileset.c +++ b/src/tileset.c @@ -10,18 +10,25 @@ tileset_init(Tileset *this, Window *win, if (strlen(path) >= sizeof(this->name)) { log_error("path length (%d) too long (max %d) '%s'", strlen(path), sizeof(this->name) - 1, path); - return -1; + return tileset_deinit(this), -1; } if (texture_load(&this->tex, win, path)) { log_error("texture_load failed"); - return -1; + return tileset_deinit(this), -1; } strncpy(this->name, path, sizeof(this->name) - 1); + this->width = this->tex.width / tile_width; + this->height = this->tex.height / tile_height; this->tile_width = tile_width; this->tile_height = tile_height; + if (this->width * this->height == 0) { + log_error("texture size is smaller than a tile"); + return tileset_deinit(this), -1; + } + return 0; } diff --git a/src/tileset.h b/src/tileset.h index 7ebdc37..28e9b41 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -5,6 +5,8 @@ typedef struct Tileset { Texture tex; Window *win; char name[256]; + int width; + int height; int tile_width; int tile_height; } Tileset; |