mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-13 07:57:51 +00:00
- sound code and most of texture code converted to FileRdr.
This allowed to remove a lot of bad pointer voodoo in the music loader, because the new class does not allow duplication of the reader object
This commit is contained in:
parent
26e948357e
commit
5fa63c396d
46 changed files with 333 additions and 307 deletions
|
@ -1224,7 +1224,7 @@ CCMD(secret)
|
||||||
int lumpno=Wads.CheckNumForName("SECRETS");
|
int lumpno=Wads.CheckNumForName("SECRETS");
|
||||||
if (lumpno < 0) return;
|
if (lumpno < 0) return;
|
||||||
|
|
||||||
FWadLump lump = Wads.OpenLumpNum(lumpno);
|
auto lump = Wads.OpenLumpReader(lumpno);
|
||||||
FString maphdr;
|
FString maphdr;
|
||||||
maphdr.Format("[%s]", mapname);
|
maphdr.Format("[%s]", mapname);
|
||||||
|
|
||||||
|
|
|
@ -563,10 +563,13 @@ char *MemoryReader::Gets(char *strbuf, int len)
|
||||||
|
|
||||||
MemoryArrayReader::MemoryArrayReader (const char *buffer, long length)
|
MemoryArrayReader::MemoryArrayReader (const char *buffer, long length)
|
||||||
{
|
{
|
||||||
buf.Resize(length);
|
if (length > 0)
|
||||||
memcpy(&buf[0], buffer, length);
|
{
|
||||||
Length=length;
|
buf.Resize(length);
|
||||||
FilePos=0;
|
memcpy(&buf[0], buffer, length);
|
||||||
|
}
|
||||||
|
Length = length;
|
||||||
|
FilePos=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryArrayReader::~MemoryArrayReader ()
|
MemoryArrayReader::~MemoryArrayReader ()
|
||||||
|
@ -696,22 +699,42 @@ size_t BufferWriter::Write(const void *buffer, size_t len)
|
||||||
|
|
||||||
bool FileRdr::OpenFile(const char *filename)
|
bool FileRdr::OpenFile(const char *filename)
|
||||||
{
|
{
|
||||||
mReader = new FileReader;
|
auto reader = new FileReader;
|
||||||
if (mReader->Open(filename)) return true;
|
if (!reader->Open(filename)) return false;
|
||||||
delete mReader;
|
Close();
|
||||||
mReader = nullptr;
|
mReader = reader;
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileRdr::OpenMemory(const void *mem, FileRdr::Size length)
|
bool FileRdr::OpenMemory(const void *mem, FileRdr::Size length)
|
||||||
{
|
{
|
||||||
|
Close();
|
||||||
mReader = new MemoryReader((const char *)mem, (long)length);
|
mReader = new MemoryReader((const char *)mem, (long)length);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileRdr::OpenMemoryArray(const void *mem, FileRdr::Size length)
|
bool FileRdr::OpenMemoryArray(const void *mem, FileRdr::Size length)
|
||||||
{
|
{
|
||||||
|
Close();
|
||||||
mReader = new MemoryArrayReader((const char *)mem, (long)length);
|
mReader = new MemoryArrayReader((const char *)mem, (long)length);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileRdr::OpenMemoryArray(std::function<bool(TArray<uint8_t>&)> getter)
|
||||||
|
{
|
||||||
|
auto reader = new MemoryArrayReader(nullptr, 0);
|
||||||
|
if (getter(reader->GetArray()))
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
reader->UpdateLength();
|
||||||
|
mReader = reader;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// This will keep the old
|
||||||
|
delete reader;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
27
src/files.h
27
src/files.h
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
#include <functional>
|
||||||
#include "bzlib.h"
|
#include "bzlib.h"
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
#include "m_swap.h"
|
#include "m_swap.h"
|
||||||
|
@ -498,8 +499,8 @@ class FileRdr // this is just a temporary name, until the old FileReader hierarc
|
||||||
{
|
{
|
||||||
FileReader *mReader = nullptr;
|
FileReader *mReader = nullptr;
|
||||||
|
|
||||||
FileRdr() {}
|
|
||||||
FileRdr(const FileRdr &r) = delete;
|
FileRdr(const FileRdr &r) = delete;
|
||||||
|
FileRdr &operator=(const FileRdr &r) = delete;
|
||||||
public:
|
public:
|
||||||
enum ESeek
|
enum ESeek
|
||||||
{
|
{
|
||||||
|
@ -510,10 +511,19 @@ public:
|
||||||
|
|
||||||
typedef ptrdiff_t Size; // let's not use 'long' here.
|
typedef ptrdiff_t Size; // let's not use 'long' here.
|
||||||
|
|
||||||
|
FileRdr() {}
|
||||||
|
|
||||||
|
// These two functions are only needed as long as the FileReader has not been fully replaced throughout the code.
|
||||||
FileRdr(FileReader *r)
|
FileRdr(FileReader *r)
|
||||||
{
|
{
|
||||||
mReader = r;
|
mReader = r;
|
||||||
}
|
}
|
||||||
|
FileReader *Reader()
|
||||||
|
{
|
||||||
|
auto r = mReader;
|
||||||
|
mReader = nullptr;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
FileRdr(FileRdr &&r)
|
FileRdr(FileRdr &&r)
|
||||||
{
|
{
|
||||||
|
@ -521,7 +531,21 @@ public:
|
||||||
r.mReader = nullptr;
|
r.mReader = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileRdr& operator =(FileRdr &&r)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
mReader = r.mReader;
|
||||||
|
r.mReader = nullptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
~FileRdr()
|
~FileRdr()
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Close()
|
||||||
{
|
{
|
||||||
if (mReader != nullptr) delete mReader;
|
if (mReader != nullptr) delete mReader;
|
||||||
mReader = nullptr;
|
mReader = nullptr;
|
||||||
|
@ -531,6 +555,7 @@ public:
|
||||||
bool OpenFilePart(FileReader *parent, Size start, Size length); // later
|
bool OpenFilePart(FileReader *parent, Size start, Size length); // later
|
||||||
bool OpenMemory(const void *mem, Size length); // read directly from the buffer
|
bool OpenMemory(const void *mem, Size length); // read directly from the buffer
|
||||||
bool OpenMemoryArray(const void *mem, Size length); // read from a copy of the buffer.
|
bool OpenMemoryArray(const void *mem, Size length); // read from a copy of the buffer.
|
||||||
|
bool OpenMemoryArray(std::function<bool(TArray<uint8_t>&)> getter); // read contents to a buffer and return a reader to it
|
||||||
|
|
||||||
Size Tell() const
|
Size Tell() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -2500,17 +2500,17 @@ static void P_LoopSidedefs (bool firstloop)
|
||||||
|
|
||||||
int P_DetermineTranslucency (int lumpnum)
|
int P_DetermineTranslucency (int lumpnum)
|
||||||
{
|
{
|
||||||
FWadLump tranmap = Wads.OpenLumpNum (lumpnum);
|
auto tranmap = Wads.OpenLumpReader (lumpnum);
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
PalEntry newcolor;
|
PalEntry newcolor;
|
||||||
PalEntry newcolor2;
|
PalEntry newcolor2;
|
||||||
|
|
||||||
tranmap.Seek (GPalette.BlackIndex * 256 + GPalette.WhiteIndex, SEEK_SET);
|
tranmap.Seek (GPalette.BlackIndex * 256 + GPalette.WhiteIndex, FileRdr::SeekSet);
|
||||||
tranmap.Read (&index, 1);
|
tranmap.Read (&index, 1);
|
||||||
|
|
||||||
newcolor = GPalette.BaseColors[GPalette.Remap[index]];
|
newcolor = GPalette.BaseColors[GPalette.Remap[index]];
|
||||||
|
|
||||||
tranmap.Seek (GPalette.WhiteIndex * 256 + GPalette.BlackIndex, SEEK_SET);
|
tranmap.Seek (GPalette.WhiteIndex * 256 + GPalette.BlackIndex, FileRdr::SeekSet);
|
||||||
tranmap.Read (&index, 1);
|
tranmap.Read (&index, 1);
|
||||||
newcolor2 = GPalette.BaseColors[GPalette.Remap[index]];
|
newcolor2 = GPalette.BaseColors[GPalette.Remap[index]];
|
||||||
if (newcolor2.r == 255) // if black on white results in white it's either
|
if (newcolor2.r == 255) // if black on white results in white it's either
|
||||||
|
|
|
@ -232,7 +232,7 @@ void R_InitColormaps ()
|
||||||
if (Wads.LumpLength (fakecmaps[j].lump) >= 256)
|
if (Wads.LumpLength (fakecmaps[j].lump) >= 256)
|
||||||
{
|
{
|
||||||
int k, r, g, b;
|
int k, r, g, b;
|
||||||
FWadLump lump = Wads.OpenLumpNum (fakecmaps[j].lump);
|
auto lump = Wads.OpenLumpReader (fakecmaps[j].lump);
|
||||||
lump.Read(map, 256);
|
lump.Read(map, 256);
|
||||||
r = g = b = 0;
|
r = g = b = 0;
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ bool FPlayList::ChangeList (const char *path)
|
||||||
{
|
{
|
||||||
FString playlistdir;
|
FString playlistdir;
|
||||||
FString song;
|
FString song;
|
||||||
FileReader fr;
|
FileRdr fr;
|
||||||
bool first;
|
bool first;
|
||||||
bool pls;
|
bool pls;
|
||||||
int i;
|
int i;
|
||||||
|
@ -62,7 +62,7 @@ bool FPlayList::ChangeList (const char *path)
|
||||||
Songs.Clear();
|
Songs.Clear();
|
||||||
Position = 0;
|
Position = 0;
|
||||||
|
|
||||||
if (!fr.Open(path))
|
if (!fr.OpenFile(path))
|
||||||
{
|
{
|
||||||
Printf ("Could not open " TEXTCOLOR_BOLD "%s" TEXTCOLOR_NORMAL ": %s\n", path, strerror(errno));
|
Printf ("Could not open " TEXTCOLOR_BOLD "%s" TEXTCOLOR_NORMAL ": %s\n", path, strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
|
@ -71,7 +71,7 @@ bool FPlayList::ChangeList (const char *path)
|
||||||
first = true;
|
first = true;
|
||||||
pls = false;
|
pls = false;
|
||||||
playlistdir = ExtractFilePath(path);
|
playlistdir = ExtractFilePath(path);
|
||||||
while ((song = NextLine(&fr)).IsNotEmpty())
|
while ((song = NextLine(fr)).IsNotEmpty())
|
||||||
{
|
{
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
|
@ -133,14 +133,14 @@ bool FPlayList::ChangeList (const char *path)
|
||||||
return Songs.Size() != 0;
|
return Songs.Size() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FString FPlayList::NextLine (FileReader *file)
|
FString FPlayList::NextLine (FileRdr &file)
|
||||||
{
|
{
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
char *skipper;
|
char *skipper;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (NULL == file->Gets (buffer, countof(buffer)))
|
if (nullptr == file.Gets (buffer, countof(buffer)))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
for (skipper = buffer; *skipper != 0 && *skipper <= ' '; skipper++)
|
for (skipper = buffer; *skipper != 0 && *skipper <= ' '; skipper++)
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#ifndef __S_PLAYLIST_H__
|
#ifndef __S_PLAYLIST_H__
|
||||||
#define __S_PLAYLIST_H__
|
#define __S_PLAYLIST_H__
|
||||||
|
|
||||||
class FileReader;
|
class FileRdr;
|
||||||
|
|
||||||
class FPlayList
|
class FPlayList
|
||||||
{
|
{
|
||||||
|
@ -53,7 +53,7 @@ public:
|
||||||
const char *GetSong (int position) const;
|
const char *GetSong (int position) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static FString NextLine (FileReader *file);
|
static FString NextLine (FileRdr &file);
|
||||||
|
|
||||||
unsigned int Position;
|
unsigned int Position;
|
||||||
TArray<FString> Songs;
|
TArray<FString> Songs;
|
||||||
|
|
|
@ -1430,7 +1430,7 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer)
|
||||||
int size = Wads.LumpLength(sfx->lumpnum);
|
int size = Wads.LumpLength(sfx->lumpnum);
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
FWadLump wlump = Wads.OpenLumpNum(sfx->lumpnum);
|
auto wlump = Wads.OpenLumpReader(sfx->lumpnum);
|
||||||
uint8_t *sfxdata = new uint8_t[size];
|
uint8_t *sfxdata = new uint8_t[size];
|
||||||
wlump.Read(sfxdata, size);
|
wlump.Read(sfxdata, size);
|
||||||
int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]);
|
int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]);
|
||||||
|
@ -1498,7 +1498,7 @@ static void S_LoadSound3D(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer)
|
||||||
int size = Wads.LumpLength(sfx->lumpnum);
|
int size = Wads.LumpLength(sfx->lumpnum);
|
||||||
if (size <= 0) return;
|
if (size <= 0) return;
|
||||||
|
|
||||||
FWadLump wlump = Wads.OpenLumpNum(sfx->lumpnum);
|
auto wlump = Wads.OpenLumpReader(sfx->lumpnum);
|
||||||
uint8_t *sfxdata = new uint8_t[size];
|
uint8_t *sfxdata = new uint8_t[size];
|
||||||
wlump.Read(sfxdata, size);
|
wlump.Read(sfxdata, size);
|
||||||
int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]);
|
int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]);
|
||||||
|
@ -2609,7 +2609,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
|
||||||
musicname += 7;
|
musicname += 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileReader *reader = NULL;
|
FileRdr reader;
|
||||||
if (!FileExists (musicname))
|
if (!FileExists (musicname))
|
||||||
{
|
{
|
||||||
if ((lumpnum = Wads.CheckNumForFullName (musicname, true, ns_music)) == -1)
|
if ((lumpnum = Wads.CheckNumForFullName (musicname, true, ns_music)) == -1)
|
||||||
|
@ -2623,17 +2623,16 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
reader = Wads.ReopenLumpNumNewFile(lumpnum);
|
reader = Wads.ReopenLumpReader(lumpnum);
|
||||||
if (reader == NULL)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Load an external file.
|
// Load an external file.
|
||||||
reader = new FileReader(musicname);
|
if (!reader.OpenFile(musicname))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// shutdown old music
|
// shutdown old music
|
||||||
|
@ -2646,7 +2645,6 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
|
||||||
mus_playing.name = musicname;
|
mus_playing.name = musicname;
|
||||||
mus_playing.baseorder = order;
|
mus_playing.baseorder = order;
|
||||||
LastSong = musicname;
|
LastSong = musicname;
|
||||||
delete reader;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2654,7 +2652,6 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
|
||||||
if (handle != NULL)
|
if (handle != NULL)
|
||||||
{
|
{
|
||||||
mus_playing.handle = handle;
|
mus_playing.handle = handle;
|
||||||
delete reader;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -398,7 +398,7 @@ static EMIDIType IdentifyMIDIType(uint32_t *id, int size)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device)
|
MusInfo *I_RegisterSong (FileRdr &reader, MidiDeviceSetting *device)
|
||||||
{
|
{
|
||||||
MusInfo *info = nullptr;
|
MusInfo *info = nullptr;
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
|
@ -406,14 +406,12 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device)
|
||||||
|
|
||||||
if (nomusic)
|
if (nomusic)
|
||||||
{
|
{
|
||||||
delete reader;
|
return nullptr;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(reader->Read(id, 32) != 32 || reader->Seek(-32, SEEK_CUR) != 0)
|
if(reader.Read(id, 32) != 32 || reader.Seek(-32, FileRdr::SeekCur) != 0)
|
||||||
{
|
{
|
||||||
delete reader;
|
return nullptr;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for gzip compression. Some formats are expected to have players
|
// Check for gzip compression. Some formats are expected to have players
|
||||||
|
@ -421,47 +419,38 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device)
|
||||||
// gzippable.
|
// gzippable.
|
||||||
if ((id[0] & MAKE_ID(255, 255, 255, 0)) == GZIP_ID)
|
if ((id[0] & MAKE_ID(255, 255, 255, 0)) == GZIP_ID)
|
||||||
{
|
{
|
||||||
int len = reader->GetLength();
|
|
||||||
uint8_t *gzipped = new uint8_t[len];
|
if (!reader.OpenMemoryArray([&reader](TArray<uint8_t> &array)
|
||||||
if (reader->Read(gzipped, len) != len)
|
|
||||||
{
|
{
|
||||||
|
bool res = false;
|
||||||
|
auto len = reader.GetLength();
|
||||||
|
uint8_t *gzipped = new uint8_t[len];
|
||||||
|
if (reader.Read(gzipped, len) == len)
|
||||||
|
{
|
||||||
|
res = ungzip(gzipped, (int)len, array);
|
||||||
|
}
|
||||||
delete[] gzipped;
|
delete[] gzipped;
|
||||||
delete reader;
|
return res;
|
||||||
|
}))
|
||||||
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
delete reader;
|
|
||||||
|
|
||||||
MemoryArrayReader *memreader = new MemoryArrayReader(nullptr, 0);
|
if (reader.Read(id, 32) != 32 || reader.Seek(-32, FileRdr::SeekCur) != 0)
|
||||||
if (!ungzip(gzipped, len, memreader->GetArray()))
|
|
||||||
{
|
{
|
||||||
delete[] gzipped;
|
return nullptr;
|
||||||
delete memreader;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
delete[] gzipped;
|
|
||||||
memreader->UpdateLength();
|
|
||||||
|
|
||||||
if (memreader->Read(id, 32) != 32 || memreader->Seek(-32, SEEK_CUR) != 0)
|
|
||||||
{
|
|
||||||
delete memreader;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
reader = memreader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EMIDIType miditype = IdentifyMIDIType(id, sizeof(id));
|
EMIDIType miditype = IdentifyMIDIType(id, sizeof(id));
|
||||||
if (miditype != MIDI_NOTMIDI)
|
if (miditype != MIDI_NOTMIDI)
|
||||||
{
|
{
|
||||||
// temporary hack so we can test before converting more.
|
auto source = CreateMIDISource(reader, miditype);
|
||||||
FileRdr rdr(reader);
|
if (source == nullptr) return nullptr;
|
||||||
reader = nullptr;
|
|
||||||
|
|
||||||
auto source = CreateMIDISource(rdr, miditype);
|
|
||||||
if (source == nullptr) return 0;
|
|
||||||
if (!source->isValid())
|
if (!source->isValid())
|
||||||
{
|
{
|
||||||
delete source;
|
delete source;
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
EMidiDevice devtype = device == nullptr? MDEV_DEFAULT : (EMidiDevice)device->device;
|
EMidiDevice devtype = device == nullptr? MDEV_DEFAULT : (EMidiDevice)device->device;
|
||||||
|
@ -474,9 +463,8 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device)
|
||||||
MIDIStreamer *streamer = CreateMIDIStreamer(devtype, device != nullptr? device->args.GetChars() : "");
|
MIDIStreamer *streamer = CreateMIDIStreamer(devtype, device != nullptr? device->args.GetChars() : "");
|
||||||
if (streamer == nullptr)
|
if (streamer == nullptr)
|
||||||
{
|
{
|
||||||
delete reader;
|
|
||||||
delete source;
|
delete source;
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
streamer->SetMIDISource(source);
|
streamer->SetMIDISource(source);
|
||||||
info = streamer;
|
info = streamer;
|
||||||
|
@ -488,22 +476,21 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device)
|
||||||
(id[0] == MAKE_ID('D','B','R','A') && id[1] == MAKE_ID('W','O','P','L')) || // DosBox Raw OPL
|
(id[0] == MAKE_ID('D','B','R','A') && id[1] == MAKE_ID('W','O','P','L')) || // DosBox Raw OPL
|
||||||
(id[0] == MAKE_ID('A','D','L','I') && *((uint8_t *)id + 4) == 'B')) // Martin Fernandez's modified IMF
|
(id[0] == MAKE_ID('A','D','L','I') && *((uint8_t *)id + 4) == 'B')) // Martin Fernandez's modified IMF
|
||||||
{
|
{
|
||||||
info = new OPLMUSSong (*reader, device != nullptr? device->args.GetChars() : "");
|
info = new OPLMUSSong (reader, device != nullptr? device->args.GetChars() : "");
|
||||||
}
|
}
|
||||||
// Check for game music
|
// Check for game music
|
||||||
else if ((fmt = GME_CheckFormat(id[0])) != nullptr && fmt[0] != '\0')
|
else if ((fmt = GME_CheckFormat(id[0])) != nullptr && fmt[0] != '\0')
|
||||||
{
|
{
|
||||||
info = GME_OpenSong(*reader, fmt);
|
info = GME_OpenSong(reader, fmt);
|
||||||
}
|
}
|
||||||
// Check for module formats
|
// Check for module formats
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
info = MOD_OpenSong(*reader);
|
info = MOD_OpenSong(reader);
|
||||||
}
|
}
|
||||||
if (info == nullptr)
|
if (info == nullptr)
|
||||||
{
|
{
|
||||||
info = SndFile_OpenSong(*reader);
|
info = SndFile_OpenSong(reader);
|
||||||
if (info != nullptr) reader = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info == nullptr)
|
if (info == nullptr)
|
||||||
|
@ -513,24 +500,21 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device)
|
||||||
{
|
{
|
||||||
uint32_t subid;
|
uint32_t subid;
|
||||||
|
|
||||||
reader->Seek(8, SEEK_CUR);
|
reader.Seek(8, FileRdr::SeekCur);
|
||||||
if (reader->Read (&subid, 4) != 4)
|
if (reader.Read (&subid, 4) != 4)
|
||||||
{
|
{
|
||||||
delete reader;
|
return nullptr;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
reader->Seek(-12, SEEK_CUR);
|
reader.Seek(-12, FileRdr::SeekCur);
|
||||||
|
|
||||||
if (subid == (('C')|(('D')<<8)|(('D')<<16)|(('A')<<24)))
|
if (subid == (('C')|(('D')<<8)|(('D')<<16)|(('A')<<24)))
|
||||||
{
|
{
|
||||||
// This is a CDDA file
|
// This is a CDDA file
|
||||||
info = new CDDAFile (*reader);
|
info = new CDDAFile (reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reader != nullptr) delete reader;
|
|
||||||
|
|
||||||
if (info && !info->IsValid ())
|
if (info && !info->IsValid ())
|
||||||
{
|
{
|
||||||
delete info;
|
delete info;
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#include "doomdef.h"
|
#include "doomdef.h"
|
||||||
#include "i_soundinternal.h"
|
#include "i_soundinternal.h"
|
||||||
|
|
||||||
class FileReader;
|
class FileRdr;
|
||||||
struct FOptionValues;
|
struct FOptionValues;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -55,7 +55,7 @@ void I_SetMusicVolume (float volume);
|
||||||
// Registers a song handle to song data.
|
// Registers a song handle to song data.
|
||||||
class MusInfo;
|
class MusInfo;
|
||||||
struct MidiDeviceSetting;
|
struct MidiDeviceSetting;
|
||||||
MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device);
|
MusInfo *I_RegisterSong (FileRdr &reader, MidiDeviceSetting *device);
|
||||||
MusInfo *I_RegisterCDSong (int track, int cdid = 0);
|
MusInfo *I_RegisterCDSong (int track, int cdid = 0);
|
||||||
|
|
||||||
// The base music class. Everything is derived from this --------------------
|
// The base music class. Everything is derived from this --------------------
|
||||||
|
|
|
@ -408,7 +408,7 @@ protected:
|
||||||
class StreamSong : public MusInfo
|
class StreamSong : public MusInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StreamSong (FileReader *reader);
|
StreamSong (FileRdr &reader);
|
||||||
~StreamSong ();
|
~StreamSong ();
|
||||||
void Play (bool looping, int subsong);
|
void Play (bool looping, int subsong);
|
||||||
void Pause ();
|
void Pause ();
|
||||||
|
@ -431,7 +431,7 @@ protected:
|
||||||
class OPLMUSSong : public StreamSong
|
class OPLMUSSong : public StreamSong
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OPLMUSSong (FileReader &reader, const char *args);
|
OPLMUSSong (FileRdr &reader, const char *args);
|
||||||
~OPLMUSSong ();
|
~OPLMUSSong ();
|
||||||
void Play (bool looping, int subsong);
|
void Play (bool looping, int subsong);
|
||||||
bool IsPlaying ();
|
bool IsPlaying ();
|
||||||
|
@ -480,18 +480,18 @@ protected:
|
||||||
class CDDAFile : public CDSong
|
class CDDAFile : public CDSong
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CDDAFile (FileReader &reader);
|
CDDAFile (FileRdr &reader);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Module played via foo_dumb -----------------------------------------------
|
// Module played via foo_dumb -----------------------------------------------
|
||||||
|
|
||||||
MusInfo *MOD_OpenSong(FileReader &reader);
|
MusInfo *MOD_OpenSong(FileRdr &reader);
|
||||||
|
|
||||||
// Music played via Game Music Emu ------------------------------------------
|
// Music played via Game Music Emu ------------------------------------------
|
||||||
|
|
||||||
const char *GME_CheckFormat(uint32_t header);
|
const char *GME_CheckFormat(uint32_t header);
|
||||||
MusInfo *GME_OpenSong(FileReader &reader, const char *fmt);
|
MusInfo *GME_OpenSong(FileRdr &reader, const char *fmt);
|
||||||
MusInfo *SndFile_OpenSong(FileReader &fr);
|
MusInfo *SndFile_OpenSong(FileRdr &fr);
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -159,9 +159,8 @@ public:
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
SoundStream *OpenStream (FileReader *reader, int flags)
|
SoundStream *OpenStream (FileRdr &reader, int flags)
|
||||||
{
|
{
|
||||||
delete reader;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,13 +370,15 @@ FString SoundRenderer::GatherStats ()
|
||||||
|
|
||||||
short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType ctype)
|
short *SoundRenderer::DecodeSample(int outlen, const void *coded, int sizebytes, ECodecType ctype)
|
||||||
{
|
{
|
||||||
MemoryReader reader((const char*)coded, sizebytes);
|
FileRdr reader;
|
||||||
short *samples = (short*)calloc(1, outlen);
|
short *samples = (short*)calloc(1, outlen);
|
||||||
ChannelConfig chans;
|
ChannelConfig chans;
|
||||||
SampleType type;
|
SampleType type;
|
||||||
int srate;
|
int srate;
|
||||||
|
|
||||||
SoundDecoder *decoder = CreateDecoder(&reader);
|
reader.OpenMemory(coded, sizebytes);
|
||||||
|
|
||||||
|
SoundDecoder *decoder = CreateDecoder(reader);
|
||||||
if(!decoder) return samples;
|
if(!decoder) return samples;
|
||||||
|
|
||||||
decoder->getInfo(&srate, &chans, &type);
|
decoder->getInfo(&srate, &chans, &type);
|
||||||
|
@ -577,16 +578,16 @@ std::pair<SoundHandle, bool> SoundRenderer::LoadSoundBuffered(FSoundLoadBuffer *
|
||||||
return std::make_pair(retval, true);
|
return std::make_pair(retval, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundDecoder *SoundRenderer::CreateDecoder(FileReader *reader)
|
SoundDecoder *SoundRenderer::CreateDecoder(FileRdr &reader)
|
||||||
{
|
{
|
||||||
SoundDecoder *decoder = NULL;
|
SoundDecoder *decoder = NULL;
|
||||||
int pos = reader->Tell();
|
auto pos = reader.Tell();
|
||||||
|
|
||||||
#ifdef HAVE_SNDFILE
|
#ifdef HAVE_SNDFILE
|
||||||
decoder = new SndFileDecoder;
|
decoder = new SndFileDecoder;
|
||||||
if (decoder->open(reader))
|
if (decoder->open(reader))
|
||||||
return decoder;
|
return decoder;
|
||||||
reader->Seek(pos, SEEK_SET);
|
reader.Seek(pos, FileRdr::SeekSet);
|
||||||
|
|
||||||
delete decoder;
|
delete decoder;
|
||||||
decoder = NULL;
|
decoder = NULL;
|
||||||
|
@ -595,7 +596,7 @@ SoundDecoder *SoundRenderer::CreateDecoder(FileReader *reader)
|
||||||
decoder = new MPG123Decoder;
|
decoder = new MPG123Decoder;
|
||||||
if (decoder->open(reader))
|
if (decoder->open(reader))
|
||||||
return decoder;
|
return decoder;
|
||||||
reader->Seek(pos, SEEK_SET);
|
reader.Seek(pos, FileRdr::SeekSet);
|
||||||
|
|
||||||
delete decoder;
|
delete decoder;
|
||||||
decoder = NULL;
|
decoder = NULL;
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
#include "i_soundinternal.h"
|
#include "i_soundinternal.h"
|
||||||
|
|
||||||
class FileReader;
|
class FileRdr;
|
||||||
|
|
||||||
enum ECodecType
|
enum ECodecType
|
||||||
{
|
{
|
||||||
|
@ -118,7 +118,7 @@ public:
|
||||||
|
|
||||||
// Streaming sounds.
|
// Streaming sounds.
|
||||||
virtual SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) = 0;
|
virtual SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) = 0;
|
||||||
virtual SoundStream *OpenStream (FileReader *reader, int flags) = 0;
|
virtual SoundStream *OpenStream (FileRdr &reader, int flags) = 0;
|
||||||
|
|
||||||
// Starts a sound.
|
// Starts a sound.
|
||||||
virtual FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan) = 0;
|
virtual FISoundChannel *StartSound (SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan) = 0;
|
||||||
|
@ -168,7 +168,7 @@ public:
|
||||||
|
|
||||||
virtual void DrawWaveDebug(int mode);
|
virtual void DrawWaveDebug(int mode);
|
||||||
|
|
||||||
static SoundDecoder *CreateDecoder(FileReader *reader);
|
static SoundDecoder *CreateDecoder(FileRdr &reader);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SoundRenderer *GSnd;
|
extern SoundRenderer *GSnd;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "vectors.h"
|
#include "vectors.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
|
|
||||||
class FileReader;
|
class FileRdr;
|
||||||
|
|
||||||
// For convenience, this structure matches FMOD_REVERB_PROPERTIES.
|
// For convenience, this structure matches FMOD_REVERB_PROPERTIES.
|
||||||
// Since I can't very well #include system-specific stuff in the
|
// Since I can't very well #include system-specific stuff in the
|
||||||
|
@ -112,7 +112,7 @@ struct FISoundChannel
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void FindLoopTags(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass);
|
void FindLoopTags(FileRdr &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass);
|
||||||
|
|
||||||
|
|
||||||
enum SampleType
|
enum SampleType
|
||||||
|
@ -143,7 +143,7 @@ struct SoundDecoder
|
||||||
virtual ~SoundDecoder() { }
|
virtual ~SoundDecoder() { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool open(FileReader *reader) = 0;
|
virtual bool open(FileRdr &reader) = 0;
|
||||||
friend class SoundRenderer;
|
friend class SoundRenderer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -128,7 +128,7 @@ struct HMISong::TrackInfo
|
||||||
|
|
||||||
HMISong::HMISong (FileRdr &reader)
|
HMISong::HMISong (FileRdr &reader)
|
||||||
{
|
{
|
||||||
auto len = reader.GetLength();
|
int len = (int)reader.GetLength();
|
||||||
if (len < 0x100)
|
if (len < 0x100)
|
||||||
{ // Way too small to be HMI.
|
{ // Way too small to be HMI.
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -74,28 +74,28 @@ static bool inited = false;
|
||||||
|
|
||||||
off_t MPG123Decoder::file_lseek(void *handle, off_t offset, int whence)
|
off_t MPG123Decoder::file_lseek(void *handle, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
FileReader *reader = reinterpret_cast<MPG123Decoder*>(handle)->Reader;
|
auto &reader = reinterpret_cast<MPG123Decoder*>(handle)->Reader;
|
||||||
|
|
||||||
if(whence == SEEK_CUR)
|
if(whence == SEEK_CUR)
|
||||||
{
|
{
|
||||||
if(offset < 0 && reader->Tell()+offset < 0)
|
if(offset < 0 && reader.Tell()+offset < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if(whence == SEEK_END)
|
else if(whence == SEEK_END)
|
||||||
{
|
{
|
||||||
if(offset < 0 && reader->GetLength()+offset < 0)
|
if(offset < 0 && reader.GetLength()+offset < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(reader->Seek(offset, whence) != 0)
|
if(reader.Seek(offset, (FileRdr::ESeek)whence) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
return reader->Tell();
|
return (off_t)reader.Tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t MPG123Decoder::file_read(void *handle, void *buffer, size_t bytes)
|
ssize_t MPG123Decoder::file_read(void *handle, void *buffer, size_t bytes)
|
||||||
{
|
{
|
||||||
FileReader *reader = reinterpret_cast<MPG123Decoder*>(handle)->Reader;
|
auto &reader = reinterpret_cast<MPG123Decoder*>(handle)->Reader;
|
||||||
return (ssize_t)reader->Read(buffer, (long)bytes);
|
return (ssize_t)reader.Read(buffer, (long)bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ MPG123Decoder::~MPG123Decoder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MPG123Decoder::open(FileReader *reader)
|
bool MPG123Decoder::open(FileRdr &reader)
|
||||||
{
|
{
|
||||||
if(!inited)
|
if(!inited)
|
||||||
{
|
{
|
||||||
|
@ -118,7 +118,7 @@ bool MPG123Decoder::open(FileReader *reader)
|
||||||
inited = true;
|
inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Reader = reader;
|
Reader = std::move(reader);
|
||||||
|
|
||||||
{
|
{
|
||||||
MPG123 = mpg123_new(NULL, NULL);
|
MPG123 = mpg123_new(NULL, NULL);
|
||||||
|
@ -214,8 +214,10 @@ bool MPG123Decoder::seek(size_t ms_offset, bool ms, bool mayrestart)
|
||||||
mpg123_delete(MPG123);
|
mpg123_delete(MPG123);
|
||||||
MPG123 = 0;
|
MPG123 = 0;
|
||||||
}
|
}
|
||||||
Reader->Seek(0, SEEK_SET);
|
Reader.Seek(0, FileRdr::SeekSet);
|
||||||
return open(Reader);
|
// Do not call open with our own reader variable, that would be catastrophic.
|
||||||
|
auto reader = std::move(Reader);
|
||||||
|
return open(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size_t MPG123Decoder::getSampleOffset()
|
size_t MPG123Decoder::getSampleOffset()
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define MPG123_DECODER_H
|
#define MPG123_DECODER_H
|
||||||
|
|
||||||
#include "i_soundinternal.h"
|
#include "i_soundinternal.h"
|
||||||
|
#include "files.h"
|
||||||
|
|
||||||
#ifdef HAVE_MPG123
|
#ifdef HAVE_MPG123
|
||||||
|
|
||||||
|
@ -29,13 +30,13 @@ struct MPG123Decoder : public SoundDecoder
|
||||||
virtual ~MPG123Decoder();
|
virtual ~MPG123Decoder();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool open(FileReader *reader);
|
virtual bool open(FileRdr &reader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mpg123_handle *MPG123;
|
mpg123_handle *MPG123;
|
||||||
bool Done;
|
bool Done;
|
||||||
|
|
||||||
FileReader *Reader;
|
FileRdr Reader;
|
||||||
static off_t file_lseek(void *handle, off_t offset, int whence);
|
static off_t file_lseek(void *handle, off_t offset, int whence);
|
||||||
static ssize_t file_read(void *handle, void *buffer, size_t bytes);
|
static ssize_t file_read(void *handle, void *buffer, size_t bytes);
|
||||||
|
|
||||||
|
|
|
@ -112,17 +112,17 @@ bool CDSong::IsPlaying ()
|
||||||
return m_Status != STATE_Stopped;
|
return m_Status != STATE_Stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDDAFile::CDDAFile (FileReader &reader)
|
CDDAFile::CDDAFile (FileRdr &reader)
|
||||||
: CDSong ()
|
: CDSong ()
|
||||||
{
|
{
|
||||||
uint32_t chunk;
|
uint32_t chunk;
|
||||||
uint16_t track;
|
uint16_t track;
|
||||||
uint32_t discid;
|
uint32_t discid;
|
||||||
long endpos = reader.Tell() + reader.GetLength() - 8;
|
auto endpos = reader.Tell() + reader.GetLength() - 8;
|
||||||
|
|
||||||
// I_RegisterSong already identified this as a CDDA file, so we
|
// I_RegisterSong already identified this as a CDDA file, so we
|
||||||
// just need to check the contents we're interested in.
|
// just need to check the contents we're interested in.
|
||||||
reader.Seek(12, SEEK_CUR);
|
reader.Seek(12, FileRdr::SeekCur);
|
||||||
|
|
||||||
while (reader.Tell() < endpos)
|
while (reader.Tell() < endpos)
|
||||||
{
|
{
|
||||||
|
@ -130,11 +130,11 @@ CDDAFile::CDDAFile (FileReader &reader)
|
||||||
if (chunk != (('f')|(('m')<<8)|(('t')<<16)|((' ')<<24)))
|
if (chunk != (('f')|(('m')<<8)|(('t')<<16)|((' ')<<24)))
|
||||||
{
|
{
|
||||||
reader.Read(&chunk, 4);
|
reader.Read(&chunk, 4);
|
||||||
reader.Seek(chunk, SEEK_CUR);
|
reader.Seek(chunk, FileRdr::SeekCur);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
reader.Seek(6, SEEK_CUR);
|
reader.Seek(6, FileRdr::SeekCur);
|
||||||
reader.Read(&track, 2);
|
reader.Read(&track, 2);
|
||||||
reader.Read(&discid, 4);
|
reader.Read(&discid, 4);
|
||||||
|
|
||||||
|
|
|
@ -550,7 +550,7 @@ static DUMBFILE_SYSTEM mem_dfs = {
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
DUMBFILE *dumb_read_allfile(dumbfile_mem_status *filestate, uint8_t *start, FileReader &reader, int lenhave, int lenfull)
|
DUMBFILE *dumb_read_allfile(dumbfile_mem_status *filestate, uint8_t *start, FileRdr &reader, int lenhave, int lenfull)
|
||||||
{
|
{
|
||||||
filestate->size = lenfull;
|
filestate->size = lenfull;
|
||||||
filestate->offset = 0;
|
filestate->offset = 0;
|
||||||
|
@ -765,7 +765,7 @@ static void MOD_SetAutoChip(DUH *duh)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
MusInfo *MOD_OpenSong(FileReader &reader)
|
MusInfo *MOD_OpenSong(FileRdr &reader)
|
||||||
{
|
{
|
||||||
DUH *duh = 0;
|
DUH *duh = 0;
|
||||||
int headsize;
|
int headsize;
|
||||||
|
@ -776,7 +776,6 @@ MusInfo *MOD_OpenSong(FileReader &reader)
|
||||||
};
|
};
|
||||||
dumbfile_mem_status filestate;
|
dumbfile_mem_status filestate;
|
||||||
DUMBFILE *f = NULL;
|
DUMBFILE *f = NULL;
|
||||||
long fpos = 0;
|
|
||||||
input_mod *state = NULL;
|
input_mod *state = NULL;
|
||||||
|
|
||||||
bool is_it = false;
|
bool is_it = false;
|
||||||
|
@ -784,8 +783,8 @@ MusInfo *MOD_OpenSong(FileReader &reader)
|
||||||
|
|
||||||
atterm(dumb_exit);
|
atterm(dumb_exit);
|
||||||
|
|
||||||
int size = reader.GetLength();
|
int size = (int)reader.GetLength();
|
||||||
fpos = reader.Tell();
|
auto fpos = reader.Tell();
|
||||||
|
|
||||||
filestate.ptr = start;
|
filestate.ptr = start;
|
||||||
filestate.offset = 0;
|
filestate.offset = 0;
|
||||||
|
@ -903,7 +902,7 @@ MusInfo *MOD_OpenSong(FileReader &reader)
|
||||||
{
|
{
|
||||||
if (!(f = dumb_read_allfile(&filestate, start, reader, headsize, size)))
|
if (!(f = dumb_read_allfile(&filestate, start, reader, headsize, size)))
|
||||||
{
|
{
|
||||||
reader.Seek(fpos, SEEK_SET);
|
reader.Seek(fpos, FileRdr::SeekSet);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -944,7 +943,7 @@ MusInfo *MOD_OpenSong(FileReader &reader)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Reposition file pointer for other codecs to do their checks.
|
// Reposition file pointer for other codecs to do their checks.
|
||||||
reader.Seek(fpos, SEEK_SET);
|
reader.Seek(fpos, FileRdr::SeekSet);
|
||||||
}
|
}
|
||||||
if (filestate.ptr != (uint8_t *)start)
|
if (filestate.ptr != (uint8_t *)start)
|
||||||
{
|
{
|
||||||
|
|
|
@ -113,7 +113,7 @@ const char *GME_CheckFormat(uint32_t id)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
MusInfo *GME_OpenSong(FileReader &reader, const char *fmt)
|
MusInfo *GME_OpenSong(FileRdr &reader, const char *fmt)
|
||||||
{
|
{
|
||||||
gme_type_t type;
|
gme_type_t type;
|
||||||
gme_err_t err;
|
gme_err_t err;
|
||||||
|
@ -128,31 +128,31 @@ MusInfo *GME_OpenSong(FileReader &reader, const char *fmt)
|
||||||
}
|
}
|
||||||
sample_rate = (int)GSnd->GetOutputRate();
|
sample_rate = (int)GSnd->GetOutputRate();
|
||||||
emu = gme_new_emu(type, sample_rate);
|
emu = gme_new_emu(type, sample_rate);
|
||||||
if (emu == NULL)
|
if (emu == nullptr)
|
||||||
{
|
{
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fpos = reader.Tell();
|
auto fpos = reader.Tell();
|
||||||
int len = reader.GetLength();
|
auto len = reader.GetLength();
|
||||||
song = new uint8_t[len];
|
song = new uint8_t[len];
|
||||||
if (reader.Read(song, len) != len)
|
if (reader.Read(song, len) != len)
|
||||||
{
|
{
|
||||||
delete[] song;
|
delete[] song;
|
||||||
gme_delete(emu);
|
gme_delete(emu);
|
||||||
reader.Seek(fpos, SEEK_SET);
|
reader.Seek(fpos, FileRdr::SeekSet);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gme_load_data(emu, song, len);
|
err = gme_load_data(emu, song, (long)len);
|
||||||
delete[] song;
|
delete[] song;
|
||||||
|
|
||||||
if (err != NULL)
|
if (err != nullptr)
|
||||||
{
|
{
|
||||||
Printf("Failed loading song: %s\n", err);
|
Printf("Failed loading song: %s\n", err);
|
||||||
gme_delete(emu);
|
gme_delete(emu);
|
||||||
reader.Seek(fpos, SEEK_SET);
|
reader.Seek(fpos, FileRdr::SeekSet);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
gme_set_stereo_depth(emu, clamp(*gme_stereodepth, 0.f, 1.f));
|
gme_set_stereo_depth(emu, clamp(*gme_stereodepth, 0.f, 1.f));
|
||||||
return new GMESong(emu, sample_rate);
|
return new GMESong(emu, sample_rate);
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
class SndFileSong : public StreamSong
|
class SndFileSong : public StreamSong
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SndFileSong(FileReader *reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass);
|
SndFileSong(FileRdr &reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass);
|
||||||
~SndFileSong();
|
~SndFileSong();
|
||||||
bool SetSubsong(int subsong);
|
bool SetSubsong(int subsong);
|
||||||
void Play(bool looping, int subsong);
|
void Play(bool looping, int subsong);
|
||||||
|
@ -56,7 +56,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FCriticalSection CritSec;
|
FCriticalSection CritSec;
|
||||||
FileReader *Reader;
|
FileRdr Reader;
|
||||||
SoundDecoder *Decoder;
|
SoundDecoder *Decoder;
|
||||||
int Channels;
|
int Channels;
|
||||||
int SampleRate;
|
int SampleRate;
|
||||||
|
@ -105,23 +105,23 @@ CUSTOM_CVAR(Int, snd_streambuffersize, 64, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static void ParseVorbisComments(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass)
|
static void ParseVorbisComments(FileRdr &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass)
|
||||||
{
|
{
|
||||||
uint8_t vc_data[4];
|
uint8_t vc_data[4];
|
||||||
|
|
||||||
// The VC block starts with a 32LE integer for the vendor string length,
|
// The VC block starts with a 32LE integer for the vendor string length,
|
||||||
// followed by the vendor string
|
// followed by the vendor string
|
||||||
if(fr->Read(vc_data, 4) != 4)
|
if(fr.Read(vc_data, 4) != 4)
|
||||||
return;
|
return;
|
||||||
uint32_t vndr_len = vc_data[0] | (vc_data[1]<<8) | (vc_data[2]<<16) | (vc_data[3]<<24);
|
uint32_t vndr_len = vc_data[0] | (vc_data[1]<<8) | (vc_data[2]<<16) | (vc_data[3]<<24);
|
||||||
|
|
||||||
// Skip vendor string
|
// Skip vendor string
|
||||||
if(fr->Seek(vndr_len, SEEK_CUR) == -1)
|
if(fr.Seek(vndr_len, FileRdr::SeekCur) == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Following the vendor string is a 32LE integer for the number of
|
// Following the vendor string is a 32LE integer for the number of
|
||||||
// comments, followed by each comment.
|
// comments, followed by each comment.
|
||||||
if(fr->Read(vc_data, 4) != 4)
|
if(fr.Read(vc_data, 4) != 4)
|
||||||
return;
|
return;
|
||||||
size_t count = vc_data[0] | (vc_data[1]<<8) | (vc_data[2]<<16) | (vc_data[3]<<24);
|
size_t count = vc_data[0] | (vc_data[1]<<8) | (vc_data[2]<<16) | (vc_data[3]<<24);
|
||||||
|
|
||||||
|
@ -129,20 +129,20 @@ static void ParseVorbisComments(FileReader *fr, uint32_t *start, bool *startass,
|
||||||
{
|
{
|
||||||
// Each comment is a 32LE integer for the comment length, followed by
|
// Each comment is a 32LE integer for the comment length, followed by
|
||||||
// the comment text (not null terminated!)
|
// the comment text (not null terminated!)
|
||||||
if(fr->Read(vc_data, 4) != 4)
|
if(fr.Read(vc_data, 4) != 4)
|
||||||
return;
|
return;
|
||||||
uint32_t length = vc_data[0] | (vc_data[1]<<8) | (vc_data[2]<<16) | (vc_data[3]<<24);
|
uint32_t length = vc_data[0] | (vc_data[1]<<8) | (vc_data[2]<<16) | (vc_data[3]<<24);
|
||||||
|
|
||||||
if(length >= 128)
|
if(length >= 128)
|
||||||
{
|
{
|
||||||
// If the comment is "big", skip it
|
// If the comment is "big", skip it
|
||||||
if(fr->Seek(length, SEEK_CUR) == -1)
|
if(fr.Seek(length, FileRdr::SeekCur) == -1)
|
||||||
return;
|
return;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char strdat[128];
|
char strdat[128];
|
||||||
if(fr->Read(strdat, length) != (long)length)
|
if(fr.Read(strdat, length) != (long)length)
|
||||||
return;
|
return;
|
||||||
strdat[length] = 0;
|
strdat[length] = 0;
|
||||||
|
|
||||||
|
@ -153,13 +153,13 @@ static void ParseVorbisComments(FileReader *fr, uint32_t *start, bool *startass,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FindFlacComments(FileReader *fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass)
|
static void FindFlacComments(FileRdr &fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass)
|
||||||
{
|
{
|
||||||
// Already verified the fLaC marker, so we're 4 bytes into the file
|
// Already verified the fLaC marker, so we're 4 bytes into the file
|
||||||
bool lastblock = false;
|
bool lastblock = false;
|
||||||
uint8_t header[4];
|
uint8_t header[4];
|
||||||
|
|
||||||
while(!lastblock && fr->Read(header, 4) == 4)
|
while(!lastblock && fr.Read(header, 4) == 4)
|
||||||
{
|
{
|
||||||
// The first byte of the block header contains the type and a flag
|
// The first byte of the block header contains the type and a flag
|
||||||
// indicating the last metadata block
|
// indicating the last metadata block
|
||||||
|
@ -175,18 +175,18 @@ static void FindFlacComments(FileReader *fr, uint32_t *loop_start, bool *startas
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fr->Seek(blocksize, SEEK_CUR) == -1)
|
if(fr.Seek(blocksize, FileRdr::SeekCur) == -1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FindOggComments(FileReader *fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass)
|
static void FindOggComments(FileRdr &fr, uint32_t *loop_start, bool *startass, uint32_t *loop_end, bool *endass)
|
||||||
{
|
{
|
||||||
uint8_t ogghead[27];
|
uint8_t ogghead[27];
|
||||||
|
|
||||||
// We already read and verified the OggS marker, so skip the first 4 bytes
|
// We already read and verified the OggS marker, so skip the first 4 bytes
|
||||||
// of the Ogg page header.
|
// of the Ogg page header.
|
||||||
while(fr->Read(ogghead+4, 23) == 23)
|
while(fr.Read(ogghead+4, 23) == 23)
|
||||||
{
|
{
|
||||||
// The 19th byte of the Ogg header is a 32LE integer for the page
|
// The 19th byte of the Ogg header is a 32LE integer for the page
|
||||||
// number, and the 27th is a uint8 for the number of segments in the
|
// number, and the 27th is a uint8 for the number of segments in the
|
||||||
|
@ -199,7 +199,7 @@ static void FindOggComments(FileReader *fr, uint32_t *loop_start, bool *startass
|
||||||
// each segment in the page. The page segment data follows contiguously
|
// each segment in the page. The page segment data follows contiguously
|
||||||
// after.
|
// after.
|
||||||
uint8_t segsizes[256];
|
uint8_t segsizes[256];
|
||||||
if(fr->Read(segsizes, ogg_segments) != ogg_segments)
|
if(fr.Read(segsizes, ogg_segments) != ogg_segments)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Find the segment with the Vorbis Comment packet (type 3)
|
// Find the segment with the Vorbis Comment packet (type 3)
|
||||||
|
@ -210,7 +210,7 @@ static void FindOggComments(FileReader *fr, uint32_t *loop_start, bool *startass
|
||||||
if(segsize > 16)
|
if(segsize > 16)
|
||||||
{
|
{
|
||||||
uint8_t vorbhead[7];
|
uint8_t vorbhead[7];
|
||||||
if(fr->Read(vorbhead, 7) != 7)
|
if(fr.Read(vorbhead, 7) != 7)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(vorbhead[0] == 3 && memcmp(vorbhead+1, "vorbis", 6) == 0)
|
if(vorbhead[0] == 3 && memcmp(vorbhead+1, "vorbis", 6) == 0)
|
||||||
|
@ -237,7 +237,7 @@ static void FindOggComments(FileReader *fr, uint32_t *loop_start, bool *startass
|
||||||
|
|
||||||
segsize -= 7;
|
segsize -= 7;
|
||||||
}
|
}
|
||||||
if(fr->Seek(segsize, SEEK_CUR) == -1)
|
if(fr.Seek(segsize, FileRdr::SeekCur) == -1)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,16 +245,16 @@ static void FindOggComments(FileReader *fr, uint32_t *loop_start, bool *startass
|
||||||
if(ogg_pagenum >= 2)
|
if(ogg_pagenum >= 2)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if(fr->Read(ogghead, 4) != 4 || memcmp(ogghead, "OggS", 4) != 0)
|
if(fr.Read(ogghead, 4) != 4 || memcmp(ogghead, "OggS", 4) != 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FindLoopTags(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass)
|
void FindLoopTags(FileRdr &fr, uint32_t *start, bool *startass, uint32_t *end, bool *endass)
|
||||||
{
|
{
|
||||||
uint8_t signature[4];
|
uint8_t signature[4];
|
||||||
|
|
||||||
fr->Read(signature, 4);
|
fr.Read(signature, 4);
|
||||||
if(memcmp(signature, "fLaC", 4) == 0)
|
if(memcmp(signature, "fLaC", 4) == 0)
|
||||||
FindFlacComments(fr, start, startass, end, endass);
|
FindFlacComments(fr, start, startass, end, endass);
|
||||||
else if(memcmp(signature, "OggS", 4) == 0)
|
else if(memcmp(signature, "OggS", 4) == 0)
|
||||||
|
@ -268,18 +268,18 @@ void FindLoopTags(FileReader *fr, uint32_t *start, bool *startass, uint32_t *end
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
MusInfo *SndFile_OpenSong(FileReader &fr)
|
MusInfo *SndFile_OpenSong(FileRdr &fr)
|
||||||
{
|
{
|
||||||
fr.Seek(0, SEEK_SET);
|
fr.Seek(0, FileRdr::SeekSet);
|
||||||
|
|
||||||
uint32_t loop_start = 0, loop_end = ~0u;
|
uint32_t loop_start = 0, loop_end = ~0u;
|
||||||
bool startass = false, endass = false;
|
bool startass = false, endass = false;
|
||||||
FindLoopTags(&fr, &loop_start, &startass, &loop_end, &endass);
|
FindLoopTags(fr, &loop_start, &startass, &loop_end, &endass);
|
||||||
|
|
||||||
fr.Seek(0, SEEK_SET);
|
fr.Seek(0, FileRdr::SeekSet);
|
||||||
auto decoder = SoundRenderer::CreateDecoder(&fr);
|
auto decoder = SoundRenderer::CreateDecoder(fr);
|
||||||
if (decoder == nullptr) return nullptr;
|
if (decoder == nullptr) return nullptr;
|
||||||
return new SndFileSong(&fr, decoder, loop_start, loop_end, startass, endass);
|
return new SndFileSong(fr, decoder, loop_start, loop_end, startass, endass);
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -288,7 +288,7 @@ MusInfo *SndFile_OpenSong(FileReader &fr)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
SndFileSong::SndFileSong(FileReader *reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass)
|
SndFileSong::SndFileSong(FileRdr &reader, SoundDecoder *decoder, uint32_t loop_start, uint32_t loop_end, bool startass, bool endass)
|
||||||
{
|
{
|
||||||
ChannelConfig iChannels;
|
ChannelConfig iChannels;
|
||||||
SampleType Type;
|
SampleType Type;
|
||||||
|
@ -300,7 +300,7 @@ SndFileSong::SndFileSong(FileReader *reader, SoundDecoder *decoder, uint32_t loo
|
||||||
|
|
||||||
Loop_Start = loop_start;
|
Loop_Start = loop_start;
|
||||||
Loop_End = clamp<uint32_t>(loop_end, 0, (uint32_t)decoder->getSampleLength());
|
Loop_End = clamp<uint32_t>(loop_end, 0, (uint32_t)decoder->getSampleLength());
|
||||||
Reader = reader;
|
Reader = std::move(reader);
|
||||||
Decoder = decoder;
|
Decoder = decoder;
|
||||||
Channels = iChannels == ChannelConfig_Stereo? 2:1;
|
Channels = iChannels == ChannelConfig_Stereo? 2:1;
|
||||||
m_Stream = GSnd->CreateStream(Read, snd_streambuffersize * 1024, iChannels == ChannelConfig_Stereo? 0 : SoundStream::Mono, SampleRate, this);
|
m_Stream = GSnd->CreateStream(Read, snd_streambuffersize * 1024, iChannels == ChannelConfig_Stereo? 0 : SoundStream::Mono, SampleRate, this);
|
||||||
|
@ -324,10 +324,6 @@ SndFileSong::~SndFileSong()
|
||||||
{
|
{
|
||||||
delete Decoder;
|
delete Decoder;
|
||||||
}
|
}
|
||||||
if (Reader != nullptr)
|
|
||||||
{
|
|
||||||
delete Reader;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,12 +69,12 @@ void OPL_SetCore(const char *args)
|
||||||
if (args != NULL && *args >= '0' && *args < '4') current_opl_core = *args - '0';
|
if (args != NULL && *args >= '0' && *args < '4') current_opl_core = *args - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
OPLMUSSong::OPLMUSSong (FileReader &reader, const char *args)
|
OPLMUSSong::OPLMUSSong (FileRdr &reader, const char *args)
|
||||||
{
|
{
|
||||||
int samples = int(OPL_SAMPLE_RATE / 14);
|
int samples = int(OPL_SAMPLE_RATE / 14);
|
||||||
|
|
||||||
OPL_SetCore(args);
|
OPL_SetCore(args);
|
||||||
Music = new OPLmusicFile (&reader);
|
Music = new OPLmusicFile (reader);
|
||||||
|
|
||||||
m_Stream = GSnd->CreateStream (FillStream, samples*4,
|
m_Stream = GSnd->CreateStream (FillStream, samples*4,
|
||||||
(current_opl_core == 0 ? SoundStream::Mono : 0) | SoundStream::Float, int(OPL_SAMPLE_RATE), this);
|
(current_opl_core == 0 ? SoundStream::Mono : 0) | SoundStream::Float, int(OPL_SAMPLE_RATE), this);
|
||||||
|
|
|
@ -85,7 +85,7 @@ StreamSong::~StreamSong ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamSong::StreamSong (FileReader *reader)
|
StreamSong::StreamSong (FileRdr &reader)
|
||||||
{
|
{
|
||||||
m_Stream = GSnd->OpenStream (reader, SoundStream::Loop);
|
m_Stream = GSnd->OpenStream (reader, SoundStream::Loop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,7 +228,7 @@ class OpenALSoundStream : public SoundStream
|
||||||
ALfloat Volume;
|
ALfloat Volume;
|
||||||
|
|
||||||
|
|
||||||
FileReader *Reader;
|
FileRdr Reader;
|
||||||
SoundDecoder *Decoder;
|
SoundDecoder *Decoder;
|
||||||
static bool DecoderCallback(SoundStream *_sstream, void *ptr, int length, void *user)
|
static bool DecoderCallback(SoundStream *_sstream, void *ptr, int length, void *user)
|
||||||
{
|
{
|
||||||
|
@ -317,7 +317,6 @@ public:
|
||||||
getALError();
|
getALError();
|
||||||
|
|
||||||
delete Decoder;
|
delete Decoder;
|
||||||
delete Reader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -604,17 +603,15 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Init(FileReader *reader, bool loop)
|
bool Init(FileRdr &reader, bool loop)
|
||||||
{
|
{
|
||||||
if(!SetupSource())
|
if(!SetupSource())
|
||||||
{
|
{
|
||||||
delete reader;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Decoder) delete Decoder;
|
if(Decoder) delete Decoder;
|
||||||
if(Reader) delete Reader;
|
Reader = std::move(reader);
|
||||||
Reader = reader;
|
|
||||||
Decoder = Renderer->CreateDecoder(Reader);
|
Decoder = Renderer->CreateDecoder(Reader);
|
||||||
if(!Decoder) return false;
|
if(!Decoder) return false;
|
||||||
|
|
||||||
|
@ -1279,7 +1276,7 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata,
|
||||||
std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, bool monoize, FSoundLoadBuffer *pBuffer)
|
std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, bool monoize, FSoundLoadBuffer *pBuffer)
|
||||||
{
|
{
|
||||||
SoundHandle retval = { NULL };
|
SoundHandle retval = { NULL };
|
||||||
MemoryReader reader((const char*)sfxdata, length);
|
FileRdr reader;
|
||||||
ALenum format = AL_NONE;
|
ALenum format = AL_NONE;
|
||||||
ChannelConfig chans;
|
ChannelConfig chans;
|
||||||
SampleType type;
|
SampleType type;
|
||||||
|
@ -1290,10 +1287,12 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int
|
||||||
/* Only downmix to mono if we can't spatialize multi-channel sounds. */
|
/* Only downmix to mono if we can't spatialize multi-channel sounds. */
|
||||||
monoize = monoize && !AL.SOFT_source_spatialize;
|
monoize = monoize && !AL.SOFT_source_spatialize;
|
||||||
|
|
||||||
FindLoopTags(&reader, &loop_start, &startass, &loop_end, &endass);
|
reader.OpenMemory(sfxdata, length);
|
||||||
|
|
||||||
reader.Seek(0, SEEK_SET);
|
FindLoopTags(reader, &loop_start, &startass, &loop_end, &endass);
|
||||||
std::unique_ptr<SoundDecoder> decoder(CreateDecoder(&reader));
|
|
||||||
|
reader.Seek(0, FileRdr::SeekSet);
|
||||||
|
std::unique_ptr<SoundDecoder> decoder(CreateDecoder(reader));
|
||||||
if (!decoder) return std::make_pair(retval, true);
|
if (!decoder) return std::make_pair(retval, true);
|
||||||
|
|
||||||
decoder->getInfo(&srate, &chans, &type);
|
decoder->getInfo(&srate, &chans, &type);
|
||||||
|
@ -1530,7 +1529,7 @@ SoundStream *OpenALSoundRenderer::CreateStream(SoundStreamCallback callback, int
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundStream *OpenALSoundRenderer::OpenStream(FileReader *reader, int flags)
|
SoundStream *OpenALSoundRenderer::OpenStream(FileRdr &reader, int flags)
|
||||||
{
|
{
|
||||||
if(StreamThread.get_id() == std::thread::id())
|
if(StreamThread.get_id() == std::thread::id())
|
||||||
StreamThread = std::thread(std::mem_fn(&OpenALSoundRenderer::BackgroundProc), this);
|
StreamThread = std::thread(std::mem_fn(&OpenALSoundRenderer::BackgroundProc), this);
|
||||||
|
|
|
@ -136,7 +136,7 @@ public:
|
||||||
|
|
||||||
// Streaming sounds.
|
// Streaming sounds.
|
||||||
virtual SoundStream *CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata);
|
virtual SoundStream *CreateStream(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata);
|
||||||
virtual SoundStream *OpenStream(FileReader *reader, int flags);
|
virtual SoundStream *OpenStream(FileRdr &reader, int flags);
|
||||||
|
|
||||||
// Starts a sound.
|
// Starts a sound.
|
||||||
virtual FISoundChannel *StartSound(SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan);
|
virtual FISoundChannel *StartSound(SoundHandle sfx, float vol, int pitch, int chanflags, FISoundChannel *reuse_chan);
|
||||||
|
|
|
@ -84,8 +84,8 @@ void OPLmusicBlock::Restart()
|
||||||
LastOffset = 0;
|
LastOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
OPLmusicFile::OPLmusicFile (FileReader *reader)
|
OPLmusicFile::OPLmusicFile (FileRdr &reader)
|
||||||
: ScoreLen (reader->GetLength())
|
: ScoreLen ((int)reader.GetLength())
|
||||||
{
|
{
|
||||||
if (io == NULL)
|
if (io == NULL)
|
||||||
{
|
{
|
||||||
|
@ -94,7 +94,7 @@ OPLmusicFile::OPLmusicFile (FileReader *reader)
|
||||||
|
|
||||||
scoredata = new uint8_t[ScoreLen];
|
scoredata = new uint8_t[ScoreLen];
|
||||||
|
|
||||||
if (reader->Read(scoredata, ScoreLen) != ScoreLen)
|
if (reader.Read(scoredata, ScoreLen) != ScoreLen)
|
||||||
{
|
{
|
||||||
fail: delete[] scoredata;
|
fail: delete[] scoredata;
|
||||||
scoredata = NULL;
|
scoredata = NULL;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "critsec.h"
|
#include "critsec.h"
|
||||||
#include "musicblock.h"
|
#include "musicblock.h"
|
||||||
|
|
||||||
class FileReader;
|
class FileRdr;
|
||||||
|
|
||||||
class OPLmusicBlock : public musicBlock
|
class OPLmusicBlock : public musicBlock
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,7 @@ protected:
|
||||||
class OPLmusicFile : public OPLmusicBlock
|
class OPLmusicFile : public OPLmusicBlock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OPLmusicFile(FileReader *reader);
|
OPLmusicFile(FileRdr &reader);
|
||||||
OPLmusicFile(const OPLmusicFile *source, const char *filename);
|
OPLmusicFile(const OPLmusicFile *source, const char *filename);
|
||||||
virtual ~OPLmusicFile();
|
virtual ~OPLmusicFile();
|
||||||
|
|
||||||
|
|
|
@ -72,23 +72,23 @@ bool IsSndFilePresent()
|
||||||
|
|
||||||
sf_count_t SndFileDecoder::file_get_filelen(void *user_data)
|
sf_count_t SndFileDecoder::file_get_filelen(void *user_data)
|
||||||
{
|
{
|
||||||
FileReader *reader = reinterpret_cast<SndFileDecoder*>(user_data)->Reader;
|
auto &reader = reinterpret_cast<SndFileDecoder*>(user_data)->Reader;
|
||||||
return reader->GetLength();
|
return reader.GetLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
sf_count_t SndFileDecoder::file_seek(sf_count_t offset, int whence, void *user_data)
|
sf_count_t SndFileDecoder::file_seek(sf_count_t offset, int whence, void *user_data)
|
||||||
{
|
{
|
||||||
FileReader *reader = reinterpret_cast<SndFileDecoder*>(user_data)->Reader;
|
auto &reader = reinterpret_cast<SndFileDecoder*>(user_data)->Reader;
|
||||||
|
|
||||||
if(reader->Seek((long)offset, whence) != 0)
|
if(reader.Seek((long)offset, (FileRdr::ESeek)whence) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
return reader->Tell();
|
return reader.Tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
sf_count_t SndFileDecoder::file_read(void *ptr, sf_count_t count, void *user_data)
|
sf_count_t SndFileDecoder::file_read(void *ptr, sf_count_t count, void *user_data)
|
||||||
{
|
{
|
||||||
FileReader *reader = reinterpret_cast<SndFileDecoder*>(user_data)->Reader;
|
auto &reader = reinterpret_cast<SndFileDecoder*>(user_data)->Reader;
|
||||||
return reader->Read(ptr, (long)count);
|
return reader.Read(ptr, (long)count);
|
||||||
}
|
}
|
||||||
|
|
||||||
sf_count_t SndFileDecoder::file_write(const void *ptr, sf_count_t count, void *user_data)
|
sf_count_t SndFileDecoder::file_write(const void *ptr, sf_count_t count, void *user_data)
|
||||||
|
@ -98,8 +98,8 @@ sf_count_t SndFileDecoder::file_write(const void *ptr, sf_count_t count, void *u
|
||||||
|
|
||||||
sf_count_t SndFileDecoder::file_tell(void *user_data)
|
sf_count_t SndFileDecoder::file_tell(void *user_data)
|
||||||
{
|
{
|
||||||
FileReader *reader = reinterpret_cast<SndFileDecoder*>(user_data)->Reader;
|
auto &reader = reinterpret_cast<SndFileDecoder*>(user_data)->Reader;
|
||||||
return reader->Tell();
|
return reader.Tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,13 +110,13 @@ SndFileDecoder::~SndFileDecoder()
|
||||||
SndFile = 0;
|
SndFile = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SndFileDecoder::open(FileReader *reader)
|
bool SndFileDecoder::open(FileRdr &reader)
|
||||||
{
|
{
|
||||||
if (!IsSndFilePresent()) return false;
|
if (!IsSndFilePresent()) return false;
|
||||||
|
|
||||||
SF_VIRTUAL_IO sfio = { file_get_filelen, file_seek, file_read, file_write, file_tell };
|
SF_VIRTUAL_IO sfio = { file_get_filelen, file_seek, file_read, file_write, file_tell };
|
||||||
|
|
||||||
Reader = reader;
|
Reader = std::move(reader);
|
||||||
SndInfo.format = 0;
|
SndInfo.format = 0;
|
||||||
SndFile = sf_open_virtual(&sfio, SFM_READ, &SndInfo, this);
|
SndFile = sf_open_virtual(&sfio, SFM_READ, &SndInfo, this);
|
||||||
if (SndFile)
|
if (SndFile)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define SNDFILE_DECODER_H
|
#define SNDFILE_DECODER_H
|
||||||
|
|
||||||
#include "i_soundinternal.h"
|
#include "i_soundinternal.h"
|
||||||
|
#include "files.h"
|
||||||
|
|
||||||
#ifdef HAVE_SNDFILE
|
#ifdef HAVE_SNDFILE
|
||||||
|
|
||||||
|
@ -25,13 +26,13 @@ struct SndFileDecoder : public SoundDecoder
|
||||||
virtual ~SndFileDecoder();
|
virtual ~SndFileDecoder();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool open(FileReader *reader);
|
virtual bool open(FileRdr &reader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SNDFILE *SndFile;
|
SNDFILE *SndFile;
|
||||||
SF_INFO SndInfo;
|
SF_INFO SndInfo;
|
||||||
|
|
||||||
FileReader *Reader;
|
FileRdr Reader;
|
||||||
static sf_count_t file_get_filelen(void *user_data);
|
static sf_count_t file_get_filelen(void *user_data);
|
||||||
static sf_count_t file_seek(sf_count_t offset, int whence, void *user_data);
|
static sf_count_t file_seek(sf_count_t offset, int whence, void *user_data);
|
||||||
static sf_count_t file_read(void *ptr, sf_count_t count, void *user_data);
|
static sf_count_t file_read(void *ptr, sf_count_t count, void *user_data);
|
||||||
|
|
|
@ -366,7 +366,7 @@ void SetDefaultColormap (const char *name)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FWadLump lumpr = Wads.OpenLumpNum (lump);
|
auto lumpr = Wads.OpenLumpReader (lump);
|
||||||
|
|
||||||
// [RH] The colormap may not have been designed for the specific
|
// [RH] The colormap may not have been designed for the specific
|
||||||
// palette we are using, so remap it to match the current palette.
|
// palette we are using, so remap it to match the current palette.
|
||||||
|
@ -427,7 +427,7 @@ static void InitBoomColormaps ()
|
||||||
if (Wads.LumpLength (fakecmaps[j].lump) >= (NUMCOLORMAPS+1)*256)
|
if (Wads.LumpLength (fakecmaps[j].lump) >= (NUMCOLORMAPS+1)*256)
|
||||||
{
|
{
|
||||||
int k, r;
|
int k, r;
|
||||||
FWadLump lump = Wads.OpenLumpNum (fakecmaps[j].lump);
|
auto lump = Wads.OpenLumpReader (fakecmaps[j].lump);
|
||||||
uint8_t *const map = realcolormaps.Maps + NUMCOLORMAPS*256*j;
|
uint8_t *const map = realcolormaps.Maps + NUMCOLORMAPS*256*j;
|
||||||
|
|
||||||
for (k = 0; k < NUMCOLORMAPS; ++k)
|
for (k = 0; k < NUMCOLORMAPS; ++k)
|
||||||
|
|
|
@ -72,7 +72,7 @@ private:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture *AutomapTexture_TryCreate(FileReader &data, int lumpnum)
|
FTexture *AutomapTexture_TryCreate(FileRdr &data, int lumpnum)
|
||||||
{
|
{
|
||||||
if (data.GetLength() < 320) return NULL;
|
if (data.GetLength() < 320) return NULL;
|
||||||
if (!Wads.CheckLumpName(lumpnum, "AUTOPAGE")) return NULL;
|
if (!Wads.CheckLumpName(lumpnum, "AUTOPAGE")) return NULL;
|
||||||
|
|
|
@ -156,7 +156,7 @@ struct DDSFileHeader
|
||||||
class FDDSTexture : public FTexture
|
class FDDSTexture : public FTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc);
|
FDDSTexture (FileRdr &lump, int lumpnum, void *surfdesc);
|
||||||
~FDDSTexture ();
|
~FDDSTexture ();
|
||||||
|
|
||||||
const uint8_t *GetColumn (unsigned int column, const Span **spans_out);
|
const uint8_t *GetColumn (unsigned int column, const Span **spans_out);
|
||||||
|
@ -181,10 +181,10 @@ protected:
|
||||||
static void CalcBitShift (uint32_t mask, uint8_t *lshift, uint8_t *rshift);
|
static void CalcBitShift (uint32_t mask, uint8_t *lshift, uint8_t *rshift);
|
||||||
|
|
||||||
void MakeTexture ();
|
void MakeTexture ();
|
||||||
void ReadRGB (FWadLump &lump, uint8_t *tcbuf = NULL);
|
void ReadRGB (FileRdr &lump, uint8_t *tcbuf = NULL);
|
||||||
void DecompressDXT1 (FWadLump &lump, uint8_t *tcbuf = NULL);
|
void DecompressDXT1 (FileRdr &lump, uint8_t *tcbuf = NULL);
|
||||||
void DecompressDXT3 (FWadLump &lump, bool premultiplied, uint8_t *tcbuf = NULL);
|
void DecompressDXT3 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf = NULL);
|
||||||
void DecompressDXT5 (FWadLump &lump, bool premultiplied, uint8_t *tcbuf = NULL);
|
void DecompressDXT5 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf = NULL);
|
||||||
|
|
||||||
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL);
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL);
|
||||||
bool UseBasePalette();
|
bool UseBasePalette();
|
||||||
|
@ -199,11 +199,11 @@ protected:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static bool CheckDDS (FileReader &file)
|
static bool CheckDDS (FileRdr &file)
|
||||||
{
|
{
|
||||||
DDSFileHeader Header;
|
DDSFileHeader Header;
|
||||||
|
|
||||||
file.Seek (0, SEEK_SET);
|
file.Seek(0, FileRdr::SeekSet);
|
||||||
if (file.Read (&Header, sizeof(Header)) != sizeof(Header))
|
if (file.Read (&Header, sizeof(Header)) != sizeof(Header))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -222,7 +222,7 @@ static bool CheckDDS (FileReader &file)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture *DDSTexture_TryCreate (FileReader &data, int lumpnum)
|
FTexture *DDSTexture_TryCreate (FileRdr &data, int lumpnum)
|
||||||
{
|
{
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
@ -232,7 +232,7 @@ FTexture *DDSTexture_TryCreate (FileReader &data, int lumpnum)
|
||||||
|
|
||||||
if (!CheckDDS(data)) return NULL;
|
if (!CheckDDS(data)) return NULL;
|
||||||
|
|
||||||
data.Seek (4, SEEK_SET);
|
data.Seek(4, FileRdr::SeekSet);
|
||||||
data.Read (&surfdesc, sizeof(surfdesc));
|
data.Read (&surfdesc, sizeof(surfdesc));
|
||||||
|
|
||||||
#ifdef __BIG_ENDIAN__
|
#ifdef __BIG_ENDIAN__
|
||||||
|
@ -286,7 +286,7 @@ FTexture *DDSTexture_TryCreate (FileReader &data, int lumpnum)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FDDSTexture::FDDSTexture (FileReader &lump, int lumpnum, void *vsurfdesc)
|
FDDSTexture::FDDSTexture (FileRdr &lump, int lumpnum, void *vsurfdesc)
|
||||||
: FTexture(NULL, lumpnum), Pixels(0), Spans(0)
|
: FTexture(NULL, lumpnum), Pixels(0), Spans(0)
|
||||||
{
|
{
|
||||||
DDSURFACEDESC2 *surf = (DDSURFACEDESC2 *)vsurfdesc;
|
DDSURFACEDESC2 *surf = (DDSURFACEDESC2 *)vsurfdesc;
|
||||||
|
@ -488,11 +488,11 @@ const uint8_t *FDDSTexture::GetPixels ()
|
||||||
|
|
||||||
void FDDSTexture::MakeTexture ()
|
void FDDSTexture::MakeTexture ()
|
||||||
{
|
{
|
||||||
FWadLump lump = Wads.OpenLumpNum (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
|
|
||||||
Pixels = new uint8_t[Width*Height];
|
Pixels = new uint8_t[Width*Height];
|
||||||
|
|
||||||
lump.Seek (sizeof(DDSURFACEDESC2) + 4, SEEK_SET);
|
lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileRdr::SeekSet);
|
||||||
|
|
||||||
if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel
|
if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel
|
||||||
{
|
{
|
||||||
|
@ -518,7 +518,7 @@ void FDDSTexture::MakeTexture ()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FDDSTexture::ReadRGB (FWadLump &lump, uint8_t *tcbuf)
|
void FDDSTexture::ReadRGB (FileRdr &lump, uint8_t *tcbuf)
|
||||||
{
|
{
|
||||||
uint32_t x, y;
|
uint32_t x, y;
|
||||||
uint32_t amask = AMask == 0 ? 0 : 0x80000000 >> AShiftL;
|
uint32_t amask = AMask == 0 ? 0 : 0x80000000 >> AShiftL;
|
||||||
|
@ -587,7 +587,7 @@ void FDDSTexture::ReadRGB (FWadLump &lump, uint8_t *tcbuf)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FDDSTexture::DecompressDXT1 (FWadLump &lump, uint8_t *tcbuf)
|
void FDDSTexture::DecompressDXT1 (FileRdr &lump, uint8_t *tcbuf)
|
||||||
{
|
{
|
||||||
const long blocklinelen = ((Width + 3) >> 2) << 3;
|
const long blocklinelen = ((Width + 3) >> 2) << 3;
|
||||||
uint8_t *blockbuff = new uint8_t[blocklinelen];
|
uint8_t *blockbuff = new uint8_t[blocklinelen];
|
||||||
|
@ -685,7 +685,7 @@ void FDDSTexture::DecompressDXT1 (FWadLump &lump, uint8_t *tcbuf)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FDDSTexture::DecompressDXT3 (FWadLump &lump, bool premultiplied, uint8_t *tcbuf)
|
void FDDSTexture::DecompressDXT3 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf)
|
||||||
{
|
{
|
||||||
const long blocklinelen = ((Width + 3) >> 2) << 4;
|
const long blocklinelen = ((Width + 3) >> 2) << 4;
|
||||||
uint8_t *blockbuff = new uint8_t[blocklinelen];
|
uint8_t *blockbuff = new uint8_t[blocklinelen];
|
||||||
|
@ -767,7 +767,7 @@ void FDDSTexture::DecompressDXT3 (FWadLump &lump, bool premultiplied, uint8_t *t
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FDDSTexture::DecompressDXT5 (FWadLump &lump, bool premultiplied, uint8_t *tcbuf)
|
void FDDSTexture::DecompressDXT5 (FileRdr &lump, bool premultiplied, uint8_t *tcbuf)
|
||||||
{
|
{
|
||||||
const long blocklinelen = ((Width + 3) >> 2) << 4;
|
const long blocklinelen = ((Width + 3) >> 2) << 4;
|
||||||
uint8_t *blockbuff = new uint8_t[blocklinelen];
|
uint8_t *blockbuff = new uint8_t[blocklinelen];
|
||||||
|
@ -881,11 +881,11 @@ void FDDSTexture::DecompressDXT5 (FWadLump &lump, bool premultiplied, uint8_t *t
|
||||||
|
|
||||||
int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
||||||
{
|
{
|
||||||
FWadLump lump = Wads.OpenLumpNum (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
|
|
||||||
uint8_t *TexBuffer = new uint8_t[4*Width*Height];
|
uint8_t *TexBuffer = new uint8_t[4*Width*Height];
|
||||||
|
|
||||||
lump.Seek (sizeof(DDSURFACEDESC2) + 4, SEEK_SET);
|
lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileRdr::SeekSet);
|
||||||
|
|
||||||
if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel
|
if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,11 +68,11 @@ protected:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture *EmptyTexture_TryCreate(FileReader & file, int lumpnum)
|
FTexture *EmptyTexture_TryCreate(FileRdr & file, int lumpnum)
|
||||||
{
|
{
|
||||||
char check[8];
|
char check[8];
|
||||||
if (file.GetLength() != 8) return NULL;
|
if (file.GetLength() != 8) return NULL;
|
||||||
file.Seek(0, SEEK_SET);
|
file.Seek(0, FileRdr::SeekSet);
|
||||||
if (file.Read(check, 8) != 8) return NULL;
|
if (file.Read(check, 8) != 8) return NULL;
|
||||||
if (memcmp(check, "\0\0\0\0\0\0\0\0", 8)) return NULL;
|
if (memcmp(check, "\0\0\0\0\0\0\0\0", 8)) return NULL;
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ protected:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture *FlatTexture_TryCreate(FileReader & file, int lumpnum)
|
FTexture *FlatTexture_TryCreate(FileRdr & file, int lumpnum)
|
||||||
{
|
{
|
||||||
return new FFlatTexture(lumpnum);
|
return new FFlatTexture(lumpnum);
|
||||||
}
|
}
|
||||||
|
@ -194,9 +194,9 @@ const uint8_t *FFlatTexture::GetPixels ()
|
||||||
|
|
||||||
void FFlatTexture::MakeTexture ()
|
void FFlatTexture::MakeTexture ()
|
||||||
{
|
{
|
||||||
FWadLump lump = Wads.OpenLumpNum (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
Pixels = new uint8_t[Width*Height];
|
Pixels = new uint8_t[Width*Height];
|
||||||
long numread = lump.Read (Pixels, Width*Height);
|
auto numread = lump.Read (Pixels, Width*Height);
|
||||||
if (numread < Width*Height)
|
if (numread < Width*Height)
|
||||||
{
|
{
|
||||||
memset (Pixels + numread, 0xBB, Width*Height - numread);
|
memset (Pixels + numread, 0xBB, Width*Height - numread);
|
||||||
|
|
|
@ -83,13 +83,13 @@ protected:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture *IMGZTexture_TryCreate(FileReader & file, int lumpnum)
|
FTexture *IMGZTexture_TryCreate(FileRdr & file, int lumpnum)
|
||||||
{
|
{
|
||||||
uint32_t magic = 0;
|
uint32_t magic = 0;
|
||||||
uint16_t w, h;
|
uint16_t w, h;
|
||||||
int16_t l, t;
|
int16_t l, t;
|
||||||
|
|
||||||
file.Seek(0, SEEK_SET);
|
file.Seek(0, FileRdr::SeekSet);
|
||||||
if (file.Read(&magic, 4) != 4) return NULL;
|
if (file.Read(&magic, 4) != 4) return NULL;
|
||||||
if (magic != MAKE_ID('I','M','G','Z')) return NULL;
|
if (magic != MAKE_ID('I','M','G','Z')) return NULL;
|
||||||
file >> w >> h >> l >> t;
|
file >> w >> h >> l >> t;
|
||||||
|
|
|
@ -50,11 +50,11 @@ extern "C"
|
||||||
|
|
||||||
struct FLumpSourceMgr : public jpeg_source_mgr
|
struct FLumpSourceMgr : public jpeg_source_mgr
|
||||||
{
|
{
|
||||||
FileReader *Lump;
|
FileRdr *Lump;
|
||||||
JOCTET Buffer[4096];
|
JOCTET Buffer[4096];
|
||||||
bool StartOfFile;
|
bool StartOfFile;
|
||||||
|
|
||||||
FLumpSourceMgr (FileReader *lump, j_decompress_ptr cinfo);
|
FLumpSourceMgr (FileRdr *lump, j_decompress_ptr cinfo);
|
||||||
static void InitSource (j_decompress_ptr cinfo);
|
static void InitSource (j_decompress_ptr cinfo);
|
||||||
static boolean FillInputBuffer (j_decompress_ptr cinfo);
|
static boolean FillInputBuffer (j_decompress_ptr cinfo);
|
||||||
static void SkipInputData (j_decompress_ptr cinfo, long num_bytes);
|
static void SkipInputData (j_decompress_ptr cinfo, long num_bytes);
|
||||||
|
@ -82,7 +82,7 @@ void FLumpSourceMgr::InitSource (j_decompress_ptr cinfo)
|
||||||
boolean FLumpSourceMgr::FillInputBuffer (j_decompress_ptr cinfo)
|
boolean FLumpSourceMgr::FillInputBuffer (j_decompress_ptr cinfo)
|
||||||
{
|
{
|
||||||
FLumpSourceMgr *me = (FLumpSourceMgr *)(cinfo->src);
|
FLumpSourceMgr *me = (FLumpSourceMgr *)(cinfo->src);
|
||||||
long nbytes = me->Lump->Read (me->Buffer, sizeof(me->Buffer));
|
auto nbytes = me->Lump->Read (me->Buffer, sizeof(me->Buffer));
|
||||||
|
|
||||||
if (nbytes <= 0)
|
if (nbytes <= 0)
|
||||||
{
|
{
|
||||||
|
@ -113,7 +113,7 @@ void FLumpSourceMgr::SkipInputData (j_decompress_ptr cinfo, long num_bytes)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
num_bytes -= (long)me->bytes_in_buffer;
|
num_bytes -= (long)me->bytes_in_buffer;
|
||||||
me->Lump->Seek (num_bytes, SEEK_CUR);
|
me->Lump->Seek (num_bytes, FileRdr::SeekCur);
|
||||||
FillInputBuffer (cinfo);
|
FillInputBuffer (cinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ void FLumpSourceMgr::TermSource (j_decompress_ptr cinfo)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FLumpSourceMgr::FLumpSourceMgr (FileReader *lump, j_decompress_ptr cinfo)
|
FLumpSourceMgr::FLumpSourceMgr (FileRdr *lump, j_decompress_ptr cinfo)
|
||||||
: Lump (lump)
|
: Lump (lump)
|
||||||
{
|
{
|
||||||
cinfo->src = this;
|
cinfo->src = this;
|
||||||
|
@ -208,7 +208,7 @@ protected:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture *JPEGTexture_TryCreate(FileReader & data, int lumpnum)
|
FTexture *JPEGTexture_TryCreate(FileRdr & data, int lumpnum)
|
||||||
{
|
{
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
@ -217,7 +217,7 @@ FTexture *JPEGTexture_TryCreate(FileReader & data, int lumpnum)
|
||||||
uint8_t b[4];
|
uint8_t b[4];
|
||||||
} first4bytes;
|
} first4bytes;
|
||||||
|
|
||||||
data.Seek(0, SEEK_SET);
|
data.Seek(0, FileRdr::SeekSet);
|
||||||
if (data.Read(&first4bytes, 4) < 4) return NULL;
|
if (data.Read(&first4bytes, 4) < 4) return NULL;
|
||||||
|
|
||||||
if (first4bytes.b[0] != 0xFF || first4bytes.b[1] != 0xD8 || first4bytes.b[2] != 0xFF)
|
if (first4bytes.b[0] != 0xFF || first4bytes.b[1] != 0xD8 || first4bytes.b[2] != 0xFF)
|
||||||
|
@ -231,7 +231,7 @@ FTexture *JPEGTexture_TryCreate(FileReader & data, int lumpnum)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
data.Seek (BigShort(first4bytes.w[0]) - 2, SEEK_CUR);
|
data.Seek (BigShort(first4bytes.w[0]) - 2, FileRdr::SeekCur);
|
||||||
if (data.Read (first4bytes.b + 2, 2) != 2 || first4bytes.b[2] != 0xFF)
|
if (data.Read (first4bytes.b + 2, 2) != 2 || first4bytes.b[2] != 0xFF)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -364,7 +364,7 @@ const uint8_t *FJPEGTexture::GetPixels ()
|
||||||
|
|
||||||
void FJPEGTexture::MakeTexture ()
|
void FJPEGTexture::MakeTexture ()
|
||||||
{
|
{
|
||||||
FWadLump lump = Wads.OpenLumpNum (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
JSAMPLE *buff = NULL;
|
JSAMPLE *buff = NULL;
|
||||||
|
|
||||||
jpeg_decompress_struct cinfo;
|
jpeg_decompress_struct cinfo;
|
||||||
|
@ -468,7 +468,7 @@ int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FC
|
||||||
{
|
{
|
||||||
PalEntry pe[256];
|
PalEntry pe[256];
|
||||||
|
|
||||||
FWadLump lump = Wads.OpenLumpNum (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
JSAMPLE *buff = NULL;
|
JSAMPLE *buff = NULL;
|
||||||
|
|
||||||
jpeg_decompress_struct cinfo;
|
jpeg_decompress_struct cinfo;
|
||||||
|
|
|
@ -814,7 +814,7 @@ void FTextureManager::AddTexturesLump (const void *lumpdata, int lumpsize, int d
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
FWadLump pnames = Wads.OpenLumpNum (patcheslump);
|
auto pnames = Wads.OpenLumpReader (patcheslump);
|
||||||
|
|
||||||
pnames >> numpatches;
|
pnames >> numpatches;
|
||||||
|
|
||||||
|
|
|
@ -81,12 +81,12 @@ protected:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static bool CheckIfPatch(FileReader & file)
|
static bool CheckIfPatch(FileRdr & file)
|
||||||
{
|
{
|
||||||
if (file.GetLength() < 13) return false; // minimum length of a valid Doom patch
|
if (file.GetLength() < 13) return false; // minimum length of a valid Doom patch
|
||||||
|
|
||||||
uint8_t *data = new uint8_t[file.GetLength()];
|
uint8_t *data = new uint8_t[file.GetLength()];
|
||||||
file.Seek(0, SEEK_SET);
|
file.Seek(0, FileRdr::SeekSet);
|
||||||
file.Read(data, file.GetLength());
|
file.Read(data, file.GetLength());
|
||||||
|
|
||||||
const patch_t *foo = (const patch_t *)data;
|
const patch_t *foo = (const patch_t *)data;
|
||||||
|
@ -129,12 +129,12 @@ static bool CheckIfPatch(FileReader & file)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture *PatchTexture_TryCreate(FileReader & file, int lumpnum)
|
FTexture *PatchTexture_TryCreate(FileRdr & file, int lumpnum)
|
||||||
{
|
{
|
||||||
patch_t header;
|
patch_t header;
|
||||||
|
|
||||||
if (!CheckIfPatch(file)) return NULL;
|
if (!CheckIfPatch(file)) return NULL;
|
||||||
file.Seek(0, SEEK_SET);
|
file.Seek(0, FileRdr::SeekSet);
|
||||||
file >> header.width >> header.height >> header.leftoffset >> header.topoffset;
|
file >> header.width >> header.height >> header.leftoffset >> header.topoffset;
|
||||||
return new FPatchTexture(lumpnum, &header);
|
return new FPatchTexture(lumpnum, &header);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,10 +99,10 @@ protected:
|
||||||
uint8_t *Pixels;
|
uint8_t *Pixels;
|
||||||
Span DummySpans[2];
|
Span DummySpans[2];
|
||||||
|
|
||||||
void ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
|
void ReadPCX1bit (uint8_t *dst, FileRdr & lump, PCXHeader *hdr);
|
||||||
void ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
|
void ReadPCX4bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr);
|
||||||
void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
|
void ReadPCX8bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr);
|
||||||
void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes);
|
void ReadPCX24bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr, int planes);
|
||||||
|
|
||||||
virtual void MakeTexture ();
|
virtual void MakeTexture ();
|
||||||
|
|
||||||
|
@ -116,11 +116,11 @@ protected:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum)
|
FTexture * PCXTexture_TryCreate(FileRdr & file, int lumpnum)
|
||||||
{
|
{
|
||||||
PCXHeader hdr;
|
PCXHeader hdr;
|
||||||
|
|
||||||
file.Seek(0, SEEK_SET);
|
file.Seek(0, FileRdr::SeekSet);
|
||||||
if (file.Read(&hdr, sizeof(hdr)) != sizeof(hdr))
|
if (file.Read(&hdr, sizeof(hdr)) != sizeof(hdr))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -141,7 +141,7 @@ FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum)
|
||||||
if (hdr.padding[i] != 0) return NULL;
|
if (hdr.padding[i] != 0) return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.Seek(0, SEEK_SET);
|
file.Seek(0, FileRdr::SeekSet);
|
||||||
file.Read(&hdr, sizeof(hdr));
|
file.Read(&hdr, sizeof(hdr));
|
||||||
|
|
||||||
return new FPCXTexture(lumpnum, hdr);
|
return new FPCXTexture(lumpnum, hdr);
|
||||||
|
@ -256,7 +256,7 @@ const uint8_t *FPCXTexture::GetPixels ()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
|
void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileRdr & lump, PCXHeader *hdr)
|
||||||
{
|
{
|
||||||
int y, i, bytes;
|
int y, i, bytes;
|
||||||
int rle_count = 0;
|
int rle_count = 0;
|
||||||
|
@ -304,7 +304,7 @@ void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
|
void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr)
|
||||||
{
|
{
|
||||||
int rle_count = 0, rle_value = 0;
|
int rle_count = 0, rle_value = 0;
|
||||||
int x, y, c;
|
int x, y, c;
|
||||||
|
@ -367,7 +367,7 @@ void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FPCXTexture::ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
|
void FPCXTexture::ReadPCX8bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr)
|
||||||
{
|
{
|
||||||
int rle_count = 0, rle_value = 0;
|
int rle_count = 0, rle_value = 0;
|
||||||
int y, bytes;
|
int y, bytes;
|
||||||
|
@ -409,7 +409,7 @@ void FPCXTexture::ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes)
|
void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileRdr & lump, PCXHeader *hdr, int planes)
|
||||||
{
|
{
|
||||||
int rle_count = 0, rle_value = 0;
|
int rle_count = 0, rle_value = 0;
|
||||||
int y, c;
|
int y, c;
|
||||||
|
@ -463,7 +463,7 @@ void FPCXTexture::MakeTexture()
|
||||||
PCXHeader header;
|
PCXHeader header;
|
||||||
int bitcount;
|
int bitcount;
|
||||||
|
|
||||||
FWadLump lump = Wads.OpenLumpNum(SourceLump);
|
auto lump = Wads.OpenLumpReader(SourceLump);
|
||||||
|
|
||||||
lump.Read(&header, sizeof(header));
|
lump.Read(&header, sizeof(header));
|
||||||
|
|
||||||
|
@ -494,7 +494,7 @@ void FPCXTexture::MakeTexture()
|
||||||
else if (bitcount == 8)
|
else if (bitcount == 8)
|
||||||
{
|
{
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
lump.Seek(-769, SEEK_END);
|
lump.Seek(-769, FileRdr::SeekEnd);
|
||||||
lump >> c;
|
lump >> c;
|
||||||
//if (c !=0x0c) memcpy(PaletteMap, GrayMap, 256); // Fallback for files without palette
|
//if (c !=0x0c) memcpy(PaletteMap, GrayMap, 256); // Fallback for files without palette
|
||||||
//else
|
//else
|
||||||
|
@ -504,7 +504,7 @@ void FPCXTexture::MakeTexture()
|
||||||
lump >> r >> g >> b;
|
lump >> r >> g >> b;
|
||||||
PaletteMap[i] = ColorMatcher.Pick(r,g,b);
|
PaletteMap[i] = ColorMatcher.Pick(r,g,b);
|
||||||
}
|
}
|
||||||
lump.Seek(sizeof(header), SEEK_SET);
|
lump.Seek(sizeof(header), FileRdr::SeekSet);
|
||||||
ReadPCX8bits (Pixels, lump, &header);
|
ReadPCX8bits (Pixels, lump, &header);
|
||||||
}
|
}
|
||||||
if (Width == Height)
|
if (Width == Height)
|
||||||
|
@ -552,7 +552,7 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo
|
||||||
int bitcount;
|
int bitcount;
|
||||||
uint8_t * Pixels;
|
uint8_t * Pixels;
|
||||||
|
|
||||||
FWadLump lump = Wads.OpenLumpNum(SourceLump);
|
auto lump = Wads.OpenLumpReader(SourceLump);
|
||||||
|
|
||||||
lump.Read(&header, sizeof(header));
|
lump.Read(&header, sizeof(header));
|
||||||
|
|
||||||
|
@ -583,7 +583,7 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo
|
||||||
else if (bitcount == 8)
|
else if (bitcount == 8)
|
||||||
{
|
{
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
lump.Seek(-769, SEEK_END);
|
lump.Seek(-769, FileRdr::SeekEnd);
|
||||||
lump >> c;
|
lump >> c;
|
||||||
c=0x0c; // Apparently there's many non-compliant PCXs out there...
|
c=0x0c; // Apparently there's many non-compliant PCXs out there...
|
||||||
if (c !=0x0c)
|
if (c !=0x0c)
|
||||||
|
@ -596,7 +596,7 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo
|
||||||
lump >> r >> g >> b;
|
lump >> r >> g >> b;
|
||||||
pe[i] = PalEntry(255, r,g,b);
|
pe[i] = PalEntry(255, r,g,b);
|
||||||
}
|
}
|
||||||
lump.Seek(sizeof(header), SEEK_SET);
|
lump.Seek(sizeof(header), FileRdr::SeekSet);
|
||||||
ReadPCX8bits (Pixels, lump, &header);
|
ReadPCX8bits (Pixels, lump, &header);
|
||||||
}
|
}
|
||||||
bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe, inf);
|
bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe, inf);
|
||||||
|
|
|
@ -90,7 +90,7 @@ protected:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum)
|
FTexture *PNGTexture_TryCreate(FileRdr & data, int lumpnum)
|
||||||
{
|
{
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,7 @@ FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum)
|
||||||
// first 4 bytes match, but later bytes don't, we assume it's
|
// first 4 bytes match, but later bytes don't, we assume it's
|
||||||
// a corrupt PNG.)
|
// a corrupt PNG.)
|
||||||
|
|
||||||
data.Seek(0, SEEK_SET);
|
data.Seek(0, FileRdr::SeekSet);
|
||||||
if (data.Read (first4bytes.b, 4) != 4) return NULL;
|
if (data.Read (first4bytes.b, 4) != 4) return NULL;
|
||||||
if (first4bytes.dw != MAKE_ID(137,'P','N','G')) return NULL;
|
if (first4bytes.dw != MAKE_ID(137,'P','N','G')) return NULL;
|
||||||
if (data.Read (first4bytes.b, 4) != 4) return NULL;
|
if (data.Read (first4bytes.b, 4) != 4) return NULL;
|
||||||
|
@ -136,7 +136,7 @@ FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just for completeness, make sure the PNG has something more than an IHDR.
|
// Just for completeness, make sure the PNG has something more than an IHDR.
|
||||||
data.Seek (4, SEEK_CUR);
|
data.Seek (4, FileRdr::SeekSet);
|
||||||
data.Read (first4bytes.b, 4);
|
data.Read (first4bytes.b, 4);
|
||||||
if (first4bytes.dw == 0)
|
if (first4bytes.dw == 0)
|
||||||
{
|
{
|
||||||
|
@ -147,7 +147,7 @@ FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FPNGTexture (data, lumpnum, FString(), BigLong((int)width), BigLong((int)height),
|
return new FPNGTexture (*data.Reader(), lumpnum, FString(), BigLong((int)width), BigLong((int)height),
|
||||||
bitdepth, colortype, interlace);
|
bitdepth, colortype, interlace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ protected:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static bool CheckIfRaw(FileReader & data)
|
static bool CheckIfRaw(FileRdr & data)
|
||||||
{
|
{
|
||||||
if (data.GetLength() != 64000) return false;
|
if (data.GetLength() != 64000) return false;
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ static bool CheckIfRaw(FileReader & data)
|
||||||
int width;
|
int width;
|
||||||
|
|
||||||
foo = (patch_t *)M_Malloc (data.GetLength());
|
foo = (patch_t *)M_Malloc (data.GetLength());
|
||||||
data.Seek (0, SEEK_SET);
|
data.Seek (0, FileRdr::SeekSet);
|
||||||
data.Read (foo, data.GetLength());
|
data.Read (foo, data.GetLength());
|
||||||
|
|
||||||
height = LittleShort(foo->height);
|
height = LittleShort(foo->height);
|
||||||
|
@ -148,7 +148,7 @@ static bool CheckIfRaw(FileReader & data)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture *RawPageTexture_TryCreate(FileReader & file, int lumpnum)
|
FTexture *RawPageTexture_TryCreate(FileRdr & file, int lumpnum)
|
||||||
{
|
{
|
||||||
if (!CheckIfRaw(file)) return NULL;
|
if (!CheckIfRaw(file)) return NULL;
|
||||||
return new FRawPageTexture(lumpnum);
|
return new FRawPageTexture(lumpnum);
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
#include "v_palette.h"
|
#include "v_palette.h"
|
||||||
|
|
||||||
typedef bool (*CheckFunc)(FileReader & file);
|
typedef bool (*CheckFunc)(FileReader & file);
|
||||||
typedef FTexture * (*CreateFunc)(FileReader & file, int lumpnum);
|
typedef FTexture * (*CreateFunc)(FileRdr & file, int lumpnum);
|
||||||
|
|
||||||
struct TexCreateInfo
|
struct TexCreateInfo
|
||||||
{
|
{
|
||||||
|
@ -66,17 +66,17 @@ void FTexture::InitGrayMap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FTexture *IMGZTexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *IMGZTexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
FTexture *PNGTexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *PNGTexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
FTexture *JPEGTexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *JPEGTexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
FTexture *DDSTexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *DDSTexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
FTexture *PCXTexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *PCXTexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
FTexture *TGATexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *TGATexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
FTexture *RawPageTexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *RawPageTexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
FTexture *FlatTexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *FlatTexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
FTexture *PatchTexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *PatchTexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
FTexture *EmptyTexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *EmptyTexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
FTexture *AutomapTexture_TryCreate(FileReader &, int lumpnum);
|
FTexture *AutomapTexture_TryCreate(FileRdr &, int lumpnum);
|
||||||
|
|
||||||
|
|
||||||
// Examines the lump contents to decide what type of texture to create,
|
// Examines the lump contents to decide what type of texture to create,
|
||||||
|
@ -99,7 +99,7 @@ FTexture * FTexture::CreateTexture (int lumpnum, int usetype)
|
||||||
|
|
||||||
if (lumpnum == -1) return NULL;
|
if (lumpnum == -1) return NULL;
|
||||||
|
|
||||||
FWadLump data = Wads.OpenLumpNum (lumpnum);
|
auto data = Wads.OpenLumpReader (lumpnum);
|
||||||
|
|
||||||
for(size_t i = 0; i < countof(CreateInfo); i++)
|
for(size_t i = 0; i < countof(CreateInfo); i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -764,16 +764,16 @@ void FTextureManager::LoadTextureDefs(int wadnum, const char *lumpname)
|
||||||
|
|
||||||
void FTextureManager::AddPatches (int lumpnum)
|
void FTextureManager::AddPatches (int lumpnum)
|
||||||
{
|
{
|
||||||
FWadLump *file = Wads.ReopenLumpNum (lumpnum);
|
auto file = Wads.ReopenLumpReader (lumpnum, true);
|
||||||
uint32_t numpatches, i;
|
uint32_t numpatches, i;
|
||||||
char name[9];
|
char name[9];
|
||||||
|
|
||||||
*file >> numpatches;
|
file >> numpatches;
|
||||||
name[8] = '\0';
|
name[8] = '\0';
|
||||||
|
|
||||||
for (i = 0; i < numpatches; ++i)
|
for (i = 0; i < numpatches; ++i)
|
||||||
{
|
{
|
||||||
file->Read (name, 8);
|
file.Read (name, 8);
|
||||||
|
|
||||||
if (CheckForTexture (name, FTexture::TEX_WallPatch, 0) == -1)
|
if (CheckForTexture (name, FTexture::TEX_WallPatch, 0) == -1)
|
||||||
{
|
{
|
||||||
|
@ -781,8 +781,6 @@ void FTextureManager::AddPatches (int lumpnum)
|
||||||
}
|
}
|
||||||
StartScreen->Progress();
|
StartScreen->Progress();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1187,7 +1185,7 @@ int FTextureManager::CountLumpTextures (int lumpnum)
|
||||||
{
|
{
|
||||||
if (lumpnum >= 0)
|
if (lumpnum >= 0)
|
||||||
{
|
{
|
||||||
FWadLump file = Wads.OpenLumpNum (lumpnum);
|
auto file = Wads.OpenLumpReader (lumpnum);
|
||||||
uint32_t numtex;
|
uint32_t numtex;
|
||||||
|
|
||||||
file >> numtex;
|
file >> numtex;
|
||||||
|
|
|
@ -94,7 +94,7 @@ protected:
|
||||||
uint8_t *Pixels;
|
uint8_t *Pixels;
|
||||||
Span **Spans;
|
Span **Spans;
|
||||||
|
|
||||||
void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel);
|
void ReadCompressed(FileRdr &lump, uint8_t * buffer, int bytesperpixel);
|
||||||
|
|
||||||
virtual void MakeTexture ();
|
virtual void MakeTexture ();
|
||||||
|
|
||||||
|
@ -107,13 +107,13 @@ protected:
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
FTexture *TGATexture_TryCreate(FileReader & file, int lumpnum)
|
FTexture *TGATexture_TryCreate(FileRdr & file, int lumpnum)
|
||||||
{
|
{
|
||||||
TGAHeader hdr;
|
TGAHeader hdr;
|
||||||
|
|
||||||
if (file.GetLength() < (long)sizeof(hdr)) return NULL;
|
if (file.GetLength() < (long)sizeof(hdr)) return NULL;
|
||||||
|
|
||||||
file.Seek(0, SEEK_SET);
|
file.Seek(0, FileRdr::SeekSet);
|
||||||
file.Read(&hdr, sizeof(hdr));
|
file.Read(&hdr, sizeof(hdr));
|
||||||
hdr.width = LittleShort(hdr.width);
|
hdr.width = LittleShort(hdr.width);
|
||||||
hdr.height = LittleShort(hdr.height);
|
hdr.height = LittleShort(hdr.height);
|
||||||
|
@ -127,7 +127,7 @@ FTexture *TGATexture_TryCreate(FileReader & file, int lumpnum)
|
||||||
if (hdr.img_type >=4 && hdr.img_type <= 8) return NULL;
|
if (hdr.img_type >=4 && hdr.img_type <= 8) return NULL;
|
||||||
if ((hdr.img_desc & 16) != 0) return NULL;
|
if ((hdr.img_desc & 16) != 0) return NULL;
|
||||||
|
|
||||||
file.Seek(0, SEEK_SET);
|
file.Seek(0, FileRdr::SeekSet);
|
||||||
file.Read(&hdr, sizeof(hdr));
|
file.Read(&hdr, sizeof(hdr));
|
||||||
hdr.width = LittleShort(hdr.width);
|
hdr.width = LittleShort(hdr.width);
|
||||||
hdr.height = LittleShort(hdr.height);
|
hdr.height = LittleShort(hdr.height);
|
||||||
|
@ -250,7 +250,7 @@ const uint8_t *FTGATexture::GetPixels ()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel)
|
void FTGATexture::ReadCompressed(FileRdr &lump, uint8_t * buffer, int bytesperpixel)
|
||||||
{
|
{
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
uint8_t data[4];
|
uint8_t data[4];
|
||||||
|
@ -290,7 +290,7 @@ void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytespe
|
||||||
void FTGATexture::MakeTexture ()
|
void FTGATexture::MakeTexture ()
|
||||||
{
|
{
|
||||||
uint8_t PaletteMap[256];
|
uint8_t PaletteMap[256];
|
||||||
FWadLump lump = Wads.OpenLumpNum (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
TGAHeader hdr;
|
TGAHeader hdr;
|
||||||
uint16_t w;
|
uint16_t w;
|
||||||
uint8_t r,g,b,a;
|
uint8_t r,g,b,a;
|
||||||
|
@ -298,7 +298,7 @@ void FTGATexture::MakeTexture ()
|
||||||
|
|
||||||
Pixels = new uint8_t[Width*Height];
|
Pixels = new uint8_t[Width*Height];
|
||||||
lump.Read(&hdr, sizeof(hdr));
|
lump.Read(&hdr, sizeof(hdr));
|
||||||
lump.Seek(hdr.id_len, SEEK_CUR);
|
lump.Seek(hdr.id_len, FileRdr::SeekCur);
|
||||||
|
|
||||||
hdr.width = LittleShort(hdr.width);
|
hdr.width = LittleShort(hdr.width);
|
||||||
hdr.height = LittleShort(hdr.height);
|
hdr.height = LittleShort(hdr.height);
|
||||||
|
@ -491,7 +491,7 @@ void FTGATexture::MakeTexture ()
|
||||||
int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
|
||||||
{
|
{
|
||||||
PalEntry pe[256];
|
PalEntry pe[256];
|
||||||
FWadLump lump = Wads.OpenLumpNum (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
TGAHeader hdr;
|
TGAHeader hdr;
|
||||||
uint16_t w;
|
uint16_t w;
|
||||||
uint8_t r,g,b,a;
|
uint8_t r,g,b,a;
|
||||||
|
@ -499,7 +499,7 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo
|
||||||
int transval = 0;
|
int transval = 0;
|
||||||
|
|
||||||
lump.Read(&hdr, sizeof(hdr));
|
lump.Read(&hdr, sizeof(hdr));
|
||||||
lump.Seek(hdr.id_len, SEEK_CUR);
|
lump.Seek(hdr.id_len, FileRdr::SeekCur);
|
||||||
|
|
||||||
hdr.width = LittleShort(hdr.width);
|
hdr.width = LittleShort(hdr.width);
|
||||||
hdr.height = LittleShort(hdr.height);
|
hdr.height = LittleShort(hdr.height);
|
||||||
|
|
|
@ -321,7 +321,7 @@ FFont *V_GetFont(const char *name)
|
||||||
{
|
{
|
||||||
uint32_t head;
|
uint32_t head;
|
||||||
{
|
{
|
||||||
FWadLump lumpy = Wads.OpenLumpNum (lump);
|
auto lumpy = Wads.OpenLumpReader (lump);
|
||||||
lumpy.Read (&head, 4);
|
lumpy.Read (&head, 4);
|
||||||
}
|
}
|
||||||
if ((head & MAKE_ID(255,255,255,0)) == MAKE_ID('F','O','N',0) ||
|
if ((head & MAKE_ID(255,255,255,0)) == MAKE_ID('F','O','N',0) ||
|
||||||
|
@ -1855,7 +1855,7 @@ void FFontChar2::SetSourceRemap(const uint8_t *sourceremap)
|
||||||
|
|
||||||
void FFontChar2::MakeTexture ()
|
void FFontChar2::MakeTexture ()
|
||||||
{
|
{
|
||||||
FWadLump lump = Wads.OpenLumpNum (SourceLump);
|
auto lump = Wads.OpenLumpReader (SourceLump);
|
||||||
int destSize = Width * Height;
|
int destSize = Width * Height;
|
||||||
uint8_t max = 255;
|
uint8_t max = 255;
|
||||||
bool rle = true;
|
bool rle = true;
|
||||||
|
@ -1868,18 +1868,18 @@ void FFontChar2::MakeTexture ()
|
||||||
{
|
{
|
||||||
lump.Read (buff, 7);
|
lump.Read (buff, 7);
|
||||||
max = buff[6];
|
max = buff[6];
|
||||||
lump.Seek (SourcePos - 11, SEEK_CUR);
|
lump.Seek (SourcePos - 11, FileRdr::SeekCur);
|
||||||
}
|
}
|
||||||
else if (buff[3] == 0x1A)
|
else if (buff[3] == 0x1A)
|
||||||
{
|
{
|
||||||
lump.Read(buff, 13);
|
lump.Read(buff, 13);
|
||||||
max = buff[12] - 1;
|
max = buff[12] - 1;
|
||||||
lump.Seek (SourcePos - 17, SEEK_CUR);
|
lump.Seek (SourcePos - 17, FileRdr::SeekCur);
|
||||||
rle = false;
|
rle = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lump.Seek (SourcePos - 4, SEEK_CUR);
|
lump.Seek (SourcePos - 4, FileRdr::SeekCur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -966,8 +966,8 @@ FStrifeStartupScreen::FStrifeStartupScreen(int max_progress, HRESULT &hr)
|
||||||
|
|
||||||
// Fill bitmap with the startup image.
|
// Fill bitmap with the startup image.
|
||||||
memset (ST_Util_BitsForBitmap(StartupBitmap), 0xF0, 64000);
|
memset (ST_Util_BitsForBitmap(StartupBitmap), 0xF0, 64000);
|
||||||
FWadLump lumpr = Wads.OpenLumpNum (startup_lump);
|
auto lumpr = Wads.OpenLumpReader (startup_lump);
|
||||||
lumpr.Seek (57 * 320, SEEK_SET);
|
lumpr.Seek (57 * 320, FileRdr::SeekSet);
|
||||||
lumpr.Read (ST_Util_BitsForBitmap(StartupBitmap) + 41 * 320, 95 * 320);
|
lumpr.Read (ST_Util_BitsForBitmap(StartupBitmap) + 41 * 320, 95 * 320);
|
||||||
|
|
||||||
// Load the animated overlays.
|
// Load the animated overlays.
|
||||||
|
@ -978,7 +978,7 @@ FStrifeStartupScreen::FStrifeStartupScreen(int max_progress, HRESULT &hr)
|
||||||
|
|
||||||
if (lumpnum >= 0 && (lumplen = Wads.LumpLength (lumpnum)) == StrifeStartupPicSizes[i])
|
if (lumpnum >= 0 && (lumplen = Wads.LumpLength (lumpnum)) == StrifeStartupPicSizes[i])
|
||||||
{
|
{
|
||||||
FWadLump lumpr = Wads.OpenLumpNum (lumpnum);
|
auto lumpr = Wads.OpenLumpReader (lumpnum);
|
||||||
StartupPics[i] = new uint8_t[lumplen];
|
StartupPics[i] = new uint8_t[lumplen];
|
||||||
lumpr.Read (StartupPics[i], lumplen);
|
lumpr.Read (StartupPics[i], lumplen);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue