You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB

#include "mapobject.h"
#include <stdlib.h>
MapObject * MapObjectInit(Sprite *sprite, int id){
MapObject *new = malloc(sizeof(MapObject));
new->sprite = sprite;
new->id = id;
new->next = 0;
new->prev = 0;
return new;
}
MapObjectList * MapObjectListInit(){
MapObjectList *new = malloc(sizeof(MapObjectList));
new->head = 0;
new->tail = 0;
return new;
}
void MapObjectListPrintForward(MapObjectList *mapObjects){
}
void MapObjectListInsert(MapObjectList *mapObjects, MapObject *data){
if(mapObjects->head == 0){
mapObjects->head = data;
mapObjects->tail = data;
}
else{
mapObjects->tail->next = data;
data->prev = mapObjects->tail;
mapObjects->tail = data;
}
}
void MapObjectListRemove(MapObjectList *mapObjects, MapObject *remove){
if(remove == 0){
printf("WARNING: TRIED TO REMOVE NULLPOINTER\n");
}
else if(mapObjects->head == remove && mapObjects->tail == remove){
mapObjects->head = 0;
mapObjects->tail = 0;
}
else if(mapObjects->head == remove){
remove->next->prev = 0;
mapObjects->head = remove->next;
}
else if(mapObjects->tail == remove){
remove->prev->next = 0;
mapObjects->tail = remove->prev;
}
else{
remove->prev->next = remove->next;
remove->next->prev = remove->prev;
}
remove->next = 0;
remove->prev = 0;
}