65 lines
1.4 KiB
C
65 lines
1.4 KiB
C
#include <stdlib.h>
|
|
#include "tile.h"
|
|
|
|
struct Tile *newTile(float x, float y, float z, struct TileData *data) {
|
|
struct Tile *tile = malloc(sizeof(struct Tile));
|
|
//printf("%fx%fx%f\n", x, y, z);
|
|
tile->x = x;
|
|
tile->y = y;
|
|
tile->z = z;
|
|
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);
|
|
}
|
|
|
|
void appendTile(struct Tile *tile_target, struct Tile *new_tile) {
|
|
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;
|
|
}
|