gcsx_tileset.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* GCSx
  2. ** TILESET.H
  3. **
  4. ** Tileset support, objects and drawing
  5. ** Doesn't include any editor-only functionality
  6. */
  7. /*****************************************************************************
  8. ** Copyright (C) 2003-2006 Janson
  9. **
  10. ** This program is free software; you can redistribute it and/or modify
  11. ** it under the terms of the GNU General Public License as published by
  12. ** the Free Software Foundation; either version 2 of the License, or
  13. ** (at your option) any later version.
  14. **
  15. ** This program is distributed in the hope that it will be useful,
  16. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ** GNU General Public License for more details.
  19. **
  20. ** You should have received a copy of the GNU General Public License
  21. ** along with this program; if not, write to the Free Software
  22. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  23. *****************************************************************************/
  24. #ifndef __GCSx_TILESET_H_
  25. #define __GCSx_TILESET_H_
  26. class TileSet : virtual public LoadOnly {
  27. protected:
  28. // Is the tile set cached to our file and not in memory?
  29. int cached;
  30. FileRead* cacheFile;
  31. int lockCount;
  32. int lockCountPlay;
  33. // Name of tile set, where it's located
  34. std::string name;
  35. std::string nameL;
  36. class World* world; // NULL if not yet added to a world
  37. // Numeric ID- computer-generated- unique to world- nonzero
  38. int id;
  39. // All tiles are the same size
  40. int width;
  41. int height;
  42. int numTiles; // count doesn't include an always-blank (transparent) tile 0
  43. // If non-zero, the "preferred" number of tiles to display per line when
  44. // editing; technically editor-only but saved, so always available
  45. int numTilesPerLine;
  46. // Size information of tile surface- Number of tiles per line
  47. int tsPerLine;
  48. // Each tile stores a tile with alpha component
  49. // Format of data is always 32bpp RGBA
  50. SDL_Surface* tiles; // CACHEABLE
  51. // If new tiles or expanded tiles have a background of black or transparent
  52. int defaultTransparent;
  53. // Font tilesets store widths for each character; this pointer is NULL
  54. // for non-font tilesets
  55. int isFont;
  56. Uint32* fontWidths; // CACHEABLE
  57. // Non-font tilesets store zero or more collision maps; this pointer is NULL
  58. // if zero collision maps or a font tileset; these maps are bitmasks,
  59. // stored vertically map-by-map (one Uint32 per 32 pix wide rounded up,
  60. // one per pix high, organized columns-first)
  61. int numCollisionMaps; // count doesn't include always-blank map 0
  62. int cmWidth; // In Uint32s
  63. int cmHeight; // In Uint32s
  64. Uint32* collisionMaps; // CACHEABLE
  65. enum {
  66. // Max pixels in each direction we can make tile storage surfaces
  67. // We don't want surfaces over a certain width due to Sint16 calculations
  68. TILE_SURFACE_MAX = 32767,
  69. // Default per line, when creating a blank set
  70. TILE_DEFAULT_PERLINE = 16,
  71. TILE_FONTSET_PERLINE = 16,
  72. // Default counts when properties dialog called with "newSet" true
  73. TILE_DEFAULT_COUNT = 64,
  74. COLLISION_DEFAULT_COUNT = 0,
  75. };
  76. // Texture data
  77. class TextureMap* texture; // CACHEABLE
  78. // Calculates cmWidth and cmHeight from width and height
  79. void calculateCmSizes();
  80. // For generating textures
  81. static const TileSet* activeGenTexture;
  82. static void genTexture(int position, const SDL_Surface*& src, int& x, int& y);
  83. int doLock(int play) throw_File;
  84. int doUnlock(int play);
  85. void cacheLoadTiles() throw_File;
  86. public:
  87. // All tile numbers are 1-based
  88. // Id must be unique; use ID of 0 if we're going to load anyways
  89. // World and ID may be NULL/0 if in process of creating
  90. TileSet(class World* myWorld, int myId = 0); // Starts with default settings
  91. virtual ~TileSet();
  92. // Accessors
  93. int getWidth() const { return width; }
  94. // Fonts only; Lock required
  95. // WARNING: asserts tile is within proper range
  96. int getGlyphWidth(int tile) const;
  97. int getHeight() const { return height; }
  98. int getCount() const { return numTiles; }
  99. int getCollisionCount() const { return numCollisionMaps; }
  100. int getTilesPerLine() const { return numTilesPerLine; }
  101. const std::string& getName() const { return name; }
  102. const std::string& getNameL() const { return nameL; }
  103. int getIsFont() const { return isFont; }
  104. int getDefaultTransparent() const { return defaultTransparent; }
  105. const class World* getWorld() const { return world; }
  106. class World* getWorld() { return world; }
  107. int getId() const { return id; }
  108. int getBlockType() const { return WorldFileLoad::BLOCKTYPE_TILESET; }
  109. // Returns ptr to surface, stores x/y of tile within that surface
  110. // Non-play lock required
  111. // Returns NULL if outside valid range of tiles
  112. const SDL_Surface* getTileSurface(int tile, int& x, int& y) const;
  113. // File access
  114. void loadHeader(FileRead* file) throw_File;
  115. void loadContent(FileRead* file);
  116. int isContentCached() const;
  117. void cacheLoad() throw_File;
  118. // Play lock stores texture; non-play stores surface
  119. // Double lock if you need both (do regular lock first for efficiency)
  120. int markLock() throw_File;
  121. int markLockPlay() throw_File;
  122. int markUnlock();
  123. int markUnlockPlay();
  124. int isLocked() const;
  125. enum {
  126. // Default tile size, when creating a blank set
  127. TILE_DEFAULT_SIZE = 32,
  128. // Fixed counts for font sets
  129. TILE_FONTSET_NORMAL_COUNT = 96,
  130. TILE_FONTSET_EXT_COUNT = 224,
  131. };
  132. // Play lock required; NULL if not locked
  133. const class TextureMap* getTexture();
  134. };
  135. #endif