summaryrefslogtreecommitdiffstats
path: root/level.c
blob: cb102a64e8a2aa4d8a0fd2b399c6867c2b412606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "level.h"
#include <stdlib.h>


void addRoom(LEVEL *lvl, ROOM *room) {
  lvl->nRooms++;
  lvl->rooms = realloc(lvl->rooms, lvl->nRooms*sizeof(ROOM));
  lvl->rooms[lvl->nRooms-1] = *room;
}

void deleteRoom(LEVEL *lvl, unsigned int n) {
  int i;
  
  lvl->nRooms--;
  
  for(i = n; i < lvl->nRooms; i++)
    lvl->rooms[i] = lvl->rooms[i+1];
  
  lvl->rooms = realloc(lvl->rooms, lvl->nRooms*sizeof(ROOM));
}

void freeLevel(LEVEL *lvl) {
  int i;
  
  if(lvl) {
    if(lvl->rooms) {
      for(i = 0; i < lvl->nRooms; i++) {
        if(lvl->rooms[i].vertices)
          free(lvl->rooms[i].vertices);
      }
      
      free(lvl->rooms);
    }
    
    free(lvl);
  }
}