1 /////////////////////////////////////////////////////////////////////////////// 2 // Copyright (C) 2004-2011 by The Allacrost Project 3 // Copyright (C) 2012-2016 by Bertram (Valyria Tear) 4 // All Rights Reserved 5 // 6 // This code is licensed under the GNU GPL version 2. It is free software 7 // and you may modify it and/or redistribute it under the terms of this license. 8 // See https://www.gnu.org/copyleft/gpl.html for details. 9 /////////////////////////////////////////////////////////////////////////////// 10 11 /** **************************************************************************** 12 *** \file map_tiles.h 13 *** \author Tyler Olsen, roots@allacrost.org 14 *** \author Yohann Ferreira, yohann ferreira orange fr 15 *** \brief Header file for map mode tile management. 16 *** 17 *** This code encapsulates everything related to tiles and tile management in 18 *** map mode. 19 *** ***************************************************************************/ 20 21 #ifndef __MAP_TILES_HEADER__ 22 #define __MAP_TILES_HEADER__ 23 24 #include "modes/map/map_utils.h" 25 26 #include "script/script_read.h" 27 28 namespace vt_video { 29 class ImageDescriptor; 30 class AnimatedImage; 31 } 32 33 namespace vt_map 34 { 35 36 class MapMode; 37 38 namespace private_map 39 { 40 41 //! \brief Layer types: Drawn before, along, or after the map objects according to their types. 42 enum LAYER_TYPE { 43 GROUND_LAYER = 0, 44 SKY_LAYER = 1, 45 INVALID_LAYER = 2 46 }; 47 48 class Layer 49 { 50 public: 51 LAYER_TYPE layer_type; 52 // Represents the tile indeces: i.e: tiles[y][x] = tile_id at (x,y) 53 std::vector< std::vector<int16_t> > tiles; 54 Layer()55 Layer(): 56 layer_type(GROUND_LAYER) 57 {} 58 }; 59 60 /** **************************************************************************** 61 *** \brief A helper class to MapMode responsible for all tile data and operations 62 *** 63 *** This class is responsible for loading, updating, and drawing all tile images 64 *** and managing the tile grid. The TileSupervisor does <b>not</b> manage the map 65 *** collision grid, which is used by map objects and sprites. 66 *** 67 *** Maps have a minimum size of 24 rows and 32 columns of tiles. Theoretically 68 *** there is no upper limit on size. 69 *** ***************************************************************************/ 70 class TileSupervisor 71 { 72 friend class vt_map::MapMode; 73 74 public: 75 TileSupervisor(); 76 77 ~TileSupervisor(); 78 79 /** \brief Handles all operations on loading tilesets and tile images from the map data file 80 *** \param map_file A reference to the Lua file containing the map data 81 *** \note The map file should already be opened with no Lua tables open 82 **/ 83 bool Load(vt_script::ReadScriptDescriptor &map_file); 84 85 //! \brief Updates all animated tile images 86 void Update(); 87 88 /** \brief Draws the various tile layers to the screen 89 *** \param frame A pointer to the computed information required to draw this frame 90 *** 91 *** \note This function does not reset the coordinate system and hence require 92 *** that the proper coordinate system is already set prior to these function 93 *** calls (0.0f, SCREEN_COLS, SCREEN_ROWS, 0.0f). These functions do make 94 *** modifications to the blending draw flag and the draw cursor position 95 *** which are not restored by the function upon its return, so take measures 96 *** to retain this information before calling these functions if necessary. 97 **/ 98 //@{ 99 void DrawLayers(const MapFrame *frame, const LAYER_TYPE &layer_type); 100 //@} 101 102 private: 103 /** \brief The number of columns of tiles in the map. 104 *** This number must be greater than or equal to 32 for the map to be valid. 105 **/ 106 uint16_t _num_tile_on_x_axis; 107 108 /** \brief The number of rows of tiles in the map. 109 *** This number must be greater than or equal to 24 for the map to be valid. 110 **/ 111 uint16_t _num_tile_on_y_axis; 112 113 //! \brief The map tile layers 114 std::vector<Layer> _tile_grid; 115 116 //! \brief Contains the image objects for all map tiles, both still and animated. 117 std::vector<vt_video::ImageDescriptor *> _tile_images; 118 119 /** \brief Contains all of the animated tile images used on the map. 120 *** The purpose of this vector is to easily update all tile animations without stepping through the 121 *** _tile_images vector, which contains both still and animated images. 122 **/ 123 std::vector<vt_video::AnimatedImage *> _animated_tile_images; 124 }; // class TileSupervisor 125 126 } // namespace private_map 127 128 } // namespace vt_map 129 130 #endif // __MAP_TILES_HEADER__ 131