Переглянути джерело

Breaking the map/layer code apart. Needs more work.

legacy
Sam Hocevar sam 14 роки тому
джерело
коміт
76b9dfc1be
3 змінених файлів з 60 додано та 18 видалено
  1. +5
    -15
      src/layer.cpp
  2. +2
    -2
      src/layer.h
  3. +53
    -1
      src/map.cpp

+ 5
- 15
src/layer.cpp Переглянути файл

@@ -1,25 +1,14 @@

#include "layer.h"

Layer::Layer(char const *name, int w, int h, FILE *fp)
Layer::Layer(int w, int h, int z, char const *base64)
{
width = w;
height = h;
level = z;
data = new unsigned int[w * h];

if (sscanf(name, "Ground %d", &z) == 1)
;
else if (sscanf(name, "Ground Decal %d", &z) == 1)
;
else if (sscanf(name, "Object %d", &z) == 1)
z++;
else if (sscanf(name, "Wall %d", &z) == 1)
z++;
else if (sscanf(name, "Wall Decal %d", &z) == 1)
z++;
else
z = -1;

#if 0
fread(data, sizeof(unsigned int), width * height, fp);
for (int n = 0; n < width * height; n++)
{
@@ -27,6 +16,7 @@ Layer::Layer(char const *name, int w, int h, FILE *fp)
// XXX: endianness swapping might be necessary here
data[n] = i ? i - 1 : 0;
}
#endif
}

Layer::~Layer()
@@ -36,7 +26,7 @@ Layer::~Layer()

int Layer::GetZ()
{
return z;
return level;
}

unsigned int Layer::GetTile(int x, int y)


+ 2
- 2
src/layer.h Переглянути файл

@@ -11,14 +11,14 @@
class Layer
{
public:
Layer(char const *name, int w, int h, FILE *fp);
Layer(int w, int h, int z, char const *base64);
~Layer();

int GetZ();
unsigned int GetTile(int x, int y);

private:
int width, height, z;
int width, height, level;
unsigned int *data;
};



+ 53
- 1
src/map.cpp Переглянути файл

@@ -9,6 +9,58 @@ Map::Map(char const *path) :
layers(0),
nlayers(0)
{
char tmp[BUFSIZ];
int firstgid = 0, width = 0, height = 0, level = 0, data = 0;

FILE *fp = fopen(path, "r");

if (!fp)
return;

while (!feof(fp))
{
char str[1024];
int i, j, k;
char a, b;

fgets(tmp, BUFSIZ, fp);

if (data)
{
if (--data == 0)
{
layers[nlayers] = new Layer(width, height, level, tmp);
nlayers++;
}
}
else if (sscanf(tmp, " <tileset firstgid=\"%i\"", &i) == 1)
{
firstgid = i;
fprintf(stderr, "found tileset, firstgid %i\n", firstgid);
}
else if (sscanf(tmp, " <image source=\"%[^\"]\"", str) == 1)
{
fprintf(stderr, "image %s\n", str);
}
else if (sscanf(tmp, " <layer name=\"%c%i%c%*[^\"]\" width=\"%i\" height=\"%i\"",
&a, &i, &b, &j, &k) == 5)
{
fprintf(stderr, "%s layer, level %i, sublevel %c, %ix%i\n",
a == 'H' ? "horizontal" : "vertical", i, b, j, k);
layers = (Layer **)realloc(layers, sizeof(Layer **) * (nlayers + 1));
width = j;
height = k;
data = 2;
}
else
{
fprintf(stderr, ".");
}
}

fclose(fp);

/*
char tmp[1024];

sprintf(tmp, "grep '\\(^ [^< ]\\|layer name\\)' %s | while read i; do echo \"$i\"; read i; echo -n \"$i\" | perl -MMIME::Base64 -ne 'print decode_base64($_)' | gunzip; done", path);
@@ -17,7 +69,6 @@ Map::Map(char const *path) :

while (fp && !feof(fp))
{
char name[1024];
int width, height;

fscanf(fp, "<layer name=\"%[^\"]\" ", name);
@@ -32,6 +83,7 @@ Map::Map(char const *path) :
}

pclose(fp);
*/
}

Map::~Map()


Завантаження…
Відмінити
Зберегти