aboutsummaryrefslogtreecommitdiff
path: root/src/texture_sys.c
diff options
context:
space:
mode:
authorUneven Prankster <unevenprankster@protonmail.com>2023-09-23 19:28:45 -0300
committerUneven Prankster <unevenprankster@protonmail.com>2023-09-23 19:28:45 -0300
commita89f892640cf12f75c7ce18e6e88c70a8d3965ed (patch)
treee917bda607b86cb7c5bd80df2e5abf549d972163 /src/texture_sys.c
parent83505b7be49dbf7789deb814bd159d9c37181d05 (diff)
things can always be nicer :D
Diffstat (limited to 'src/texture_sys.c')
-rw-r--r--src/texture_sys.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/texture_sys.c b/src/texture_sys.c
index cb7f631..b4c3c4d 100644
--- a/src/texture_sys.c
+++ b/src/texture_sys.c
@@ -1,5 +1,5 @@
#include "utils.h"
-#include "config.h"
+#include "text.h"
#include <stddef.h>
@@ -7,26 +7,32 @@
static Texture2D texture_slots[MAX_TEX_SIZE] = {0};
static i32 texture_modtimes[MAX_TEX_SIZE] = {0};
-static const char* texture_paths[MAX_TEX_SIZE] = {0};
+static s8 texture_paths[MAX_TEX_SIZE] = {0};
void init_tex_sys(void)
{
for(i32 i = 0; i < MAX_TEX_SIZE; ++i){
- texture_slots[i] = (Texture2D){0};
texture_modtimes[i] = BLANK_DEFAULT;
- texture_paths[i] = NULL;
}
}
i32 load_new_tex(const char* path)
{
+ s8 path_str = cstr_to_s8(path);
+
i32 current_idx = BLANK_DEFAULT;
for(i32 i = 0; i < MAX_TEX_SIZE; ++i){
+
+ if(equal_s8(path_str, texture_paths[current_idx])){
+ free_s8(&path_str);
+ return i;
+ }
+
if(texture_slots[i].id <= 0){
current_idx = i;
- texture_slots[current_idx] = LoadTexture(path);
- texture_modtimes[current_idx] = GetFileModTime(path);
- texture_paths[current_idx] = path;
+ texture_slots[current_idx] = LoadTexture((const char*)path_str.buf);
+ texture_modtimes[current_idx] = GetFileModTime((const char*)path_str.buf);
+ texture_paths[current_idx] = path_str;
break;
}
}
@@ -46,13 +52,13 @@ void update_textures(void)
{
for(i32 i = 0; i < MAX_TEX_SIZE; ++i){
if(texture_slots[i].id > 0){
- i32 current_mod = GetFileModTime(texture_paths[i]);
+ i32 current_mod = GetFileModTime((const char*)texture_paths[i].buf);
if(current_mod != texture_modtimes[i]){
texture_modtimes[i] = current_mod;
UnloadTexture(texture_slots[i]);
- texture_slots[i] = LoadTexture(texture_paths[i]);
+ texture_slots[i] = LoadTexture((const char*)texture_paths[i].buf);
}
}
}
@@ -61,10 +67,10 @@ void update_textures(void)
void unload_tex(i32 idx)
{
assert(idx >= 0 && idx < MAX_TEX_SIZE);
+
UnloadTexture(texture_slots[idx]);
- texture_slots[idx] = (Texture2D){0};
texture_modtimes[idx] = BLANK_DEFAULT;
- texture_paths[idx] = NULL;
+ free_s8(&texture_paths[idx]);
}
void unload_active_textures(void)