mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Merge branch 'slow-startup' into 'master'
Optimize PNG detection and generate blendtables on parallel thread See merge request KartKrew/Kart!498
This commit is contained in:
commit
3ca0dc376d
7 changed files with 59 additions and 36 deletions
|
|
@ -1417,6 +1417,9 @@ void D_SRB2Main(void)
|
||||||
// setup loading screen
|
// setup loading screen
|
||||||
SCR_Startup();
|
SCR_Startup();
|
||||||
|
|
||||||
|
// Do this in background; lots of number crunching
|
||||||
|
R_InitTranslucencyTables();
|
||||||
|
|
||||||
CON_SetLoadingProgress(LOADED_ISTARTUPGRAPHICS);
|
CON_SetLoadingProgress(LOADED_ISTARTUPGRAPHICS);
|
||||||
|
|
||||||
CONS_Printf("HU_Init()...\n");
|
CONS_Printf("HU_Init()...\n");
|
||||||
|
|
|
||||||
40
src/r_draw.c
40
src/r_draw.c
|
|
@ -26,6 +26,7 @@
|
||||||
#include "z_zone.h"
|
#include "z_zone.h"
|
||||||
#include "console.h" // Until buffering gets finished
|
#include "console.h" // Until buffering gets finished
|
||||||
#include "k_color.h" // SRB2kart
|
#include "k_color.h" // SRB2kart
|
||||||
|
#include "i_threads.h"
|
||||||
|
|
||||||
#ifdef HWRENDER
|
#ifdef HWRENDER
|
||||||
#include "hardware/hw_main.h"
|
#include "hardware/hw_main.h"
|
||||||
|
|
@ -192,6 +193,29 @@ CV_PossibleValue_t Followercolor_cons_t[MAXSKINCOLORS+3]; // +3 to account for "
|
||||||
|
|
||||||
#define TRANSTAB_AMTMUL10 (255.0f / 10.0f)
|
#define TRANSTAB_AMTMUL10 (255.0f / 10.0f)
|
||||||
|
|
||||||
|
static void R_AllocateBlendTables(void)
|
||||||
|
{
|
||||||
|
INT32 i;
|
||||||
|
|
||||||
|
for (i = 0; i < NUMBLENDMAPS; i++)
|
||||||
|
{
|
||||||
|
if (i == blendtab_modulate)
|
||||||
|
continue;
|
||||||
|
blendtables[i] = Z_MallocAlign((NUMTRANSTABLES + 1) * 0x10000, PU_STATIC, NULL, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modulation blending only requires a single table
|
||||||
|
blendtables[blendtab_modulate] = Z_MallocAlign(0x10000, PU_STATIC, NULL, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
static void R_GenerateBlendTables_Thread(void *userdata)
|
||||||
|
{
|
||||||
|
(void)userdata;
|
||||||
|
R_GenerateBlendTables();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** \brief Initializes the translucency tables used by the Software renderer.
|
/** \brief Initializes the translucency tables used by the Software renderer.
|
||||||
*/
|
*/
|
||||||
void R_InitTranslucencyTables(void)
|
void R_InitTranslucencyTables(void)
|
||||||
|
|
@ -212,20 +236,20 @@ void R_InitTranslucencyTables(void)
|
||||||
W_ReadLump(W_GetNumForName("TRANS80"), transtables+0x70000);
|
W_ReadLump(W_GetNumForName("TRANS80"), transtables+0x70000);
|
||||||
W_ReadLump(W_GetNumForName("TRANS90"), transtables+0x80000);
|
W_ReadLump(W_GetNumForName("TRANS90"), transtables+0x80000);
|
||||||
|
|
||||||
|
R_AllocateBlendTables();
|
||||||
|
|
||||||
|
#ifdef HAVE_THREADS
|
||||||
|
I_spawn_thread("blend-tables",
|
||||||
|
R_GenerateBlendTables_Thread, NULL);
|
||||||
|
#else
|
||||||
R_GenerateBlendTables();
|
R_GenerateBlendTables();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void R_GenerateBlendTables(void)
|
void R_GenerateBlendTables(void)
|
||||||
{
|
{
|
||||||
INT32 i;
|
INT32 i;
|
||||||
|
|
||||||
for (i = 0; i < NUMBLENDMAPS; i++)
|
|
||||||
{
|
|
||||||
if (i == blendtab_modulate)
|
|
||||||
continue;
|
|
||||||
blendtables[i] = Z_MallocAlign((NUMTRANSTABLES + 1) * 0x10000, PU_STATIC, NULL, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i <= 9; i++)
|
for (i = 0; i <= 9; i++)
|
||||||
{
|
{
|
||||||
const size_t offs = (0x10000 * i);
|
const size_t offs = (0x10000 * i);
|
||||||
|
|
@ -236,8 +260,6 @@ void R_GenerateBlendTables(void)
|
||||||
R_GenerateTranslucencyTable(blendtables[blendtab_reversesubtract] + offs, AST_REVERSESUBTRACT, alpha);
|
R_GenerateTranslucencyTable(blendtables[blendtab_reversesubtract] + offs, AST_REVERSESUBTRACT, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modulation blending only requires a single table
|
|
||||||
blendtables[blendtab_modulate] = Z_MallocAlign(0x10000, PU_STATIC, NULL, 16);
|
|
||||||
R_GenerateTranslucencyTable(blendtables[blendtab_modulate], AST_MODULATE, 0);
|
R_GenerateTranslucencyTable(blendtables[blendtab_modulate], AST_MODULATE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1137,7 +1137,7 @@ void R_Init(void)
|
||||||
R_InitLightTables();
|
R_InitLightTables();
|
||||||
|
|
||||||
//I_OutputMsg("\nR_InitTranslucencyTables\n");
|
//I_OutputMsg("\nR_InitTranslucencyTables\n");
|
||||||
R_InitTranslucencyTables();
|
//R_InitTranslucencyTables();
|
||||||
|
|
||||||
R_InitDrawNodes();
|
R_InitDrawNodes();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ typedef struct
|
||||||
} spriteinfo_t;
|
} spriteinfo_t;
|
||||||
|
|
||||||
// Portable Network Graphics
|
// Portable Network Graphics
|
||||||
|
#define PNG_HEADER_SIZE (8)
|
||||||
boolean Picture_IsLumpPNG(const UINT8 *d, size_t s);
|
boolean Picture_IsLumpPNG(const UINT8 *d, size_t s);
|
||||||
#define Picture_ThrowPNGError(lumpname, wadfilename) I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .png - please convert to either Doom or Flat (raw) image format.", lumpname, wadfilename); // Fears Of LJ Sonic
|
#define Picture_ThrowPNGError(lumpname, wadfilename) I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .png - please convert to either Doom or Flat (raw) image format.", lumpname, wadfilename); // Fears Of LJ Sonic
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -725,6 +725,7 @@ Rloadflats (INT32 i, INT32 w)
|
||||||
UINT16 texstart, texend;
|
UINT16 texstart, texend;
|
||||||
texture_t *texture;
|
texture_t *texture;
|
||||||
texpatch_t *patch;
|
texpatch_t *patch;
|
||||||
|
UINT8 header[PNG_HEADER_SIZE];
|
||||||
|
|
||||||
// Yes
|
// Yes
|
||||||
if (wadfiles[w]->type == RET_PK3)
|
if (wadfiles[w]->type == RET_PK3)
|
||||||
|
|
@ -743,7 +744,6 @@ Rloadflats (INT32 i, INT32 w)
|
||||||
// Work through each lump between the markers in the WAD.
|
// Work through each lump between the markers in the WAD.
|
||||||
for (j = 0; j < (texend - texstart); j++)
|
for (j = 0; j < (texend - texstart); j++)
|
||||||
{
|
{
|
||||||
UINT8 *flatlump;
|
|
||||||
UINT16 wadnum = (UINT16)w;
|
UINT16 wadnum = (UINT16)w;
|
||||||
lumpnum_t lumpnum = texstart + j;
|
lumpnum_t lumpnum = texstart + j;
|
||||||
size_t lumplength;
|
size_t lumplength;
|
||||||
|
|
@ -755,7 +755,7 @@ Rloadflats (INT32 i, INT32 w)
|
||||||
continue; // If it is then SKIP IT
|
continue; // If it is then SKIP IT
|
||||||
}
|
}
|
||||||
|
|
||||||
flatlump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
|
W_ReadLumpHeaderPwad(wadnum, lumpnum, header, sizeof header, 0);
|
||||||
lumplength = W_LumpLengthPwad(wadnum, lumpnum);
|
lumplength = W_LumpLengthPwad(wadnum, lumpnum);
|
||||||
|
|
||||||
switch (lumplength)
|
switch (lumplength)
|
||||||
|
|
@ -790,12 +790,14 @@ Rloadflats (INT32 i, INT32 w)
|
||||||
M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name));
|
M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name));
|
||||||
|
|
||||||
#ifndef NO_PNG_LUMPS
|
#ifndef NO_PNG_LUMPS
|
||||||
if (Picture_IsLumpPNG((UINT8 *)flatlump, lumplength))
|
if (Picture_IsLumpPNG(header, lumplength))
|
||||||
{
|
{
|
||||||
|
UINT8 *flatlump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
|
||||||
INT32 width, height;
|
INT32 width, height;
|
||||||
Picture_PNGDimensions((UINT8 *)flatlump, &width, &height, NULL, NULL, lumplength);
|
Picture_PNGDimensions((UINT8 *)flatlump, &width, &height, NULL, NULL, lumplength);
|
||||||
texture->width = (INT16)width;
|
texture->width = (INT16)width;
|
||||||
texture->height = (INT16)height;
|
texture->height = (INT16)height;
|
||||||
|
Z_Free(flatlump);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -814,8 +816,6 @@ Rloadflats (INT32 i, INT32 w)
|
||||||
patch->lump = texstart + j;
|
patch->lump = texstart + j;
|
||||||
patch->flip = 0;
|
patch->flip = 0;
|
||||||
|
|
||||||
Z_Free(flatlump);
|
|
||||||
|
|
||||||
texturewidth[i] = texture->width;
|
texturewidth[i] = texture->width;
|
||||||
textureheight[i] = texture->height << FRACBITS;
|
textureheight[i] = texture->height << FRACBITS;
|
||||||
i++;
|
i++;
|
||||||
|
|
@ -835,8 +835,8 @@ Rloadtextures (INT32 i, INT32 w)
|
||||||
UINT16 j;
|
UINT16 j;
|
||||||
UINT16 texstart, texend, texturesLumpPos;
|
UINT16 texstart, texend, texturesLumpPos;
|
||||||
texture_t *texture;
|
texture_t *texture;
|
||||||
softwarepatch_t *patchlump;
|
|
||||||
texpatch_t *patch;
|
texpatch_t *patch;
|
||||||
|
softwarepatch_t patchlump;
|
||||||
|
|
||||||
// Get the lump numbers for the markers in the WAD, if they exist.
|
// Get the lump numbers for the markers in the WAD, if they exist.
|
||||||
if (wadfiles[w]->type == RET_PK3)
|
if (wadfiles[w]->type == RET_PK3)
|
||||||
|
|
@ -876,7 +876,7 @@ Rloadtextures (INT32 i, INT32 w)
|
||||||
continue; // If it is then SKIP IT
|
continue; // If it is then SKIP IT
|
||||||
}
|
}
|
||||||
|
|
||||||
patchlump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
|
W_ReadLumpHeaderPwad(wadnum, lumpnum, &patchlump, PNG_HEADER_SIZE, 0);
|
||||||
#ifndef NO_PNG_LUMPS
|
#ifndef NO_PNG_LUMPS
|
||||||
lumplength = W_LumpLengthPwad(wadnum, lumpnum);
|
lumplength = W_LumpLengthPwad(wadnum, lumpnum);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -888,18 +888,20 @@ Rloadtextures (INT32 i, INT32 w)
|
||||||
M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name));
|
M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name));
|
||||||
|
|
||||||
#ifndef NO_PNG_LUMPS
|
#ifndef NO_PNG_LUMPS
|
||||||
if (Picture_IsLumpPNG((UINT8 *)patchlump, lumplength))
|
if (Picture_IsLumpPNG((UINT8 *)&patchlump, lumplength))
|
||||||
{
|
{
|
||||||
|
UINT8 *png = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
|
||||||
INT32 width, height;
|
INT32 width, height;
|
||||||
Picture_PNGDimensions((UINT8 *)patchlump, &width, &height, NULL, NULL, lumplength);
|
Picture_PNGDimensions(png, &width, &height, NULL, NULL, lumplength);
|
||||||
texture->width = (INT16)width;
|
texture->width = (INT16)width;
|
||||||
texture->height = (INT16)height;
|
texture->height = (INT16)height;
|
||||||
|
Z_Free(png);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
texture->width = SHORT(patchlump->width);
|
texture->width = SHORT(patchlump.width);
|
||||||
texture->height = SHORT(patchlump->height);
|
texture->height = SHORT(patchlump.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
texture->type = TEXTURETYPE_SINGLEPATCH;
|
texture->type = TEXTURETYPE_SINGLEPATCH;
|
||||||
|
|
@ -915,8 +917,6 @@ Rloadtextures (INT32 i, INT32 w)
|
||||||
patch->lump = texstart + j;
|
patch->lump = texstart + j;
|
||||||
patch->flip = 0;
|
patch->flip = 0;
|
||||||
|
|
||||||
Z_Free(patchlump);
|
|
||||||
|
|
||||||
texturewidth[i] = texture->width;
|
texturewidth[i] = texture->width;
|
||||||
textureheight[i] = texture->height << FRACBITS;
|
textureheight[i] = texture->height << FRACBITS;
|
||||||
i++;
|
i++;
|
||||||
|
|
|
||||||
|
|
@ -286,16 +286,18 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16
|
||||||
|
|
||||||
#ifndef NO_PNG_LUMPS
|
#ifndef NO_PNG_LUMPS
|
||||||
{
|
{
|
||||||
softwarepatch_t *png = W_CacheLumpNumPwad(wadnum, l, PU_STATIC);
|
UINT8 header[PNG_HEADER_SIZE];
|
||||||
size_t len = W_LumpLengthPwad(wadnum, l);
|
size_t len = W_LumpLengthPwad(wadnum, l);
|
||||||
|
|
||||||
if (Picture_IsLumpPNG((UINT8 *)png, len))
|
W_ReadLumpHeaderPwad(wadnum, l, header, sizeof header, 0);
|
||||||
|
|
||||||
|
if (Picture_IsLumpPNG(header, len))
|
||||||
{
|
{
|
||||||
|
UINT8 *png = W_CacheLumpNumPwad(wadnum, l, PU_STATIC);
|
||||||
Picture_PNGDimensions((UINT8 *)png, &width, &height, &topoffset, &leftoffset, len);
|
Picture_PNGDimensions((UINT8 *)png, &width, &height, &topoffset, &leftoffset, len);
|
||||||
isPNG = true;
|
isPNG = true;
|
||||||
|
Z_Free(png);
|
||||||
}
|
}
|
||||||
|
|
||||||
Z_Free(png);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isPNG)
|
if (!isPNG)
|
||||||
|
|
|
||||||
13
src/w_wad.c
13
src/w_wad.c
|
|
@ -1480,10 +1480,10 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
|
||||||
int zErr; // Helper var.
|
int zErr; // Helper var.
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
unsigned long rawSize = l->disksize;
|
unsigned long rawSize = l->disksize;
|
||||||
unsigned long decSize = l->size;
|
unsigned long decSize = size;
|
||||||
|
|
||||||
rawData = Z_Malloc(rawSize, PU_STATIC, NULL);
|
rawData = Z_Malloc(rawSize, PU_STATIC, NULL);
|
||||||
decData = Z_Malloc(decSize, PU_STATIC, NULL);
|
decData = dest;
|
||||||
|
|
||||||
if (fread(rawData, 1, rawSize, handle) < rawSize)
|
if (fread(rawData, 1, rawSize, handle) < rawSize)
|
||||||
I_Error("wad %d, lump %d: cannot read compressed data", wad, lump);
|
I_Error("wad %d, lump %d: cannot read compressed data", wad, lump);
|
||||||
|
|
@ -1501,12 +1501,8 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
|
||||||
zErr = inflateInit2(&strm, -15);
|
zErr = inflateInit2(&strm, -15);
|
||||||
if (zErr == Z_OK)
|
if (zErr == Z_OK)
|
||||||
{
|
{
|
||||||
zErr = inflate(&strm, Z_FINISH);
|
zErr = inflate(&strm, Z_SYNC_FLUSH);
|
||||||
if (zErr == Z_STREAM_END)
|
if (zErr != Z_OK && zErr != Z_STREAM_END)
|
||||||
{
|
|
||||||
M_Memcpy(dest, decData, size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
size = 0;
|
size = 0;
|
||||||
zerr(zErr);
|
zerr(zErr);
|
||||||
|
|
@ -1520,7 +1516,6 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
|
||||||
}
|
}
|
||||||
|
|
||||||
Z_Free(rawData);
|
Z_Free(rawData);
|
||||||
Z_Free(decData);
|
|
||||||
|
|
||||||
#ifdef NO_PNG_LUMPS
|
#ifdef NO_PNG_LUMPS
|
||||||
if (Picture_IsLumpPNG((UINT8 *)dest, size))
|
if (Picture_IsLumpPNG((UINT8 *)dest, size))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue