Support reading PICTURE/MINIMAP/ENCORE/TWEAKMAP lumps from a map resource

This supersedes the header-based method of fetching those lumps.

(G: a LOT of creative liberties... but i'd rather this thing compiles)
This commit is contained in:
SteelT 2022-09-12 17:29:15 -04:00 committed by GenericHeroGuy
parent 1147d3eaa8
commit 14e5796cf2
11 changed files with 100 additions and 59 deletions

View file

@ -347,7 +347,7 @@ static bool D_Display(void)
if (gamestate != GS_LEVEL && rendermode != render_none)
{
V_SetPaletteLump("PLAYPAL"); // Reset the palette
R_ReInitColormaps(0, LUMPERROR);
R_ReInitColormaps(0, NULL, 0, false);
}
F_WipeStartScreen();

View file

@ -350,6 +350,8 @@ struct mapheader_t
{
char * lumpname; ///< Lump name can be really long
lumpnum_t lumpnum; ///< Lump number for the map
void * thumbnailPic; ///< Lump data for the level select thumbnail.
void * minimapPic; ///< Lump data for the minimap graphic.
char lvlttl[22]; ///< Level name without "Zone". (21 character limit instead of 32, 21 characters can display on screen max anyway)
char subttl[33]; ///< Subtitle for level
char zonttl[22]; ///< "ZONE" replacement name

View file

@ -3300,7 +3300,6 @@ static void K_drawKartMinimapWaypoint(waypoint_t *wp, INT32 hudx, INT32 hudy, IN
static void K_drawKartMinimap(void)
{
INT32 lumpnum;
patch_t *AutomapPic, *workingPic;
INT32 i = 0;
INT32 x, y;
@ -3323,12 +3322,12 @@ static void K_drawKartMinimap(void)
if (stplyr != &players[displayplayers[0]])
return;
lumpnum = W_CheckNumForName(va("%sR", G_BuildMapName(gamemap)));
AutomapPic = mapheaderinfo[gamemap-1]->minimapPic;
if (lumpnum != -1)
AutomapPic = W_CachePatchName(va("%sR", G_BuildMapName(gamemap)), PU_HUDGFX);
else
if (!AutomapPic)
{
return; // no pic, just get outta here
}
if (r_splitscreen < 2) // 1/2P right aligned
{

View file

@ -597,7 +597,6 @@ static int libd_drawOnMinimap(lua_State *L)
huddrawlist_h list;
// variables used to replicate k_kart's mmap drawer:
INT32 lumpnum;
patch_t *AutomapPic;
INT32 mx, my;
INT32 splitflags, minimaptrans;
@ -683,12 +682,12 @@ static int libd_drawOnMinimap(lua_State *L)
if (stplyr != &players[displayplayers[0]])
return 0;
lumpnum = W_CheckNumForName(va("%sR", G_BuildMapName(gamemap)));
AutomapPic = mapheaderinfo[gamemap-1]->minimapPic;
if (lumpnum != -1)
AutomapPic = W_CachePatchName(va("%sR", G_BuildMapName(gamemap)), PU_HUDGFX);
else
if (!AutomapPic)
{
return 0; // no pic, just get outta here
}
mx = MM_X - (AutomapPic->width/2);
my = MM_Y - (AutomapPic->height/2);

View file

@ -8947,15 +8947,11 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade)
patch_t *PictureOfLevel;
INT32 x, y, w, i, oldval, trans, dupadjust = ((vid.width/vid.dupx) - BASEVIDWIDTH)>>1;
// A 160x100 image of the level as entry MAPxxP
// A 160x100 image of the level
if (cv_nextmap.value)
{
char *mapname = va("%sP", G_BuildMapName(cv_nextmap.value+1));
SINT8 length = strlen(mapname);
lumpnum = W_CheckNumForName(mapname);
if (lumpnum != LUMPERROR && (length < 7))
PictureOfLevel = W_CachePatchNum(lumpnum, PU_CACHE);
else
PictureOfLevel = mapheaderinfo[cv_nextmap.value+1]->thumbnailPic;
if (!PictureOfLevel)
PictureOfLevel = W_CachePatchName("BLANKLVL", PU_CACHE);
}
else
@ -9018,12 +9014,8 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade)
// A 160x100 image of the level as entry MAPxxP
if (i+1)
{
char *mapname = va("%sP", G_BuildMapName(i+1));
SINT8 length = strlen(mapname);
lumpnum = W_CheckNumForName(mapname);
if (lumpnum != LUMPERROR && (length < 7))
PictureOfLevel = W_CachePatchNum(lumpnum, PU_CACHE);
else
PictureOfLevel = mapheaderinfo[i+1]->thumbnailPic;
if (!PictureOfLevel)
PictureOfLevel = W_CachePatchName("BLANKLVL", PU_CACHE);
}
else
@ -9058,12 +9050,8 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade)
// A 160x100 image of the level as entry MAPxxP
if (i+1)
{
char *mapname = va("%sP", G_BuildMapName(i+1));
SINT8 length = strlen(mapname);
lumpnum = W_CheckNumForName(mapname);
if (lumpnum != LUMPERROR && (length < 7))
PictureOfLevel = W_CachePatchNum(lumpnum, PU_CACHE);
else
PictureOfLevel = mapheaderinfo[i+1]->thumbnailPic;
if (!PictureOfLevel)
PictureOfLevel = W_CachePatchName("BLANKLVL", PU_CACHE);
}
else

View file

@ -397,7 +397,19 @@ static void P_ClearSingleMapHeaderInfo(INT16 i)
{
const INT16 num = (INT16)(i-1);
boolean exists = (mapheaderinfo[gamemap-1]->alreadyExists == true);
if (mapheaderinfo[num]->thumbnailPic)
{
Z_Free(mapheaderinfo[num]->thumbnailPic);
mapheaderinfo[num]->thumbnailPic = NULL;
}
if (mapheaderinfo[num]->minimapPic)
{
Z_Free(mapheaderinfo[num]->minimapPic);
mapheaderinfo[num]->minimapPic = NULL;
}
mapheaderinfo[num]->lvlttl[0] = '\0';
mapheaderinfo[num]->selectheading[0] = '\0';
mapheaderinfo[num]->subttl[0] = '\0';
@ -479,6 +491,8 @@ void P_AllocMapHeader(INT16 i)
mapheaderinfo[i] = Z_Malloc(sizeof(mapheader_t), PU_STATIC, NULL);
mapheaderinfo[i]->lumpnum = LUMPERROR;
mapheaderinfo[i]->lumpname = NULL;
mapheaderinfo[i]->thumbnailPic = NULL;
mapheaderinfo[i]->minimapPic = NULL;
mapheaderinfo[i]->flickies = NULL;
mapheaderinfo[i]->grades = NULL;
nummapheaders++;
@ -8152,6 +8166,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
// Map header should always be in place at this point
INT32 i, ranspecialwipe = 0;
sector_t *ss;
virtlump_t *encoreLump = NULL;
levelloading = true;
@ -8370,8 +8385,26 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
curmapvirt = vres_GetMap(lastloadedmaplumpnum);
R_ReInitColormaps(mapheaderinfo[gamemap-1]->palette,
W_CheckNumForName(va("%s%c", maplumpname, (encoremode ? 'E' : 'T'))));
if (mapheaderinfo[gamemap-1])
{
if (encoremode)
{
encoreLump = vres_Find(curmapvirt, "ENCORE");
}
else
{
encoreLump = vres_Find(curmapvirt, "TWEAKMAP");
}
}
if (encoreLump)
{
R_ReInitColormaps(mapheaderinfo[gamemap-1]->palette, encoreLump->data, encoreLump->size, false);
}
else
{
R_ReInitColormaps(mapheaderinfo[gamemap-1]->palette, NULL, 0, false);
}
CON_SetupBackColormap();
// SRB2 determines the sky texture to be used depending on the map header.
@ -8733,6 +8766,8 @@ UINT8 P_InitMapData(void)
UINT8 ret = 0;
INT32 i;
lumpnum_t maplump;
virtres_t *virtmap;
virtlump_t *minimap, *thumbnailPic;
char *name;
for (i = 0; i < nummapheaders; ++i)
@ -8768,6 +8803,23 @@ UINT8 P_InitMapData(void)
mapheaderinfo[i]->lumpnum = maplump;
if (maplump == wadnamelump)
wadnamemap = i+1;
// Get map thumbnail and minimap
virtmap = vres_GetMap(mapheaderinfo[i]->lumpnum);
thumbnailPic = vres_Find(virtmap, "PICTURE");
minimap = vres_Find(virtmap, "MINIMAP");
if (thumbnailPic)
{
mapheaderinfo[i]->thumbnailPic = vres_GetPatch(thumbnailPic, PU_CACHE);
}
if (minimap)
{
mapheaderinfo[i]->minimapPic = vres_GetPatch(minimap, PU_HUDGFX);
}
vres_Free(virtmap);
}
}
@ -8799,6 +8851,8 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, wadcompat_t compat)
UINT16 numlumps, wadnum;
char *name;
lumpinfo_t *lumpinfo;
virtres_t *virtmap;
virtlump_t *minimap, *thumbnailPic;
// Vars to help us with the position start and amount of each resource type.
// Useful for PK3s since they use folders.

