Mercurial > molko
comparison librpg/rpg/map-file.h @ 197:852d0b7817ce
rpg: map, extreme cleanup, closes #2508 @4h
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 09 Nov 2020 10:37:36 +0100 |
parents | |
children | 70e6ed74940d |
comparison
equal
deleted
inserted
replaced
196:658ee50b8bcb | 197:852d0b7817ce |
---|---|
1 /* | |
2 * map-file.h -- map 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_MAP_FILE_H | |
20 #define MOLKO_MAP_FILE_H | |
21 | |
22 /** | |
23 * \file map-file.h | |
24 * \brief Map file loader. | |
25 * | |
26 * Because a map is a complicated object that require several components to be | |
27 * loaded, the way it is loaded from a source is implemented separately to keep | |
28 * the \ref map.h module as simple as possible. | |
29 * | |
30 * This module load map files generated from mlk-map tool and expect some | |
31 * convention from the user: | |
32 * | |
33 * - A tileset image must be present in the same directory as the map itself. | |
34 * | |
35 * This module allocates some dynamic data that are stored in the map object as | |
36 * such the map_file structure must be kept until the map is no longer used | |
37 * itself. | |
38 */ | |
39 | |
40 #include <stdbool.h> | |
41 | |
42 #include <core/plat.h> | |
43 #include <core/sprite.h> | |
44 #include <core/texture.h> | |
45 | |
46 #include "map.h" | |
47 | |
48 /** | |
49 * \brief Maximum title map length in file. | |
50 */ | |
51 #define MAP_FILE_TITLE_MAX 64 | |
52 | |
53 /** | |
54 * \brief Context for loading maps. | |
55 * | |
56 * Member fields should not be modified directly but must be modified in the | |
57 * underlying associated map object once loaded. | |
58 * | |
59 * Since the map object does not own resources, this map file will dynamically | |
60 * load and store them from the file and thus must not be destroyed until the | |
61 * map is no longer use itself. | |
62 */ | |
63 struct map_file { | |
64 /** | |
65 * (*) Map title loaded from file. | |
66 */ | |
67 char title[MAP_FILE_TITLE_MAX]; | |
68 | |
69 /** | |
70 * (*) Map layers stored dynamically here. | |
71 */ | |
72 struct map_layer layers[MAP_LAYER_TYPE_NUM]; | |
73 | |
74 struct texture tileset; /*!< (*) Tileset image. */ | |
75 struct sprite sprite; /*!< (*) Tileset sprite. */ | |
76 }; | |
77 | |
78 /** | |
79 * Try to open a map from a file path. | |
80 * | |
81 * \pre file != NULL | |
82 * \pre path != NULL | |
83 * \pre map != NULL | |
84 * \param file the loader to use | |
85 * \param path the path to the map file | |
86 * \param map the map to set | |
87 * \warning Keep file object until map is no longer used. | |
88 */ | |
89 bool | |
90 map_file_open(struct map_file *file, const char *path, struct map *map) PLAT_NODISCARD; | |
91 | |
92 /** | |
93 * Close resources from the loader. | |
94 * | |
95 * \pre file != NULL | |
96 * \param file the file to loader to destroy | |
97 * \warning Destroy the map itself before calling this function. | |
98 */ | |
99 void | |
100 map_file_finish(struct map_file *file); | |
101 | |
102 #endif /* !MOLKO_MAP_FILE_H */ |