doom

a minimalistic implementation of doom
git clone git://ssnf.xyz/doom
Log | Files | Refs

commit 4fbdc92f7a6bcb94bd6525d8280426affa389e88
parent 8646ab8b7fe8b7e17a1b2471647c5517006d5102
Author: ssnf <ssnf@ssnf.xyz>
Date:   Mon, 21 Jun 2021 00:34:33 +0000

i fixed some dumb shit

Diffstat:
Msrc/p_floor.c | 8++++----
Msrc/r_data.c | 832+++++++++++++++++++++++++++++++++++++------------------------------------------
Msrc/r_segs.c | 6+++---
Msrc/r_state.h | 2+-
4 files changed, 398 insertions(+), 450 deletions(-)

diff --git a/src/p_floor.c b/src/p_floor.c @@ -293,16 +293,16 @@ EV_DoFloor { side = getSide(secnum,i,0); if (side->bottomtexture >= 0) - if (textureheight[side->bottomtexture] < + if (textureheight_g[side->bottomtexture] < minsize) minsize = - textureheight[side->bottomtexture]; + textureheight_g[side->bottomtexture]; side = getSide(secnum,i,1); if (side->bottomtexture >= 0) - if (textureheight[side->bottomtexture] < + if (textureheight_g[side->bottomtexture] < minsize) minsize = - textureheight[side->bottomtexture]; + textureheight_g[side->bottomtexture]; } } floor->floordestheight = diff --git a/src/r_data.c b/src/r_data.c @@ -1,46 +1,49 @@ +#include <stdlib.h> +#include <alloca.h> + +#include "m_swap.h" #include "i_system.h" #include "z_zone.h" -#include "m_swap.h" #include "w_wad.h" #include "doomdef.h" #include "r_local.h" #include "p_local.h" #include "doomstat.h" #include "r_sky.h" -#include <alloca.h> #include "r_data.h" -typedef struct -{ - short originx; - short originy; - short patch; - short stepdir; - short colormap; + +typedef struct { + short originx; + short originy; + short patch; + short stepdir; + short colormap; } mappatch_t; -typedef struct -{ - char name[8]; - boolean masked; - short width; - short height; - void **columndirectory; - short patchcount; - mappatch_t patches[1]; + +typedef struct { + char name[8]; + boolean masked; + short width; + short height; + char columndirectory[4]; /* obsolete btw */ + short patchcount; + mappatch_t patches[1]; } maptexture_t; -typedef struct -{ - int originx; - int originy; - int patch; + +typedef struct { + int originx; + int originy; + int patch; } texpatch_t; -typedef struct -{ - char name[8]; - short width; - short height; - short patchcount; - texpatch_t patches[1]; + +typedef struct { + char name[8]; + short width; + short height; + short patchcount; + texpatch_t patches[1]; } texture_t; + int firstflat; int lastflat; int numflats; @@ -51,456 +54,401 @@ int firstspritelump; int lastspritelump; int numspritelumps; int numtextures; -texture_t** textures; -int* texturewidthmask; -fixed_t* textureheight; -int* texturecompositesize; -short** texturecolumnlump; -unsigned short** texturecolumnofs; -byte** texturecomposite; +int flatmemory; +int texturememory; +int spritememory; +texture_t** textures_g; +int* texturewidthmask_g; +fixed_t* textureheight_g; +int* texturecompositesize_g; +short** texturecolumnlump_g; +unsigned short** texturecolumnofs_g; +byte** texturecomposite_g; int* flattranslation; int* texturetranslation; -fixed_t* spritewidth; +fixed_t* spritewidth; fixed_t* spriteoffset; fixed_t* spritetopoffset; lighttable_t *colormaps; + void -R_DrawColumnInCache -( column_t* patch, - byte* cache, - int originy, - int cacheheight ) +R_DrawColumnInCache(column_t* patch, byte* cache, int originy, int cacheheight) { - int count; - int position; - byte* source; - while (patch->topdelta != 0xff) - { - source = (byte *)patch + 3; - count = patch->length; - position = originy + patch->topdelta; - if (position < 0) - { - count += position; - position = 0; + byte* source; + int count, position; + + while (patch->topdelta != 0xff) { + source = (byte *)patch + 3; + count = patch->length; + position = originy + patch->topdelta; + if (position < 0) { + count += position; + position = 0; + } + if (position + count > cacheheight) + count = cacheheight - position; + if (count > 0) + memcpy (cache + position, source, count); + patch = (column_t *)( (byte *)patch + patch->length + 4); } - if (position + count > cacheheight) - count = cacheheight - position; - if (count > 0) - memcpy (cache + position, source, count); - patch = (column_t *)( (byte *)patch + patch->length + 4); - } } -void R_GenerateComposite (int texnum) + +void +R_GenerateComposite(int texnum) { - byte* block; - texture_t* texture; - texpatch_t* patch; - patch_t* realpatch; - int x; - int x1; - int x2; - int i; - column_t* patchcol; - short* collump; - unsigned short* colofs; - texture = textures[texnum]; - block = Z_Malloc (texturecompositesize[texnum], - PU_STATIC, - &texturecomposite[texnum]); - collump = texturecolumnlump[texnum]; - colofs = texturecolumnofs[texnum]; - patch = texture->patches; - for (i=0 , patch = texture->patches; - i<texture->patchcount; - i++, patch++) - { - realpatch = W_CacheLumpNum (patch->patch, PU_CACHE); - x1 = patch->originx; - x2 = x1 + SHORT(realpatch->width); - if (x1<0) - x = 0; - else - x = x1; - if (x2 > texture->width) - x2 = texture->width; - for ( ; x<x2 ; x++) - { - if (collump[x] >= 0) - continue; - patchcol = (column_t *)((byte *)realpatch - + LONG(realpatch->columnofs[x-x1])); - R_DrawColumnInCache (patchcol, - block + colofs[x], - patch->originy, - texture->height); + byte* block; + texture_t* texture; + texpatch_t* patch; + patch_t* realpatch; + column_t* patchcol; + short* collump; + unsigned short* colofs; + int x, x1, x2, i; + + texture = textures_g[texnum]; + block = Z_Malloc(texturecompositesize_g[texnum], PU_STATIC, &texturecomposite_g[texnum]); + collump = texturecolumnlump_g[texnum]; + colofs = texturecolumnofs_g[texnum]; + patch = texture->patches; + for (i = 0, patch = texture->patches; i < texture->patchcount; ++i, ++patch) { + realpatch = W_CacheLumpNum(patch->patch, PU_CACHE); + x1 = patch->originx; + x2 = x1 + realpatch->width; + if (x1 < 0) + x = 0; + else x = x1; + if (x2 > texture->width) + x2 = texture->width; + for (; x < x2; ++x) { + if (collump[x] >= 0) + continue; + patchcol = (column_t *)((byte *)realpatch + realpatch->columnofs[x-x1]); + R_DrawColumnInCache (patchcol, block + colofs[x], patch->originy, texture->height); + } } - } - Z_ChangeTag (block, PU_CACHE); + Z_ChangeTag(block, PU_CACHE); } -void R_GenerateLookup (int texnum) + +void +R_GenerateLookup(int texnum) { - texture_t* texture; - byte* patchcount; - texpatch_t* patch; - patch_t* realpatch; - int x; - int x1; - int x2; - int i; - short* collump; - unsigned short* colofs; - texture = textures[texnum]; - texturecomposite[texnum] = 0; - texturecompositesize[texnum] = 0; - collump = texturecolumnlump[texnum]; - colofs = texturecolumnofs[texnum]; - patchcount = (byte *)alloca (texture->width); - memset (patchcount, 0, texture->width); - patch = texture->patches; - for (i=0 , patch = texture->patches; - i<texture->patchcount; - i++, patch++) - { - realpatch = W_CacheLumpNum (patch->patch, PU_CACHE); - x1 = patch->originx; - x2 = x1 + SHORT(realpatch->width); - if (x1 < 0) - x = 0; - else - x = x1; - if (x2 > texture->width) - x2 = texture->width; - for ( ; x<x2 ; x++) - { - patchcount[x]++; - collump[x] = patch->patch; - colofs[x] = LONG(realpatch->columnofs[x-x1])+3; - } - } - for (x=0 ; x<texture->width ; x++) - { - if (!patchcount[x]) - { - printf ("R_GenerateLookup: column without a patch (%s)\n", - texture->name); - return; + texture_t* texture; + byte* patchcount; + texpatch_t* patch; + patch_t* realpatch; + short* collump; + unsigned short* colofs; + int x, x1, x2, i; + + texture = textures_g[texnum]; + texturecomposite_g[texnum] = 0; + texturecompositesize_g[texnum] = 0; + collump = texturecolumnlump_g[texnum]; + colofs = texturecolumnofs_g[texnum]; + patchcount = (byte*)alloca(texture->width); + memset(patchcount, 0, texture->width); + patch = texture->patches; + for (i = 0, patch = texture->patches; i < texture->patchcount; ++i, ++patch) { + realpatch = W_CacheLumpNum (patch->patch, PU_CACHE); + x1 = patch->originx; + x2 = x1 + realpatch->width; + if (x1 < 0) + x = 0; + else x = x1; + if (x2 > texture->width) + x2 = texture->width; + for (; x < x2 ; ++x) { + ++patchcount[x]; + collump[x] = patch->patch; + colofs[x] = realpatch->columnofs[x-x1]+3; + } } - if (patchcount[x] > 1) - { - collump[x] = -1; - colofs[x] = texturecompositesize[texnum]; - if (texturecompositesize[texnum] > 0x10000-texture->height) - { - I_Error ("R_GenerateLookup: texture %i is >64k", - texnum); - } - texturecompositesize[texnum] += texture->height; + for (x = 0; x < texture->width; ++x) { + if (!patchcount[x]) { + printf ("R_GenerateLookup: column without a patch (%s)\n", texture->name); + return; + } + if (patchcount[x] > 1) { + collump[x] = -1; + colofs[x] = texturecompositesize_g[texnum]; + if (texturecompositesize_g[texnum] > 0x10000-texture->height) + I_Error ("R_GenerateLookup: texture %i is >64k", texnum); + texturecompositesize_g[texnum] += texture->height; + } } - } } + byte* -R_GetColumn -( int tex, - int col ) +R_GetColumn(int tex, int col) { - int lump; - int ofs; - 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; + int lump, ofs; + + col &= texturewidthmask_g[tex]; + lump = texturecolumnlump_g[tex][col]; + ofs = texturecolumnofs_g[tex][col]; + if (lump > 0) + return (byte*)W_CacheLumpNum(lump,PU_CACHE)+ofs; + if (!texturecomposite_g[tex]) + R_GenerateComposite (tex); + return texturecomposite_g[tex] + ofs; } -void R_InitTextures (void) + +void +R_InitTextures() { - 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; - 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); - 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; - temp1 = W_GetNumForName ("S_START"); - 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) - { - maptex = maptex2; - maxoff = maxoff2; - directory = maptex+1; + maptexture_t* mtexture; + texture_t* texture; + mappatch_t* mpatch; + texpatch_t* patch; + int* maptex, *maptex1, *maptex2, *patchlookup, *directory; + char* names, *name_p; + char name[9]; + int i, j, totalwidth, num_mappatches, offset, maxoff, maxoff2, numtextures1, numtextures2, temp1, temp2, temp3; + + name[8] = 0; + names = W_CacheLumpName("PNAMES", PU_STATIC); + num_mappatches = *((int*)names); + name_p = names+4; + patchlookup = alloca(num_mappatches*sizeof(*patchlookup)); + for (i = 0; i < num_mappatches; ++i) { + strncpy(name, name_p+i*8, 8); + patchlookup[i] = W_CheckNumForName(name); } - 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); - for (i=0 ; i<numtextures ; i++) - R_GenerateLookup (i); - texturetranslation = Z_Malloc ((numtextures+1)*4, PU_STATIC, 0); - for (i=0 ; i<numtextures ; i++) - texturetranslation[i] = i; + Z_Free(names); + maptex = maptex1 = W_CacheLumpName("TEXTURE1", PU_STATIC); + numtextures1 = *maptex; + maxoff = W_LumpLength(W_GetNumForName ("TEXTURE1")); + directory = maptex+1; + if (W_CheckNumForName("TEXTURE2") == -1) { + maptex2 = NULL; + numtextures2 = 0; + maxoff2 = 0; + } else { + maptex2 = W_CacheLumpName("TEXTURE2", PU_STATIC); + numtextures2 = *maptex2; + maxoff2 = W_LumpLength(W_GetNumForName ("TEXTURE2")); + } + numtextures = numtextures1 + numtextures2; + textures_g = Z_Malloc(numtextures * sizeof(void*), PU_STATIC, 0); + texturecolumnlump_g = Z_Malloc(numtextures * sizeof(void*), PU_STATIC, 0); + texturecolumnofs_g = Z_Malloc(numtextures * sizeof(void*), PU_STATIC, 0); + texturecomposite_g = Z_Malloc(numtextures * sizeof(void*), PU_STATIC, 0); + texturecompositesize_g = Z_Malloc(numtextures * sizeof(void*), PU_STATIC, 0); + texturewidthmask_g = Z_Malloc(numtextures * sizeof(void*), PU_STATIC, 0); + textureheight_g = Z_Malloc(numtextures * sizeof(void*), PU_STATIC, 0); + totalwidth = 0; + temp1 = W_GetNumForName ("S_START"); + 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) { + maptex = maptex2; + maxoff = maxoff2; + directory = maptex+1; + } + offset = *directory; + if (offset > maxoff) + I_Error("R_InitTextures: bad texture directory"); + mtexture = (maptexture_t*)((byte*)maptex + offset); + texture = textures_g[i] = Z_Malloc(sizeof(texture_t) + sizeof(texpatch_t)*(mtexture->patchcount-1), PU_STATIC, 0); + 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[mpatch->patch]; + if (patch->patch == -1) + I_Error("R_InitTextures: Missing patch in texture %s", texture->name); + } + texturecolumnlump_g[i] = Z_Malloc(texture->width * 2, PU_STATIC,0); + texturecolumnofs_g[i] = Z_Malloc(texture->width * 2, PU_STATIC,0); + for (j = 1; j * 2 <= texture->width; j <<= 1); + texturewidthmask_g[i] = j-1; + textureheight_g[i] = texture->height<<FRACBITS; + totalwidth += texture->width; + } + Z_Free(maptex1); + if (maptex2) + Z_Free(maptex2); + for (i = 0; i < numtextures; ++i) + R_GenerateLookup(i); + texturetranslation = Z_Malloc((numtextures+1) * 4, PU_STATIC, 0); + for (i = 0; i < numtextures; ++i) + texturetranslation[i] = i; } -void R_InitFlats (void) + +void +R_InitFlats() { - int i; - firstflat = W_GetNumForName ("F_START") + 1; - lastflat = W_GetNumForName ("F_END") - 1; - numflats = lastflat - firstflat + 1; - flattranslation = Z_Malloc ((numflats+1)*4, PU_STATIC, 0); - for (i=0 ; i<numflats ; i++) - flattranslation[i] = i; + int i; + + firstflat = W_GetNumForName ("F_START") + 1; + lastflat = W_GetNumForName ("F_END") - 1; + numflats = lastflat - firstflat + 1; + flattranslation = Z_Malloc((numflats+1) * 4, PU_STATIC, 0); + for (i = 0; i < numflats; ++i) + flattranslation[i] = i; } -void R_InitSpriteLumps (void) + +void +R_InitSpriteLumps() { - int i; - patch_t *patch; - firstspritelump = W_GetNumForName ("S_START") + 1; - lastspritelump = W_GetNumForName ("S_END") - 1; - numspritelumps = lastspritelump - firstspritelump + 1; - spritewidth = Z_Malloc (numspritelumps*4, PU_STATIC, 0); - spriteoffset = Z_Malloc (numspritelumps*4, PU_STATIC, 0); - spritetopoffset = Z_Malloc (numspritelumps*4, PU_STATIC, 0); - for (i=0 ; i< numspritelumps ; i++) - { - if (!(i&63)) - printf ("."); - patch = W_CacheLumpNum (firstspritelump+i, PU_CACHE); - spritewidth[i] = SHORT(patch->width)<<FRACBITS; - spriteoffset[i] = SHORT(patch->leftoffset)<<FRACBITS; - spritetopoffset[i] = SHORT(patch->topoffset)<<FRACBITS; - } + patch_t* patch; + int i; + + firstspritelump = W_GetNumForName("S_START") + 1; + lastspritelump = W_GetNumForName("S_END") - 1; + numspritelumps = lastspritelump - firstspritelump + 1; + spritewidth = Z_Malloc(numspritelumps * sizeof(*spritewidth), PU_STATIC, 0); + spriteoffset = Z_Malloc(numspritelumps * sizeof(*spriteoffset), PU_STATIC, 0); + spritetopoffset = Z_Malloc(numspritelumps * sizeof(*spritetopoffset), PU_STATIC, 0); + for (i = 0; i < numspritelumps; ++i) { + if (!(i & 63)) + printf ("."); + patch = W_CacheLumpNum(firstspritelump+i, PU_CACHE); + spritewidth[i] = patch->width<<FRACBITS; + spriteoffset[i] = patch->leftoffset<<FRACBITS; + spritetopoffset[i] = patch->topoffset<<FRACBITS; + } } -void R_InitColormaps (void) + +void +R_InitColormaps() { - int lump, length; - lump = W_GetNumForName("COLORMAP"); - length = W_LumpLength (lump) + 255; - colormaps = Z_Malloc (length, PU_STATIC, 0); - colormaps = (byte *)( ((long)colormaps + 255)&~0xff); - W_ReadLump (lump,colormaps); + int lump, length; + + lump = W_GetNumForName("COLORMAP"); + length = W_LumpLength (lump) + 255; + colormaps = Z_Malloc (length, PU_STATIC, 0); + colormaps = (byte*)(((long)colormaps + 255)&~0xff); + W_ReadLump(lump, colormaps); } -void R_InitData (void) + +void +R_InitData() { - R_InitTextures (); - printf ("\nInitTextures"); - R_InitFlats (); - printf ("\nInitFlats"); - R_InitSpriteLumps (); - printf ("\nInitSprites"); - R_InitColormaps (); - printf ("\nInitColormaps"); + R_InitTextures(); + printf("\nInitTextures"); + R_InitFlats(); + printf("\nInitFlats"); + R_InitSpriteLumps(); + printf("\nInitSprites"); + R_InitColormaps(); + printf("\nInitColormaps"); } -int R_FlatNumForName (char* name) + +int +R_FlatNumForName(char* name) { - int i; - char namet[9]; - i = W_CheckNumForName (name); - if (i == -1) - { - namet[8] = 0; - memcpy (namet, name,8); - I_Error ("R_FlatNumForName: %s not found",namet); - } - return i - firstflat; + char namet[9]; + int i; + + i = W_CheckNumForName(name); + if (i == -1) { + namet[8] = 0; + memcpy(namet, name,8); + I_Error("R_FlatNumForName: %s not found", namet); + } + return i - firstflat; } -int R_CheckTextureNumForName (char *name) + +int +R_CheckTextureNumForName(char *name) { - int i; - if (name[0] == '-') - return 0; - for (i=0 ; i<numtextures ; i++) - if (!strncasecmp (textures[i]->name, name, 8) ) - return i; - return -1; + int i; + + if (name[0] == '-') + return 0; + for (i = 0; i < numtextures; ++i) + if (!strncasecmp(textures_g[i]->name, name, 8)) + return i; + return -1; } -int R_TextureNumForName (char* name) + +int +R_TextureNumForName(char* name) { - int i; - i = R_CheckTextureNumForName (name); - if (i==-1) - { - I_Error ("R_TextureNumForName: %s not found", - name); - } - return i; + int i; + + i = R_CheckTextureNumForName(name); + if (i == -1) + I_Error("R_TextureNumForName: %s not found", name); + return i; } -int flatmemory; -int texturememory; -int spritememory; -void R_PrecacheLevel (void) + +void +R_PrecacheLevel() { - char* flatpresent; - char* texturepresent; - char* spritepresent; - int i; - int j; - int k; - int lump; - texture_t* texture; - thinker_t* th; - spriteframe_t* sf; - if (demoplayback) - return; - flatpresent = alloca(numflats); - memset (flatpresent,0,numflats); - for (i=0 ; i<numsectors ; i++) - { - flatpresent[sectors[i].floorpic] = 1; - flatpresent[sectors[i].ceilingpic] = 1; - } - flatmemory = 0; - for (i=0 ; i<numflats ; i++) - { - if (flatpresent[i]) - { - lump = firstflat + i; - flatmemory += lumpinfo_g[lump].size; - W_CacheLumpNum(lump, PU_CACHE); + texture_t* texture; + thinker_t* th; + spriteframe_t* sf; + char* flatpresent, *texturepresent, *spritepresent; + int i, j, k, lump; + + if (demoplayback) + return; + flatpresent = alloca(numflats); + memset(flatpresent,0,numflats); + for (i = 0; i < numsectors; ++i) { + flatpresent[sectors[i].floorpic] = 1; + flatpresent[sectors[i].ceilingpic] = 1; + } + flatmemory = 0; + for (i = 0; i < numflats; ++i) { + if (flatpresent[i]) { + lump = firstflat + i; + flatmemory += lumpinfo_g[lump].size; + W_CacheLumpNum(lump, PU_CACHE); + } + } + texturepresent = alloca(numtextures); + memset (texturepresent,0, numtextures); + for (i = 0; i < numsides; ++i) { + texturepresent[sides[i].toptexture] = 1; + texturepresent[sides[i].midtexture] = 1; + texturepresent[sides[i].bottomtexture] = 1; } - } - texturepresent = alloca(numtextures); - memset (texturepresent,0, numtextures); - for (i=0 ; i<numsides ; i++) - { - texturepresent[sides[i].toptexture] = 1; - texturepresent[sides[i].midtexture] = 1; - texturepresent[sides[i].bottomtexture] = 1; - } - texturepresent[skytexture] = 1; - texturememory = 0; - for (i=0 ; i<numtextures ; i++) - { - if (!texturepresent[i]) - continue; - texture = textures[i]; - for (j=0 ; j<texture->patchcount ; j++) - { - lump = texture->patches[j].patch; - texturememory += lumpinfo_g[lump].size; - W_CacheLumpNum(lump , PU_CACHE); + texturepresent[skytexture] = 1; + texturememory = 0; + for (i = 0; i < numtextures; ++i) { + if (!texturepresent[i]) + continue; + texture = textures_g[i]; + for (j = 0; j < texture->patchcount; ++j) { + lump = texture->patches[j].patch; + texturememory += lumpinfo_g[lump].size; + W_CacheLumpNum(lump , PU_CACHE); + } } - } - spritepresent = alloca(numsprites); - memset (spritepresent,0, numsprites); - for (th = thinkercap.next ; th != &thinkercap ; th=th->next) - { - if (th->function.acp1 == (actionf_p1)P_MobjThinker) - spritepresent[((mobj_t *)th)->sprite] = 1; - } - spritememory = 0; - for (i=0 ; i<numsprites ; i++) - { - if (!spritepresent[i]) - continue; - for (j=0 ; j<sprites[i].numframes ; j++) - { - sf = &sprites[i].spriteframes[j]; - for (k=0 ; k<8 ; k++) - { - lump = firstspritelump + sf->lump[k]; - spritememory += lumpinfo_g[lump].size; - W_CacheLumpNum(lump , PU_CACHE); - } + spritepresent = alloca(numsprites); + memset (spritepresent,0, numsprites); + for (th = thinkercap.next ; th != &thinkercap ; th=th->next) + if (th->function.acp1 == (actionf_p1)P_MobjThinker) + spritepresent[((mobj_t *)th)->sprite] = 1; + spritememory = 0; + for (i = 0; i < numsprites; ++i) { + if (!spritepresent[i]) + continue; + for (j = 0; j < sprites[i].numframes; ++j) { + sf = &sprites[i].spriteframes[j]; + for (k = 0; k < 8; ++k) { + lump = firstspritelump + sf->lump[k]; + spritememory += lumpinfo_g[lump].size; + W_CacheLumpNum(lump , PU_CACHE); + } + } } - } } diff --git a/src/r_segs.c b/src/r_segs.c @@ -71,7 +71,7 @@ R_RenderMaskedSegRange { dc_texturemid = frontsector->floorheight > backsector->floorheight ? frontsector->floorheight : backsector->floorheight; - dc_texturemid = dc_texturemid + textureheight[texnum] - viewz; + dc_texturemid = dc_texturemid + textureheight_g[texnum] - viewz; } else { @@ -294,7 +294,7 @@ R_StoreWallRange if (linedef->flags & ML_DONTPEGBOTTOM) { vtop = frontsector->floorheight + - textureheight[sidedef->midtexture]; + textureheight_g[sidedef->midtexture]; rw_midtexturemid = vtop - viewz; } else @@ -387,7 +387,7 @@ R_StoreWallRange { vtop = backsector->ceilingheight - + textureheight[sidedef->toptexture]; + + textureheight_g[sidedef->toptexture]; rw_toptexturemid = vtop - viewz; } } diff --git a/src/r_state.h b/src/r_state.h @@ -5,7 +5,7 @@ #ifdef __GNUG__ #pragma interface #endif -extern fixed_t* textureheight; +extern fixed_t* textureheight_g; extern fixed_t* spritewidth; extern fixed_t* spriteoffset; extern fixed_t* spritetopoffset;