View file

@ -287,7 +287,7 @@ void R_InitColormaps(void)
#endif
}
void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap)
void R_ReInitColormaps(UINT16 num, void *newencoremap, size_t encoremapsize, boolean compat)
{
char colormap[9] = "COLORMAP";
lumpnum_t lump;
@ -325,18 +325,17 @@ void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap)
}
// Encore mode.
if (newencoremap != LUMPERROR)
if (newencoremap)
{
lighttable_t *colormap_p, *colormap_p2;
size_t p, i;
encoremap = Z_MallocAlign(256 + 10, PU_LEVEL, NULL, 8);
W_ReadLump(newencoremap, encoremap);
M_Memcpy(encoremap, newencoremap, encoremapsize);
colormap_p = colormap_p2 = colormaps;
colormap_p += COLORMAP_REMAPOFFSET;
remap = wadfiles[WADFILENUM(newencoremap)]->compatmode;
if (remap)
if (compat)
{
UINT8 *copy = malloc(256);
memcpy(copy, encoremap, 256);

View file

@ -55,7 +55,7 @@ extern size_t flatmemory, spritememory, texturememory;
//#define COLORMAPREVERSELIST
void R_InitColormaps(void);
void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap);
void R_ReInitColormaps(UINT16 num, void *newencoremap, size_t encoremapsize, boolean compat);
void R_ClearColormaps(void);
extracolormap_t *R_CreateDefaultColormap(boolean lighttable);
extracolormap_t *R_GetDefaultColormap(void);

View file

@ -1979,7 +1979,7 @@ void *W_CacheLumpName(const char *name, INT32 tag)
// Cache a patch into heap memory, convert the patch format as necessary
//
static void MakePatch(void *lumpdata, size_t size, INT32 tag, void *cache, boolean remap)
static void *MakePatch(void *lumpdata, size_t size, INT32 tag, void *cache, boolean remap)
{
void *ptr, *dest;
size_t len = size;
@ -1995,9 +1995,10 @@ static void MakePatch(void *lumpdata, size_t size, INT32 tag, void *cache, boole
R_DoPaletteRemapPatch(ptr, len);
dest = Z_Calloc(sizeof(patch_t), tag, cache);
Patch_Create(ptr, len, dest);
Z_Free(ptr);
return dest;
}
void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
@ -2018,6 +2019,7 @@ void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
W_ReadLumpHeaderPwad(wad, lump, lumpdata, 0, 0);
MakePatch(lumpdata, len, tag, &lumpcache[lump], wadfiles[wad]->compatmode);
Z_Free(lumpdata);
}
else
Z_ChangeTag(lumpcache[lump], tag);
@ -2504,7 +2506,6 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
vlumps[i].name[8] = '\0';
vlumps[i].data = Z_Malloc(vlumps[i].size, PU_LEVEL, NULL); // This is memory inefficient, sorry about that.
memcpy(vlumps[i].data, wadData + (fileinfo + i)->filepos, vlumps[i].size);
vlumps[i].cache = NULL;
}
Z_Free(wadData);
@ -2536,7 +2537,6 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
memcpy(vlumps[i].name, W_CheckNameForNum(lumpnum), 8);
vlumps[i].name[8] = '\0';
vlumps[i].data = W_CacheLumpNum(lumpnum, PU_LEVEL);
vlumps[i].cache = NULL;
}
}
vres = Z_Malloc(sizeof(virtres_t), PU_LEVEL, NULL);
@ -2559,7 +2559,12 @@ void vres_Free(virtres_t* vres)
}
while (vres->numlumps--)
Z_Free(vres->vlumps[vres->numlumps].data);
{
if (vres->vlumps[vres->numlumps].data)
{
Z_Free(vres->vlumps[vres->numlumps].data);
}
}
Z_Free(vres->vlumps);
Z_Free(vres);
}
@ -2604,14 +2609,7 @@ void *vres_GetPatch(virtlump_t *vlump, INT32 tag)
if (!vlump)
return NULL;
if (!vlump->cache)
{
MakePatch(vlump->data, vlump->size, tag, &vlump->cache, false);
}
else
Z_ChangeTag(vlump->cache, tag);
patch = vlump->cache;
patch = MakePatch(vlump->data, vlump->size, tag, NULL, false);
#ifdef HWRENDER
// Software-only compile cache the data without conversion

