diff --git a/src/engine/blend.hh b/src/engine/blend.hh index 10f390f..e4ed332 100644 --- a/src/engine/blend.hh +++ b/src/engine/blend.hh @@ -2,11 +2,11 @@ #define ENGINE_BLEND_HH #include +#include #include #include -#include extern int worldsize; /* FIXME: remove */ diff --git a/src/engine/command.cc b/src/engine/command.cc index 52478e1..d7ba469 100644 --- a/src/engine/command.cc +++ b/src/engine/command.cc @@ -9,8 +9,10 @@ #include #include +#include #include +#include #include "console.hh" #include "main.hh" // fatal, timings diff --git a/src/engine/console.hh b/src/engine/console.hh index 7ee18d9..229503f 100644 --- a/src/engine/console.hh +++ b/src/engine/console.hh @@ -1,7 +1,7 @@ #ifndef ENGINE_CONSOLE_HH #define ENGINE_CONSOLE_HH -#include +#include struct tagval; /* command.hh */ struct ident; diff --git a/src/engine/main.cc b/src/engine/main.cc index f3c7954..b24625e 100644 --- a/src/engine/main.cc +++ b/src/engine/main.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/src/engine/movie.cc b/src/engine/movie.cc index 77449ee..c042f36 100644 --- a/src/engine/movie.cc +++ b/src/engine/movie.cc @@ -11,6 +11,8 @@ #include +#include + #include #include "console.hh" /* conoutf */ diff --git a/src/engine/octaedit.cc b/src/engine/octaedit.cc index 361e946..0a0f59f 100644 --- a/src/engine/octaedit.cc +++ b/src/engine/octaedit.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include "blend.hh" #include "command.hh" diff --git a/src/engine/pvs.hh b/src/engine/pvs.hh index f12f02a..1e2c10f 100644 --- a/src/engine/pvs.hh +++ b/src/engine/pvs.hh @@ -1,8 +1,9 @@ #ifndef ENGINE_PVS_HH #define ENGINE_PVS_HH +#include + #include -#include void clearpvs(); bool pvsoccluded(const ivec &bbmin, const ivec &bbmax); diff --git a/src/engine/rendermodel.cc b/src/engine/rendermodel.cc index 5a50ef5..15bc77f 100644 --- a/src/engine/rendermodel.cc +++ b/src/engine/rendermodel.cc @@ -6,6 +6,7 @@ #include #include +#include #include #include diff --git a/src/engine/texture.cc b/src/engine/texture.cc index 85e2b31..6ba0823 100644 --- a/src/engine/texture.cc +++ b/src/engine/texture.cc @@ -12,7 +12,9 @@ #include #include +#include #include +#include #include "command.hh" // identflags #include "console.hh" /* conoutf */ diff --git a/src/engine/worldio.cc b/src/engine/worldio.cc index 822b078..f0acd5b 100644 --- a/src/engine/worldio.cc +++ b/src/engine/worldio.cc @@ -9,6 +9,7 @@ #include #include +#include #include #include "blend.hh" diff --git a/src/game/game.cc b/src/game/game.cc index ed12e3c..acd6ded 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -1,3 +1,5 @@ +#include + #include #include diff --git a/src/sauerlib/stream.cc b/src/sauerlib/stream.cc index aa42c35..b1c6b06 100644 --- a/src/sauerlib/stream.cc +++ b/src/sauerlib/stream.cc @@ -1,7 +1,10 @@ -#include "tools.hh" +#include "stream.hh" #include "encoding.hh" +// FIXME +#include + stream::offset stream::size() { offset pos = tell(), endpos; @@ -310,10 +313,8 @@ stream *openrawfile(const char *filename, const char *mode) stream *openfile(const char *filename, const char *mode) { -#ifndef STANDALONE stream *s = openzipfile(filename, mode); if(s) return s; -#endif return openrawfile(filename, mode); } diff --git a/src/sauerlib/stream.hh b/src/sauerlib/stream.hh new file mode 100644 index 0000000..f816b22 --- /dev/null +++ b/src/sauerlib/stream.hh @@ -0,0 +1,76 @@ +#ifndef SAUERLIB_STREAM_HH +#define SAUERLIB_STREAM_HH + +#include "tools.hh" + +/* workaround for some C platforms that have these two functions as macros - not used anywhere */ +#ifdef getchar +#undef getchar +#endif +#ifdef putchar +#undef putchar +#endif + +struct stream +{ +#ifdef WIN32 +#if defined(__GNUC__) && !defined(__MINGW32__) + typedef off64_t offset; +#else + typedef __int64 offset; +#endif +#else + typedef off_t offset; +#endif + + virtual ~stream() {} + virtual void close() = 0; + virtual bool end() = 0; + virtual offset tell() { return -1; } + virtual offset rawtell() { return tell(); } + virtual bool seek(offset pos, int whence = SEEK_SET) { return false; } + virtual offset size(); + virtual offset rawsize() { return size(); } + virtual size_t read(void *buf, size_t len) { return 0; } + virtual size_t write(const void *buf, size_t len) { return 0; } + virtual bool flush() { return true; } + virtual int getchar() { uchar c; return read(&c, 1) == 1 ? c : -1; } + virtual bool putchar(int n) { uchar c = n; return write(&c, 1) == 1; } + virtual bool getline(char *str, size_t len); + virtual bool putstring(const char *str) { size_t len = strlen(str); return write(str, len) == len; } + virtual bool putline(const char *str) { return putstring(str) && putchar('\n'); } + virtual size_t printf(const char *fmt, ...) PRINTFARGS(2, 3); + virtual uint getcrc() { return 0; } + + template size_t put(const T *v, size_t n) { return write(v, n*sizeof(T))/sizeof(T); } + template bool put(T n) { return write(&n, sizeof(n)) == sizeof(n); } + template bool putlil(T n) { return put(lilswap(n)); } + template bool putbig(T n) { return put(bigswap(n)); } + + template size_t get(T *v, size_t n) { return read(v, n*sizeof(T))/sizeof(T); } + template T get() { T n; return read(&n, sizeof(n)) == sizeof(n) ? n : 0; } + template T getlil() { return lilswap(get()); } + template T getbig() { return bigswap(get()); } +}; + +template +struct streambuf +{ + stream *s; + + streambuf(stream *s) : s(s) {} + + T get() { return s->get(); } + size_t get(T *vals, size_t numvals) { return s->get(vals, numvals); } + void put(const T &val) { s->put(&val, 1); } + void put(const T *vals, size_t numvals) { s->put(vals, numvals); } + size_t length() { return s->size(); } +}; + +stream *openrawfile(const char *filename, const char *mode); +stream *openfile(const char *filename, const char *mode); +stream *opentempfile(const char *filename, const char *mode); +stream *openutf8file(const char *filename, const char *mode, stream *file = nullptr); +char *loadfile(const char *fn, size_t *size, bool utf8 = true); + +#endif diff --git a/src/sauerlib/tools.hh b/src/sauerlib/tools.hh index 4b24ab2..e8ca511 100644 --- a/src/sauerlib/tools.hh +++ b/src/sauerlib/tools.hh @@ -1090,70 +1090,6 @@ template inline T bigswap(T n) { return islittleendian() ? endianswap(n template inline void bigswap(T *buf, size_t len) { if(islittleendian()) endianswap(buf, len); } #endif -/* workaround for some C platforms that have these two functions as macros - not used anywhere */ -#ifdef getchar -#undef getchar -#endif -#ifdef putchar -#undef putchar -#endif - -struct stream -{ -#ifdef WIN32 -#if defined(__GNUC__) && !defined(__MINGW32__) - typedef off64_t offset; -#else - typedef __int64 offset; -#endif -#else - typedef off_t offset; -#endif - - virtual ~stream() {} - virtual void close() = 0; - virtual bool end() = 0; - virtual offset tell() { return -1; } - virtual offset rawtell() { return tell(); } - virtual bool seek(offset pos, int whence = SEEK_SET) { return false; } - virtual offset size(); - virtual offset rawsize() { return size(); } - virtual size_t read(void *buf, size_t len) { return 0; } - virtual size_t write(const void *buf, size_t len) { return 0; } - virtual bool flush() { return true; } - virtual int getchar() { uchar c; return read(&c, 1) == 1 ? c : -1; } - virtual bool putchar(int n) { uchar c = n; return write(&c, 1) == 1; } - virtual bool getline(char *str, size_t len); - virtual bool putstring(const char *str) { size_t len = strlen(str); return write(str, len) == len; } - virtual bool putline(const char *str) { return putstring(str) && putchar('\n'); } - virtual size_t printf(const char *fmt, ...) PRINTFARGS(2, 3); - virtual uint getcrc() { return 0; } - - template size_t put(const T *v, size_t n) { return write(v, n*sizeof(T))/sizeof(T); } - template bool put(T n) { return write(&n, sizeof(n)) == sizeof(n); } - template bool putlil(T n) { return put(lilswap(n)); } - template bool putbig(T n) { return put(bigswap(n)); } - - template size_t get(T *v, size_t n) { return read(v, n*sizeof(T))/sizeof(T); } - template T get() { T n; return read(&n, sizeof(n)) == sizeof(n) ? n : 0; } - template T getlil() { return lilswap(get()); } - template T getbig() { return bigswap(get()); } -}; - -template -struct streambuf -{ - stream *s; - - streambuf(stream *s) : s(s) {} - - T get() { return s->get(); } - size_t get(T *vals, size_t numvals) { return s->get(vals, numvals); } - void put(const T &val) { s->put(&val, 1); } - void put(const T *vals, size_t numvals) { s->put(vals, numvals); } - size_t length() { return s->size(); } -}; - extern string homedir; extern char *makerelpath(const char *dir, const char *file, const char *prefix = nullptr, const char *cmd = nullptr); @@ -1166,17 +1102,8 @@ extern size_t fixpackagedir(char *dir); extern const char *sethomedir(const char *dir); extern const char *addpackagedir(const char *dir); extern const char *findfile(const char *filename, const char *mode); -extern bool findzipfile(const char *filename); -extern stream *openrawfile(const char *filename, const char *mode); -extern stream *openzipfile(const char *filename, const char *mode); -extern stream *openfile(const char *filename, const char *mode); -extern stream *opentempfile(const char *filename, const char *mode); -extern stream *opengzfile(const char *filename, const char *mode, stream *file = nullptr); -extern stream *openutf8file(const char *filename, const char *mode, stream *file = nullptr); -extern char *loadfile(const char *fn, size_t *size, bool utf8 = true); extern bool listdir(const char *dir, bool rel, const char *ext, vector &files); extern int listfiles(const char *dir, const char *ext, vector &files); -extern int listzipfiles(const char *dir, const char *ext, vector &files); extern void seedMT(uint seed); extern uint randomMT(); diff --git a/src/shared/gzstream.hh b/src/shared/gzstream.hh new file mode 100644 index 0000000..e078da4 --- /dev/null +++ b/src/shared/gzstream.hh @@ -0,0 +1,8 @@ +#ifndef SHARED_GZSTREAM_HH +#define SHARED_GZSTREAM_HH + +#include + +stream *opengzfile(const char *filename, const char *mode, stream *file = nullptr); + +#endif diff --git a/src/shared/igame.hh b/src/shared/igame.hh index 8ce8bbd..d3149ba 100644 --- a/src/shared/igame.hh +++ b/src/shared/igame.hh @@ -7,6 +7,8 @@ struct dynent; struct selinfo; struct VSlot; +#include + #include "tools.hh" #include "geom.hh" diff --git a/src/shared/stream.cc b/src/shared/stream.cc index f70f3b6..3a177fb 100644 --- a/src/shared/stream.cc +++ b/src/shared/stream.cc @@ -1,7 +1,6 @@ #include -#include - +#include "zip.hh" #include "tools.hh" ///////////////////////// file system /////////////////////// diff --git a/src/shared/zip.hh b/src/shared/zip.hh new file mode 100644 index 0000000..4b76cc7 --- /dev/null +++ b/src/shared/zip.hh @@ -0,0 +1,11 @@ +#ifndef SHARED_ZIP_HH +#define SHARED_ZIP_HH + +#include +#include + +bool findzipfile(const char *filename); +stream *openzipfile(const char *filename, const char *mode); +int listzipfiles(const char *dir, const char *ext, vector &files); + +#endif