Mercurial > molko
comparison libmlk-adventure/adventure/assets.c @ 267:bead76f6c793
adventure: start a global assets registry
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 10 Dec 2020 16:28:30 +0100 |
parents | |
children | eadd3dbfa0af |
comparison
equal
deleted
inserted
replaced
266:e48ffbcf9bcc | 267:bead76f6c793 |
---|---|
1 /* | |
2 * assets.c -- global atlas for every resources | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <core/image.h> | |
20 #include <core/panic.h> | |
21 #include <core/sprite.h> | |
22 #include <core/texture.h> | |
23 #include <core/util.h> | |
24 | |
25 #include <adventure/molko.h> | |
26 | |
27 #include "assets.h" | |
28 | |
29 #define SPRITE(which, file, w, h) { which, file, w, h } | |
30 | |
31 static struct { | |
32 enum assets_sprite index; | |
33 const char *path; | |
34 unsigned int cellw; | |
35 unsigned int cellh; | |
36 struct texture texture; | |
37 struct sprite sprite; | |
38 } table_sprites[] = { | |
39 SPRITE(ASSETS_SPRITE_UI_CURSOR, "sprites/ui-cursor.png", 24, 24) | |
40 }; | |
41 | |
42 struct sprite *assets_sprites[ASSETS_SPRITE_NUM] = {0}; | |
43 | |
44 static void | |
45 init_sprites(void) | |
46 { | |
47 for (size_t i = 0; i < UTIL_SIZE(table_sprites); ++i) { | |
48 if (!image_open(&table_sprites[i].texture, molko_path(table_sprites[i].path))) | |
49 panic(); | |
50 | |
51 sprite_init(&table_sprites[i].sprite, &table_sprites[i].texture, | |
52 table_sprites[i].cellw, table_sprites[i].cellh); | |
53 | |
54 assets_sprites[table_sprites[i].index] = &table_sprites[i].sprite; | |
55 } | |
56 } | |
57 | |
58 void | |
59 assets_init(void) | |
60 { | |
61 init_sprites(); | |
62 } | |
63 | |
64 void | |
65 assets_finish(void) | |
66 { | |
67 for (size_t i = 0; i < UTIL_SIZE(table_sprites); ++i) | |
68 texture_finish(&table_sprites[i].texture); | |
69 } |