/* Copyright (c) 2023 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __TileMapVisual_H__ #define __TileMapVisual_H__ typedef struct TileMapVisual TileMapVisual; #define TileMapVisual_superclass StemObject #include "stemobject/StemObject.h" #include "tileset/TileMapEditData.h" #include "tileset/TileAdjacencyBehaviorSet.h" #include "tileset/TilesetAdjacencyBlendMap.h" typedef enum TileMapVisual_shape { TILE_SHAPE_QUAD, TILE_SHAPE_TRIANGLE_UPPER_LEFT, TILE_SHAPE_TRIANGLE_UPPER_RIGHT, TILE_SHAPE_TRIANGLE_LOWER_LEFT, TILE_SHAPE_TRIANGLE_LOWER_RIGHT } TileMapVisual_shape; typedef struct TileMapVisual_drawnTile { Vector2i tilePosition; // Tile's upper left corner in the tile grid Vector2i offset; Vector2u size; Rect4f textureBounds; TileMapVisual_shape shape; TileID tileID; int drawPriority; unsigned int listOrder; } TileMapVisual_drawnTile; #define TileMapVisual_ivars \ StemObject_ivars \ \ TilesetEditData * tileset; \ ImageCollection * imageCollection; \ unsigned int drawnTileCount; \ unsigned int drawnTileAllocatedCount; \ TileMapVisual_drawnTile * drawnTiles; \ unsigned int nextListOrder; #define TileMapVisual_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(TileMapVisual) TileMapVisual * TileMapVisual_create(TilesetEditData * tileset, ImageCollection * imageCollection); bool TileMapVisual_init(TileMapVisual * self, TilesetEditData * tileset, ImageCollection * imageCollection); void TileMapVisual_dispose(TileMapVisual * self); TileMapVisual * TileMapVisual_copy(TileMapVisual * self); // Adds drawnTile entries for every drawable tile in tileGrid in reading order. No adjacencies will be calculated. void TileMapVisual_addTileInstanceGrid(TileMapVisual * self, TileInstanceGrid * tileGrid, Vector2i tileOffset); // Adds drawnTile entries for every drawable tile in tileGrid in reading order, using blendMap to look up adjacencies. void TileMapVisual_addTileInstanceGridWithBlendMap(TileMapVisual * self, TileInstanceGrid * tileGrid, TilesetAdjacencyBlendMap * blendMap, Vector2i tileOffset); // Adds drawnTile entries for each tile in tileRect, as looked up with queryCallback. behaviorSet is used to determine // slices and overlays. tileRect is noninclusive; rows and columns covered run from x/yMin to x/yMax - 1. void TileMapVisual_addTileInstanceGridWithBehaviorSet(TileMapVisual * self, TileAdjacencyBehaviorSet * behaviorSet, Rect4i tileRect, TileQueryCallback queryCallback, void * callbackContext); // Removes all drawnTile entries. void TileMapVisual_clear(TileMapVisual * self); // Returns a rectangle consisting of the union of every drawn tile in the TileMapVisual. The origin of the rectangle is the // tile map's top left corner, and it may extend negatively if edge tiles protrude upward or leftward, and may extend beyond // toe tile map's opposite corner if edge tiles protrude downward or rightward. Likewise, if an edge has no tiles defined, // the returned edge may be inward from the tile map's edge. This value is not cached, so calls may be expensive for visuals // with lots of tiles. Rect4i TileMapVisual_calculateExtendedBounds(TileMapVisual * self); // Sorts drawnTiles by drawPriority first, tilePosition.y second, tilePosition.x third, listOrder fourth. Higher is later. void TileMapVisual_sortByDrawPriority(TileMapVisual * self); #endif