#include "TZR_resource.h" #include "TZR_globals.h" #include #include #include #include static int reserve_ressources(size_t size) { if (size <= ___tzr_resources_capacity) return 0; size_t target = 16; while (target < size * sizeof(TZR_Resource)) target *= 2; TZR_Resource *new_resources; if (___tzr_resources == NULL) new_resources = malloc(target); else new_resources = realloc(___tzr_resources, target); if (new_resources == NULL) { perror("TZR_LoadResourceFromMemory:reserve_ressources"); return 1; } ___tzr_resources = new_resources; return 0; } TZR_Uint TZR_LoadResourceFromMemory(TZR_ResourceType type, const void *data, int size) { if (reserve_ressources(___tzr_resources_size + 1)) { fprintf(stderr, "failed to reserve for new ressource\n"); return 0; } TZR_Resource *const res = &___tzr_resources[___tzr_resources_size]; res->type = type; res->path = NULL; if (TZR_DirectResourceLoad(res, data, size)) return 0; ___tzr_resources_size += 1; return ___tzr_resources_size; }