aboutsummaryrefslogtreecommitdiff
path: root/sources/TZR_DestroyResource.c
blob: de235e49c666412fcfafb28d3d1ee7e412a7f110 (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
31
32
33
34
35
36
37
38
#include "TZR_resource.h"
#include <SDL2/SDL_mixer.h>

void
TZR_DestroyResource(TZR_Resource *res, int free_path)
{
	if (res->path != NULL && free_path)
		free(res->path);
	switch (res->type) {
	case TZR_RES_RAW:
		if (res->raw.data != NULL)
			free(res->raw.data);
		break;
	case TZR_RES_IMAGE:
		if (res->image.ptr != NULL)
			SDL_DestroyTexture(res->image.ptr);
		break;
	case TZR_RES_SOUND:
#ifdef TZR_SOLOUD
		if (res->sound.ptr != NULL)
			Wav_destroy(res->sound.ptr);
#else
		if (res->sound.ptr != NULL)
			Mix_FreeChunk(res->sound.ptr);
#endif
		break;
	case TZR_RES_FONT:
#ifdef TZR_TTF
		if (res->ttf.ptr != NULL)
			TTF_CloseFont(res->ttf.ptr);
#endif
		break;
	default:
		fprintf(stderr, "unknown resource type %u\n", res->type);
		break;
	}
}