From c05e188ef6a4b715848f9f0b401351a43c80168d Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Wed, 30 Jul 2025 23:33:22 +0300 Subject: Small Refactor --- src/assets.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'src/assets.c') diff --git a/src/assets.c b/src/assets.c index 8edfde6..073c748 100644 --- a/src/assets.c +++ b/src/assets.c @@ -4,18 +4,6 @@ #include #include "assets.h" -typedef enum AssetType { - Texture_Asset -} AssetType; - -typedef struct Asset { - AssetType type; - const char* name; - const char* filePath; - - Texture2D texture; -} Asset; - Asset assets[] = { { .type = Texture_Asset, @@ -37,9 +25,12 @@ void LoadAssets() { Asset* c = &assets[i]; switch (c->type) { - case Texture_Asset: - c->texture = LoadTexture(c->filePath); - break; + case Texture_Asset: + c->texture = LoadTexture(c->filePath); + break; + + default: + break; } } } @@ -52,16 +43,21 @@ Asset* GetMatchingAssetWithType(const char* targetName, AssetType targetType) { return c; } - return NULL; + printf("Failed to load asset with name: %s, exitting!\n", targetName); + exit(EXIT_FAILURE); } -Texture2D GetTexture(const char* name) { - Asset* textureAsset = GetMatchingAssetWithType(name, Texture_Asset); +void UnloadAssets() { + for (size_t i = 0; i < ASSET_COUNT; i++) { + Asset* c = &assets[i]; + + switch (c->type) { + case Texture_Asset: + UnloadTexture(c->texture); + break; - if (textureAsset == NULL) { - fprintf(stderr, "Failed to load texture with name: %s, exitting!\n", name); - exit(EXIT_FAILURE); + default: + break; + } } - - return textureAsset->texture; } -- cgit v1.2.3