Skip to content

Commit

Permalink
Better fix for loading textures in Scientist 2023
Browse files Browse the repository at this point in the history
Commit 939321e brought back bug described here: https://www.doomworld.com/forum/post/2039799.
  • Loading branch information
bradharding committed Nov 19, 2024
1 parent 2b7e84a commit f0db099
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/r_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,44 @@ static void R_InitTextures(void)
const int *maptex1;
const int *maptex2 = NULL;
char name[9];
char *names = W_CacheLumpName("PNAMES");
char *name_p = names + 4;
int nummappatches = LONG(*((int *)names));
int *patchlookup = malloc(nummappatches * sizeof(*patchlookup));
int *patchlookup;
int nummappatches = 0;
int maxoff;
int maxoff2 = 0;
int numtextures1;
int numtextures2 = 0;
const int *directory;

for (int i = 0; i < nummappatches; i++)
{
strncpy(name, name_p + i * 8, 8);
patchlookup[i] = W_CheckNumForName(name);
}
for (int i = numlumps - 1; i >= 0; i--)
if (!strncasecmp(lumpinfo[i]->name, "PNAMES", 6))
{
if (numpnameslumps == maxpnameslumps)
{
maxpnameslumps++;
pnameslumps = I_Realloc(pnameslumps, maxpnameslumps * sizeof(pnameslump_t));
}

pnameslumps[numpnameslumps].names = W_CacheLumpNum(i);
pnameslumps[numpnameslumps].nummappatches = LONG(*((int *)pnameslumps[numpnameslumps].names));

// [crispy] accumulated number of patches in the lookup tables excluding the current one
pnameslumps[numpnameslumps].name_p = (char *)pnameslumps[numpnameslumps].names + 4;

// [crispy] calculate total number of patches
nummappatches += pnameslumps[numpnameslumps].nummappatches;
numpnameslumps++;
}

patchlookup = malloc(nummappatches * sizeof(*patchlookup)); // killough

for (int i = 0, patch = 0; i < numpnameslumps; i++)
for (int j = 0; j < pnameslumps[i].nummappatches; j++)
{
M_StringCopy(name, &pnameslumps[i].name_p[j * 8], sizeof(name));
patchlookup[patch++] = W_CheckNumForName(name);
}

Z_Free(names);
free(pnameslumps);

// Load the map texture definitions from textures.lmp.
// The data is contained in one or two lumps,
Expand Down

0 comments on commit f0db099

Please sign in to comment.