Browse Source

shuffle around stream and zip apis

master
Daniel Kolesa 3 months ago
parent
commit
ea850a7261
18 changed files with 118 additions and 81 deletions
  1. +1
    -1
      src/engine/blend.hh
  2. +2
    -0
      src/engine/command.cc
  3. +1
    -1
      src/engine/console.hh
  4. +1
    -0
      src/engine/main.cc
  5. +2
    -0
      src/engine/movie.cc
  6. +1
    -0
      src/engine/octaedit.cc
  7. +2
    -1
      src/engine/pvs.hh
  8. +1
    -0
      src/engine/rendermodel.cc
  9. +2
    -0
      src/engine/texture.cc
  10. +1
    -0
      src/engine/worldio.cc
  11. +2
    -0
      src/game/game.cc
  12. +4
    -3
      src/sauerlib/stream.cc
  13. +76
    -0
      src/sauerlib/stream.hh
  14. +0
    -73
      src/sauerlib/tools.hh
  15. +8
    -0
      src/shared/gzstream.hh
  16. +2
    -0
      src/shared/igame.hh
  17. +1
    -2
      src/shared/stream.cc
  18. +11
    -0
      src/shared/zip.hh

+ 1
- 1
src/engine/blend.hh View File

@@ -2,11 +2,11 @@
#define ENGINE_BLEND_HH

#include <sauerlib/types.hh>
#include <sauerlib/stream.hh>

#include <shared/gl.hh>

#include <shared/geom.hh>
#include <shared/tools.hh>

extern int worldsize; /* FIXME: remove */



+ 2
- 0
src/engine/command.cc View File

@@ -9,8 +9,10 @@
#include <algorithm>

#include <sauerlib/encoding.hh>
#include <sauerlib/stream.hh>

#include <shared/igame.hh>
#include <shared/zip.hh>

#include "console.hh"
#include "main.hh" // fatal, timings


+ 1
- 1
src/engine/console.hh View File

@@ -1,7 +1,7 @@
#ifndef ENGINE_CONSOLE_HH
#define ENGINE_CONSOLE_HH

#include <shared/tools.hh>
#include <sauerlib/stream.hh>

struct tagval; /* command.hh */
struct ident;


+ 1
- 0
src/engine/main.cc View File

@@ -7,6 +7,7 @@
#include <algorithm>

#include <sauerlib/encoding.hh>
#include <sauerlib/stream.hh>

#include <shared/command.hh>
#include <shared/glemu.hh>


+ 2
- 0
src/engine/movie.cc View File

@@ -11,6 +11,8 @@

#include <cassert>

#include <sauerlib/stream.hh>

#include <shared/command.hh>

#include "console.hh" /* conoutf */


+ 1
- 0
src/engine/octaedit.cc View File

@@ -8,6 +8,7 @@
#include <shared/command.hh>
#include <shared/glemu.hh>
#include <shared/igame.hh>
#include <shared/gzstream.hh>

#include "blend.hh"
#include "command.hh"


+ 2
- 1
src/engine/pvs.hh View File

@@ -1,8 +1,9 @@
#ifndef ENGINE_PVS_HH
#define ENGINE_PVS_HH

#include <sauerlib/stream.hh>

#include <shared/geom.hh>
#include <shared/tools.hh>

void clearpvs();
bool pvsoccluded(const ivec &bbmin, const ivec &bbmax);


+ 1
- 0
src/engine/rendermodel.cc View File

@@ -6,6 +6,7 @@
#include <algorithm>

#include <sauerlib/encoding.hh>
#include <sauerlib/stream.hh>

#include <shared/command.hh>
#include <shared/glemu.hh>


+ 2
- 0
src/engine/texture.cc View File

@@ -12,7 +12,9 @@

#include <shared/command.hh>
#include <shared/igame.hh>
#include <shared/gzstream.hh>
#include <shared/rwops.hh>
#include <shared/zip.hh>

#include "command.hh" // identflags
#include "console.hh" /* conoutf */


+ 1
- 0
src/engine/worldio.cc View File

@@ -9,6 +9,7 @@
#include <sauerlib/encoding.hh>

#include <shared/command.hh>
#include <shared/gzstream.hh>
#include <shared/igame.hh>

#include "blend.hh"


+ 2
- 0
src/game/game.cc View File

@@ -1,3 +1,5 @@
#include <sauerlib/stream.hh>

#include <shared/command.hh>

#include <engine/main.hh>


+ 4
- 3
src/sauerlib/stream.cc View File

@@ -1,7 +1,10 @@
#include "tools.hh"
#include "stream.hh"

#include "encoding.hh"

// FIXME
#include <shared/zip.hh>

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);
}



+ 76
- 0
src/sauerlib/stream.hh View File

@@ -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

+ 0
- 73
src/sauerlib/tools.hh View File

@@ -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); }
#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 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<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 uint randomMT();



+ 8
- 0
src/shared/gzstream.hh View File

@@ -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

+ 2
- 0
src/shared/igame.hh View File

@@ -7,6 +7,8 @@ struct dynent;
struct selinfo;
struct VSlot;

#include <sauerlib/stream.hh>

#include "tools.hh"
#include "geom.hh"



+ 1
- 2
src/shared/stream.cc View File

@@ -1,7 +1,6 @@
#include <new>

#include <sauerlib/encoding.hh>

#include "zip.hh"
#include "tools.hh"

///////////////////////// file system ///////////////////////


+ 11
- 0
src/shared/zip.hh View File

@@ -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…
Cancel
Save