mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-11 07:11:54 +00:00
- use a TArray to pass the screenshot buffer
This also removes a few other explicit buffer allocations.
This commit is contained in:
parent
b3d6dfb55f
commit
cf18dbdfa7
6 changed files with 18 additions and 28 deletions
|
@ -756,8 +756,8 @@ void ProcessEDSectors()
|
|||
|
||||
// collect all Extradata sector records up front so we do not need to search the complete line array for each sector separately.
|
||||
auto numsectors = level.sectors.Size();
|
||||
int *sectorrecord = new int[numsectors];
|
||||
memset(sectorrecord, -1, numsectors * sizeof(int));
|
||||
TArray<int> sectorrecord(numsectors, true);
|
||||
memset(sectorrecord.Data(), -1, numsectors * sizeof(int));
|
||||
for (auto &line : level.lines)
|
||||
{
|
||||
if (line.special == Static_Init && line.args[1] == Init_EDSector)
|
||||
|
@ -773,7 +773,6 @@ void ProcessEDSectors()
|
|||
ProcessEDSector(&level.sectors[i], sectorrecord[i]);
|
||||
}
|
||||
}
|
||||
delete[] sectorrecord;
|
||||
}
|
||||
|
||||
void LoadMapinfoACSLump()
|
||||
|
|
|
@ -2829,16 +2829,15 @@ bool G_CheckDemoStatus (void)
|
|||
// uncompressed size of the BODY.
|
||||
uLong len = uLong(demo_p - demobodyspot);
|
||||
uLong outlen = (len + len/100 + 12);
|
||||
Byte *compressed = new Byte[outlen];
|
||||
int r = compress2 (compressed, &outlen, demobodyspot, len, 9);
|
||||
TArray<Byte> compressed(outlen, true);
|
||||
int r = compress2 (compressed.Data(), &outlen, demobodyspot, len, 9);
|
||||
if (r == Z_OK && outlen < len)
|
||||
{
|
||||
formlen = democompspot;
|
||||
WriteLong (len, &democompspot);
|
||||
memcpy (demobodyspot, compressed, outlen);
|
||||
memcpy (demobodyspot, compressed.Data(), outlen);
|
||||
demo_p = demobodyspot + outlen;
|
||||
}
|
||||
delete[] compressed;
|
||||
}
|
||||
FinishChunk (&demo_p);
|
||||
formlen = demobuffer + 4;
|
||||
|
|
|
@ -425,7 +425,7 @@ void OpenGLFrameBuffer::BeginFrame()
|
|||
//
|
||||
//===========================================================================
|
||||
|
||||
void OpenGLFrameBuffer::GetScreenshotBuffer(const uint8_t *&buffer, int &pitch, ESSType &color_type, float &gamma)
|
||||
TArray<uint8_t> OpenGLFrameBuffer::GetScreenshotBuffer(int &pitch, ESSType &color_type, float &gamma)
|
||||
{
|
||||
const auto &viewport = mOutputLetterbox;
|
||||
|
||||
|
@ -441,7 +441,7 @@ void OpenGLFrameBuffer::GetScreenshotBuffer(const uint8_t *&buffer, int &pitch,
|
|||
int w = SCREENWIDTH;
|
||||
int h = SCREENHEIGHT;
|
||||
|
||||
auto ScreenshotBuffer = new uint8_t[w * h * 3];
|
||||
TArray<uint8_t> ScreenshotBuffer(w * h * 3, true);
|
||||
|
||||
float rcpWidth = 1.0f / w;
|
||||
float rcpHeight = 1.0f / h;
|
||||
|
@ -463,10 +463,10 @@ void OpenGLFrameBuffer::GetScreenshotBuffer(const uint8_t *&buffer, int &pitch,
|
|||
|
||||
pitch = w * 3;
|
||||
color_type = SS_RGB;
|
||||
buffer = ScreenshotBuffer;
|
||||
|
||||
// Screenshot should not use gamma correction if it was already applied to rendered image
|
||||
gamma = 1 == vid_hwgamma || (2 == vid_hwgamma && !fullscreen) ? 1.0f : Gamma;
|
||||
return ScreenshotBuffer;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
// Retrieves a buffer containing image data for a screenshot.
|
||||
// Hint: Pitch can be negative for upside-down images, in which case buffer
|
||||
// points to the last row in the buffer, which will be the first row output.
|
||||
virtual void GetScreenshotBuffer(const uint8_t *&buffer, int &pitch, ESSType &color_type, float &gamma) override;
|
||||
virtual TArray<uint8_t> GetScreenshotBuffer(int &pitch, ESSType &color_type, float &gamma) override;
|
||||
|
||||
void Swap();
|
||||
bool IsHWGammaActive() const { return HWGammaActive; }
|
||||
|
|
|
@ -96,7 +96,7 @@ void M_FindResponseFile (void)
|
|||
else
|
||||
{
|
||||
char **argv;
|
||||
char *file = NULL;
|
||||
TArray<uint8_t> file;
|
||||
int argc = 0;
|
||||
int size;
|
||||
long argsize = 0;
|
||||
|
@ -116,10 +116,9 @@ void M_FindResponseFile (void)
|
|||
{
|
||||
Printf ("Found response file %s!\n", Args->GetArg(i) + 1);
|
||||
size = (int)fr.GetLength();
|
||||
file = new char[size+1];
|
||||
fr.Read (file, size);
|
||||
file = fr.Read (size);
|
||||
file[size] = 0;
|
||||
argsize = ParseCommandLine (file, &argc, NULL);
|
||||
argsize = ParseCommandLine ((char*)file.Data(), &argc, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -131,7 +130,7 @@ void M_FindResponseFile (void)
|
|||
{
|
||||
argv = (char **)M_Malloc (argc*sizeof(char *) + argsize);
|
||||
argv[0] = (char *)argv + argc*sizeof(char *);
|
||||
ParseCommandLine (file, NULL, argv);
|
||||
ParseCommandLine ((char*)file.Data(), NULL, argv);
|
||||
|
||||
// Create a new argument vector
|
||||
FArgs *newargs = new FArgs;
|
||||
|
@ -161,10 +160,6 @@ void M_FindResponseFile (void)
|
|||
// Remove the response file from the Args object
|
||||
Args->RemoveArg(i);
|
||||
}
|
||||
if (file != NULL)
|
||||
{
|
||||
delete[] file;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (added_stuff > 0)
|
||||
|
@ -609,13 +604,12 @@ void M_ScreenShot (const char *filename)
|
|||
}
|
||||
|
||||
// save the screenshot
|
||||
const uint8_t *buffer;
|
||||
int pitch;
|
||||
ESSType color_type;
|
||||
float gamma;
|
||||
|
||||
screen->GetScreenshotBuffer(buffer, pitch, color_type, gamma);
|
||||
if (buffer != NULL)
|
||||
auto buffer = screen->GetScreenshotBuffer(pitch, color_type, gamma);
|
||||
if (buffer.Size() > 0)
|
||||
{
|
||||
PalEntry palette[256];
|
||||
|
||||
|
@ -627,21 +621,19 @@ void M_ScreenShot (const char *filename)
|
|||
if (file == NULL)
|
||||
{
|
||||
Printf ("Could not open %s\n", autoname.GetChars());
|
||||
delete[] buffer;
|
||||
return;
|
||||
}
|
||||
if (writepcx)
|
||||
{
|
||||
WritePCXfile(file, buffer, palette, color_type,
|
||||
WritePCXfile(file, buffer.Data(), palette, color_type,
|
||||
screen->GetWidth(), screen->GetHeight(), pitch);
|
||||
}
|
||||
else
|
||||
{
|
||||
WritePNGfile(file, buffer, palette, color_type,
|
||||
WritePNGfile(file, buffer.Data(), palette, color_type,
|
||||
screen->GetWidth(), screen->GetHeight(), pitch, gamma);
|
||||
}
|
||||
delete file;
|
||||
delete[] buffer;
|
||||
|
||||
if (!screenshot_quiet)
|
||||
{
|
||||
|
|
|
@ -553,7 +553,7 @@ public:
|
|||
// Retrieves a buffer containing image data for a screenshot.
|
||||
// Hint: Pitch can be negative for upside-down images, in which case buffer
|
||||
// points to the last row in the buffer, which will be the first row output.
|
||||
virtual void GetScreenshotBuffer(const uint8_t *&buffer, int &pitch, ESSType &color_type, float &gamma) {}
|
||||
virtual TArray<uint8_t> GetScreenshotBuffer(int &pitch, ESSType &color_type, float &gamma) {}
|
||||
|
||||
static float GetZNear() { return 5.f; }
|
||||
static float GetZFar() { return 65536.f; }
|
||||
|
|
Loading…
Reference in a new issue