View file

@ -82,7 +82,6 @@ struct virtlump_t {
char name[9];
UINT8* data;
size_t size;
void *cache;
};
struct virtres_t {
@ -93,7 +92,7 @@ struct virtres_t {
virtres_t* vres_GetMap(lumpnum_t);
void vres_Free(virtres_t*);
virtlump_t* vres_Find(const virtres_t*, const char*);
void* vres_GetPatch(virtlump_t *vlump, INT32 tag);
void* vres_GetPatch(virtlump_t *vlump, INT32);
// =========================================================================
// DYNAMIC WAD LOADING

View file

@ -1640,8 +1640,6 @@ void Y_StartVote(void)
for (i = 0; i < 4; i++)
{
lumpnum_t lumpnum;
// set up the encore
levelinfo[i].encore = (votelevels[i][1] & 0x80);
votelevels[i][1] &= ~0x80;
@ -1684,9 +1682,14 @@ void Y_StartVote(void)
levelinfo[i].gts = NULL;
// set up the pic
lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(votelevels[i][0]+1)));
if (lumpnum != LUMPERROR)
levelinfo[i].pic = W_CachePatchName(va("%sP", G_BuildMapName(votelevels[i][0]+1)), PU_STATIC);
patch_t *thumbnailPic = NULL;
if (mapheaderinfo[votelevels[i][0]+1])
{
thumbnailPic = mapheaderinfo[votelevels[i][0]]->thumbnailPic;
}
if (thumbnailPic)
levelinfo[i].pic = thumbnailPic;
else
levelinfo[i].pic = W_CachePatchName("BLANKLVL", PU_STATIC);
}