shuffle around stream and zip apis
parent
3275fd3b5e
commit
ea850a7261
|
@ -2,11 +2,11 @@
|
||||||
#define ENGINE_BLEND_HH
|
#define ENGINE_BLEND_HH
|
||||||
|
|
||||||
#include <sauerlib/types.hh>
|
#include <sauerlib/types.hh>
|
||||||
|
#include <sauerlib/stream.hh>
|
||||||
|
|
||||||
#include <shared/gl.hh>
|
#include <shared/gl.hh>
|
||||||
|
|
||||||
#include <shared/geom.hh>
|
#include <shared/geom.hh>
|
||||||
#include <shared/tools.hh>
|
|
||||||
|
|
||||||
extern int worldsize; /* FIXME: remove */
|
extern int worldsize; /* FIXME: remove */
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <sauerlib/encoding.hh>
|
#include <sauerlib/encoding.hh>
|
||||||
|
#include <sauerlib/stream.hh>
|
||||||
|
|
||||||
#include <shared/igame.hh>
|
#include <shared/igame.hh>
|
||||||
|
#include <shared/zip.hh>
|
||||||
|
|
||||||
#include "console.hh"
|
#include "console.hh"
|
||||||
#include "main.hh" // fatal, timings
|
#include "main.hh" // fatal, timings
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef ENGINE_CONSOLE_HH
|
#ifndef ENGINE_CONSOLE_HH
|
||||||
#define ENGINE_CONSOLE_HH
|
#define ENGINE_CONSOLE_HH
|
||||||
|
|
||||||
#include <shared/tools.hh>
|
#include <sauerlib/stream.hh>
|
||||||
|
|
||||||
struct tagval; /* command.hh */
|
struct tagval; /* command.hh */
|
||||||
struct ident;
|
struct ident;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <sauerlib/encoding.hh>
|
#include <sauerlib/encoding.hh>
|
||||||
|
#include <sauerlib/stream.hh>
|
||||||
|
|
||||||
#include <shared/command.hh>
|
#include <shared/command.hh>
|
||||||
#include <shared/glemu.hh>
|
#include <shared/glemu.hh>
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <sauerlib/stream.hh>
|
||||||
|
|
||||||
#include <shared/command.hh>
|
#include <shared/command.hh>
|
||||||
|
|
||||||
#include "console.hh" /* conoutf */
|
#include "console.hh" /* conoutf */
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <shared/command.hh>
|
#include <shared/command.hh>
|
||||||
#include <shared/glemu.hh>
|
#include <shared/glemu.hh>
|
||||||
#include <shared/igame.hh>
|
#include <shared/igame.hh>
|
||||||
|
#include <shared/gzstream.hh>
|
||||||
|
|
||||||
#include "blend.hh"
|
#include "blend.hh"
|
||||||
#include "command.hh"
|
#include "command.hh"
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#ifndef ENGINE_PVS_HH
|
#ifndef ENGINE_PVS_HH
|
||||||
#define ENGINE_PVS_HH
|
#define ENGINE_PVS_HH
|
||||||
|
|
||||||
|
#include <sauerlib/stream.hh>
|
||||||
|
|
||||||
#include <shared/geom.hh>
|
#include <shared/geom.hh>
|
||||||
#include <shared/tools.hh>
|
|
||||||
|
|
||||||
void clearpvs();
|
void clearpvs();
|
||||||
bool pvsoccluded(const ivec &bbmin, const ivec &bbmax);
|
bool pvsoccluded(const ivec &bbmin, const ivec &bbmax);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <sauerlib/encoding.hh>
|
#include <sauerlib/encoding.hh>
|
||||||
|
#include <sauerlib/stream.hh>
|
||||||
|
|
||||||
#include <shared/command.hh>
|
#include <shared/command.hh>
|
||||||
#include <shared/glemu.hh>
|
#include <shared/glemu.hh>
|
||||||
|
|
|
@ -12,7 +12,9 @@
|
||||||
|
|
||||||
#include <shared/command.hh>
|
#include <shared/command.hh>
|
||||||
#include <shared/igame.hh>
|
#include <shared/igame.hh>
|
||||||
|
#include <shared/gzstream.hh>
|
||||||
#include <shared/rwops.hh>
|
#include <shared/rwops.hh>
|
||||||
|
#include <shared/zip.hh>
|
||||||
|
|
||||||
#include "command.hh" // identflags
|
#include "command.hh" // identflags
|
||||||
#include "console.hh" /* conoutf */
|
#include "console.hh" /* conoutf */
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <sauerlib/encoding.hh>
|
#include <sauerlib/encoding.hh>
|
||||||
|
|
||||||
#include <shared/command.hh>
|
#include <shared/command.hh>
|
||||||
|
#include <shared/gzstream.hh>
|
||||||
#include <shared/igame.hh>
|
#include <shared/igame.hh>
|
||||||
|
|
||||||
#include "blend.hh"
|
#include "blend.hh"
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include <sauerlib/stream.hh>
|
||||||
|
|
||||||
#include <shared/command.hh>
|
#include <shared/command.hh>
|
||||||
|
|
||||||
#include <engine/main.hh>
|
#include <engine/main.hh>
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
#include "tools.hh"
|
#include "stream.hh"
|
||||||
|
|
||||||
#include "encoding.hh"
|
#include "encoding.hh"
|
||||||
|
|
||||||
|
// FIXME
|
||||||
|
#include <shared/zip.hh>
|
||||||
|
|
||||||
stream::offset stream::size()
|
stream::offset stream::size()
|
||||||
{
|
{
|
||||||
offset pos = tell(), endpos;
|
offset pos = tell(), endpos;
|
||||||
|
@ -310,10 +313,8 @@ stream *openrawfile(const char *filename, const char *mode)
|
||||||
|
|
||||||
stream *openfile(const char *filename, const char *mode)
|
stream *openfile(const char *filename, const char *mode)
|
||||||
{
|
{
|
||||||
#ifndef STANDALONE
|
|
||||||
stream *s = openzipfile(filename, mode);
|
stream *s = openzipfile(filename, mode);
|
||||||
if(s) return s;
|
if(s) return s;
|
||||||
#endif
|
|
||||||
return openrawfile(filename, mode);
|
return openrawfile(filename, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<class T> size_t put(const T *v, size_t n) { return write(v, n*sizeof(T))/sizeof(T); }
|
||||||
|
template<class T> bool put(T n) { return write(&n, sizeof(n)) == sizeof(n); }
|
||||||
|
template<class T> bool putlil(T n) { return put<T>(lilswap(n)); }
|
||||||
|
template<class T> bool putbig(T n) { return put<T>(bigswap(n)); }
|
||||||
|
|
||||||
|
template<class T> size_t get(T *v, size_t n) { return read(v, n*sizeof(T))/sizeof(T); }
|
||||||
|
template<class T> T get() { T n; return read(&n, sizeof(n)) == sizeof(n) ? n : 0; }
|
||||||
|
template<class T> T getlil() { return lilswap(get<T>()); }
|
||||||
|
template<class T> T getbig() { return bigswap(get<T>()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct streambuf
|
||||||
|
{
|
||||||
|
stream *s;
|
||||||
|
|
||||||
|
streambuf(stream *s) : s(s) {}
|
||||||
|
|
||||||
|
T get() { return s->get<T>(); }
|
||||||
|
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
|
|
@ -1090,70 +1090,6 @@ template<class T> inline T bigswap(T n) { return islittleendian() ? endianswap(n
|
||||||
template<class T> inline void bigswap(T *buf, size_t len) { if(islittleendian()) endianswap(buf, len); }
|
template<class T> inline void bigswap(T *buf, size_t len) { if(islittleendian()) endianswap(buf, len); }
|
||||||
#endif
|
#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<class T> size_t put(const T *v, size_t n) { return write(v, n*sizeof(T))/sizeof(T); }
|
|
||||||
template<class T> bool put(T n) { return write(&n, sizeof(n)) == sizeof(n); }
|
|
||||||
template<class T> bool putlil(T n) { return put<T>(lilswap(n)); }
|
|
||||||
template<class T> bool putbig(T n) { return put<T>(bigswap(n)); }
|
|
||||||
|
|
||||||
template<class T> size_t get(T *v, size_t n) { return read(v, n*sizeof(T))/sizeof(T); }
|
|
||||||
template<class T> T get() { T n; return read(&n, sizeof(n)) == sizeof(n) ? n : 0; }
|
|
||||||
template<class T> T getlil() { return lilswap(get<T>()); }
|
|
||||||
template<class T> T getbig() { return bigswap(get<T>()); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct streambuf
|
|
||||||
{
|
|
||||||
stream *s;
|
|
||||||
|
|
||||||
streambuf(stream *s) : s(s) {}
|
|
||||||
|
|
||||||
T get() { return s->get<T>(); }
|
|
||||||
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 string homedir;
|
||||||
|
|
||||||
extern char *makerelpath(const char *dir, const char *file, const char *prefix = nullptr, const char *cmd = nullptr);
|
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 *sethomedir(const char *dir);
|
||||||
extern const char *addpackagedir(const char *dir);
|
extern const char *addpackagedir(const char *dir);
|
||||||
extern const char *findfile(const char *filename, const char *mode);
|
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<char *> &files);
|
extern bool listdir(const char *dir, bool rel, const char *ext, vector<char *> &files);
|
||||||
extern int listfiles(const char *dir, const char *ext, vector<char *> &files);
|
extern int listfiles(const char *dir, const char *ext, vector<char *> &files);
|
||||||
extern int listzipfiles(const char *dir, const char *ext, vector<char *> &files);
|
|
||||||
extern void seedMT(uint seed);
|
extern void seedMT(uint seed);
|
||||||
extern uint randomMT();
|
extern uint randomMT();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef SHARED_GZSTREAM_HH
|
||||||
|
#define SHARED_GZSTREAM_HH
|
||||||
|
|
||||||
|
#include <sauerlib/stream.hh>
|
||||||
|
|
||||||
|
stream *opengzfile(const char *filename, const char *mode, stream *file = nullptr);
|
||||||
|
|
||||||
|
#endif
|
|
@ -7,6 +7,8 @@ struct dynent;
|
||||||
struct selinfo;
|
struct selinfo;
|
||||||
struct VSlot;
|
struct VSlot;
|
||||||
|
|
||||||
|
#include <sauerlib/stream.hh>
|
||||||
|
|
||||||
#include "tools.hh"
|
#include "tools.hh"
|
||||||
#include "geom.hh"
|
#include "geom.hh"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include <sauerlib/encoding.hh>
|
#include "zip.hh"
|
||||||
|
|
||||||
#include "tools.hh"
|
#include "tools.hh"
|
||||||
|
|
||||||
///////////////////////// file system ///////////////////////
|
///////////////////////// file system ///////////////////////
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef SHARED_ZIP_HH
|
||||||
|
#define SHARED_ZIP_HH
|
||||||
|
|
||||||
|
#include <sauerlib/stream.hh>
|
||||||
|
#include <sauerlib/tools.hh>
|
||||||
|
|
||||||
|
bool findzipfile(const char *filename);
|
||||||
|
stream *openzipfile(const char *filename, const char *mode);
|
||||||
|
int listzipfiles(const char *dir, const char *ext, vector<char *> &files);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue