/* 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 __TileAdjacencyBehaviorSet_H__ #define __TileAdjacencyBehaviorSet_H__ #include "serialization/DeserializationContext.h" #include "serialization/SerializationContext.h" #include "tileset/ImageCollection.h" #include "tileset/TileAdjacencyBehavior.h" #include "utilities/HashTable.h" typedef uint32_t TileAdjacencyBehaviorSetID; #define TILE_ADJACENCY_BEHAVIOR_SET_FORMAT_TYPE "tile_adjacency_behavior_set" #define TILE_ADJACENCY_BEHAVIOR_SET_FORMAT_VERSION 0 #define TILE_ADJACENCY_BEHAVIOR_SET_BEHAVIOR_COUNT_MAX 16384 typedef struct TileAdjacencyBehaviorSet { TileAdjacencyBehaviorSetID identifier; char * name; unsigned int behaviorCount; TileAdjacencyBehavior * behaviors; HashTable * behaviorLookup; bool lookupDirty; } TileAdjacencyBehaviorSet; // If copy is false, ownership will be taken on all contents of behaviors. Ownership is never taken of the behaviors pointer itself. TileAdjacencyBehaviorSet * TileAdjacencyBehaviorSet_create(TileAdjacencyBehaviorSetID identifier, const char * name, unsigned int behaviorCount, TileAdjacencyBehavior * behaviors, bool copy); TileAdjacencyBehaviorSet * TileAdjacencyBehaviorSet_copy(TileAdjacencyBehaviorSet * behaviorSet); void TileAdjacencyBehaviorSet_dispose(TileAdjacencyBehaviorSet * behaviorSet); void TileAdjacencyBehaviorSet_serializeMinimal(TileAdjacencyBehaviorSet * behaviorSet, compat_type(SerializationContext *) serializationContext); void TileAdjacencyBehaviorSet_serialize(TileAdjacencyBehaviorSet * behaviorSet, compat_type(SerializationContext *) serializationContext); TileAdjacencyBehaviorSet * TileAdjacencyBehaviorSet_deserializeMinimal(compat_type(DeserializationContext *) deserializationContext, uint16_t formatVersion); TileAdjacencyBehaviorSet * TileAdjacencyBehaviorSet_deserialize(compat_type(DeserializationContext *) deserializationContext); // Takes ownership of behavior void TileAdjacencyBehaviorSet_addBehavior(TileAdjacencyBehaviorSet * behaviorSet, TileAdjacencyBehavior behavior); void TileAdjacencyBehaviorSet_insertBehavior(TileAdjacencyBehaviorSet * behaviorSet, unsigned int behaviorIndex, TileAdjacencyBehavior behavior); void TileAdjacencyBehaviorSet_removeBehaviorAtIndex(TileAdjacencyBehaviorSet * behaviorSet, unsigned int behaviorIndex); void TileAdjacencyBehaviorSet_reorderBehavior(TileAdjacencyBehaviorSet * behaviorSet, unsigned int fromBehaviorIndex, unsigned int toBehaviorIndex); void TileAdjacencyBehaviorSet_resolveImageIndexes(TileAdjacencyBehaviorSet * behaviorSet, ImageCollection * imageCollection); void TileAdjacencyBehaviorSet_calculateTotalBounds(TileAdjacencyBehaviorSet * behaviorSet, ImageCollection * imageCollection); // If behaviorCountMax is 0, return value is unclamped; if > 0, return value is clamped to number written to outBehaviors unsigned int TileAdjacencyBehaviorSet_getApplicableBehaviors(TileAdjacencyBehaviorSet * behaviorSet, Vector2i position, TileID tileID, TileQueryCallback queryCallback, void * callbackContext, unsigned int behaviorCountMax, TileAdjacencyBehavior ** outBehaviors); #endif