aboutsummaryrefslogtreecommitdiff
path: root/sources/TZR_LoadResourceFromMemory.c
blob: b995b4c8fbabdf80fa923aebd48cab310cf2a81b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "TZR_resource.h"
#include "TZR_globals.h"
#include "reserve.h"
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_rwops.h>
#include <stdio.h>
#include <stdlib.h>

TZR_Uint
TZR_LoadResourceFromMemory(TZR_ResourceType type, const void *data, int size)
{
	void *vec = ___tzr_resources;
	if (reserve(&vec,
	            ___tzr_resources_size + 1,
	            &___tzr_resources_capacity,
	            sizeof(TZR_Resource)))
	{
		TZR_Log("failed to reserve for new ressource");
		return 0;
	}
	___tzr_resources = vec;

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