WID comments
[Lilanci.git] / map.c
blobee171f7ce70e4953a668e92ae7b6544da08d6af1
1 #include "map.h"
3 int AreaInMap(TMap *m, Area *p, int FromLayer, int ToLayer){ //returns 0 if p collides with something in m otherwise 1
4 int i,j;
5 if(!AreaInAreaComp(m->BoundingArea, p)){
6 return 0;
8 for(i = FromLayer; i < m->noLayer && i <= ToLayer; i++){
9 for(j=0; j < m->Layer[i]->noFArea; j++)
10 if(AreaInArea(p, m->Layer[i]->FArea[j]))
11 return 0;
13 return 1;
16 //TODO: support for another architectures than 32-bit x86
17 typedef unsigned int uint32;
18 typedef int int32;
19 typedef double double64;
21 typedef struct {
22 double64 XX;
23 double64 YY;
24 double64 X;
25 double64 Y;
26 uint32 noSprites;
27 uint32 noLayer;
28 uint32 *Layer_seek; //[noLayer]
29 uint32 *Sprite_seek; //[noSprite]
30 uint32 size;
31 }TMapFileHeader;
33 typedef struct{
34 uint32 noFArea;
35 uint32 *string_seek; //noFArea
36 uint32 size;
37 }TMapFileLayer;
39 typedef struct{
40 double64 x;
41 double64 y;
42 uint32 filename_seek;
43 uint32 size;
44 }TMapFileSprite;
46 typedef struct{
47 void *buffer;
48 TMapFileHeader header;
49 TMapFileLayer *layers;
50 TMapFileSprite *sprites;
51 uint32 buffer_lenght;
52 }TMapFileHelper;
54 uint32 AddStringToFile(TMapFileHelper *h, char *s) {
55 uint32 strl = strlen(s);
56 h->buffer = realloc(h->buffer, h->buffer_lenght + strl*sizeof(char) + 1);
57 memcpy(h->buffer+h->buffer_lenght, s, strl*sizeof(char) + 1);
58 h->buffer_lenght += strl*sizeof(char) + 1;
60 return h->buffer_lenght - strl*sizeof(char) + 1;
64 //TODO:
65 void FillTMapFileHeader(TMapFileHeader *header, TMap *m) {
67 char *TMapFileHeader2String (TMapFileHeader *header) {
70 char *Map2String(TMap *m, size_t *bytes) {
71 TMapFileHelper h;
72 char *buffer;
74 memset(&h, 0, sizeof(TMapFileHelper));
76 FillTMapFileHeader(&h.header, m); //warning, Layer_seek&Sprite_seek are only allocated, not filled
77 buffer = TMapFileHeader2String (&h.header);
78 AddStringToFile(&h, buffer);
79 free (buffer);
81 //TODO:
83 *bytes = h.buffer_lenght;
84 return (char *)(h.buffer);