From: Mattia Basaglia Date: Fri, 28 Nov 2014 17:00:36 +0000 (+0100) Subject: Add some cleanup functions X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9aa67a1c563fa9d963353b70a2d0398c7efff579;p=xonotic%2Fdarkplaces.git Add some cleanup functions --- diff --git a/xml.c b/xml.c index 8201906d..f739674e 100644 --- a/xml.c +++ b/xml.c @@ -332,6 +332,18 @@ struct Tiled_PropertyNode { typedef Tiled_PropertyNode* Tiled_Properties; +// clear the properties structure +static void tmx_properties_clean(Tiled_Properties props) +{ + if ( !props ) + return; + if ( props->next ) + tmx_properties_clean(props->next); + free(props->property.name); + free(props->property.value); + free(props); +} + // Image/Tile data typedef struct { // Name of the image file @@ -344,6 +356,12 @@ typedef struct { unsigned id; } Tiled_Image; +// Clean a Tiled_Image(Doesn't free the given pointer) +static void tmx_image_clean(Tiled_Image *img) +{ + free(img->source); +} + // Tileset typedef struct { // Images of acollection or single image split in a grid @@ -381,14 +399,6 @@ struct Tiled_Layer Tiled_Layer* next_layer; }; -// Load common data for and -static Tiled_Layer tmx_layer_common(xmlNodePtr xml_node) -{ - Tiled_Layer l; - // TODO - return l; -} - // Tile layer typedef struct { Tiled_Layer layer; @@ -396,13 +406,6 @@ typedef struct { unsigned data_size; } Tiled_TileLayer; -// Load -static Tiled_TileLayer* tmx_layer(xmlNodePtr xml_node) -{ - // TODO - return NULL; -} - // Object typedef struct { char* name; @@ -426,19 +429,27 @@ typedef struct { unsigned objects_size; } Tiled_ObjectLayer; -// load -static Tiled_ObjectLayer* tmx_objectgroup(xmlNodePtr xml_node) -{ - // TODO - return NULL; -} - // Image layer typedef struct { Tiled_Layer layer; Tiled_Image image; } Tiled_ImageLayer; +// Load common data for and +static Tiled_Layer tmx_layer_common(xmlNodePtr xml_node) +{ + Tiled_Layer l; + // TODO + return l; +} + +// Load +static Tiled_TileLayer* tmx_layer(xmlNodePtr xml_node) +{ + // TODO + return NULL; +} + // load static Tiled_ImageLayer* tmx_imagelayer(xmlNodePtr xml_node) { @@ -446,6 +457,31 @@ static Tiled_ImageLayer* tmx_imagelayer(xmlNodePtr xml_node) return NULL; } +// load +static Tiled_ObjectLayer* tmx_objectgroup(xmlNodePtr xml_node) +{ + // TODO + return NULL; +} + +// clean up and friends +static void tmx_layer_clean(Tiled_Layer* layer) +{ + if ( !layer ) + return; + if ( layer->next_layer ) + tmx_layer_clean(layer->next_layer); + free(layer->name); + tmx_properties_clean(layer->properties); + if ( layer->type == TILED_TILELAYER ) + free( ((Tiled_TileLayer*)layer)->data ); + else if ( layer->type == TILED_OBJECTLAYER ) + ; // TODO clean objects + else if ( layer->type == TILED_IMAGELAYER ) + tmx_image_clean(&((Tiled_ImageLayer*)layer)->image); + +} + // Map typedef struct { // File format version @@ -558,3 +594,12 @@ static Tiled_Map* tmx_map_load(const char* filename) return map; } + +// Clean up the map struct +static void tmx_map_clean(Tiled_Map* map) +{ + tmx_properties_clean(map->properties); + tmx_layer_clean(map->first_layer); + free(map); +} +