Compare commits

..
Author SHA1 Message Date
Alug 5289f13891 Show report issue button also on I_Error
also make wrapper functions for everything, to reduce code dupe
2026-01-20 17:32:22 +01:00
Alug 073b35690b dont attempt to show sdl message box on non dedicated builds running as dedicated 2026-01-20 17:32:19 +01:00
Alug 43d3ac102d HWR_RenderPlane: cleanup code that does nothing 2026-01-20 15:42:37 +01:00
6 changed files with 166 additions and 190 deletions

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@ hw_bsp.c
hw_draw.c
hw_main.cpp
hw_clip.c
hw_md2.cpp
hw_md2.c
hw_cache.c
hw_md2load.c
hw_md3load.c
+30 -44
View File
@@ -16,7 +16,6 @@
#ifdef HWRENDER
#include <unordered_set>
#include <unordered_map>
#include "hw_main.h"
#include "hw_glob.h"
@@ -36,10 +35,6 @@
#include "../p_spec.h" // anim_t
#include "../r_sky.h"
struct ColorMipMap {
std::unordered_map<const UINT8*, GLMipmap_t*> map;
};
INT32 patchformat = GL_TEXFMT_AP_88; // use alpha for holes
INT32 textureformat = GL_TEXFMT_P_8; // use chromakey for hole
@@ -453,7 +448,7 @@ typedef struct
} GLMapTextureSet_t; // idk i suck at naming things
static size_t gl_numtextures = 0; // Texture count
static GLMapTextureSet_t *gl_textures = NULL; // For all textures
static GLMapTextureSet_t *gl_textures; // For all textures
static void HWR_FreeTextureData(patch_t *patch)
{
@@ -509,31 +504,34 @@ static void HWR_FreeTextureColormaps(patch_t *patch)
return;
// The mipmap must be valid, obviously
if (!pat->mipmap)
return;
if (pat->mipmap->nextcolormap)
while (pat->mipmap)
{
for (auto& pair : pat->mipmap->nextcolormap->map)
{
GLMipmap_t *glMipmap = pair.second;
// Confusing at first, but pat->mipmap->nextcolormap
// at the beginning of the loop is the first colormap
// from the linked list of colormaps.
GLMipmap_t *next = NULL;
if (glMipmap)
{
// Free image data from memory.
Z_Free(glMipmap->data);
Z_Free(glMipmap->colormap);
glMipmap->data = NULL;
glMipmap->colormap = NULL;
GL_DeleteTexture(glMipmap);
// No mipmap in this patch, break out of the loop.
if (!pat->mipmap)
break;
// Free the colormap mipmap from memory.
free(glMipmap);
}
}
// No colormap mipmaps either.
if (!pat->mipmap->nextcolormap)
break;
delete pat->mipmap->nextcolormap;
pat->mipmap->nextcolormap = NULL;
// Set the first colormap to the one that comes after it.
next = pat->mipmap->nextcolormap;
pat->mipmap->nextcolormap = next->nextcolormap;
// Free image data from memory.
Z_Free(next->data);
Z_Free(next->colormap);
next->data = NULL;
next->colormap = NULL;
GL_DeleteTexture(next);
// Free the old colormap mipmap from memory.
free(next);
}
}
@@ -1087,7 +1085,7 @@ void HWR_GetPatch(patch_t *patch)
void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
{
GLPatch_t *glPatch;
GLMipmap_t *newMipmap;
GLMipmap_t *glMipmap, *newMipmap;
if (!patch->hardware)
Patch_CreateGL(patch);
@@ -1101,19 +1099,11 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
return;
}
// gotta make our map if theres none
if (!glPatch->mipmap->nextcolormap)
{
glPatch->mipmap->nextcolormap = new ColorMipMap();
}
// search for the mipmap
auto& map = glPatch->mipmap->nextcolormap->map;
auto it = map.find(colormap);
if (it != map.end())
// skip the first (no colormap translated)
for (glMipmap = glPatch->mipmap; glMipmap->nextcolormap;)
{
GLMipmap_t *glMipmap = it->second;
glMipmap = glMipmap->nextcolormap;
if (glMipmap->colormap && glMipmap->colormap->source == colormap)
{
@@ -1123,9 +1113,7 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
HWR_UpdatePatchMipmap(patch, glMipmap);
}
else
{
HWR_LoadPatchMipmap(patch, glMipmap);
}
return;
}
@@ -1140,9 +1128,7 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
newMipmap = static_cast<GLMipmap_t *>(calloc(1, sizeof (*newMipmap)));
if (newMipmap == NULL)
I_Error("%s: Out of memory", "HWR_GetMappedPatch");
// add to nextcolormap map
map[colormap] = newMipmap;
glMipmap->nextcolormap = newMipmap;
newMipmap->colormap = static_cast<GLColormap_t *>(Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL));
newMipmap->colormap->source = colormap;
+1 -2
View File
@@ -23,7 +23,6 @@
typedef enum GLTextureFormat_e
{
GL_TEXFMT_NULL = 0x00,
GL_TEXFMT_P_8 = 0x01, /* 8-bit palette */
GL_TEXFMT_AP_88 = 0x02, /* 8-bit alpha, 8-bit palette */
@@ -55,7 +54,7 @@ struct GLMipmap_s
UINT16 width, height;
UINT32 downloaded; // The GPU has this texture.
struct ColorMipMap *nextcolormap;
struct GLMipmap_s *nextcolormap;
struct GLColormap_s *colormap;
};
typedef struct GLMipmap_s GLMipmap_t;
+21 -24
View File
@@ -101,7 +101,8 @@ sector_t *gl_backsector = NULL;
static constexpr float clipping_distances[] = {1024.0f, 2048.0f, 4096.0f, 6144.0f, 8192.0f, 12288.0f, 16384.0f};
// values for bsp culling
// slightly higher than the far clipping plane to compensate for impreciseness
static constexpr INT32 bsp_culling_distances[] = {(1024+512)*FRACUNIT, (2048+512)*FRACUNIT, (4096+512)*FRACUNIT,
static constexpr INT32 bsp_culling_distances[] = {
(1024+512)*FRACUNIT, (2048+512)*FRACUNIT, (4096+512)*FRACUNIT,
(6144+512)*FRACUNIT, (8192+512)*FRACUNIT, (12288+512)*FRACUNIT, (16384+512)*FRACUNIT};
// Performance stats
@@ -587,15 +588,11 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
const sector_t *sec = FOFsector ? FOFsector : gl_frontsector;
// Get the slope pointer to simplify future code
if (sec->f_slope && !isceiling)
if (!isceiling && sec->f_slope)
slope = sec->f_slope;
else if (sec->c_slope && isceiling)
else if (isceiling && sec->c_slope)
slope = sec->c_slope;
// Set fixedheight to the slope's height from our viewpoint, if we have a slope
if (slope)
fixedheight = P_GetSlopeZAt(slope, viewx, viewy);
height = FixedToFloat(fixedheight);
// Allocate plane-vertex buffer if we need to
@@ -687,18 +684,19 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
vert->s = (tempxsow * cosangf) - (tempytow * sinangf);\
vert->t = (tempxsow * sinangf) + (tempytow * cosangf);\
}\
\
if (slope)\
{\
fixedheight = P_GetSlopeZAt(slope, FloatToFixed((vx)), FloatToFixed((vy)));\
height = FixedToFloat(fixedheight);\
}\
\
vert->x = (vx);\
vert->y = height;\
vert->z = (vy);\
\
if (slope)\
{\
fixedheight = P_GetSlopeZAt(slope, FloatToFixed((vx)), FloatToFixed((vy)));\
vert->y = FixedToFloat(fixedheight);\
}\
}
for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++,v3d++,pv++)
for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++,v3d++, pv++)
SETUP3DVERT(v3d, pv->x, pv->y);
if (slope)
@@ -1785,10 +1783,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
// Single sided line... Deal only with the middletexture (if one exists)
if (gl_midtexture && gl_linedef->special != HORIZONSPECIAL) // Ignore horizon line for OGL
{
glTex = HWR_GetTexture(gl_midtexture, noencore);
fixed_t texturevpeg;
glTex = HWR_GetTexture(gl_midtexture, noencore);
// PEGGING
if ((gl_linedef->flags & (ML_DONTPEGBOTTOM|ML_EFFECT2)) == (ML_DONTPEGBOTTOM|ML_EFFECT2))
texturevpeg = gl_frontsector->floorheight + textureheight[gl_sidedef->midtexture] - gl_frontsector->ceilingheight + gl_sidedef->rowoffset;
@@ -1875,8 +1873,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
//Hurdler: 3d-floors test
if (!gl_drawing_stencil && gl_backsector && gl_frontsector->tag != gl_backsector->tag && (gl_backsector->ffloors || gl_frontsector->ffloors))
{
ffloor_t * rover;
fixed_t highcut = 0, lowcut = 0;
ffloor_t *rover;
fixed_t highcut = 0, lowcut = 0;
fixed_t lowcutslope = 0, highcutslope = 0;
// Used for height comparisons and etc across FOFs and slopes
@@ -2947,7 +2945,7 @@ static void HWR_Subsector(size_t num)
static sector_t tempsec; //SoM: 4/7/2000
INT32 floorlightlevel;
INT32 ceilinglightlevel;
INT32 locFloorHeight, locCeilingHeight;
INT32 locFloorHeight = 0, locCeilingHeight = 0;
INT32 cullFloorHeight, cullCeilingHeight;
INT32 light = 0;
extracolormap_t *floorcolormap;
@@ -2993,11 +2991,12 @@ static void HWR_Subsector(size_t num)
cullFloorHeight = P_GetSectorFloorZAt (gl_frontsector, viewx, viewy);
cullCeilingHeight = P_GetSectorCeilingZAt(gl_frontsector, viewx, viewy);
locFloorHeight = P_GetSectorFloorZAt (gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y);
locCeilingHeight = P_GetSectorCeilingZAt(gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y);
if (gl_frontsector->ffloors)
{
locFloorHeight = P_GetSectorFloorZAt (gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y);
locCeilingHeight = P_GetSectorCeilingZAt(gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y);
boolean anyMoved = gl_frontsector->moved;
if (anyMoved == false)
@@ -3052,8 +3051,7 @@ static void HWR_Subsector(size_t num)
{
HWR_GetFlat(levelflats[gl_frontsector->floorpic].lumpnum, R_NoEncore(gl_frontsector, false));
HWR_RenderPlane(sub, &extrasubsectors[num], false,
// Hack to make things continue to work around slopes.
locFloorHeight == cullFloorHeight ? locFloorHeight : gl_frontsector->floorheight,
gl_frontsector->floorheight,
// We now return you to your regularly scheduled rendering.
PF_Occlude, floorlightlevel, levelflats[gl_frontsector->floorpic].lumpnum, NULL, 255, floorcolormap);
}
@@ -3068,8 +3066,7 @@ static void HWR_Subsector(size_t num)
{
HWR_GetFlat(levelflats[gl_frontsector->ceilingpic].lumpnum, R_NoEncore(gl_frontsector, true));
HWR_RenderPlane(sub, &extrasubsectors[num], true,
// Hack to make things continue to work around slopes.
locCeilingHeight == cullCeilingHeight ? locCeilingHeight : gl_frontsector->ceilingheight,
gl_frontsector->ceilingheight,
// We now return you to your regularly scheduled rendering.
PF_Occlude, ceilinglightlevel, levelflats[gl_frontsector->ceilingpic].lumpnum, NULL, 255, ceilingcolormap);
}
@@ -13,7 +13,6 @@
/// Inspired from md2.c by Mete Ciragan (mete@swissquake.ch)
#include "hw_data.h"
#ifdef __GNUC__
#include <unistd.h>
#endif
@@ -73,12 +72,6 @@
#include <errno.h>
#endif
#include <unordered_map>
struct ColorMipMap {
std::unordered_map<const UINT8*, GLMipmap_t*> map;
};
md2_t md2_models[NUMSPRITES] = {};
md2_t md2_playermodels[MAXSKINS] = {};
md2_t md2_localplayermodels[MAXLOCALSKINS] = {};
@@ -100,10 +93,10 @@ static void md2_freeModel (model_t *model)
static model_t *md2_readModel(const char *filename)
{
//Filename checking fixed ~Monster Iestyn and Golden
if (FIL_FileExists(va("%s" PATHSEP "%s", srb2home, filename)))
return LoadModel(va("%s" PATHSEP "%s", srb2home, filename), PU_STATIC);
else if (FIL_FileExists(va("%s" PATHSEP "%s", srb2path, filename)))
return LoadModel(va("%s" PATHSEP "%s", srb2path, filename), PU_STATIC);
if (FIL_FileExists(va("%s"PATHSEP"%s", srb2home, filename)))
return LoadModel(va("%s"PATHSEP"%s", srb2home, filename), PU_STATIC);
else if (FIL_FileExists(va("%s"PATHSEP"%s", srb2path, filename)))
return LoadModel(va("%s"PATHSEP"%s", srb2path, filename), PU_STATIC);
return NULL;
}
@@ -166,18 +159,18 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_
#endif
volatile png_FILE_p png_FILE;
//Filename checking fixed ~Monster Iestyn and Golden
char *pngfilename = va("%s" PATHSEP "mdls" PATHSEP "%s", srb2home, filename);
char *pngfilename = va("%s"PATHSEP"mdls"PATHSEP"%s", srb2home, filename);
FIL_ForceExtension(pngfilename, ".png");
png_FILE = fopen(pngfilename, "rb");
if (!png_FILE)
{
pngfilename = va("%s" PATHSEP "mdls" PATHSEP "%s", srb2path, filename);
pngfilename = va("%s"PATHSEP"mdls"PATHSEP"%s", srb2path, filename);
FIL_ForceExtension(pngfilename, ".png");
png_FILE = fopen(pngfilename, "rb");
//CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for loading\n", filename);
if (!png_FILE)
return GL_TEXFMT_NULL;
return 0;
}
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
@@ -186,7 +179,7 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_
{
CONS_Debug(DBG_RENDER, "PNG_Load: Error on initialize libpng\n");
fclose(png_FILE);
return GL_TEXFMT_NULL;
return 0;
}
png_info_ptr = png_create_info_struct(png_ptr);
@@ -195,7 +188,7 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_
CONS_Debug(DBG_RENDER, "PNG_Load: Error on allocate for libpng\n");
png_destroy_read_struct(&png_ptr, NULL, NULL);
fclose(png_FILE);
return GL_TEXFMT_NULL;
return 0;
}
#ifdef USE_FAR_KEYWORD
@@ -208,7 +201,7 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_
png_destroy_read_struct(&png_ptr, &png_info_ptr, NULL);
fclose(png_FILE);
Z_Free(glpatch->mipmap->data);
return GL_TEXFMT_NULL;
return 0;
}
#ifdef USE_FAR_KEYWORD
png_memcpy(png_jmpbuf(png_ptr), jmpbuf, sizeof jmp_buf);
@@ -248,8 +241,8 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_
{
png_uint_32 i, pitch = png_get_rowbytes(png_ptr, png_info_ptr);
png_bytep PNG_image = static_cast<png_bytep>(Z_Malloc(pitch*height, PU_HWRMODELTEXTURE, &glpatch->mipmap->data));
png_bytepp row_pointers = static_cast<png_bytepp>(png_malloc(png_ptr, height * sizeof (png_bytep)));
png_bytep PNG_image = Z_Malloc(pitch*height, PU_HWRMODELTEXTURE, &glpatch->mipmap->data);
png_bytepp row_pointers = png_malloc(png_ptr, height * sizeof (png_bytep));
for (i = 0; i < height; i++)
row_pointers[i] = PNG_image + i*pitch;
png_read_image(png_ptr, row_pointers);
@@ -299,42 +292,42 @@ static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h,
INT32 ch, rep;
FILE *file;
//Filename checking fixed ~Monster Iestyn and Golden
char *pcxfilename = va("%s" PATHSEP "mdls" PATHSEP "%s", srb2home, filename);
char *pcxfilename = va("%s"PATHSEP"mdls"PATHSEP"%s", srb2home, filename);
FIL_ForceExtension(pcxfilename, ".pcx");
file = fopen(pcxfilename, "rb");
if (!file)
{
pcxfilename = va("%s" PATHSEP "mdls" PATHSEP "%s", srb2path, filename);
pcxfilename = va("%s"PATHSEP"mdls"PATHSEP"%s", srb2path, filename);
FIL_ForceExtension(pcxfilename, ".pcx");
file = fopen(pcxfilename, "rb");
if (!file)
return GL_TEXFMT_NULL;
return 0;
}
if (fread(&header, sizeof (PcxHeader), 1, file) != 1)
{
fclose(file);
return GL_TEXFMT_NULL;
return 0;
}
if (header.bitsPerPixel != 8)
{
fclose(file);
return GL_TEXFMT_NULL;
return 0;
}
fseek(file, -PALSIZE, SEEK_END);
pw = *w = header.xmax - header.xmin + 1;
ph = *h = header.ymax - header.ymin + 1;
image = static_cast<RGBA_t *>(Z_Malloc(pw*ph*4, PU_HWRMODELTEXTURE, &glpatch->mipmap->data));
image = Z_Malloc(pw*ph*4, PU_HWRMODELTEXTURE, &glpatch->mipmap->data);
if (fread(palette, sizeof (UINT8), PALSIZE, file) != PALSIZE)
{
Z_Free(image);
fclose(file);
return GL_TEXFMT_NULL;
return 0;
}
fseek(file, sizeof (PcxHeader), SEEK_SET);
@@ -376,8 +369,8 @@ static void md2_loadTexture(md2_t *model)
if (model->glpatch)
{
patch = static_cast<patch_t *>(model->glpatch);
glPatch = static_cast<GLPatch_t *>(patch->hardware);
patch = model->glpatch;
glPatch = (GLPatch_t *)(patch->hardware);
if (glPatch)
Z_Free(glPatch->mipmap->data);
}
@@ -388,7 +381,7 @@ static void md2_loadTexture(md2_t *model)
Patch_AllocateHardwarePatch(patch);
if (glPatch == NULL)
glPatch = static_cast<GLPatch_t *>(patch->hardware);
glPatch = (GLPatch_t *)(patch->hardware);
if (!glPatch->mipmap->downloaded && !glPatch->mipmap->data)
{
@@ -396,10 +389,10 @@ static void md2_loadTexture(md2_t *model)
#ifdef HAVE_PNG
glPatch->mipmap->format = PNG_Load(filename, &w, &h, glPatch);
if (glPatch->mipmap->format == GL_TEXFMT_NULL)
if (glPatch->mipmap->format == 0)
#endif
glPatch->mipmap->format = PCX_Load(filename, &w, &h, glPatch);
if (glPatch->mipmap->format == GL_TEXFMT_NULL)
if (glPatch->mipmap->format == 0)
{
model->notexturefile = true; // mark it so its not searched for again repeatedly
return;
@@ -419,7 +412,7 @@ static void md2_loadTexture(md2_t *model)
UINT32 size;
RGBA_t *image;
// Lactozilla: Apply colour cube
image = static_cast<RGBA_t *>(glPatch->mipmap->data);
image = glPatch->mipmap->data;
size = w*h;
while (size--)
{
@@ -440,7 +433,7 @@ static void md2_loadBlendTexture(md2_t *model)
patch_t *patch;
GLPatch_t *glPatch = NULL;
char *filename = static_cast<char *>(Z_Malloc(strlen(model->filename)+7, PU_STATIC, NULL));
char *filename = Z_Malloc(strlen(model->filename)+7, PU_STATIC, NULL);
strcpy(filename, model->filename);
@@ -448,8 +441,8 @@ static void md2_loadBlendTexture(md2_t *model)
if (model->blendglpatch)
{
patch = static_cast<patch_t *>(model->blendglpatch);
glPatch = static_cast<GLPatch_t *>(patch->hardware);
patch = model->blendglpatch;
glPatch = (GLPatch_t *)(patch->hardware);
if (glPatch)
Z_Free(glPatch->mipmap->data);
}
@@ -460,17 +453,17 @@ static void md2_loadBlendTexture(md2_t *model)
Patch_AllocateHardwarePatch(patch);
if (glPatch == NULL)
glPatch = static_cast<GLPatch_t *>(patch->hardware);
glPatch = (GLPatch_t *)(patch->hardware);
if (!glPatch->mipmap->downloaded && !glPatch->mipmap->data)
{
int w = 0, h = 0;
#ifdef HAVE_PNG
glPatch->mipmap->format = PNG_Load(filename, &w, &h, glPatch);
if (glPatch->mipmap->format == GL_TEXFMT_NULL)
if (glPatch->mipmap->format == 0)
#endif
glPatch->mipmap->format = PCX_Load(filename, &w, &h, glPatch);
if (glPatch->mipmap->format == GL_TEXFMT_NULL)
if (glPatch->mipmap->format == 0)
{
model->noblendfile = true; // mark it so its not searched for again repeatedly
Z_Free(filename);
@@ -539,11 +532,11 @@ void HWR_InitMD2(void)
// read the mdls.dat file
//Filename checking fixed ~Monster Iestyn and Golden
f = fopen(va("%s" PATHSEP "%s", srb2home, "mdls.dat"), "rt");
f = fopen(va("%s"PATHSEP"%s", srb2home, "mdls.dat"), "rt");
if (!f)
{
f = fopen(va("%s" PATHSEP "%s", srb2path, "mdls.dat"), "rt");
f = fopen(va("%s"PATHSEP"%s", srb2path, "mdls.dat"), "rt");
if (!f)
{
CONS_Printf("%s %s\n", M_GetText("Error while loading mdls.dat:"), strerror(errno));
@@ -600,11 +593,11 @@ void HWR_AddPlayerMD2(int skin, boolean local) // For MD2's that were added afte
// read the mdls.dat file
//Filename checking fixed ~Monster Iestyn and Golden
f = fopen(va("%s" PATHSEP "%s", srb2home, "mdls.dat"), "rt");
f = fopen(va("%s"PATHSEP"%s", srb2home, "mdls.dat"), "rt");
if (!f)
{
f = fopen(va("%s" PATHSEP "%s", srb2path, "mdls.dat"), "rt");
f = fopen(va("%s"PATHSEP"%s", srb2path, "mdls.dat"), "rt");
if (!f)
{
CONS_Printf("%s %s\n", M_GetText("Error while loading mdls.dat:"), strerror(errno));
@@ -652,11 +645,11 @@ void HWR_AddSpriteMD2(size_t spritenum) // For MD2s that were added after startu
// Read the md2.dat file
//Filename checking fixed ~Monster Iestyn and Golden
f = fopen(va("%s" PATHSEP "%s", srb2home, "mdls.dat"), "rt");
f = fopen(va("%s"PATHSEP"%s", srb2home, "mdls.dat"), "rt");
if (!f)
{
f = fopen(va("%s" PATHSEP "%s", srb2path, "mdls.dat"), "rt");
f = fopen(va("%s"PATHSEP"%s", srb2path, "mdls.dat"), "rt");
if (!f)
{
@@ -696,8 +689,8 @@ spritemd2found:
static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMipmap_t *glMipmap, INT32 skinnum, skincolors_t color)
{
GLPatch_t *hwrPatch = static_cast<GLPatch_t *>(gpatch->hardware);
GLPatch_t *hwrBlendPatch = static_cast<GLPatch_t *>(blendgpatch->hardware);
GLPatch_t *hwrPatch = gpatch->hardware;
GLPatch_t *hwrBlendPatch = blendgpatch->hardware;
UINT16 w = gpatch->width, h = gpatch->height;
UINT32 size = w*h;
RGBA_t *image, *blendimage, *cur, blendcolor;
@@ -729,11 +722,11 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi
glMipmap->data = NULL;
}
cur = static_cast<RGBA_t *>(Z_Malloc(size*4, PU_HWRMODELTEXTURE, &glMipmap->data));
cur = Z_Malloc(size*4, PU_HWRMODELTEXTURE, &glMipmap->data);
memset(cur, 0x00, size*4);
image = static_cast<RGBA_t *>(hwrPatch->mipmap->data);
blendimage = static_cast<RGBA_t *>(hwrBlendPatch->mipmap->data);
image = hwrPatch->mipmap->data;
blendimage = hwrBlendPatch->mipmap->data;
// TC_METALSONIC includes an actual skincolor translation, on top of its flashing.
if (skinnum == TC_METALSONIC)
@@ -979,15 +972,15 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi
colorbright = 1; // no dividing by 0 please
tempcolor = (brightness * blendcolor.s.red) / colorbright;
tempcolor = std::min<UINT32>(255, tempcolor);
tempcolor = min(255, tempcolor);
cur->s.red = (UINT8)tempcolor;
tempcolor = (brightness * blendcolor.s.green) / colorbright;
tempcolor = std::min<UINT32>(255, tempcolor);
tempcolor = min(255, tempcolor);
cur->s.green = (UINT8)tempcolor;
tempcolor = (brightness * blendcolor.s.blue) / colorbright;
tempcolor = std::min<UINT32>(255, tempcolor);
tempcolor = min(255, tempcolor);
cur->s.blue = (UINT8)tempcolor;
cur->s.alpha = image->s.alpha;
}
@@ -997,15 +990,15 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi
INT32 tempcolor;
tempcolor = ((image->s.red * (255-blendimage->s.alpha)) / 255) + ((blendcolor.s.red * blendimage->s.alpha) / 255);
tempcolor = std::min<UINT32>(255, tempcolor);
tempcolor = min(255, tempcolor);
cur->s.red = (UINT8)tempcolor;
tempcolor = ((image->s.green * (255-blendimage->s.alpha)) / 255) + ((blendcolor.s.green * blendimage->s.alpha) / 255);
tempcolor = std::min<UINT32>(255, tempcolor);
tempcolor = min(255, tempcolor);
cur->s.green = (UINT8)tempcolor;
tempcolor = ((image->s.blue * (255-blendimage->s.alpha)) / 255) + ((blendcolor.s.blue * blendimage->s.alpha) / 255);
tempcolor = std::min<UINT32>(255, tempcolor);
tempcolor = min(255, tempcolor);
cur->s.blue = (UINT8)tempcolor;
cur->s.alpha = image->s.alpha;
}
@@ -1041,30 +1034,22 @@ skippixel:
static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 skinnum, const UINT8 *colormap, skincolors_t color)
{
// mostly copied from HWR_GetMappedPatch, hence the similarities and comment
GLPatch_t *glPatch = static_cast<GLPatch_t *>(patch->hardware);
GLMipmap_t *newMipmap;
GLPatch_t *glPatch = patch->hardware;
GLMipmap_t *glMipmap, *newMipmap;
if (blendgpatch == NULL || colormap == colormaps
|| colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET))
if (blendgpatch == NULL || colormap == colormaps || colormap == NULL)
{
// Don't do any blending
GL_SetTexture(glPatch->mipmap);
return;
}
// gotta make our map if theres none
if (!glPatch->mipmap->nextcolormap)
{
glPatch->mipmap->nextcolormap = new ColorMipMap();
}
// search for the Mipmap
auto& map = glPatch->mipmap->nextcolormap->map;
auto it = map.find(colormap);
if (it != map.end())
// skip the first (no colormap translated)
for (glMipmap = glPatch->mipmap; glMipmap->nextcolormap; )
{
GLMipmap_t *glMipmap = it->second;
glMipmap = glMipmap->nextcolormap;
if (glMipmap->colormap && glMipmap->colormap->source == colormap)
{
@@ -1092,14 +1077,12 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 sk
// (it have a liste of mipmap)
// this malloc is cleared in HWR_FreeTextureCache
// (...) unfortunately z_malloc fragment alot the memory :(so malloc is better
newMipmap = static_cast<GLMipmap_t *>(calloc(1, sizeof(*newMipmap)));
newMipmap = calloc(1, sizeof (*newMipmap));
if (newMipmap == NULL)
I_Error("%s: Out of memory", "HWR_GetBlendedTexture");
glMipmap->nextcolormap = newMipmap;
// add to nextcolormap map
map[colormap] = newMipmap;
newMipmap->colormap = static_cast<GLColormap_t *>(Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL));
newMipmap->colormap = Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL);
newMipmap->colormap->source = colormap;
memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8));
@@ -1196,7 +1179,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr)
else
blendmode = spr->mobj->blendmode;
blendmode = std::min<INT32>(AST_MODULATE, blendmode);
blendmode = min(AST_MODULATE, blendmode);
if (spr->mobj->flags2 & MF2_SHADOW)
{
@@ -1285,7 +1268,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr)
}
//Hurdler: arf, I don't like that implementation at all... too much crappy
gpatch = static_cast<patch_t *>(md2->glpatch);
gpatch = md2->glpatch;
if (gpatch)
hwrPatch = ((GLPatch_t *)gpatch->hardware);
@@ -1294,12 +1277,12 @@ void HWR_DrawMD2(gl_vissprite_t *spr)
md2_loadTexture(md2);
// Load it again, because it isn't being loaded into gpatch after md2_loadtexture...
gpatch = static_cast<patch_t *>(md2->glpatch);
gpatch = md2->glpatch;
if (gpatch)
hwrPatch = ((GLPatch_t *)gpatch->hardware);
// Load blend texture
blendgpatch = static_cast<patch_t *>(md2->blendglpatch);
blendgpatch = md2->blendglpatch;
if (blendgpatch)
hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware);
@@ -1309,7 +1292,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr)
md2_loadBlendTexture(md2);
// Load it again, because it isn't being loaded into blendgpatch after md2_loadblendtexture...
blendgpatch = static_cast<patch_t *>(md2->blendglpatch);
blendgpatch = md2->blendglpatch;
if (blendgpatch)
hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware);
@@ -1525,7 +1508,7 @@ void HWR_Draw2DModel(md2_t *md2, INT32 x, INT32 y, INT32 skinnum, skincolors_t c
else
frame = 0;
gpatch = static_cast<patch_t *>(md2->glpatch);
gpatch = (patch_t *)(md2->glpatch);
if (gpatch)
hwrPatch = ((GLPatch_t *)gpatch->hardware);
@@ -1533,11 +1516,11 @@ void HWR_Draw2DModel(md2_t *md2, INT32 x, INT32 y, INT32 skinnum, skincolors_t c
((!hwrPatch->mipmap->format || !hwrPatch->mipmap->downloaded) && !md2->notexturefile))
md2_loadTexture(md2);
gpatch = static_cast<patch_t *>(md2->glpatch);
gpatch = (patch_t*)(md2->glpatch);
if (gpatch)
hwrPatch = ((GLPatch_t *)gpatch->hardware);
blendgpatch = static_cast<patch_t *>(md2->blendglpatch);
blendgpatch = (patch_t*)(md2->blendglpatch);
if (blendgpatch)
hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware);
@@ -1546,7 +1529,7 @@ void HWR_Draw2DModel(md2_t *md2, INT32 x, INT32 y, INT32 skinnum, skincolors_t c
((!hwrBlendPatch->mipmap->format || !hwrBlendPatch->mipmap->downloaded) && !md2->noblendfile)))
md2_loadBlendTexture(md2);
blendgpatch = static_cast<patch_t *>(md2->blendglpatch);
blendgpatch = (patch_t*)(md2->blendglpatch);
if (blendgpatch)
hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware);
+46 -35
View File
@@ -1629,24 +1629,13 @@ static int I_OpenURL(const char *url)
#endif
}
static void I_ReportSignal(int num, int coredumped)
static void I_ShowErrorBox(const char *title, const char *msg)
{
char sigmsg[512];
char signame[128];
char sigttl[512] = "Process killed by signal: ";
const char *reportmsg = "\n\n\nTo help us figure out the cause, please report the issue to our github page with " CRASH_LOGFILE_NAME " attached.\n\nSorry for the inconvenience!";
I_PrintSignal(num, coredumped, sigmsg, signame);
size_t len = strlen(sigmsg);
snprintf(sigmsg + len, sizeof(sigmsg) - len, "\n\nCrash report has been saved into %s", CRASH_LOGFILE_NAME);
strcat(sigttl, signame);
I_OutputMsg("\n%s\n\n", sigttl);
if (M_CheckParm("-dedicated"))
return;
const char *reportmsg = "\n\n\nTo help us figure out the cause, please report the issue to our github page with " CRASH_LOGFILE_NAME " attached.\n\nSorry for the inconvenience!";
const SDL_MessageBoxButtonData buttons[] = {
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "OK" },
{ 0, 1, "Report Issue" },
@@ -1655,8 +1644,8 @@ static void I_ReportSignal(int num, int coredumped)
const SDL_MessageBoxData messageboxdata = {
SDL_MESSAGEBOX_ERROR, /* .flags */
NULL, /* .window */
sigttl, /* .title */
va("%s %s", sigmsg, reportmsg), /* .message */
title, /* .title */
va("%s %s", msg, reportmsg), /* .message */
SDL_arraysize(buttons), /* .numbuttons */
buttons, /* .buttons */
NULL /* .colorScheme */
@@ -1670,6 +1659,39 @@ static void I_ReportSignal(int num, int coredumped)
I_OpenURL("https://github.com/Indev450/SRB2Kart-Saturn/issues");
}
static void I_ShowSimpleErrorBox(const char *title, char *msg)
{
if (M_CheckParm("-dedicated"))
return;
// Implement message box with SDL_ShowSimpleMessageBox,
// which should fail gracefully if it can't put a message box up
// on the target system
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, msg, NULL);
// Note that SDL_ShowSimpleMessageBox does *not* require SDL to be
// initialized at the time, so calling it after SDL_Quit() is
// perfectly okay! In addition, we do this on purpose so the
// fullscreen window is closed before displaying the error message
// in case the fullscreen window blocks it for some absurd reason.
}
static void I_ReportSignal(int num, int coredumped)
{
char sigmsg[512];
char signame[128];
char sigttl[512] = "Process killed by signal: ";
I_PrintSignal(num, coredumped, sigmsg, signame);
size_t len = strlen(sigmsg);
snprintf(sigmsg + len, sizeof(sigmsg) - len, "\n\nCrash report has been saved into %s", CRASH_LOGFILE_NAME);
strcat(sigttl, signame);
I_OutputMsg("\n%s\n\n", sigttl);
//I_ShowSimpleErrorBox(sigttl, sigmsg);
I_ShowErrorBox(sigttl, sigmsg);
}
#ifndef NEWSIGNALHANDLER
FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
{
@@ -1775,10 +1797,7 @@ FUNCNORETURN static ATTRNORETURN void newsignalhandler_Warn(const char *pr)
);
I_OutputMsg("%s\n", text);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Startup error",
text, NULL);
I_ShowSimpleErrorBox("Startup error", text);
I_ShutdownConsole();
exit(-1);
@@ -1940,6 +1959,7 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...)
{
va_list argptr;
char buffer[8192];
const char *sigttl = "";
#ifdef HAVE_THREADS
if (std::this_thread::get_id() != g_main_thread_id)
@@ -1976,12 +1996,9 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...)
va_start(argptr, error);
vsnprintf(buffer, 8192, error, argptr);
va_end(argptr);
// Implement message box with SDL_ShowSimpleMessageBox,
// which should fail gracefully if it can't put a message box up
// on the target system
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"SRB2Kart " VERSIONSTRING " Recursive Error",
buffer, NULL);
sigttl = "SRB2Kart " VERSIONSTRING " Recursive Error";
I_ShowSimpleErrorBox(sigttl, buffer);
W_Shutdown();
exit(-1); // recursive errors detected
@@ -2021,15 +2038,9 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...)
I_ShutdownSystem();
SDL_Quit();
// Implement message box with SDL_ShowSimpleMessageBox,
// which should fail gracefully if it can't put a message box up
// on the target system
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "SRB2Kart " VERSIONSTRING " Error", buffer, NULL);
// Note that SDL_ShowSimpleMessageBox does *not* require SDL to be
// initialized at the time, so calling it after SDL_Quit() is
// perfectly okay! In addition, we do this on purpose so the
// fullscreen window is closed before displaying the error message
// in case the fullscreen window blocks it for some absurd reason.
sigttl = "SRB2Kart " VERSIONSTRING " Error";
//I_ShowSimpleErrorBox(sigttl, buffer);
I_ShowErrorBox(sigttl, buffer);
W_Shutdown();