// // R_GetColumn // byte *R_GetColumn(int tex, int col) { int lump; int ofs; if (lookuptextures[tex] == false) R_GenerateLookup(tex); col &= texturewidthmask[tex]; lump = texturecolumnlump[tex][col]; ofs = texturecolumnofs[tex][col]; if (lump > 0) return ((byte *)W_CacheLumpNum(lump, PU_CACHE) + ofs); if (!texturecomposite[tex]) R_GenerateComposite(tex); return (texturecomposite[tex] + ofs); }
// // R_InitTextures // Initializes the texture list // with the textures from the world map. // void R_InitTextures (void) { maptexture_t* mtexture; texture_t* texture; mappatch_t* mpatch; texpatch_t* patch; int i; int j; int* maptex; int* maptex2; int* maptex1; char name[9]; char* names; char* name_p; int* patchlookup; int totalwidth; int nummappatches; int offset; int maxoff; int maxoff2; int numtextures1; int numtextures2; int* directory; int temp1; int temp2; int temp3; // Load the patch names from pnames.lmp. name[8] = 0; names = W_CacheLumpName ("PNAMES", PU_STATIC); nummappatches = LONG ( *((int *)names) ); name_p = names+4; patchlookup = _alloca (nummappatches*sizeof(*patchlookup)); for (i=0 ; i<nummappatches ; i++) { strncpy (name,name_p+i*8, 8); patchlookup[i] = W_CheckNumForName (name); } Z_Free (names); // Load the map texture definitions from textures.lmp. // The data is contained in one or two lumps, // TEXTURE1 for shareware, plus TEXTURE2 for commercial. maptex = maptex1 = W_CacheLumpName ("TEXTURE1", PU_STATIC); numtextures1 = LONG(*maptex); maxoff = W_LumpLength (W_GetNumForName ("TEXTURE1")); directory = maptex+1; if (W_CheckNumForName ("TEXTURE2") != -1) { maptex2 = W_CacheLumpName ("TEXTURE2", PU_STATIC); numtextures2 = LONG(*maptex2); maxoff2 = W_LumpLength (W_GetNumForName ("TEXTURE2")); } else { maptex2 = NULL; numtextures2 = 0; maxoff2 = 0; } numtextures = numtextures1 + numtextures2; textures = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecolumnlump = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecolumnofs = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecomposite = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecompositesize = Z_Malloc (numtextures*4, PU_STATIC, 0); texturewidthmask = Z_Malloc (numtextures*4, PU_STATIC, 0); textureheight = Z_Malloc (numtextures*4, PU_STATIC, 0); totalwidth = 0; // Really complex printing shit... temp1 = W_GetNumForName ("S_START"); // P_??????? temp2 = W_GetNumForName ("S_END") - 1; temp3 = ((temp2-temp1+63)/64) + ((numtextures+63)/64); printf("["); for (i = 0; i < temp3; i++) printf(" "); printf(" ]"); for (i = 0; i < temp3; i++) printf("\x8"); printf("\x8\x8\x8\x8\x8\x8\x8\x8\x8\x8"); for (i=0 ; i<numtextures ; i++, directory++) { if (!(i&63)) printf ("."); if (i == numtextures1) { // Start looking in second texture file. maptex = maptex2; maxoff = maxoff2; directory = maptex+1; } offset = LONG(*directory); if (offset > maxoff) I_Error ("R_InitTextures: bad texture directory"); mtexture = (maptexture_t *) ( (byte *)maptex + offset); texture = textures[i] = Z_Malloc (sizeof(texture_t) + sizeof(texpatch_t)*(SHORT(mtexture->patchcount)-1), PU_STATIC, 0); texture->width = SHORT(mtexture->width); texture->height = SHORT(mtexture->height); texture->patchcount = SHORT(mtexture->patchcount); memcpy (texture->name, mtexture->name, sizeof(texture->name)); mpatch = &mtexture->patches[0]; patch = &texture->patches[0]; for (j=0 ; j<texture->patchcount ; j++, mpatch++, patch++) { patch->originx = SHORT(mpatch->originx); patch->originy = SHORT(mpatch->originy); patch->patch = patchlookup[SHORT(mpatch->patch)]; if (patch->patch == -1) { I_Error ("R_InitTextures: Missing patch in texture %s", texture->name); } } texturecolumnlump[i] = Z_Malloc (texture->width*2, PU_STATIC,0); texturecolumnofs[i] = Z_Malloc (texture->width*2, PU_STATIC,0); j = 1; while (j*2 <= texture->width) j<<=1; texturewidthmask[i] = j-1; textureheight[i] = texture->height<<FRACBITS; totalwidth += texture->width; } Z_Free (maptex1); if (maptex2) Z_Free (maptex2); // Precalculate whatever possible. for (i=0 ; i<numtextures ; i++) R_GenerateLookup (i); // Create translation table for global animation. texturetranslation = Z_Malloc ((numtextures+1)*4, PU_STATIC, 0); for (i=0 ; i<numtextures ; i++) texturetranslation[i] = i; }
// // R_InitTextures // Initializes the texture list // with the textures from the world map. // void R_InitTextures (void) { maptexture_t* mtexture; texture_t* texture; mappatch_t* mpatch; texpatch_t* patch; int i; int j; int* maptex; int* maptex2; int* maptex1; int* patchlookup; int totalwidth; int nummappatches; int offset; int maxoff; int maxoff2; int numtextures1; int numtextures2; int* directory; int errors = 0; // Load the patch names from pnames.lmp. { char *names = (char *)W_CacheLumpName ("PNAMES", PU_STATIC); char *name_p = names+4; nummappatches = LELONG ( *((int *)names) ); patchlookup = new int[nummappatches]; for (i = 0; i < nummappatches; i++) { patchlookup[i] = W_CheckNumForName (name_p + i*8); if (patchlookup[i] == -1) { // killough 4/17/98: // Some wads use sprites as wall patches, so repeat check and // look for sprites this time, but only if there were no wall // patches found. This is the same as allowing for both, except // that wall patches always win over sprites, even when they // appear first in a wad. This is a kludgy solution to the wad // lump namespace problem. patchlookup[i] = W_CheckNumForName (name_p + i*8, ns_sprites); } } Z_Free (names); } // Load the map texture definitions from textures.lmp. // The data is contained in one or two lumps, // TEXTURE1 for shareware, plus TEXTURE2 for commercial. maptex = maptex1 = (int *)W_CacheLumpName ("TEXTURE1", PU_STATIC); numtextures1 = LELONG(*maptex); maxoff = W_LumpLength (W_GetNumForName ("TEXTURE1")); directory = maptex+1; if (W_CheckNumForName ("TEXTURE2") != -1) { maptex2 = (int *)W_CacheLumpName ("TEXTURE2", PU_STATIC); numtextures2 = LELONG(*maptex2); maxoff2 = W_LumpLength (W_GetNumForName ("TEXTURE2")); } else { maptex2 = NULL; numtextures2 = 0; maxoff2 = 0; } // denis - fix memory leaks for (i = 0; i < numtextures; i++) { delete[] texturecolumnlump[i]; delete[] texturecolumnofs[i]; } // denis - fix memory leaks delete[] textures; delete[] texturecolumnlump; delete[] texturecolumnofs; delete[] texturecomposite; delete[] texturecompositesize; delete[] texturewidthmask; delete[] textureheight; delete[] texturescalex; delete[] texturescaley; numtextures = numtextures1 + numtextures2; textures = new texture_t *[numtextures]; texturecolumnlump = new short *[numtextures]; texturecolumnofs = new unsigned int *[numtextures]; texturecomposite = new byte *[numtextures]; texturecompositesize = new int[numtextures]; texturewidthmask = new int[numtextures]; textureheight = new fixed_t[numtextures]; texturescalex = new fixed_t[numtextures]; texturescaley = new fixed_t[numtextures]; totalwidth = 0; for (i = 0; i < numtextures; i++, directory++) { if (i == numtextures1) { // Start looking in second texture file. maptex = maptex2; maxoff = maxoff2; directory = maptex+1; } offset = LELONG(*directory); if (offset > maxoff) I_FatalError ("R_InitTextures: bad texture directory"); mtexture = (maptexture_t *) ( (byte *)maptex + offset); texture = textures[i] = (texture_t *) Z_Malloc (sizeof(texture_t) + sizeof(texpatch_t)*(SAFESHORT(mtexture->patchcount)-1), PU_STATIC, 0); texture->width = SAFESHORT(mtexture->width); texture->height = SAFESHORT(mtexture->height); texture->patchcount = SAFESHORT(mtexture->patchcount); strncpy (texture->name, mtexture->name, 9); // denis - todo string limit? std::transform(texture->name, texture->name + strlen(texture->name), texture->name, toupper); mpatch = &mtexture->patches[0]; patch = &texture->patches[0]; for (j=0 ; j<texture->patchcount ; j++, mpatch++, patch++) { patch->originx = LESHORT(mpatch->originx); patch->originy = LESHORT(mpatch->originy); patch->patch = patchlookup[LESHORT(mpatch->patch)]; if (patch->patch == -1) { Printf (PRINT_HIGH, "R_InitTextures: Missing patch in texture %s\n", texture->name); errors++; } } texturecolumnlump[i] = new short[texture->width]; texturecolumnofs[i] = new unsigned int[texture->width]; for (j = 1; j*2 <= texture->width; j <<= 1) ; texturewidthmask[i] = j-1; textureheight[i] = texture->height << FRACBITS; // [RH] Special for beta 29: Values of 0 will use the tx/ty cvars // to determine scaling instead of defaulting to 8. I will likely // remove this once I finish the betas, because by then, users // should be able to actually create scaled textures. texturescalex[i] = mtexture->scalex ? mtexture->scalex << (FRACBITS - 3) : FRACUNIT; texturescaley[i] = mtexture->scaley ? mtexture->scaley << (FRACBITS - 3) : FRACUNIT; totalwidth += texture->width; } delete[] patchlookup; Z_Free (maptex1); if (maptex2) Z_Free (maptex2); if (errors) I_FatalError ("%d errors in R_InitTextures.", errors); // [RH] Setup hash chains. Go from back to front so that if // duplicates are found, the first one gets used instead // of the last (thus mimicing the original behavior // of R_CheckTextureNumForName(). for (i = 0; i < numtextures; i++) textures[i]->index = -1; for (i = numtextures - 1; i >= 0; i--) { j = 0; //W_LumpNameHash (textures[i]->name) % (unsigned) numtextures; textures[i]->next = textures[j]->index; textures[j]->index = i; } if (clientside) // server doesn't need to load patches ever { // Precalculate whatever possible. for (i = 0; i < numtextures; i++) R_GenerateLookup (i, &errors); } // if (errors) // I_FatalError ("%d errors encountered during texture generation.", errors); // Create translation table for global animation. delete[] texturetranslation; texturetranslation = new int[numtextures+1]; for (i = 0; i < numtextures; i++) texturetranslation[i] = i; }
// // R_InitTextures // Initializes the texture list // with the textures from the world map. // static void R_InitTextures(void) { maptexture_t *mtexture; texture_t *texture; mappatch_t *mpatch; texpatch_t *patch; int i; int j; int *maptex; int *maptex2; int *maptex1; char name[9]; char *names; char *name_p; int *patchlookup; int totalwidth; int nummappatches; int offset; int maxoff; int maxoff2; int numtextures1; int numtextures2; int *directory; // Load the patch names from pnames.lmp. name[8] = 0; names = (char *)W_CacheLumpName("PNAMES", PU_STATIC); nummappatches = LONG(*((int *)names)); name_p = names + 4; patchlookup = (int *)Z_Malloc(nummappatches * sizeof(*patchlookup), PU_STATIC, NULL); for (i = 0; i < nummappatches; i++) { M_StringCopy(name, name_p + i * 8, sizeof(name)); patchlookup[i] = W_CheckNumForName(name); } W_ReleaseLumpName("PNAMES"); // Load the map texture definitions from textures.lmp. // The data is contained in one or two lumps, // TEXTURE1 for shareware, plus TEXTURE2 for commercial. maptex = maptex1 = W_CacheLumpName("TEXTURE1", PU_STATIC); numtextures1 = LONG(*maptex); maxoff = W_LumpLength(W_GetNumForName("TEXTURE1")); directory = maptex + 1; if (W_CheckNumForName("TEXTURE2") != -1) { maptex2 = W_CacheLumpName("TEXTURE2", PU_STATIC); numtextures2 = LONG(*maptex2); maxoff2 = W_LumpLength(W_GetNumForName("TEXTURE2")); } else { maptex2 = NULL; numtextures2 = 0; maxoff2 = 0; } numtextures = numtextures1 + numtextures2; textures = Z_Malloc(numtextures * sizeof(*textures), PU_STATIC, 0); texturecolumnlump = Z_Malloc(numtextures * sizeof(*texturecolumnlump), PU_STATIC, 0); texturecolumnofs = Z_Malloc(numtextures * sizeof(*texturecolumnofs), PU_STATIC, 0); texturecomposite = Z_Malloc(numtextures * sizeof(*texturecomposite), PU_STATIC, 0); texturecompositesize = Z_Malloc(numtextures * sizeof(*texturecompositesize), PU_STATIC, 0); texturewidthmask = Z_Malloc(numtextures * sizeof(*texturewidthmask), PU_STATIC, 0); textureheight = Z_Malloc(numtextures * sizeof(*textureheight), PU_STATIC, 0); texturefullbright = Z_Malloc(numtextures * sizeof(*texturefullbright), PU_STATIC, 0); totalwidth = 0; for (i = 0; i < numtextures; i++, directory++) { if (i == numtextures1) { // Start looking in second texture file. maptex = maptex2; maxoff = maxoff2; directory = maptex + 1; } offset = LONG(*directory); if (offset > maxoff) I_Error("R_InitTextures: bad texture directory"); mtexture = (maptexture_t *)((byte *)maptex + offset); texture = textures[i] = Z_Malloc(sizeof(texture_t) + sizeof(texpatch_t) * (SHORT(mtexture->patchcount) - 1), PU_STATIC, 0); texture->width = SHORT(mtexture->width); texture->height = SHORT(mtexture->height); texture->patchcount = SHORT(mtexture->patchcount); memcpy(texture->name, mtexture->name, sizeof(texture->name)); mpatch = &mtexture->patches[0]; patch = &texture->patches[0]; for (j = 0; j < texture->patchcount; j++, mpatch++, patch++) { patch->originx = SHORT(mpatch->originx); patch->originy = SHORT(mpatch->originy); patch->patch = patchlookup[SHORT(mpatch->patch)]; if (patch->patch == -1) patch->patch = 0; // [crispy] make non-fatal } texturecolumnlump[i] = Z_Malloc(texture->width * sizeof(**texturecolumnlump), PU_STATIC, 0); texturecolumnofs[i] = Z_Malloc(texture->width * sizeof(**texturecolumnofs), PU_STATIC, 0); for (j = 1; j * 2 <= texture->width; j <<= 1); texturewidthmask[i] = j - 1; textureheight[i] = texture->height << FRACBITS; totalwidth += texture->width; R_DoomTextureHacks(texture); } Z_Free(patchlookup); W_ReleaseLumpName("TEXTURE1"); if (maptex2) W_ReleaseLumpName("TEXTURE2"); lookuptextures = Z_Malloc(numtextures * sizeof(boolean), PU_STATIC, 0); for (i = 0; i < numtextures; i++) lookuptextures[i] = false; lookupprogress = numtextures; // Precalculate whatever possible. for (i = 0; i < numtextures; i++) R_GenerateLookup(i); // Create translation table for global animation. texturetranslation = Z_Malloc((numtextures + 1) * sizeof(*texturetranslation), PU_STATIC, 0); for (i = 0; i < numtextures; i++) texturetranslation[i] = i; GenerateTextureHashTable(); // [BH] Initialize partially fullbright textures. memset(texturefullbright, 0, numtextures * sizeof(*texturefullbright)); if (brightmaps) { i = 0; while (fullbright[i].colormask) { if (fullbright[i].texture) { int num = R_CheckTextureNumForName(fullbright[i].texture); if (num != -1) texturefullbright[num] = fullbright[i].colormask; i++; } } } }
/* ================== = = R_InitTextures = = Initializes the texture list with the textures from the world map = ================== */ void R_InitTextures (void) { maptexture_t *mtexture; texture_t *texture; dstex_t *texture_ds; mappatch_t *mpatch; texpatch_t *patch; int i,j; int *maptex, *maptex2, *maptex1; char name[9], *names, *name_p; int *patchlookup; int totalwidth; int nummappatches; int offset, maxoff, maxoff2; int numtextures1, numtextures2; int *directory; // // load the patch names from pnames.lmp // name[8] = 0; names = W_CacheLumpName ("PNAMES", PU_STATIC); nummappatches = LONG ( *((int *)names) ); name_p = names+4; patchlookup = malloc (nummappatches*sizeof(*patchlookup)); if(patchlookup == 0) { I_Error("patchlookup == 0\n"); } for (i=0 ; i<nummappatches ; i++) { strncpy (name,name_p+i*8, 8); patchlookup[i] = W_CheckNumForName (name); } Z_Free (names); // // load the map texture definitions from textures.lmp // maptex = maptex1 = W_CacheLumpName ("TEXTURE1", PU_STATIC); numtextures1 = LONG(*maptex); maxoff = W_LumpLength (W_GetNumForName ("TEXTURE1")); directory = maptex+1; if (W_CheckNumForName ("TEXTURE2") != -1) { maptex2 = W_CacheLumpName ("TEXTURE2", PU_STATIC); numtextures2 = LONG(*maptex2); maxoff2 = W_LumpLength (W_GetNumForName ("TEXTURE2")); } else { maptex2 = NULL; numtextures2 = 0; maxoff2 = 0; } numtextures = numtextures1 + numtextures2; printf("num textures %d\n",numtextures); // // Init the startup thermometer at this point... // { int spramount; spramount = W_GetNumForName("S_END") - W_GetNumForName("S_START") + 1; InitThermo(spramount + numtextures + 6); } textures = Z_Malloc (numtextures*4, PU_STATIC, 0); textures_ds = Z_Malloc (numtextures*sizeof(*textures_ds), PU_STATIC, 0); texturecolumnlump = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecolumnofs = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecomposite = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecompositesize = Z_Malloc (numtextures*4, PU_STATIC, 0); texturewidthmask = Z_Malloc (numtextures*4, PU_STATIC, 0); textureheight = Z_Malloc (numtextures*4, PU_STATIC, 0); totalwidth = 0; for (i=0 ; i<numtextures ; i++, directory++) { #ifdef __NEXT__ if(!(i&63)) printf ("."); #else IncThermo(); #endif if (i == numtextures1) { // start looking in second texture file maptex = maptex2; maxoff = maxoff2; directory = maptex+1; } offset = LONG(*directory); if (offset > maxoff) I_Error ("R_InitTextures: bad texture directory"); mtexture = (maptexture_t *) ( (byte *)maptex + offset); texture = textures[i] = Z_Malloc (sizeof(texture_t) + sizeof(texpatch_t)*(SHORT(mtexture->patchcount)-1), PU_STATIC, 0); texture->width = SHORT(mtexture->width); texture->height = SHORT(mtexture->height); texture->patchcount = SHORT(mtexture->patchcount); texture_ds = &textures_ds[i]; ds_init_texture(i,texture,texture_ds); memcpy (texture->name, mtexture->name, sizeof(texture->name)); //printf("%d: %p %8s %p %8s\n",i,texture->name,texture->name,mtexture->name,mtexture->name); if(*texture->name == 0) { while(1); } mpatch = &mtexture->patches[0]; patch = &texture->patches[0]; for (j=0 ; j<texture->patchcount ; j++, mpatch++, patch++) { patch->originx = SHORT(mpatch->originx); patch->originy = SHORT(mpatch->originy); patch->patch = patchlookup[SHORT(mpatch->patch)]; if (patch->patch == -1) I_Error ( "R_InitTextures: Missing patch in texture %s",texture->name); } texturecolumnlump[i] = Z_Malloc (texture->width*2, PU_STATIC,0); texturecolumnofs[i] = Z_Malloc (texture->width*2, PU_STATIC,0); j = 1; while (j*2 <= texture->width) j<<=1; texturewidthmask[i] = j-1; textureheight[i] = texture->height<<FRACBITS; totalwidth += texture->width; } free(patchlookup); Z_Free (maptex1); if (maptex2) Z_Free (maptex2); // // precalculate whatever possible // for(i = 0; i < numtextures; i++) { R_GenerateLookup(i); CheckAbortStartup(); } // // translation table for global animation // texturetranslation = Z_Malloc ((numtextures+1)*4, PU_STATIC, 0); for (i=0 ; i<numtextures ; i++) texturetranslation[i] = i; ds_init_textures();
// // R_InitTextures // Initializes the texture list // with the textures from the world map. // void R_InitTextures (void) { maptexture_t* mtexture; texture_t* texture; mappatch_t* mpatch; texpatch_t* patch; int i; int j; int* maptex; int* maptex2; int* maptex1; std::string name(9,'0'); char* names; char* name_p; int* patchlookup; int totalwidth; int nummappatches; int offset; int maxoff; int maxoff2; int numtextures1; int numtextures2; int* directory; int temp1; int temp2; int temp3; // Load the patch names from pnames.lmp. names = (char*)WadManager::getLump ("PNAMES"); nummappatches = *((int *)names) ; name_p = names+4; patchlookup = (int*)alloca (nummappatches*sizeof(*patchlookup)); for (i=0 ; i<nummappatches ; i++) { name = std::string(name_p+i*8, 8); patchlookup[i] = WadManager::checkNumForName (name); } // Load the map texture definitions from textures.lmp. // The data is contained in one or two lumps, // TEXTURE1 for shareware, plus TEXTURE2 for commercial. maptex = maptex1 = (int*)WadManager::getLump ("TEXTURE1"); numtextures1 = *maptex; maxoff = WadManager::getLumpLength (WadManager::getNumForName ("TEXTURE1")); directory = maptex+1; if (WadManager::checkNumForName ("TEXTURE2") != -1) { maptex2 = (int*)WadManager::getLump ("TEXTURE2"); numtextures2 = *maptex2; maxoff2 = WadManager::getLumpLength (WadManager::getNumForName ("TEXTURE2")); } else { maptex2 = NULL; numtextures2 = 0; maxoff2 = 0; } numtextures = numtextures1 + numtextures2; textures = (texture_t**)malloc (numtextures*sizeof(void*)); texturecolumnlump = (short**)malloc (numtextures*sizeof(void*)); texturecolumnofs = (unsigned short**)malloc (numtextures*sizeof(void*)); texturecomposite = (unsigned char**)malloc (numtextures*sizeof(void*)); texturecompositesize = (int*)malloc (numtextures*sizeof(void*)); texturewidthmask = (int*)malloc (numtextures*sizeof(void*)); textureheight = (int*)malloc (numtextures*sizeof(void*)); totalwidth = 0; // Really complex printing shit... temp1 = WadManager::getNumForName ("S_START"); // P_??????? temp2 = WadManager::getNumForName ("S_END") - 1; temp3 = ((temp2-temp1+63)/64) + ((numtextures+63)/64); printf("["); for (i = 0; i < temp3; i++) printf(" "); printf(" ]"); for (i = 0; i < temp3; i++) printf("\x8"); printf("\x8\x8\x8\x8\x8\x8\x8\x8\x8\x8"); for (i=0 ; i<numtextures ; i++, directory++) { if (!(i&63)) printf ("."); if (i == numtextures1) { // Start looking in second texture file. maptex = maptex2; maxoff = maxoff2; directory = maptex+1; } offset = *directory; if (offset > maxoff) I_Error ("R_InitTextures: bad texture directory"); mtexture = (maptexture_t *) ( (unsigned char *)maptex + offset); texture = textures[i] = (texture_t*)malloc (sizeof(texture_t) + sizeof(texpatch_t)*(mtexture->patchcount-1)); texture->width = mtexture->width; texture->height = mtexture->height; texture->patchcount = mtexture->patchcount; memcpy (texture->name, mtexture->name, sizeof(texture->name)); mpatch = &mtexture->patches[0]; patch = &texture->patches[0]; for (j=0 ; j<texture->patchcount ; j++, mpatch++, patch++) { patch->originx = mpatch->originx; patch->originy = mpatch->originy; patch->patch = patchlookup[short(mpatch->patch)]; if (patch->patch == -1) { I_Error ("R_InitTextures: Missing patch in texture %s", texture->name); } } texturecolumnlump[i] = (short*)malloc (texture->width*2); texturecolumnofs[i] = (unsigned short*)malloc (texture->width*2); j = 1; while (j*2 <= texture->width) j<<=1; texturewidthmask[i] = j-1; textureheight[i] = texture->height<<FRACBITS; totalwidth += texture->width; } // Precalculate whatever possible. for (i=0 ; i<numtextures ; i++) R_GenerateLookup (i); // Create translation table for global animation. texturetranslation = (int*)malloc ((numtextures+1)*4); for (i=0 ; i<numtextures ; i++) texturetranslation[i] = i; }
/* ================== = = R_InitTextures = = Initializes the texture list with the textures from the world map = ================== */ void R_InitTextures (void) { maptexture_t *mtexture; texture_t *texture; mappatch_t *mpatch; texpatch_t *patch; int i,j; int *maptex, *maptex2, *maptex1; char name[9], *names, *name_p; int *patchlookup; int totalwidth; int nummappatches; int offset, maxoff, maxoff2; int numtextures1, numtextures2; int *directory; // // load the patch names from pnames.lmp // name[8] = 0; names = W_CacheLumpName ("PNAMES", PU_STATIC); nummappatches = LONG ( *((int *)names) ); name_p = names+4; //rww begin patchlookup = alloca (nummappatches*sizeof(*patchlookup)); //patchlookup = Z_Malloc(nummappatches*sizeof(*patchlookup), PU_STATIC, 0); //rww end for (i=0 ; i<nummappatches ; i++) { strncpy (name,name_p+i*8, 8); patchlookup[i] = W_CheckNumForName (name); } Z_Free (names); // // load the map texture definitions from textures.lmp // maptex = maptex1 = W_CacheLumpName ("TEXTURE1", PU_STATIC); numtextures1 = LONG(*maptex); maxoff = W_LumpLength (W_GetNumForName ("TEXTURE1")); directory = maptex+1; if (W_CheckNumForName ("TEXTURE2") != -1) { maptex2 = W_CacheLumpName ("TEXTURE2", PU_STATIC); numtextures2 = LONG(*maptex2); maxoff2 = W_LumpLength (W_GetNumForName ("TEXTURE2")); } else { maptex2 = NULL; numtextures2 = 0; maxoff2 = 0; } numtextures = numtextures1 + numtextures2; //rww begin ST_Message("R_InitTextures: %i\n", numtextures); //rww end textures = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecolumnlump = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecolumnofs = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecomposite = Z_Malloc (numtextures*4, PU_STATIC, 0); texturecompositesize = Z_Malloc (numtextures*4, PU_STATIC, 0); texturewidthmask = Z_Malloc (numtextures*4, PU_STATIC, 0); textureheight = Z_Malloc (numtextures*4, PU_STATIC, 0); totalwidth = 0; for (i=0 ; i<numtextures ; i++, directory++) { if (i == numtextures1) { // start looking in second texture file maptex = maptex2; maxoff = maxoff2; directory = maptex+1; } offset = LONG(*directory); if (offset > maxoff) I_Error ("R_InitTextures: bad texture directory"); mtexture = (maptexture_t *) ( (byte *)maptex + offset); #ifdef _TEXTURE_PATCH_DEBUG ST_Message("%s: %i, %i, %i, %i, %i \n", mtexture->name, mtexture->patches[0].patch, mtexture->patches[0].colormap, mtexture->patches[0].originx, mtexture->patches[0].originy, mtexture->patches[0].stepdir); #ifdef _HEXENDS { int j = 0; while (j < 60) { swiWaitForVBlank(); j++; } } #endif #endif texture = textures[i] = Z_Malloc (sizeof(texture_t) + sizeof(texpatch_t)*(SHORT(mtexture->patchcount)-1), PU_STATIC, 0); texture->width = SHORT(mtexture->width); texture->height = SHORT(mtexture->height); texture->patchcount = SHORT(mtexture->patchcount); memcpy (texture->name, mtexture->name, sizeof(texture->name)); mpatch = &mtexture->patches[0]; patch = &texture->patches[0]; // ST_Message("tex (%s: %i %i %i %i %i %i)\n", texture->name, texture->width, texture->height, // texture->patchcount, mtexture->patchcount, mtexture->patches[0].patch, patchlookup[SHORT(mpatch->patch)]); for (j=0 ; j<texture->patchcount ; j++, mpatch++, patch++) { patch->originx = SHORT(mpatch->originx); patch->originy = SHORT(mpatch->originy); patch->patch = patchlookup[SHORT(mpatch->patch)]; if (patch->patch == -1) I_Error ( "R_InitTextures: Missing patch in texture %s",texture->name); } // ST_Message("tex (%s: %i %i %i %i %i %i)\n", texture->name, texture->width, texture->height, // texture->patchcount, texture->patches[0].originx, texture->patches[0].originy, texture->patches[0].patch); texturecolumnlump[i] = Z_Malloc (texture->width*2, PU_STATIC,0); texturecolumnofs[i] = Z_Malloc (texture->width*2, PU_STATIC,0); j = 1; while (j*2 <= texture->width) j<<=1; texturewidthmask[i] = j-1; textureheight[i] = texture->height<<FRACBITS; totalwidth += texture->width; } Z_Free (maptex1); if (maptex2) Z_Free (maptex2); // // precalculate whatever possible // for (i=0 ; i<numtextures ; i++) { R_GenerateLookup (i); if(!(i&31)) ST_Progress(); } // // translation table for global animation // texturetranslation = Z_Malloc ((numtextures+1)*4, PU_STATIC, 0); for (i=0 ; i<numtextures ; i++) texturetranslation[i] = i; //rww begin //Z_Free(patchlookup); //rww end