Mercurial > molko
comparison libmlk-rpg/mlk/rpg/tileset-loader.h @ 631:bb67f935a93f
rpg: rework a little tileset/map loaders
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 27 Aug 2023 11:28:35 +0200 |
parents | f9e85d0aca74 |
children |
comparison
equal
deleted
inserted
replaced
630:8d8fe99b357c | 631:bb67f935a93f |
---|---|
23 * \file mlk/rpg/tileset-loader.h | 23 * \file mlk/rpg/tileset-loader.h |
24 * \brief Abstract tileset loader | 24 * \brief Abstract tileset loader |
25 * | 25 * |
26 * This module provides a generic way to open tilesets. It uses a callback | 26 * This module provides a generic way to open tilesets. It uses a callback |
27 * system whenever an action has to be taken by the user. by itself, this | 27 * system whenever an action has to be taken by the user. by itself, this |
28 * module does not alloate nor owns any data. | 28 * module does not allocate nor owns any data. |
29 * | 29 * |
30 * It is designed in mind that the loader knows how to decode a tileset data | 30 * It is designed in mind that the loader knows how to decode a tileset data |
31 * format file but has no indication on how it should allocate, arrange and | 31 * format file but has no indication on how it should allocate, arrange and |
32 * find tileset images and other resources. | 32 * find tileset images and other resources. |
33 * | 33 * |
34 * See tileset-file.h for an implementation of this module using files. | 34 * See tileset-loader-file.h for an implementation of this module using files. |
35 */ | 35 */ |
36 | 36 |
37 #include <stddef.h> | 37 #include <stddef.h> |
38 | 38 |
39 struct mlk_animation; | |
40 struct mlk_sprite; | |
41 struct mlk_texture; | |
42 struct mlk_tileset; | 39 struct mlk_tileset; |
43 struct mlk_tileset_animations; | 40 struct mlk_tileset_animations; |
44 struct mlk_tileset_collision; | 41 struct mlk_tileset_collision; |
45 | 42 |
46 /** | 43 /** |
123 */ | 120 */ |
124 struct mlk_tileset_animation * (*expand_animations)(struct mlk_tileset_loader *self, | 121 struct mlk_tileset_animation * (*expand_animations)(struct mlk_tileset_loader *self, |
125 struct mlk_tileset *tileset, | 122 struct mlk_tileset *tileset, |
126 struct mlk_tileset_animation *array, | 123 struct mlk_tileset_animation *array, |
127 size_t arraysz); | 124 size_t arraysz); |
125 | |
126 /** | |
127 * (read-write, optional) | |
128 * | |
129 * Cleanup resources allocated for this tileset. | |
130 * | |
131 * This is different than finalizing the loader itself, it should be | |
132 * re-usable after calling this function. | |
133 * | |
134 * \param self this loader | |
135 * \param tileset the underlying tileset to cleanup | |
136 */ | |
137 void (*clear)(struct mlk_tileset_loader *self, struct mlk_tileset *tileset); | |
138 | |
139 /** | |
140 * (read-write, optional) | |
141 * | |
142 * Cleanup the tileset loader. | |
143 * | |
144 * \param self this loader | |
145 */ | |
146 void (*finish)(struct mlk_tileset_loader *self); | |
128 | 147 |
129 /** \cond MLK_PRIVATE_DECLS */ | 148 /** \cond MLK_PRIVATE_DECLS */ |
130 unsigned int tilewidth; | 149 unsigned int tilewidth; |
131 unsigned int tileheight; | 150 unsigned int tileheight; |
132 /** \endcond MLK_PRIVATE_DECLS */ | 151 /** \endcond MLK_PRIVATE_DECLS */ |
171 mlk_tileset_loader_openmem(struct mlk_tileset_loader *loader, | 190 mlk_tileset_loader_openmem(struct mlk_tileset_loader *loader, |
172 struct mlk_tileset *tileset, | 191 struct mlk_tileset *tileset, |
173 const void *data, | 192 const void *data, |
174 size_t datasz); | 193 size_t datasz); |
175 | 194 |
195 /** | |
196 * Cleanup data for this tileset. | |
197 * | |
198 * The loader is re-usable after calling this function to load a new tileset. | |
199 * | |
200 * Invokes ::mlk_tileset_loader::clear. | |
201 * | |
202 * \pre loader != NULL | |
203 * \param loader the loader interface | |
204 * \param tileset the tileset used with this loader | |
205 */ | |
206 void | |
207 mlk_tileset_loader_clear(struct mlk_tileset_loader *loader, | |
208 struct mlk_tileset *tileset); | |
209 | |
210 /** | |
211 * Finalize the loader itself. | |
212 * | |
213 * The underlying interface should also clear tileset resources by convenience | |
214 * if the user forgot to call ::mlk_tileset_loader_clear. | |
215 * | |
216 * Invokes ::mlk_tileset_loader::finish. | |
217 * | |
218 * \pre loader != NULL | |
219 * \param loader the loader to finalize | |
220 */ | |
221 void | |
222 mlk_tileset_loader_finish(struct mlk_tileset_loader *loader); | |
223 | |
176 #if defined(__cplusplus) | 224 #if defined(__cplusplus) |
177 } | 225 } |
178 #endif | 226 #endif |
179 | 227 |
180 #endif /* !MLK_RPG_TILESET_LOADER_H */ | 228 #endif /* !MLK_RPG_TILESET_LOADER_H */ |