mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 14:01:45 +00:00
use std::vector as return value for the FileReader's buffer readers.
This commit is contained in:
parent
12c7413149
commit
21d6eb99eb
18 changed files with 66 additions and 63 deletions
|
@ -182,8 +182,8 @@ static void SetupGenMidi()
|
|||
auto data = fileSystem.OpenFileReader(lump);
|
||||
|
||||
auto genmidi = data.Read();
|
||||
if (genmidi.Size() < 8 + 175 * 36 || memcmp(genmidi.Data(), "#OPL_II#", 8)) return;
|
||||
ZMusic_SetGenMidi(genmidi.Data()+8);
|
||||
if (genmidi.size() < 8 + 175 * 36 || memcmp(genmidi.data(), "#OPL_II#", 8)) return;
|
||||
ZMusic_SetGenMidi(genmidi.data()+8);
|
||||
}
|
||||
|
||||
static void SetupWgOpn()
|
||||
|
@ -337,7 +337,7 @@ static ZMusic_MidiSource GetMIDISource(const char *fn)
|
|||
}
|
||||
|
||||
auto data = wlump.Read();
|
||||
auto source = ZMusic_CreateMIDISource(data.Data(), data.Size(), type);
|
||||
auto source = ZMusic_CreateMIDISource(data.data(), data.size(), type);
|
||||
|
||||
if (source == nullptr)
|
||||
{
|
||||
|
|
|
@ -744,32 +744,33 @@ sfxinfo_t *SoundEngine::LoadSound(sfxinfo_t *sfx)
|
|||
DPrintf(DMSG_NOTIFY, "Loading sound \"%s\" (%td)\n", sfx->name.GetChars(), sfx - &S_sfx[0]);
|
||||
|
||||
auto sfxdata = ReadSound(sfx->lumpnum);
|
||||
int size = sfxdata.Size();
|
||||
int size = (int)sfxdata.size();
|
||||
if (size > 8)
|
||||
{
|
||||
int32_t dmxlen = LittleLong(((int32_t *)sfxdata.Data())[1]);
|
||||
auto sfxp = sfxdata.data();
|
||||
int32_t dmxlen = LittleLong(((int32_t *)sfxp)[1]);
|
||||
|
||||
// If the sound is voc, use the custom loader.
|
||||
if (strncmp ((const char *)sfxdata.Data(), "Creative Voice File", 19) == 0)
|
||||
if (memcmp (sfxp, "Creative Voice File", 19) == 0)
|
||||
{
|
||||
sfx->data = GSnd->LoadSoundVoc(sfxdata.Data(), size);
|
||||
sfx->data = GSnd->LoadSoundVoc(sfxp, size);
|
||||
}
|
||||
// If the sound is raw, just load it as such.
|
||||
else if (sfx->bLoadRAW)
|
||||
{
|
||||
sfx->data = GSnd->LoadSoundRaw(sfxdata.Data(), size, sfx->RawRate, 1, 8, sfx->LoopStart);
|
||||
sfx->data = GSnd->LoadSoundRaw(sfxp, size, sfx->RawRate, 1, 8, sfx->LoopStart);
|
||||
}
|
||||
// Otherwise, try the sound as DMX format.
|
||||
else if (((uint8_t *)sfxdata.Data())[0] == 3 && ((uint8_t *)sfxdata.Data())[1] == 0 && dmxlen <= size - 8)
|
||||
else if (((uint8_t *)sfxp)[0] == 3 && ((uint8_t *)sfxp)[1] == 0 && dmxlen <= size - 8)
|
||||
{
|
||||
int frequency = LittleShort(((uint16_t *)sfxdata.Data())[1]);
|
||||
int frequency = LittleShort(((uint16_t *)sfxp)[1]);
|
||||
if (frequency == 0) frequency = 11025;
|
||||
sfx->data = GSnd->LoadSoundRaw(sfxdata.Data()+8, dmxlen, frequency, 1, 8, sfx->LoopStart);
|
||||
sfx->data = GSnd->LoadSoundRaw(sfxp+8, dmxlen, frequency, 1, 8, sfx->LoopStart);
|
||||
}
|
||||
// If that fails, let the sound system try and figure it out.
|
||||
else
|
||||
{
|
||||
sfx->data = GSnd->LoadSound(sfxdata.Data(), size, sfx->LoopStart, sfx->LoopEnd);
|
||||
sfx->data = GSnd->LoadSound(sfxp, size, sfx->LoopStart, sfx->LoopEnd);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ private:
|
|||
|
||||
// Checks if a copy of this sound is already playing.
|
||||
bool CheckSingular(FSoundID sound_id);
|
||||
virtual TArray<uint8_t> ReadSound(int lumpnum) = 0;
|
||||
virtual std::vector<uint8_t> ReadSound(int lumpnum) = 0;
|
||||
|
||||
protected:
|
||||
virtual bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel, float attenuation);
|
||||
|
|
|
@ -153,7 +153,7 @@ class AnmPlayer : public MoviePlayer
|
|||
{
|
||||
// This doesn't need its own class type
|
||||
anim_t anim;
|
||||
TArray<uint8_t> buffer;
|
||||
std::vector<uint8_t> buffer;
|
||||
int numframes = 0;
|
||||
int curframe = 1;
|
||||
int frametime = 0;
|
||||
|
@ -173,7 +173,7 @@ public:
|
|||
buffer = fr.ReadPadded(1);
|
||||
fr.Close();
|
||||
|
||||
if (ANIM_LoadAnim(&anim, buffer.Data(), buffer.Size() - 1) < 0)
|
||||
if (ANIM_LoadAnim(&anim, buffer.data(), buffer.size() - 1) < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -231,7 +231,6 @@ public:
|
|||
|
||||
~AnmPlayer()
|
||||
{
|
||||
buffer.Reset();
|
||||
animtex.Clean();
|
||||
}
|
||||
|
||||
|
|
|
@ -148,9 +148,9 @@ bool FScanner::OpenFile (const char *name)
|
|||
if (!fr.OpenFile(name)) return false;
|
||||
auto filesize = fr.GetLength();
|
||||
auto filebuff = fr.Read();
|
||||
if (filebuff.Size() == 0 && filesize > 0) return false;
|
||||
if (filebuff.size() == 0 && filesize > 0) return false;
|
||||
|
||||
ScriptBuffer = FString((const char *)filebuff.Data(), filesize);
|
||||
ScriptBuffer = FString((const char *)filebuff.data(), filesize);
|
||||
ScriptName = name; // This is used for error messages so the full file name is preferable
|
||||
LumpNum = -1;
|
||||
PrepareScript ();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef __SC_MAN_H__
|
||||
#define __SC_MAN_H__
|
||||
|
||||
#include <vector>
|
||||
#include "zstring.h"
|
||||
#include "tarray.h"
|
||||
#include "name.h"
|
||||
|
@ -74,6 +75,10 @@ public:
|
|||
{
|
||||
OpenMem(name, (const char*)buffer.Data(), buffer.Size());
|
||||
}
|
||||
void OpenMem(const char* name, const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
OpenMem(name, (const char*)buffer.data(), (int)buffer.size());
|
||||
}
|
||||
void OpenString(const char *name, FString buffer);
|
||||
void OpenLumpNum(int lump);
|
||||
void Close();
|
||||
|
|
|
@ -214,28 +214,26 @@ public:
|
|||
return mReader->Read(buffer, (long)len);
|
||||
}
|
||||
|
||||
TArray<uint8_t> Read(size_t len)
|
||||
std::vector<uint8_t> Read(size_t len)
|
||||
{
|
||||
TArray<uint8_t> buffer((int)len, true);
|
||||
std::vector<uint8_t> buffer(len);
|
||||
Size length = mReader->Read(&buffer[0], (long)len);
|
||||
buffer.Clamp((int)length);
|
||||
buffer.resize((size_t)length);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
TArray<uint8_t> Read()
|
||||
std::vector<uint8_t> Read()
|
||||
{
|
||||
TArray<uint8_t> buffer(mReader->Length, true);
|
||||
Size length = mReader->Read(&buffer[0], mReader->Length);
|
||||
if (length < mReader->Length) buffer.Clear();
|
||||
return buffer;
|
||||
return Read(GetLength());
|
||||
}
|
||||
|
||||
TArray<uint8_t> ReadPadded(int padding)
|
||||
std::vector<uint8_t> ReadPadded(size_t padding)
|
||||
{
|
||||
TArray<uint8_t> buffer(mReader->Length + padding, true);
|
||||
Size length = mReader->Read(&buffer[0], mReader->Length);
|
||||
if (length < mReader->Length) buffer.Clear();
|
||||
else memset(buffer.Data() + mReader->Length, 0, padding);
|
||||
auto len = GetLength();
|
||||
std::vector<uint8_t> buffer(len + padding);
|
||||
Size length = mReader->Read(&buffer[0], (long)len);
|
||||
if (length < len) buffer.clear();
|
||||
else memset(buffer.data() + len, 0, padding);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -217,7 +217,7 @@ static inline void drawframe(anim_t *anim, uint16_t framenumber)
|
|||
}
|
||||
|
||||
// <length> is the file size, for consistency checking.
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, uint8_t *buffer, int32_t length)
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, uint8_t *buffer, size_t length)
|
||||
{
|
||||
if (memcmp(buffer, "LPF ", 4)) return -1;
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ struct anim_t
|
|||
//
|
||||
//****************************************************************************
|
||||
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, uint8_t *buffer, int32_t length);
|
||||
int32_t ANIM_LoadAnim(anim_t *anim, uint8_t *buffer, size_t length);
|
||||
|
||||
//****************************************************************************
|
||||
//
|
||||
|
|
|
@ -73,7 +73,7 @@ FImageSource *AnmImage_TryCreate(FileReader & file, int lumpnum)
|
|||
auto buffer = file.ReadPadded(1);
|
||||
|
||||
anim_t anim;
|
||||
if (ANIM_LoadAnim(&anim, buffer.Data(), buffer.Size() - 1) < 0)
|
||||
if (ANIM_LoadAnim(&anim, buffer.data(), buffer.size() - 1) < 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ static bool CheckIfPatch(FileReader & file, bool &isalpha)
|
|||
file.Seek(0, FileReader::SeekSet);
|
||||
auto data = file.Read(file.GetLength());
|
||||
|
||||
const patch_t *foo = (const patch_t *)data.Data();
|
||||
const patch_t *foo = (const patch_t *)data.data();
|
||||
|
||||
int height = LittleShort(foo->height);
|
||||
int width = LittleShort(foo->width);
|
||||
|
@ -111,7 +111,7 @@ static bool CheckIfPatch(FileReader & file, bool &isalpha)
|
|||
{
|
||||
// only check this if the texture passed validation.
|
||||
// Here is a good point because we already have a valid buffer of the lump's data.
|
||||
isalpha = checkPatchForAlpha(data.Data(), (uint32_t)file.GetLength());
|
||||
isalpha = checkPatchForAlpha(data.data(), (uint32_t)file.GetLength());
|
||||
}
|
||||
return !gapAtStart;
|
||||
}
|
||||
|
|
|
@ -160,8 +160,8 @@ void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
|
|||
int rle_count = 0;
|
||||
uint8_t rle_value = 0;
|
||||
|
||||
TArray<uint8_t> srcp = lump.Read(lump.GetLength() - sizeof(PCXHeader));
|
||||
uint8_t * src = srcp.Data();
|
||||
auto srcp = lump.Read(lump.GetLength() - sizeof(PCXHeader));
|
||||
uint8_t * src = srcp.data();
|
||||
|
||||
for (y = 0; y < Height; ++y)
|
||||
{
|
||||
|
@ -210,8 +210,8 @@ void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
|
|||
TArray<uint8_t> line(hdr->bytesPerScanLine, true);
|
||||
TArray<uint8_t> colorIndex(Width, true);
|
||||
|
||||
TArray<uint8_t> srcp = lump.Read(lump.GetLength() - sizeof(PCXHeader));
|
||||
uint8_t * src = srcp.Data();
|
||||
auto srcp = lump.Read(lump.GetLength() - sizeof(PCXHeader));
|
||||
uint8_t * src = srcp.data();
|
||||
|
||||
for (y = 0; y < Height; ++y)
|
||||
{
|
||||
|
@ -265,7 +265,7 @@ void FPCXTexture::ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
|
|||
int y, bytes;
|
||||
|
||||
auto srcp = lump.Read(lump.GetLength() - sizeof(PCXHeader));
|
||||
uint8_t * src = srcp.Data();
|
||||
uint8_t * src = srcp.data();
|
||||
|
||||
for (y = 0; y < Height; ++y)
|
||||
{
|
||||
|
@ -306,7 +306,7 @@ void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr
|
|||
int bytes;
|
||||
|
||||
auto srcp = lump.Read(lump.GetLength() - sizeof(PCXHeader));
|
||||
uint8_t * src = srcp.Data();
|
||||
uint8_t * src = srcp.data();
|
||||
|
||||
for (y = 0; y < Height; ++y)
|
||||
{
|
||||
|
|
|
@ -142,13 +142,13 @@ int FQOITexture::CopyPixels(FBitmap *bmp, int conversion)
|
|||
|
||||
auto lump = fileSystem.OpenFileReader(SourceLump);
|
||||
auto bytes = lump.Read();
|
||||
if (bytes.Size() < 22) return 0; // error
|
||||
if (bytes.size() < 22) return 0; // error
|
||||
PalEntry index[64] = {};
|
||||
PalEntry pe = 0xff000000;
|
||||
|
||||
size_t p = 14, run = 0;
|
||||
|
||||
size_t chunks_len = bytes.Size() - 8;
|
||||
size_t chunks_len = bytes.size() - 8;
|
||||
|
||||
for (int h = 0; h < Height; h++)
|
||||
{
|
||||
|
|
|
@ -74,7 +74,7 @@ bool CheckIfRaw(FileReader & data, unsigned desiredsize)
|
|||
|
||||
data.Seek(0, FileReader::SeekSet);
|
||||
auto bits = data.Read(data.GetLength());
|
||||
foo = (patch_t *)bits.Data();
|
||||
foo = (patch_t *)bits.data();
|
||||
|
||||
height = LittleShort(foo->height);
|
||||
width = LittleShort(foo->width);
|
||||
|
|
|
@ -59,9 +59,9 @@ FImageSource *WebPImage_TryCreate(FileReader &file, int lumpnum)
|
|||
file.Seek(0, FileReader::SeekSet);
|
||||
auto bytes = file.Read();
|
||||
|
||||
if (WebPGetInfo(bytes.Data(), bytes.Size(), &width, &height))
|
||||
if (WebPGetInfo(bytes.data(), bytes.size(), &width, &height))
|
||||
{
|
||||
WebPData data{ bytes.Data(), bytes.Size() };
|
||||
WebPData data{ bytes.data(), bytes.size() };
|
||||
WebPData chunk_data;
|
||||
auto mux = WebPMuxCreate(&data, 0);
|
||||
if (mux)
|
||||
|
@ -137,7 +137,7 @@ int FWebPTexture::CopyPixels(FBitmap *bmp, int conversion)
|
|||
config.output.u.RGBA.stride = bmp->GetPitch();
|
||||
config.output.is_external_memory = 1;
|
||||
|
||||
(void)WebPDecode(bytes.Data(), bytes.Size(), &config);
|
||||
(void)WebPDecode(bytes.data(), bytes.size(), &config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ void M_FindResponseFile (void)
|
|||
else
|
||||
{
|
||||
char **argv;
|
||||
TArray<uint8_t> file;
|
||||
std::vector<uint8_t> file;
|
||||
int argc = 0;
|
||||
int size;
|
||||
size_t argsize = 0;
|
||||
|
@ -119,8 +119,8 @@ void M_FindResponseFile (void)
|
|||
Printf ("Found response file %s!\n", Args->GetArg(i) + 1);
|
||||
size = (int)fr.GetLength();
|
||||
file = fr.Read (size);
|
||||
file[size] = 0;
|
||||
argsize = ParseCommandLine ((char*)file.Data(), &argc, NULL);
|
||||
file.push_back(0);
|
||||
argsize = ParseCommandLine ((char*)file.data(), &argc, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -132,7 +132,7 @@ void M_FindResponseFile (void)
|
|||
{
|
||||
argv = (char **)M_Malloc (argc*sizeof(char *) + argsize);
|
||||
argv[0] = (char *)argv + argc*sizeof(char *);
|
||||
ParseCommandLine ((char*)file.Data(), NULL, argv);
|
||||
ParseCommandLine ((char*)file.data(), NULL, argv);
|
||||
|
||||
// Create a new argument vector
|
||||
FArgs *newargs = new FArgs;
|
||||
|
|
|
@ -209,7 +209,7 @@ bool MapLoader::LoadGLVertexes(FileReader &lump)
|
|||
auto gllen=lump.GetLength();
|
||||
if (gllen < 4)
|
||||
return false;
|
||||
auto gldata = glbuf.Data();
|
||||
auto gldata = glbuf.data();
|
||||
|
||||
if (*(int *)gldata == gNd5)
|
||||
{
|
||||
|
@ -288,13 +288,13 @@ bool MapLoader::LoadGLSegs(FileReader &lump)
|
|||
const unsigned numverts = Level->vertexes.Size();
|
||||
const unsigned numlines = Level->lines.Size();
|
||||
|
||||
if (!format5 && memcmp(data.Data(), "gNd3", 4))
|
||||
if (!format5 && memcmp(data.data(), "gNd3", 4))
|
||||
{
|
||||
numsegs/=sizeof(glseg_t);
|
||||
segs.Alloc(numsegs);
|
||||
memset(&segs[0],0,sizeof(seg_t)*numsegs);
|
||||
|
||||
glseg_t * ml = (glseg_t*)data.Data();
|
||||
glseg_t * ml = (glseg_t*)data.data();
|
||||
for(i = 0; i < numsegs; i++)
|
||||
{
|
||||
// check for gl-vertices
|
||||
|
@ -365,7 +365,7 @@ bool MapLoader::LoadGLSegs(FileReader &lump)
|
|||
segs.Alloc(numsegs);
|
||||
memset(&segs[0],0,sizeof(seg_t)*numsegs);
|
||||
|
||||
glseg3_t * ml = (glseg3_t*)(data.Data() + (format5? 0:4));
|
||||
glseg3_t * ml = (glseg3_t*)(data.data() + (format5? 0:4));
|
||||
for(i = 0; i < numsegs; i++)
|
||||
{ // check for gl-vertices
|
||||
const unsigned v1idx = checkGLVertex3(LittleLong(ml->v1));
|
||||
|
@ -454,9 +454,9 @@ bool MapLoader::LoadGLSubsectors(FileReader &lump)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!format5 && memcmp(datab.Data(), "gNd3", 4))
|
||||
if (!format5 && memcmp(datab.data(), "gNd3", 4))
|
||||
{
|
||||
mapsubsector_t * data = (mapsubsector_t*) datab.Data();
|
||||
mapsubsector_t * data = (mapsubsector_t*) datab.data();
|
||||
numsubsectors /= sizeof(mapsubsector_t);
|
||||
Level->subsectors.Alloc(numsubsectors);
|
||||
auto &subsectors = Level->subsectors;
|
||||
|
@ -478,7 +478,7 @@ bool MapLoader::LoadGLSubsectors(FileReader &lump)
|
|||
}
|
||||
else
|
||||
{
|
||||
gl3_mapsubsector_t * data = (gl3_mapsubsector_t*) (datab.Data()+(format5? 0:4));
|
||||
gl3_mapsubsector_t * data = (gl3_mapsubsector_t*) (datab.data()+(format5? 0:4));
|
||||
numsubsectors /= sizeof(gl3_mapsubsector_t);
|
||||
Level->subsectors.Alloc(numsubsectors);
|
||||
auto &subsectors = Level->subsectors;
|
||||
|
@ -545,7 +545,7 @@ bool MapLoader::LoadNodes (FileReader &lump)
|
|||
lump.Seek(0, FileReader::SeekSet);
|
||||
|
||||
auto buf = lump.Read();
|
||||
basemn = mn = (mapnode_t*)buf.Data();
|
||||
basemn = mn = (mapnode_t*)buf.data();
|
||||
|
||||
used.Resize(numnodes);
|
||||
memset (used.Data(), 0, sizeof(uint16_t)*numnodes);
|
||||
|
@ -601,7 +601,7 @@ bool MapLoader::LoadNodes (FileReader &lump)
|
|||
lump.Seek(0, FileReader::SeekSet);
|
||||
|
||||
auto buf = lump.Read();
|
||||
basemn = mn = (gl5_mapnode_t*)buf.Data();
|
||||
basemn = mn = (gl5_mapnode_t*)buf.data();
|
||||
|
||||
used.Resize(numnodes);
|
||||
memset(used.Data(), 0, sizeof(uint16_t)*numnodes);
|
||||
|
|
|
@ -81,7 +81,7 @@ class DoomSoundEngine : public SoundEngine
|
|||
|
||||
void CalcPosVel(int type, const void* source, const float pt[3], int channum, int chanflags, FSoundID soundid, FVector3* pos, FVector3* vel, FSoundChan *) override;
|
||||
bool ValidatePosVel(int sourcetype, const void* source, const FVector3& pos, const FVector3& vel);
|
||||
TArray<uint8_t> ReadSound(int lumpnum);
|
||||
std::vector<uint8_t> ReadSound(int lumpnum);
|
||||
FSoundID PickReplacement(FSoundID refid);
|
||||
FSoundID ResolveSound(const void *ent, int type, FSoundID soundid, float &attenuation) override;
|
||||
void CacheSound(sfxinfo_t* sfx) override;
|
||||
|
@ -1165,7 +1165,7 @@ bool DoomSoundEngine::ValidatePosVel(int sourcetype, const void* source, const F
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
TArray<uint8_t> DoomSoundEngine::ReadSound(int lumpnum)
|
||||
std::vector<uint8_t> DoomSoundEngine::ReadSound(int lumpnum)
|
||||
{
|
||||
auto wlump = fileSystem.OpenFileReader(lumpnum);
|
||||
return wlump.Read();
|
||||
|
|
Loading…
Reference in a new issue