comparison libmlk-rpg/rpg/tileset-file.h @ 243:71b3b7036de7

misc: lot of cleanups, - prefix libraries with libmlk, - move assets from source directories closes #2520, - prefix header guards closes #2519
author David Demelier <markand@malikania.fr>
date Sat, 28 Nov 2020 22:37:30 +0100
parents librpg/rpg/tileset-file.h@e71039d820a7
children 08ab73b32832
comparison
equal deleted inserted replaced
242:4c24604efcab 243:71b3b7036de7
1 /*
2 * tileset-file.h -- tileset file loader
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 #ifndef MOLKO_RPG_TILESET_FILE_H
20 #define MOLKO_RPG_TILESET_FILE_H
21
22 /**
23 * \file tileset-file.h
24 * \brief Tileset file loader.
25 */
26
27 #include <stdbool.h>
28 #include <stddef.h>
29
30 #include <core/alloc.h>
31 #include <core/sprite.h>
32 #include <core/texture.h>
33
34 struct tileset;
35 struct tileset_tiledef;
36
37 /**
38 * \brief Context for loading tileset from files
39 *
40 * This structure own animations, tile definitions and sprites that are
41 * associated with the tileset. By this mean, the structure must be kept until
42 * the tileset is no longer used.
43 *
44 * Structure members should not be modified directly but only one exposed in
45 * the final tileset destination.
46 */
47 struct tileset_file {
48 struct alloc_pool tiledefs; /*!< (*) Tile definitions. */
49 struct alloc_pool anims[2]; /*!< (*) Animations data. */
50 struct texture image; /*!< (*) Image file. */
51 struct sprite sprite; /*!< (*) Sprite. */
52 };
53
54 /**
55 * Try to load a tileset from a file.
56 *
57 * This function will load the tileset file along with optional animations in
58 * the same directory.
59 *
60 * \pre tf != NULL
61 * \pre tileset != NULL
62 * \pre path != NULL
63 * \param tf the context file
64 * \param tileset the destination tileset
65 * \param path path to the tileset
66 * \return False on errors.
67 */
68 bool
69 tileset_file_open(struct tileset_file *tf, struct tileset *tileset, const char *path);
70
71 /**
72 * Close all resources allocated from the tileset file context.
73 *
74 * \warning The tileset that was created must not be used anymore.
75 * \pre tf != NULL
76 * \param tf the tileset to clear
77 */
78 void
79 tileset_file_finish(struct tileset_file *tf);
80
81 #endif /* !MOLKO_RPG_TILESET_FILE_H */