zlib used for (de)compression

This commit is contained in:
Zeno Rogue 2020-01-26 00:30:13 +01:00
parent 76a0ea8795
commit f20a6bf2f6
5 changed files with 48 additions and 4 deletions

View File

@ -52,7 +52,7 @@ ifeq (${OS},linux)
LDFLAGS_GL := -lGL
LDFLAGS_GLEW := -lGLEW
LDFLAGS_PNG := -lpng
LDFLAGS_SDL := -lSDL -lSDL_gfx -lSDL_mixer -lSDL_ttf -lpthread
LDFLAGS_SDL := -lSDL -lSDL_gfx -lSDL_mixer -lSDL_ttf -lpthread -lz
OBJ_EXTENSION := .o
hyper_RES :=
endif
@ -63,7 +63,7 @@ ifeq (${OS},mingw)
LDFLAGS_GL := -lopengl32
LDFLAGS_GLEW := -lglew32
LDFLAGS_PNG := -lpng
LDFLAGS_SDL := -lSDL -lSDL_gfx -lSDL_mixer -lSDL_ttf
LDFLAGS_SDL := -lSDL -lSDL_gfx -lSDL_mixer -lSDL_ttf -lz -lphtread
OBJ_EXTENSION := .o
hyper_RES := hyper.res
ifeq (${HYPERROGUE_USE_GLEW},)
@ -78,7 +78,7 @@ ifeq (${OS},osx)
LDFLAGS_GL := -framework AppKit -framework OpenGL
LDFLAGS_GLEW := -lGLEW
LDFLAGS_PNG := -lpng
LDFLAGS_SDL := -lSDL -lSDLMain -lSDL_gfx -lSDL_mixer -lSDL_ttf
LDFLAGS_SDL := -lSDL -lSDLMain -lSDL_gfx -lSDL_mixer -lSDL_ttf -lz -lpthread
OBJ_EXTENSION := .o
hyper_RES :=
endif

View File

@ -30,6 +30,7 @@ AC_SEARCH_LIBS([aacircleColor], [SDL_gfx], [], AC_MSG_RESULT([SDL_gfx library wa
AC_SEARCH_LIBS([Mix_LoadMUS], [SDL_mixer], [], AC_MSG_ERROR([SDL_mixer library was not found]))
AC_SEARCH_LIBS([TTF_OpenFont], [SDL_ttf], [], AC_MSG_RESULT([SDL_ttf library was not found]))
AC_SEARCH_LIBS(pthread_create, [pthread], ,AC_MSG_ERROR([pthread library was not found]))
AC_SEARCH_LIBS(deflateInit, [z], ,AC_MSG_ERROR([zlib was not found]))
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

View File

@ -30,7 +30,7 @@ string compiler =
string linker =
"g++ -rdynamic -o hyper";
string libs = " savepng-loc.o -lSDL -lSDL_ttf -lSDL_mixer -lSDL_gfx -lGLEW -lGL -lpng -rdynamic -lpthread";
string libs = " savepng-loc.o -lSDL -lSDL_ttf -lSDL_mixer -lSDL_gfx -lGLEW -lGL -lpng -rdynamic -lpthread -lz";
vector<string> modules;

View File

@ -426,6 +426,8 @@ extern "C" {
#include <complex>
#include <new>
#include <zlib.h>
#if CAP_THREAD
#if WINDOWS
#include "mingw.thread.h"

View File

@ -523,4 +523,45 @@ bignum::bignum(ld d) {
while(n >= 0) { digits[n] = int(d); d -= digits[n]; d *= BASE; n--; }
}
/* compression/decompression */
EX string compress_string(string s) {
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
println(hlog, "pre init");
auto ret = deflateInit(&strm, 9);
if(ret != Z_OK) throw "z-error";
println(hlog, "init ok");
strm.avail_in = isize(s);
strm.next_in = (Bytef*) &s[0];
vector<char> buf(1000000, 0);
strm.avail_out = 1000000;
strm.next_out = (Bytef*) &buf[0];
if(deflate(&strm, Z_FINISH) != Z_STREAM_END) throw "z-error-2";
println(hlog, "deflate ok");
string out(&buf[0], (char*)(strm.next_out) - &buf[0]);
println(hlog, isize(s), " -> ", isize(out));
return out;
}
EX string decompress_string(string s) {
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
auto ret = inflateInit(&strm);
if(ret != Z_OK) throw "z-error";
strm.avail_in = isize(s);
strm.next_in = (Bytef*) &s[0];
vector<char> buf(1000000, 0);
strm.avail_out = 1000000;
strm.next_out = (Bytef*) &buf[0];
if(inflate(&strm, Z_FINISH) != Z_STREAM_END) throw "z-error-2";
string out(&buf[0], (char*)(strm.next_out) - &buf[0]);
println(hlog, isize(s), " -> ", isize(out));
return out;
}
}