use std::vector for our image buffers
this is just to have it cleaner and less code bloat the resizing loop will almost never trigger, 1meg is enough to even rotate gigantamax eevee without needing to grow
This commit is contained in:
1 parent
94fdae6f21
commit
dae87fe802
4 files changed
+57
-57
No files matched your search
+1
-1
@@ -53,7 +53,7 @@ r_data.c
|
||||
r_draw.c
|
||||
r_fps.cpp
|
||||
r_main.cpp
|
||||
r_patch.c
|
||||
r_patch.cpp
|
||||
r_patchrotation.c
|
||||
r_plane.cpp
|
||||
r_segs.cpp
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "r_skins.h"
|
||||
#include "z_zone.h"
|
||||
#include "w_wad.h"
|
||||
#include <vector>
|
||||
|
||||
#ifdef HWRENDER
|
||||
#include "hardware/hw_glob.h"
|
||||
@@ -37,7 +38,7 @@ static void R_ParseSpriteInfoFrame(spriteinfo_t *info)
|
||||
UINT8 frameFrame = 0xFF;
|
||||
INT16 frameXPivot = 0;
|
||||
INT16 frameYPivot = 0;
|
||||
rotaxis_t frameRotAxis = 0;
|
||||
rotaxis_t frameRotAxis = ROTAXIS_X;
|
||||
|
||||
// Sprite identifier
|
||||
sprinfoToken = M_GetToken(NULL);
|
||||
@@ -158,14 +159,14 @@ static void R_ParseSpriteInfo(boolean spr2)
|
||||
I_Error("Error parsing SPRTINFO lump: Unknown sprite name \"%s\"", newSpriteName);
|
||||
if (!memcmp(newSpriteName,sprnames[i],4))
|
||||
{
|
||||
sprnum = i;
|
||||
sprnum = static_cast<spritenum_t>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// allocate a spriteinfo
|
||||
info = Z_Calloc(sizeof(spriteinfo_t), PU_STATIC, NULL);
|
||||
info = static_cast<spriteinfo_t*>(Z_Calloc(sizeof(spriteinfo_t), PU_STATIC, NULL));
|
||||
info->available = true;
|
||||
|
||||
// Left Curly Brace
|
||||
@@ -329,7 +330,7 @@ void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps)
|
||||
|
||||
patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest)
|
||||
{
|
||||
patch_t *patch = (dest == NULL) ? Z_Calloc(sizeof(patch_t), PU_PATCH, NULL) : (patch_t *)(dest);
|
||||
patch_t *patch = static_cast<patch_t*>((dest == NULL) ? Z_Calloc(sizeof(patch_t), PU_PATCH, NULL) : dest);
|
||||
|
||||
if (source)
|
||||
{
|
||||
@@ -341,7 +342,7 @@ patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest)
|
||||
patch->height = SHORT(source->height);
|
||||
patch->leftoffset = SHORT(source->leftoffset);
|
||||
patch->topoffset = SHORT(source->topoffset);
|
||||
patch->columnofs = Z_Calloc(size, PU_PATCH_DATA, NULL);
|
||||
patch->columnofs = static_cast<INT32*>(Z_Calloc(size, PU_PATCH_DATA, NULL));
|
||||
|
||||
for (col = 0; col < source->width; col++)
|
||||
{
|
||||
@@ -357,7 +358,7 @@ patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest)
|
||||
if (colsize <= 0)
|
||||
I_Error("Patch_Create: no column data!");
|
||||
|
||||
patch->columns = Z_Calloc(colsize, PU_PATCH_DATA, NULL);
|
||||
patch->columns = static_cast<UINT8*>(Z_Calloc(colsize, PU_PATCH_DATA, NULL));
|
||||
M_Memcpy(patch->columns, ((UINT8 *)source + LONG(source->columnofs[0])), colsize);
|
||||
}
|
||||
|
||||
@@ -429,8 +430,8 @@ void *Patch_AllocateHardwarePatch(patch_t *patch)
|
||||
{
|
||||
if (!patch->hardware)
|
||||
{
|
||||
GLPatch_t *glPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, &patch->hardware);
|
||||
glPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, &glPatch->mipmap);
|
||||
GLPatch_t *glPatch = static_cast<GLPatch_t*>(Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, &patch->hardware));
|
||||
glPatch->mipmap = static_cast<GLMipmap_t*>(Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, &glPatch->mipmap));
|
||||
}
|
||||
return (void *)(patch->hardware);
|
||||
}
|
||||
@@ -448,7 +449,8 @@ void *Patch_CreateGL(patch_t *patch)
|
||||
}
|
||||
#endif // HWRENDER
|
||||
|
||||
static UINT8 *imgbuf = NULL;
|
||||
// 1 MB should be enough for most cases
|
||||
static std::vector<UINT8> imgbuf(1024 * 1024);
|
||||
|
||||
//
|
||||
// R_MaskedFlatToPatch
|
||||
@@ -473,8 +475,12 @@ void *R_PixelsToPatch(UINT8 *raw, INT16 width, INT16 height, INT16 leftoffset, I
|
||||
size_t maxoutsize = maxcolumnsize * width + (8 + 4 * width);
|
||||
// so, a 512x512 flat should maximally need 393,760 (384.53 KiB) bytes.
|
||||
// quite a bit smaller than 64 megabytes, and much less annoying to the windows debug allocator!
|
||||
imgbuf = Z_Malloc(maxoutsize, PU_STATIC, NULL);
|
||||
imgptr = imgbuf;
|
||||
while (imgbuf.size() < maxoutsize)
|
||||
{
|
||||
imgbuf.resize(imgbuf.size() * 2);
|
||||
}
|
||||
|
||||
imgptr = imgbuf.data();
|
||||
|
||||
// Write image size and offset
|
||||
WRITEINT16(imgptr, width);
|
||||
@@ -494,7 +500,7 @@ void *R_PixelsToPatch(UINT8 *raw, INT16 width, INT16 height, INT16 leftoffset, I
|
||||
startofspan = NULL;
|
||||
|
||||
// Write column pointer
|
||||
WRITEINT32(colpointers, imgptr - imgbuf);
|
||||
WRITEINT32(colpointers, imgptr - imgbuf.data());
|
||||
|
||||
// Write pixels
|
||||
for (y = 0; y < height; y++)
|
||||
@@ -563,9 +569,9 @@ void *R_PixelsToPatch(UINT8 *raw, INT16 width, INT16 height, INT16 leftoffset, I
|
||||
WRITEUINT8(imgptr, 0xFF);
|
||||
}
|
||||
|
||||
size = imgptr-imgbuf;
|
||||
img = Z_Malloc(size, PU_STATIC, NULL);
|
||||
memcpy(img, imgbuf, size);
|
||||
size = imgptr-imgbuf.data();
|
||||
img = static_cast<UINT8*>(Z_Malloc(size, PU_STATIC, NULL));
|
||||
memcpy(img, imgbuf.data(), size);
|
||||
|
||||
if (destsize != NULL)
|
||||
*destsize = size;
|
||||
@@ -603,8 +609,12 @@ void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffs
|
||||
size_t maxoutsize = maxcolumnsize * width + (8 + 4 * width);
|
||||
// so, a 512x512 flat should maximally need 393,760 (384.53 KiB) bytes.
|
||||
// quite a bit smaller than 64 megabytes, and much less annoying to the windows debug allocator!
|
||||
imgbuf = Z_Malloc(maxoutsize, PU_STATIC, NULL);
|
||||
imgptr = imgbuf;
|
||||
while (imgbuf.size() < maxoutsize)
|
||||
{
|
||||
imgbuf.resize(imgbuf.size() * 2);
|
||||
}
|
||||
|
||||
imgptr = imgbuf.data();
|
||||
|
||||
// Write image size and offset
|
||||
WRITEINT16(imgptr, width);
|
||||
@@ -624,7 +634,7 @@ void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffs
|
||||
startofspan = NULL;
|
||||
|
||||
// Write column pointer
|
||||
WRITEINT32(colpointers, imgptr - imgbuf);
|
||||
WRITEINT32(colpointers, imgptr - imgbuf.data());
|
||||
|
||||
// Write pixels
|
||||
for (y = 0; y < height; y++)
|
||||
@@ -694,9 +704,9 @@ void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffs
|
||||
WRITEUINT8(imgptr, 0xFF);
|
||||
}
|
||||
|
||||
size = imgptr-imgbuf;
|
||||
img = Z_Malloc(size, PU_STATIC, NULL);
|
||||
memcpy(img, imgbuf, size);
|
||||
size = imgptr-imgbuf.data();
|
||||
img = static_cast<UINT8*>(Z_Malloc(size, PU_STATIC, NULL));
|
||||
memcpy(img, imgbuf.data(), size);
|
||||
|
||||
if (destsize != NULL)
|
||||
*destsize = size;
|
||||
@@ -14,6 +14,10 @@
|
||||
#ifndef __R_PATCH__
|
||||
#define __R_PATCH__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "r_defs.h"
|
||||
|
||||
// Structs
|
||||
@@ -63,4 +67,8 @@ void *R_PixelsToPatch(UINT8 *raw, INT16 width, INT16 height, INT16 leftoffset, I
|
||||
UINT16 R_GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip);
|
||||
void R_PatchToPixels(patch_t *patch, UINT8 *dst); // Important: dst must have enough space for patch->width*patch->height pixels!
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // __R_PATCH__
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "r_patchrotation.h"
|
||||
#include "z_zone.h"
|
||||
#include "w_wad.h"
|
||||
#include <vector>
|
||||
|
||||
#ifdef ROTSPRITE
|
||||
//
|
||||
@@ -89,14 +90,14 @@ patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spri
|
||||
RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip);
|
||||
}
|
||||
|
||||
return rotsprite->patches[idx];
|
||||
return static_cast<patch_t*>(rotsprite->patches[idx]);
|
||||
}
|
||||
|
||||
rotsprite_t *RotatedPatch_Create(INT32 numangles)
|
||||
{
|
||||
rotsprite_t *rotsprite = Z_Calloc(sizeof(rotsprite_t), PU_STATIC, NULL);
|
||||
rotsprite_t *rotsprite = static_cast<rotsprite_t*>(Z_Calloc(sizeof(rotsprite_t), PU_STATIC, NULL));
|
||||
rotsprite->angles = numangles;
|
||||
rotsprite->patches = Z_Calloc(rotsprite->angles * 2 * sizeof(void *), PU_STATIC, NULL);
|
||||
rotsprite->patches = static_cast<void**>(Z_Calloc(rotsprite->angles * 2 * sizeof(void *), PU_STATIC, NULL));
|
||||
return rotsprite;
|
||||
}
|
||||
|
||||
@@ -118,30 +119,8 @@ static void RotatedPatch_CalculateDimensions(
|
||||
h1 = FixedInt(FixedCeil(h1 + (FRACUNIT/2)));
|
||||
h2 = FixedInt(FixedCeil(h2 + (FRACUNIT/2)));
|
||||
|
||||
*newwidth = max(width, max(w1, w2));
|
||||
*newheight = max(height, max(h1, h2));
|
||||
}
|
||||
|
||||
static void RotatedPatch_AllocImgBuf(UINT16 **buf, size_t size, size_t *capacity)
|
||||
{
|
||||
if (!*buf)
|
||||
{
|
||||
*buf = Z_Malloc(*capacity, PU_STATIC, NULL);
|
||||
}
|
||||
|
||||
size_t allocsize = size * sizeof(UINT16);
|
||||
|
||||
// make sure our buffer always fits with what we need
|
||||
if (allocsize > *capacity)
|
||||
{
|
||||
while (*capacity < allocsize)
|
||||
*capacity *= 2;
|
||||
|
||||
Z_Free(*buf);
|
||||
*buf = Z_Malloc(*capacity, PU_STATIC, NULL);
|
||||
}
|
||||
|
||||
//CONS_Printf("RotatedPatch_AllocBuf: Allocated %.2f KB\n", *capacity / 1024.0);
|
||||
*newwidth = std::max(width, std::max(w1, w2));
|
||||
*newheight = std::max(height, std::max(h1, h2));
|
||||
}
|
||||
|
||||
void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip)
|
||||
@@ -149,10 +128,10 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle
|
||||
UINT32 i;
|
||||
patch_t *rotated;
|
||||
|
||||
static UINT16 *rawdst = NULL, *rawconv = NULL;
|
||||
static std::vector<UINT16> rawdst(1024 * 1024), rawconv(1024 * 1024); // 1 MB should be enough for most cases
|
||||
|
||||
UINT16 *rawout;
|
||||
size_t size;
|
||||
static size_t dst_capacity = (1024 * 1024), conv_capacity = (1024 * 1024); // 1 MB should be enough for most cases
|
||||
INT32 bflip = (flip != 0x00);
|
||||
|
||||
INT32 width = patch->width;
|
||||
@@ -206,7 +185,10 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle
|
||||
if (!size)
|
||||
size = (width * height);
|
||||
|
||||
RotatedPatch_AllocImgBuf(&rawdst, size, &dst_capacity);
|
||||
while (rawdst.size() < size)
|
||||
{
|
||||
rawdst.resize(rawdst.size() * 2);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
rawdst[i] = 0xFF00;
|
||||
@@ -250,11 +232,11 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle
|
||||
|
||||
size = (width * height);
|
||||
|
||||
RotatedPatch_AllocImgBuf(&rawconv, size, &conv_capacity);
|
||||
memset(rawconv, 0, conv_capacity * sizeof(UINT16));
|
||||
rawconv.resize(size);
|
||||
memset(rawconv.data(), 0, size * sizeof(UINT16));
|
||||
|
||||
src = &rawdst[(miny * newwidth) + minx];
|
||||
dest = rawconv;
|
||||
dest = rawconv.data();
|
||||
dy = height;
|
||||
|
||||
while (dy--)
|
||||
@@ -267,14 +249,14 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle
|
||||
ox -= minx;
|
||||
oy -= miny;
|
||||
|
||||
rawout = rawconv;
|
||||
rawout = rawconv.data();
|
||||
}
|
||||
else
|
||||
{
|
||||
width = newwidth;
|
||||
height = newheight;
|
||||
|
||||
rawout = rawdst;
|
||||
rawout = rawdst.data();
|
||||
}
|
||||
|
||||
// make patch
|
||||
Reference in new issue
Block a user