diff --git a/makefile b/makefile index b0167d4..4b5cabf 100644 --- a/makefile +++ b/makefile @@ -24,7 +24,7 @@ CXXFLAGS += -Wall -Wempty-body -ansi -pedantic -Werror -Wstrict-prototypes -Werr CXXFLAGS += -g -lefence CXXFLAGS += -fms-extensions -std=gnu11 -LDFLAGS += `sdl2-config --libs` -lSDL2_mixer -lSDL2_image -lSDL2_ttf -lm +LDFLAGS += `sdl2-config --libs` -lSDL2_mixer -lSDL2_image -lSDL2_ttf -lm -lz SHARED_FILES = CHANGELOG LICENSE README.md data gfx manual music sound icons DIST_FILES = $(SHARED_FILES) locale $(PROG) diff --git a/src/system/io.c b/src/system/io.c index 0b4ac85..a2001b2 100644 --- a/src/system/io.c +++ b/src/system/io.c @@ -74,6 +74,42 @@ char *readFile(const char *filename) return buffer; } +char *readCompressedFile(const char *filename) +{ + unsigned char *buffer, *cBuffer; + unsigned long length, cLength; + FILE *file = fopen(getFileLocation(filename), "rb"); + + buffer = 0; + cBuffer = 0; + + if (file) + { + fread(&length, sizeof(unsigned long), 1, file); + fread(&cLength, sizeof(unsigned long), 1, file); + + buffer = malloc(length + 1); + memset(buffer, 0, length + 1); + + cBuffer = malloc(cLength + 1); + memset(cBuffer, 0, cLength + 1); + + fread(cBuffer, 1, cLength, file); + + uncompress(buffer, &length, cBuffer, cLength); + + fclose(file); + + buffer[length] = '\0'; + + free(cBuffer); + + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Decompressed '%s' %ld -> %ld", filename, cLength, length); + } + + return (char*) buffer; +} + int writeFile(const char *filename, const char *data) { FILE *file = fopen(filename, "wb"); diff --git a/src/system/io.h b/src/system/io.h index a1ee589..9091925 100644 --- a/src/system/io.h +++ b/src/system/io.h @@ -22,5 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "sys/stat.h" #include "dirent.h" +#include extern App app; diff --git a/src/world/map.c b/src/world/map.c index 1a69b43..6ecbeee 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -245,11 +245,11 @@ static void loadMapData(void) char *data, *p; int i, x, y; - sprintf(filename, "data/maps/raw/%s.raw", world.id); + sprintf(filename, "data/maps/raw/%s.raw.z", world.id); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename); - data = readFile(filename); + data = readCompressedFile(filename); p = data; diff --git a/src/world/map.h b/src/world/map.h index ef6579c..831b0f7 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern float limit(float i, float a, float b); extern int rrnd(int low, int high); extern char *readFile(const char *filename); +extern char *readCompressedFile(const char *filename); extern Atlas *getImageFromAtlas(char *filename); extern Texture *getTexture(const char *filename); extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);