comparison libmlk-rpg/mlk/rpg/tileset-loader-file.h @ 552:ffd972a3d084

rpg: major rewrite of tilesets - Now tilesets can be opened using a custom allocator/loader. - A default mlk_tileset_loader_file implementation is provided. - Put a simple example-tileset example to demonstrate.
author David Demelier <markand@malikania.fr>
date Tue, 07 Mar 2023 20:45:00 +0100
parents
children cdbc13ceff85
comparison
equal deleted inserted replaced
551:856c2e96189d 552:ffd972a3d084
1 /*
2 * tileset-loader-file.h -- tileset file loader implementation
3 *
4 * Copyright (c) 2020-2023 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 MLK_RPG_TILESET_LOADER_FILE_H
20 #define MLK_RPG_TILESET_LOADER_FILE_H
21
22 /**
23 * \file mlk/rpg/tileset-loader-file.h
24 * \brief Tileset file loader implementation
25 *
26 * This convenient tileset loader loads tilesets from file and its associative
27 * resources relative to the tileset file directory.
28 *
29 * It also allocate memory for individual element and as such must be kept
30 * valid until the tileset is no longer used. If this behavior is not wanted,
31 * the allocator functions can be changed.
32 */
33
34 #include <mlk/util/util.h>
35
36 struct mlk_animation;
37 struct mlk_sprite;
38 struct mlk_texture;
39 struct mlk_tileset_animation;
40 struct mlk_tileset_collision;
41 struct mlk_tileset_loader;
42
43 /**
44 * \struct mlk_tileset_loader_file
45 * \brief Tileset file loader structure
46 */
47 struct mlk_tileset_loader_file {
48 /**
49 * (read-only)
50 *
51 * Computed tileset file directory.
52 */
53 char directory[MLK_PATH_MAX];
54
55 /** \cond MLK_PRIVATE_DECLS */
56 struct mlk_texture **textures;
57 struct mlk_sprite **sprites;
58 struct mlk_animation **animations;
59 struct mlk_tileset_collision *tilecollisions;
60 struct mlk_tileset_animation *tileanimations;
61 /** \endcond MLK_PRIVATE_DECLS */
62 };
63
64 /**
65 * Fill the abstract loader with appropriate implementation.
66 *
67 * All loader member functions will be set and ::mlk_tileset_loader::data will
68 * be set to file loader.
69 *
70 * The file and loader structure are zero'ed before being initialized.
71 *
72 * \pre file != NULL
73 * \pre loader != NULL
74 * \pre filename != NULL
75 * \param file the file loader
76 * \param loader the abstract loader interface
77 * \param filename path to the tileset file
78 */
79 void
80 mlk_tileset_loader_file_init(struct mlk_tileset_loader_file *file,
81 struct mlk_tileset_loader *loader,
82 const char *filename);
83
84 /**
85 * Cleanup allocated resources by this file loader.
86 *
87 * \pre file != NULL
88 * \param file the file loader
89 */
90 void
91 mlk_tileset_loader_file_finish(struct mlk_tileset_loader_file *file);
92
93 #endif /* !MLK_RPG_TILESET_LOADER_FILE_H */