mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-28 12:30:46 +00:00
- removed the unused CompressedFileWriter class.
This commit is contained in:
parent
6ef93ba514
commit
672a9eb912
4 changed files with 32 additions and 144 deletions
|
@ -1,13 +1,28 @@
|
|||
#ifndef __BASICS_H
|
||||
#define __BASICS_H
|
||||
|
||||
#ifndef MAKE_ID
|
||||
#ifndef __BIG_ENDIAN__
|
||||
#define MAKE_ID(a,b,c,d) ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24)))
|
||||
#else
|
||||
#define MAKE_ID(a,b,c,d) ((uint32_t)((d)|((c)<<8)|((b)<<16)|((a)<<24)))
|
||||
#endif
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
//
|
||||
// fixed point, 32bit as 16.16.
|
||||
//
|
||||
#define FRACBITS 16
|
||||
#define FRACUNIT (1<<FRACBITS)
|
||||
|
||||
typedef int32_t fixed_t;
|
||||
|
||||
#define FIXED_MAX (signed)(0x7fffffff)
|
||||
#define FIXED_MIN (signed)(0x80000000)
|
||||
|
||||
// the last remnants of tables.h
|
||||
#define ANGLE_90 (0x40000000)
|
||||
#define ANGLE_180 (0x80000000)
|
||||
#define ANGLE_270 (0xc0000000)
|
||||
#define ANGLE_MAX (0xffffffff)
|
||||
|
||||
typedef uint32_t angle_t;
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define GCCPRINTF(stri,firstargi) __attribute__((format(printf,stri,firstargi)))
|
||||
|
@ -19,6 +34,14 @@
|
|||
#define GCCNOWARN
|
||||
#endif
|
||||
|
||||
using INTBOOL = int;
|
||||
|
||||
#ifndef MAKE_ID
|
||||
#ifndef __BIG_ENDIAN__
|
||||
#define MAKE_ID(a,b,c,d) ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24)))
|
||||
#else
|
||||
#define MAKE_ID(a,b,c,d) ((uint32_t)((d)|((c)<<8)|((b)<<16)|((a)<<24)))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
using INTBOOL = int;
|
||||
using BITFIELD = uint32_t;
|
||||
#endif
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
|
||||
FILE *myfopen(const char *filename, const char *flags)
|
||||
{
|
||||
// fix this later
|
||||
#ifndef _WIN32
|
||||
return fopen(filename, flags);
|
||||
#else
|
||||
|
|
|
@ -318,9 +318,6 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class FileWriter
|
||||
{
|
||||
protected:
|
||||
|
@ -368,23 +365,5 @@ public:
|
|||
TArray<unsigned char>&& TakeBuffer() { return std::move(mBuffer); }
|
||||
};
|
||||
|
||||
class CompressedFileWriter : public FileWriter
|
||||
{
|
||||
FileWriter *target;
|
||||
struct z_stream_s *zipstream;
|
||||
uint8_t outbuf[1024];
|
||||
size_t compressedSize;
|
||||
bool ownsWriter;
|
||||
|
||||
size_t WriteBlock(const void *buffer, size_t bytes);
|
||||
|
||||
public:
|
||||
CompressedFileWriter(FileWriter *wr, bool transfer = false);
|
||||
CompressedFileWriter(FILE *wr);
|
||||
~CompressedFileWriter() { Close(); }
|
||||
virtual size_t Write(const void *buffer, size_t len) override;
|
||||
virtual void Close() override;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -651,116 +651,3 @@ bool FileReader::OpenDecompressor(FileReader &parent, Size length, int method, b
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
CompressedFileWriter::CompressedFileWriter(FileWriter *targ, bool transfer)
|
||||
{
|
||||
target = targ;
|
||||
zipstream = new z_stream;
|
||||
|
||||
compressedSize = 0;
|
||||
zipstream->next_in = Z_NULL;
|
||||
zipstream->avail_in = 0;
|
||||
zipstream->zalloc = Z_NULL;
|
||||
zipstream->zfree = Z_NULL;
|
||||
int err = deflateInit2 (zipstream, Z_BEST_COMPRESSION, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY);
|
||||
if (err != Z_OK)
|
||||
{
|
||||
delete zipstream;
|
||||
zipstream = nullptr;
|
||||
return;
|
||||
}
|
||||
zipstream->next_out = outbuf;
|
||||
zipstream->avail_out = sizeof(outbuf);
|
||||
ownsWriter = transfer;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
CompressedFileWriter::CompressedFileWriter(FILE *targ)
|
||||
: CompressedFileWriter(new FileWriter(targ), true)
|
||||
{
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
size_t CompressedFileWriter::Write(const void *buffer, size_t bytes)
|
||||
{
|
||||
size_t wrote = 0;
|
||||
size_t towrite = bytes;
|
||||
|
||||
zipstream->next_in = (Bytef *)buffer;
|
||||
while (towrite > 0)
|
||||
{
|
||||
auto chunk = std::min(towrite, (size_t)0x40000000);
|
||||
zipstream->avail_in = chunk;
|
||||
buffer = ((char*)buffer) + chunk;
|
||||
towrite -= chunk;
|
||||
|
||||
while (zipstream->avail_in != 0)
|
||||
{
|
||||
if (zipstream->avail_out == 0)
|
||||
{
|
||||
zipstream->next_out = outbuf;
|
||||
zipstream->avail_out = 1024;
|
||||
wrote += 1024;
|
||||
target->Write(outbuf, 1024);
|
||||
}
|
||||
deflate (zipstream, Z_NO_FLUSH);
|
||||
}
|
||||
}
|
||||
compressedSize += wrote;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void CompressedFileWriter::Close()
|
||||
{
|
||||
if (!zipstream) return;
|
||||
// Flush the zlib stream buffer.
|
||||
|
||||
for (bool done = false;;)
|
||||
{
|
||||
auto len = sizeof(outbuf) - zipstream->avail_out;
|
||||
if (len != 0)
|
||||
{
|
||||
compressedSize += len;
|
||||
|
||||
target->Write(outbuf, len);
|
||||
zipstream->next_out = outbuf;
|
||||
zipstream->avail_out = sizeof(outbuf);
|
||||
}
|
||||
if (done)
|
||||
{
|
||||
break;
|
||||
}
|
||||
auto err = deflate (zipstream, Z_FINISH);
|
||||
done = zipstream->avail_out != 0 || err == Z_STREAM_END;
|
||||
if (err != Z_STREAM_END && err != Z_OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
deflateEnd (zipstream);
|
||||
delete zipstream;
|
||||
zipstream = nullptr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue