68 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C
		
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C
		
	
	
| #include <stdlib.h>
 | |
| #include <stdio.h> // for printf TODO: create own debug/print system
 | |
| #include "tile.h"
 | |
| 
 | |
| struct Tile *newTile(struct TileData *data) {
 | |
|   struct Tile *tile = malloc(sizeof(struct Tile));
 | |
|   tile->x = 0.0f;
 | |
|   tile->y = 0.0f;
 | |
|   tile->z = 0.0f;
 | |
|   tile->set = 0;
 | |
|   tile->frame = 0;
 | |
|   tile->data = duplicateTileData(data);
 | |
|   if (tile->data == NULL) {
 | |
|     printf("ERR: duplicateTileData failed\n");
 | |
|   }
 | |
|   tile->next = NULL;
 | |
|   tile->prev = NULL;
 | |
|   return tile;
 | |
| }
 | |
| 
 | |
| void freeTile(struct Tile *tile) {
 | |
|   freeTileData(tile->data);
 | |
|   free(tile);
 | |
| }
 | |
| 
 | |
| // TODO: return non-VOID and check for NULL tile_target and new_tile
 | |
| void appendTile(struct Tile *tile_target, struct Tile *new_tile) {
 | |
|   if (tile_target == NULL)
 | |
|     return;
 | |
|   if (new_tile == tile_target)
 | |
|     return;
 | |
|   struct Tile *current_tile = tile_target;
 | |
|   while (current_tile->next != NULL) {
 | |
|     current_tile = current_tile->next;
 | |
|   }
 | |
|   current_tile->next = new_tile;
 | |
|   new_tile->prev = current_tile;
 | |
| }
 | |
| 
 | |
| void insertTile(struct Tile* tile_target, struct Tile* new_tile) {
 | |
|   if (new_tile == tile_target)
 | |
|     return;
 | |
|   if (tile_target->next) {
 | |
|     new_tile->next = tile_target->next;
 | |
|   }
 | |
|   tile_target->next = new_tile;
 | |
|   new_tile->prev = tile_target;
 | |
| }
 | |
| 
 | |
| void removeTile(struct Tile* tile) {
 | |
|   if (tile->prev) {
 | |
|     if (tile->next) {
 | |
|       tile->prev->next = tile->next;
 | |
|     } else {
 | |
|       tile->prev->next = NULL;
 | |
|     }
 | |
|   }
 | |
|   if (tile->next) {
 | |
|     if (tile->prev) {
 | |
|       tile->next->prev = tile->prev;
 | |
|     } else {
 | |
|       tile->next->prev = NULL;
 | |
|     }
 | |
|   }
 | |
|   tile->prev = NULL;
 | |
|   tile->next = NULL;
 | |
| }
 |