/* Copyright (c) 2024 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 __AutoTileNew_H__ #define __AutoTileNew_H__ #include "gamemath/Rect4i.h" #include "serialization/DeserializationContext.h" #include "serialization/SerializationContext.h" #include "tileset/TilesetEditData.h" #define TILE_ID_SELF ((TileID) -1) #define TILE_ADJACENCY_FORMAT_VERSION 0 #define TILE_ADJACENCY_CONDITION_COUNT_MAX 128 #define TILE_ADJACENCY_MATCH_COUNT_MAX 1024 #define TILE_ADJACENCY_OVERLAY_COUNT_MAX 128 typedef TileID (* TileQueryCallback)(Vector2i position, void * context); #define TileAdjacencyRule_empty ((TileAdjacencyRule) {TILE_CONDITION_MATCH_SINGLE, {.single = {{0, 0}, 0}}}) typedef enum TileAdjacencyRuleType { TILE_CONDITION_AND, TILE_CONDITION_OR, TILE_CONDITION_MATCH_SINGLE, TILE_CONDITION_NONMATCH_SINGLE, TILE_CONDITION_MATCH_MULTIPLE, TILE_CONDITION_NONMATCH_MULTIPLE } TileAdjacencyRuleType; typedef struct TileAdjacencyMatchSingle { Vector2i offset; TileID tileID; } TileAdjacencyMatchSingle; typedef struct TileAdjacencyMatchMultiple { Vector2i offset; unsigned int tileIDCount; TileID * tileIDs; } TileAdjacencyMatchMultiple; typedef struct TileAdjacencyRule { TileAdjacencyRuleType type; union { struct { unsigned int count; struct TileAdjacencyRule * conditions; } conditionList; TileAdjacencyMatchSingle single; TileAdjacencyMatchMultiple multiple; } rule; } TileAdjacencyRule; typedef struct TileAdjacencyOverlay { ImageID imageID; Vector2i offset; Rect4i sliceInsets; int32_t drawPriority; unsigned int imageIndex; // Runtime only; use TileAdjacencyBehaviorSet_resolveImageIndexes() to initialize } TileAdjacencyOverlay; typedef struct TileAdjacencyBehavior { TileID ownTileID; bool exclusive; TileAdjacencyRule rule; Rect4i sliceInsets; unsigned int overlayCount; TileAdjacencyOverlay * overlays; Rect4i totalBounds; // Runtime only; use TileAdjacencyBehaviorSet_calculateTotalBounds() or TileAdjacencyBehavior_calculateTotalBounds() (after imageIndex has been resolved) to initialize } TileAdjacencyBehavior; // If copy is false, all contents of rule and overlays are assumed to be heap-allocated, and ownership is taken of them TileAdjacencyBehavior TileAdjacencyBehavior_init(TileID ownTileID, bool exclusive, TileAdjacencyRule rule, Rect4i sliceInsets, unsigned int overlayCount, TileAdjacencyOverlay * overlays, bool copy); TileAdjacencyBehavior TileAdjacencyBehavior_copy(TileAdjacencyBehavior * behavior); void TileAdjacencyBehavior_dispose(TileAdjacencyBehavior * behavior); void TileAdjacencyBehavior_serializeMinimal(TileAdjacencyBehavior * behavior, compat_type(SerializationContext *) serializationContext); bool TileAdjacencyBehavior_deserializeMinimal(TileAdjacencyBehavior * behavior, compat_type(DeserializationContext *) deserializationContext, uint16_t formatVersion); void TileAdjacencyBehavior_addOverlay(TileAdjacencyBehavior * behavior, TileAdjacencyOverlay overlay); void TileAdjacencyBehavior_insertOverlay(TileAdjacencyBehavior * behavior, unsigned int overlayIndex, TileAdjacencyOverlay overlay); void TileAdjacencyBehavior_removeOverlayAtIndex(TileAdjacencyBehavior * behavior, unsigned int overlayIndex); void TileAdjacencyBehavior_reorderOverlay(TileAdjacencyBehavior * behavior, unsigned int fromOverlayIndex, unsigned int toOverlayIndex); void TileAdjacencyBehavior_calculateTotalBounds(TileAdjacencyBehavior * behavior, ImageCollection * imageCollection); bool TileAdjacencyBehavior_isApplicable(TileAdjacencyBehavior * behavior, Vector2i position, TileQueryCallback queryCallback, void * callbackContext); TileAdjacencyRule TileAdjacencyRule_copy(TileAdjacencyRule * rule); void TileAdjacencyRule_dispose(TileAdjacencyRule * rule); bool TileAdjacencyRule_isEqual(TileAdjacencyRule * rule1, TileAdjacencyRule * rule2); #endif