Mercurial > molko
view src/core/map.h @ 98:c7e993455985
map: split the map structure into two definitions
While here, add some macros to increase map_state readability.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 30 Mar 2020 20:30:00 +0200 |
parents | ed72843a7194 |
children |
line wrap: on
line source
/* * map.h -- game map * * Copyright (c) 2020 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef MOLKO_MAP_H #define MOLKO_MAP_H /** * \file map.h * \brief Game map. */ #include <stdbool.h> #include <stdio.h> #include "texture.h" /** * \brief Max title length for a map. */ #define MAP_TITLE_MAX 32 /** * \brief Max filename for tilesets. */ #define MAP_TILESET_MAX FILENAME_MAX /** * \brief Map layer. */ struct map_layer { unsigned short *tiles; /*!< (RO) Array of tiles, depending on the map size. */ }; /** * \brief Map definition structure. * * This structure only defines the map characteristics. It does not have any * logic and is left for game state. */ struct map_data { char title[MAP_TITLE_MAX]; /*!< (RW) The map title. */ char tileset[MAP_TILESET_MAX]; /*!< (RO) Name of tileset to use. */ int origin_x; /*!< (RO) Where the player starts in X. */ int origin_y; /*!< (RO) Where the player starts in Y. */ unsigned int real_w; /*!< (RO) Real width in pixels. */ unsigned int real_h; /*!< (RO) Real height in pixels. */ unsigned int w; /*!< (RO) Map width in cells. */ unsigned int h; /*!< (RO) Map height in cells. */ unsigned short tile_w; /*!< (RO) Pixels per cell (width). */ unsigned short tile_h; /*!< (RO) Pixels per cell (height). */ struct map_layer layers[2]; /*!< (RO) Layers (background, foreground). */ }; /** * \brief High level map object. * * This structure reference a map and perform drawing operations. */ struct map { struct map_data *data; /*!< (RW, ref) Map data. */ struct texture tileset; /*!< (RW) Tileset to use. */ struct texture picture; /*!< (RO) Map drawn into a picture. */ }; /** * Open a map defintion * * \pre data != NULL * \pre path != NULL * \param data the map defintion to fill * \param path the path to the map * \return True if successfully loaded. */ bool map_data_open(struct map_data *data, const char *path); /** * Dispose the map definition data. * * \pre data != NULL * \param data the map definition */ void map_data_finish(struct map_data *data); /** * Initialize this map. * * \pre map != NULL * \pre data != NULL * \param map the map to initialize * \param data the definition to reference * \return False on errors. */ bool map_init(struct map *map, struct map_data *data); /** * Render a map. * * \pre map != NULL * \param map the map to render * \param srcx the x coordinate region * \param srcy the y coordinate region */ void map_draw(struct map *map, int srcx, int srcy); /** * Force map repaint on its texture. * * \pre map != NULL * \param map the map to repaint * \warning This function does not render anything on the screen. */ void map_repaint(struct map *map); /** * Dispose map resources. * * \pre map != NULL * \param map the map to close */ void map_finish(struct map *map); #endif /* !MOLKO_MAP_H */