// // W_CacheLumpNum // void* W_CacheLumpNum ( unsigned lump, int tag ) { byte* ptr; if ((unsigned)lump >= numlumps) I_Error ("W_CacheLumpNum: %i >= numlumps",lump); if (!lumpcache[lump]) { // read the lump in //printf ("cache miss on lump %i\n",lump); ptr = (byte *)Z_Malloc (W_LumpLength (lump) + 1, tag, &lumpcache[lump]); W_ReadLump (lump, lumpcache[lump]); ptr [W_LumpLength (lump)] = 0; } else { //printf ("cache hit on lump %i\n",lump); Z_ChangeTag (lumpcache[lump],tag); } return lumpcache[lump]; }
// // P_DialogLoad // // [STRIFE] New function // haleyjd 09/02/10: Loads the dialog script for the current map. Also loads // SCRIPT00 if it has not yet been loaded. // void P_DialogLoad(void) { char lumpname[9]; int lumpnum; // load the SCRIPTxy lump corresponding to MAPxy, if it exists. DEH_snprintf(lumpname, sizeof(lumpname), "script%02d", gamemap); if((lumpnum = W_CheckNumForName(lumpname)) == -1) numleveldialogs = 0; else { byte *leveldialogptr = W_CacheLumpNum(lumpnum, PU_STATIC); numleveldialogs = W_LumpLength(lumpnum) / ORIG_MAPDIALOG_SIZE; P_ParseDialogLump(leveldialogptr, &leveldialogs, numleveldialogs, PU_LEVEL); Z_Free(leveldialogptr); // haleyjd: free the original lump } // also load SCRIPT00 if it has not been loaded yet if(!script0loaded) { byte *script0ptr; script0loaded = true; // BUG: Rogue should have used W_GetNumForName here... lumpnum = W_CheckNumForName(DEH_String("script00")); script0ptr = W_CacheLumpNum(lumpnum, PU_STATIC); numscript0dialogs = W_LumpLength(lumpnum) / ORIG_MAPDIALOG_SIZE; P_ParseDialogLump(script0ptr, &script0dialogs, numscript0dialogs, PU_STATIC); Z_Free(script0ptr); // haleyjd: free the original lump } }
void parse_include(char *lumpname) { int lumpnum; char *lump, *end; char *saved_rover; if(-1 == (lumpnum = W_GetNumForName(lumpname)) ) { script_error("include lump '%s' not found!\n", lumpname); return; } lump = W_CacheLumpNum(lumpnum, PU_STATIC); // realloc bigger for NULL at end lump = Z_Realloc(lump, W_LumpLength(lumpnum)+10, PU_STATIC, NULL); saved_rover = rover; // save rover during include rover = lump; end = lump+W_LumpLength(lumpnum); *end = 0; // preprocess the include // we assume that it does not include sections or labels or // other nasty things process_find_char(lump, 0); // now parse the lump parse_data(lump, end); // restore rover rover = saved_rover; // free the lump Z_Free(lump); }
void P_LoadVertexes (int lump) { #ifdef MARS numvertexes = W_LumpLength (lump) / sizeof(vertex_t); vertexes = (vertex_t *)(wadfileptr+BIGLONG(lumpinfo[lump].filepos)); #else byte *data; int i; mapvertex_t *ml; vertex_t *li; numvertexes = W_LumpLength (lump) / sizeof(mapvertex_t); vertexes = Z_Malloc (numvertexes*sizeof(vertex_t),PU_LEVEL,0); data = I_TempBuffer (); W_ReadLump (lump,data); ml = (mapvertex_t *)data; li = vertexes; for (i=0 ; i<numvertexes ; i++, li++, ml++) { li->x = LITTLESHORT(ml->x)<<FRACBITS; li->y = LITTLESHORT(ml->y)<<FRACBITS; } #endif }
void P_LoadNodes (int lump) { #ifdef MARS numnodes = W_LumpLength (lump) / sizeof(node_t); nodes = (node_t *)(wadfileptr+BIGLONG(lumpinfo[lump].filepos)); #else byte *data; int i,j,k; mapnode_t *mn; node_t *no; numnodes = W_LumpLength (lump) / sizeof(mapnode_t); nodes = Z_Malloc (numnodes*sizeof(node_t),PU_LEVEL,0); data = I_TempBuffer (); W_ReadLump (lump,data); mn = (mapnode_t *)data; no = nodes; for (i=0 ; i<numnodes ; i++, no++, mn++) { no->x = LITTLESHORT(mn->x)<<FRACBITS; no->y = LITTLESHORT(mn->y)<<FRACBITS; no->dx = LITTLESHORT(mn->dx)<<FRACBITS; no->dy = LITTLESHORT(mn->dy)<<FRACBITS; for (j=0 ; j<2 ; j++) { no->children[j] = (unsigned short)LITTLESHORT(mn->children[j]); for (k=0 ; k<4 ; k++) no->bbox[j][k] = LITTLESHORT(mn->bbox[j][k])<<FRACBITS; } } #endif }
// // TextureManger::cachePatch // void TextureManager::cachePatch(texhandle_t handle) { unsigned int lumpnum = handle & ~(PATCH_HANDLE_MASK | SPRITE_HANDLE_MASK); unsigned int lumplen = W_LumpLength(lumpnum); byte* lumpdata = new byte[lumplen]; W_ReadLump(lumpnum, lumpdata); int width = LESHORT(*(short*)(lumpdata + 0)); int height = LESHORT(*(short*)(lumpdata + 2)); int offsetx = LESHORT(*(short*)(lumpdata + 4)); int offsety = LESHORT(*(short*)(lumpdata + 6)); Texture* texture = createTexture(handle, width, height); texture->mOffsetX = offsetx; texture->mOffsetY = offsety; if (clientside) { // TODO: remove this once proper masking is in place memset(texture->mData, 0, width * height); // initialize the mask to entirely transparent memset(texture->mMask, 0, width * height); R_DrawPatchIntoTexture(texture, lumpdata, 0, 0); texture->mHasMask = (memchr(texture->mMask, 0, width * height) != NULL); } delete [] lumpdata; }
// // TextureManager::readPNamesDirectory // void TextureManager::readPNamesDirectory() { int lumpnum = W_GetNumForName("PNAMES"); size_t lumplen = W_LumpLength(lumpnum); byte* lumpdata = new byte[lumplen]; W_ReadLump(lumpnum, lumpdata); int num_pname_mappings = LELONG(*((int*)(lumpdata + 0))); mPNameLookup = new int[num_pname_mappings]; for (int i = 0; i < num_pname_mappings; i++) { const char* lumpname = (const char*)(lumpdata + 4 + 8 * i); mPNameLookup[i] = W_CheckNumForName(lumpname); // 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. if (mPNameLookup[i] == -1) mPNameLookup[i] = W_CheckNumForName(lumpname, ns_sprites); } delete [] lumpdata; }
// // TextureManager::cacheRawTexture // // Converts a linear 320x200 block of pixels into a Texture // void TextureManager::cacheRawTexture(texhandle_t handle) { const int width = 320; const int height = 200; Texture* texture = createTexture(handle, width, height); if (clientside) { unsigned int lumpnum = (handle & ~RAW_HANDLE_MASK); unsigned int lumplen = W_LumpLength(lumpnum); byte *lumpdata = new byte[lumplen]; W_ReadLump(lumpnum, lumpdata); // convert the row-major flat lump to into column-major byte* dest = texture->mData; for (int x = 0; x < width; x++) { const byte* source = lumpdata + x; for (int y = 0; y < height; y++) { *dest = *source; source += width; dest++; } } delete [] lumpdata; } }
// // W_CacheLumpNum // // Load a lump into memory and return a pointer to a buffer containing // the lump data. // // 'tag' is the type of zone memory buffer to allocate for the lump // (usually PU_STATIC or PU_CACHE). If the lump is loaded as // PU_STATIC, it should be released back using W_ReleaseLumpNum // when no longer needed (do not use Z_ChangeTag). // void *W_CacheLumpNum(lumpindex_t lumpnum, int tag) { byte *result; lumpinfo_t *lump; if (lumpnum >= numlumps) I_Error("W_CacheLumpNum: %i >= numlumps", lumpnum); lump = lumpinfo[lumpnum]; // Get the pointer to return. If the lump is in a memory-mapped // file, we can just return a pointer to within the memory-mapped // region. If the lump is in an ordinary file, we may already // have it cached; otherwise, load it into memory. if (lump->wad_file->mapped) { // Memory mapped file, return from the mmapped region. result = lump->wad_file->mapped + lump->position; } else if (lump->cache) { // Already cached, so just switch the zone tag. result = (byte *)lump->cache; Z_ChangeTag(lump->cache, tag); } else { // Not yet loaded, so load it now lump->cache = Z_Malloc(W_LumpLength(lumpnum), tag, &lump->cache); W_ReadLump(lumpnum, lump->cache); result = (byte *)lump->cache; } return result; }
static char *GetFinaleText(int sequence) { char *msgLumpName; int msgSize; int msgLump; static char *winMsgLumpNames[] = { "win1msg", "win2msg", "win3msg" }; msgLumpName = winMsgLumpNames[sequence]; msgLump = W_CheckNumForName(msgLumpName); if (msgLump<0) { strcpy(ClusterMessage,"CONGRADULATIONS!"); return ClusterMessage; } msgSize = W_LumpLength(msgLump); if(msgSize >= MAX_INTRMSN_MESSAGE_SIZE) { I_Error("Finale message too long (%s)", msgLumpName); } W_ReadLump(msgLump, ClusterMessage); ClusterMessage[msgSize] = 0; // Append terminator return ClusterMessage; }
void P_LoadSideDefs(int lump) { byte *data; int i; mapsidedef_t *msd; side_t *sd; for(i = 0; i < numtextures; i++) textures[i].usecount = 0; numsides = W_LumpLength(lump) / sizeof(mapsidedef_t); sides = Z_Malloc(numsides * sizeof(side_t), PU_LEVEL, 0); D_memset(sides, 0, numsides * sizeof(side_t)); data = I_TempBuffer(); W_ReadLump(lump, data); msd = (mapsidedef_t *)data; sd = sides; for(i = 0; i < numsides; i++, msd++, sd++) { sd->textureoffset = LITTLESHORT(msd->textureoffset) << FRACBITS; sd->rowoffset = LITTLESHORT(msd->rowoffset) << FRACBITS; sd->toptexture = R_TextureNumForName(msd->toptexture); sd->bottomtexture = R_TextureNumForName(msd->bottomtexture); sd->midtexture = R_TextureNumForName(msd->midtexture); sd->sector = §ors[LITTLESHORT(msd->sector)]; textures[sd->toptexture].usecount++; textures[sd->bottomtexture].usecount++; textures[sd->midtexture].usecount++; } }
void P_LoadSectors(int lump) { byte *data; int i; mapsector_t *ms; sector_t *ss; numsectors = W_LumpLength(lump) / sizeof(mapsector_t); sectors = Z_Malloc(numsectors * sizeof(sector_t), PU_LEVEL, 0); D_memset(sectors, 0, numsectors * sizeof(sector_t)); data = I_TempBuffer(); W_ReadLump(lump, data); ms = (mapsector_t *)data; ss = sectors; for(i = 0; i < numsectors; i++, ss++, ms++) { ss->floorheight = LITTLESHORT(ms->floorheight) << FRACBITS; ss->ceilingheight = LITTLESHORT(ms->ceilingheight) << FRACBITS; ss->floorpic = R_FlatNumForName(ms->floorpic); if(!D_strncasecmp(ms->ceilingpic,"F_SKY1", 6)) ss->ceilingpic = -1; else { ss->ceilingpic = R_FlatNumForName(ms->ceilingpic); } ss->lightlevel = LITTLESHORT(ms->lightlevel); ss->special = LITTLESHORT(ms->special); ss->tag = LITTLESHORT(ms->tag); ss->thinglist = NULL; } }
void P_LoadSideDefs (int lump) { byte *data; int i; mapsidedef_t *msd; side_t *sd; numsides = W_LumpLength (lump) / sizeof(mapsidedef_t); sides = Z_Malloc (numsides*sizeof(side_t),PU_LEVEL,0); memset (sides, 0, numsides*sizeof(side_t)); data = W_CacheLumpNum (lump,PU_STATIC); msd = (mapsidedef_t *)data; sd = sides; // Make sure primary lumps are used for texture searching W_UsePrimary(); for(i = 0; i < numsides; i++, msd++, sd++) { sd->textureoffset = SHORT(msd->textureoffset)<<FRACBITS; sd->rowoffset = SHORT(msd->rowoffset)<<FRACBITS; sd->toptexture = R_TextureNumForName(msd->toptexture); sd->bottomtexture = R_TextureNumForName(msd->bottomtexture); sd->midtexture = R_TextureNumForName(msd->midtexture); sd->sector = §ors[SHORT(msd->sector)]; } if(DevMaps) { W_UseAuxiliary(); } Z_Free(data); }
void P_LoadBlockMap(int lump) { int i, count; int lumplen; lumplen = W_LumpLength(lump); blockmaplump = Z_Malloc(lumplen, PU_LEVEL, NULL); W_ReadLump(lump, blockmaplump); blockmap = blockmaplump + 4; // Swap all short integers to native byte ordering: count = lumplen / 2; for (i = 0; i < count; i++) blockmaplump[i] = SHORT(blockmaplump[i]); bmaporgx = blockmaplump[0] << FRACBITS; bmaporgy = blockmaplump[1] << FRACBITS; bmapwidth = blockmaplump[2]; bmapheight = blockmaplump[3]; // clear out mobj chains count = sizeof(*blocklinks) * bmapwidth * bmapheight; blocklinks = Z_Malloc(count, PU_LEVEL, 0); memset(blocklinks, 0, count); }
static void setpalette(int pal) { if (colours == NULL) { int pplump = W_GetNumForName("PLAYPAL"); register const byte * palette = W_CacheLumpNum(pplump); register int i; num_pals = W_LumpLength(pplump) / (3*256); num_pals *= 256; if (!colours) colours = malloc(sizeof(*colours) * num_pals); for (i = 0; (size_t)i < num_pals; i++) { colours[i].r = palette[0]; colours[i].g = palette[1]; colours[i].b = palette[2]; palette += 3; } W_UnlockLumpNum(pplump); num_pals /= 256; } SDL_SetPalette(surface, SDL_LOGPAL | SDL_PHYSPAL, colours + 256 * pal, 0, 256); }
void P_LoadNodes(int lump) { byte *data; int i, j, k; mapnode_t *mn; node_t *no; numnodes = W_LumpLength(lump) / sizeof(mapnode_t); nodes = Z_Malloc(numnodes * sizeof(node_t), PU_LEVEL, 0); data = W_CacheLumpNum(lump, PU_STATIC); mn = (mapnode_t *) data; no = nodes; for (i = 0; i < numnodes; i++, no++, mn++) { no->x = SHORT(mn->x) << FRACBITS; no->y = SHORT(mn->y) << FRACBITS; no->dx = SHORT(mn->dx) << FRACBITS; no->dy = SHORT(mn->dy) << FRACBITS; for (j = 0; j < 2; j++) { no->children[j] = SHORT(mn->children[j]); for (k = 0; k < 4; k++) no->bbox[j][k] = SHORT(mn->bbox[j][k]) << FRACBITS; } } W_ReleaseLumpNum(lump); }
void P_LoadSideDefs(int lump) { byte *data; int i; mapsidedef_t *msd; side_t *sd; numsides = W_LumpLength(lump) / sizeof(mapsidedef_t); sides = Z_Malloc(numsides * sizeof(side_t), PU_LEVEL, 0); memset(sides, 0, numsides * sizeof(side_t)); data = W_CacheLumpNum(lump, PU_STATIC); msd = (mapsidedef_t *) data; sd = sides; for (i = 0; i < numsides; i++, msd++, sd++) { sd->textureoffset = SHORT(msd->textureoffset) << FRACBITS; sd->rowoffset = SHORT(msd->rowoffset) << FRACBITS; sd->toptexture = R_TextureNumForName(msd->toptexture); sd->bottomtexture = R_TextureNumForName(msd->bottomtexture); sd->midtexture = R_TextureNumForName(msd->midtexture); sd->sector = §ors[SHORT(msd->sector)]; } W_ReleaseLumpNum(lump); }
void *W_CacheLumpNum(int lump, int tag) { byte *ptr; if((unsigned) lump >= (unsigned) numlumps) { Con_Error("W_CacheLumpNum: %i >= numlumps", lump); } // Return the name instead of data? if(tag == PU_GETNAME) { strncpy(retname, lumpinfo[lump].name, 8); retname[8] = 0; return retname; } if(!lumpcache[lump]) { // Need to read the lump in ptr = Z_Malloc(W_LumpLength(lump), tag, &lumpcache[lump]); W_ReadLump(lump, lumpcache[lump]); } else { Z_ChangeTag(lumpcache[lump], tag); } return lumpcache[lump]; }
void P_LoadSectors(int lump) { byte *data; int i; mapsector_t *ms; sector_t *ss; numsectors = W_LumpLength(lump) / sizeof(mapsector_t); sectors = Z_Malloc(numsectors * sizeof(sector_t), PU_LEVEL, 0); memset(sectors, 0, numsectors * sizeof(sector_t)); data = W_CacheLumpNum(lump, PU_STATIC); ms = (mapsector_t *) data; ss = sectors; for (i = 0; i < numsectors; i++, ss++, ms++) { ss->floorheight = SHORT(ms->floorheight) << FRACBITS; ss->ceilingheight = SHORT(ms->ceilingheight) << FRACBITS; ss->floorpic = R_FlatNumForName(ms->floorpic); ss->ceilingpic = R_FlatNumForName(ms->ceilingpic); ss->lightlevel = SHORT(ms->lightlevel); ss->special = SHORT(ms->special); ss->tag = SHORT(ms->tag); ss->thinglist = NULL; ss->seqType = SEQTYPE_STONE; // default seqType } W_ReleaseLumpNum(lump); }
/////////////////////////////////////////////////////////// // Palette stuff. // static void I_UploadNewPalette(int pal) { // This is used to replace the current 256 colour cmap with a new one // Used by 256 colour PseudoColor modes // Array of XColor structs used for setting the 256-colour palette static XColor* colours; static int cachedgamma; static size_t num_pals; if ((colours == NULL) || (cachedgamma != usegamma)) { int lump = W_GetNumForName("PLAYPAL"); const byte *palette = W_CacheLumpNum(lump); register const byte *const gtable = gammatable[cachedgamma = usegamma]; register int i; num_pals = W_LumpLength(lump) / (3*256); num_pals *= 256; if (!colours) { // First call - allocate and prepare colour array colours = malloc(sizeof(*colours)*num_pals); for (i=0 ; i<num_pals ; i++) { colours[i].pixel = i & 0xff; colours[i].flags = DoRed|DoGreen|DoBlue; } } // set the X colormap entries for (i=0 ; i<num_pals ; i++) { register int c; c = gtable[palette[0]]; colours[i].red = (c<<8) + c; c = gtable[palette[1]]; colours[i].green = (c<<8) + c; c = gtable[palette[2]]; colours[i].blue = (c<<8) + c; palette += 3; } W_UnlockLumpNum(lump); num_pals/=256; } #ifdef RANGECHECK if (pal >= num_pals) I_Error("I_UploadNewPalette: Palette number out of range (%d>=%d)", pal, num_pals); #endif // store the colors to the current colormap XStoreColors(X_display, X_cmap, colours + 256*pal, 256); #ifdef HAVE_LIBXXF86DGA /* install DGA colormap */ if(doDga) XF86DGAInstallColormap(X_display, X_screen, X_cmap); #endif }
// // R_InitColormaps // void R_InitColormaps (int lump) { int length; if (lump == 0) { lump = W_GetNumForName("COLORMAP"); firstcollump = W_CheckNumForName ("C_START"); lastcollump = W_CheckNumForName ("C_END"); } if ((lump != prevcollump) || (colourmap_size == 0)) { prevcollump = lump; length = W_LumpLength (lump) + 255; if (length > colourmap_size) { colourmap_size = length + 0x200; if (colourmaps_a) Z_Free (colourmaps_a); // Load in the light tables, colourmaps_a = Z_Malloc (colourmap_size, PU_STATIC, 0); // 256 byte align tables. colormaps = (byte *)( ((uintptr_t)colourmaps_a + 255)&~0xff); } W_ReadLump (lump,colormaps); } }
/* * W_LockLumpNum * * This copies the lump into a malloced memory region and returns its address * instead of returning a pointer into the memory mapped area * */ const void* W_LockLumpNum(int lump) { size_t len = W_LumpLength(lump); const void *data = W_CacheLumpNum(lump); if (!cachelump[lump].cache) { // read the lump in Z_Malloc(len, PU_CACHE, &cachelump[lump].cache); memcpy(cachelump[lump].cache, data, len); } /* cph - if wasn't locked but now is, tell z_zone to hold it */ if (cachelump[lump].locks <= 0) { Z_ChangeTag(cachelump[lump].cache,PU_STATIC); #ifdef TIMEDIAG cachelump[lump].locktic = gametic; #endif // reset lock counter cachelump[lump].locks = 1; } else { // increment lock counter cachelump[lump].locks += 1; } #ifdef SIMPLECHECKS if (!((cachelump[lump].locks+1) & 0xf)) lprintf(LO_DEBUG, "W_CacheLumpNum: High lock on %8s (%d)\n", lumpinfo[lump].name, cachelump[lump].locks); #endif return cachelump[lump].cache; }
static int R_DemoEx_GetVersion(void) { int result = -1; int lump, ver; unsigned int size; const char *data; char str_ver[32]; lump = W_CheckNumForName(DEMOEX_VERSION_LUMPNAME); if (lump != -1) { size = W_LumpLength(lump); if (size > 0) { data = W_CacheLumpNum(lump); strncpy(str_ver, data, MIN(size, sizeof(str_ver))); if (sscanf(str_ver, "%d", &ver) == 1) { result = ver; } } W_UnlockLumpNum(lump); } return result; }
void I_CacheSound(sfxinfo_t *sound) { if(sound->data) return; // already cached // sf: changed if(sound->link) I_CacheSound(sound->link); else { char name[20]; int sfxlump; // Get the sound data from the WAD, allocate lump // in zone memory. sprintf(name, "ds%s", sound->name); sfxlump = W_CheckNumForName(name); // use dspistol for lumps that are not found // fix bug with doom2 sounds in doom 1 if(sfxlump < 0) sfxlump = W_GetNumForName("dspistol"); sound->length = W_LumpLength(sfxlump); sound->data = W_CacheLumpNum(sfxlump, PU_STATIC); } }
// // P_LoadVertexes // void P_LoadVertexes (int lump) { byte* data; int i; mapvertex_t* ml; vertex_t* li; // Determine number of lumps: // total lump length / vertex record length. numvertexes = W_LumpLength (lump) / sizeof(mapvertex_t); // Allocate zone memory for buffer. vertexes = Z_Malloc (numvertexes*sizeof(vertex_t),PU_LEVEL,0); // Load data into cache. data = W_CacheLumpNum (lump,PU_STATIC); ml = (mapvertex_t *)data; li = vertexes; // Copy and convert vertex coordinates, // internal representation as fixed. for (i=0 ; i<numvertexes ; i++, li++, ml++) { li->x = SHORT(ml->x)<<FRACBITS; li->y = SHORT(ml->y)<<FRACBITS; } // Free buffer memory. Z_Free (data); }
const void *W_CacheLumpNum(int lump) { const int locks = 1; #ifdef RANGECHECK if ((unsigned)lump >= (unsigned)numlumps) I_Error ("W_CacheLumpNum: %i >= numlumps",lump); #endif if (!cachelump[lump].cache) // read the lump in W_ReadLump(lump, Z_Malloc(W_LumpLength(lump), PU_CACHE, &cachelump[lump].cache)); /* cph - if wasn't locked but now is, tell z_zone to hold it */ if (!cachelump[lump].locks && locks) { Z_ChangeTag(cachelump[lump].cache,PU_STATIC); #ifdef TIMEDIAG cachelump[lump].locktic = gametic; #endif } cachelump[lump].locks += locks; #ifdef SIMPLECHECKS if (!((cachelump[lump].locks+1) & 0xf)) lprintf(LO_DEBUG, "W_CacheLumpNum: High lock on %8s (%d)\n", lumpinfo[lump].name, cachelump[lump].locks); #endif return cachelump[lump].cache; }
void P_LoadBlockMap (int lump) { int count; #ifdef MARS blockmaplump = (short *)(wadfileptr+BIGLONG(lumpinfo[lump].filepos)); blockmap = blockmaplump+4; #else int i; blockmaplump = W_CacheLumpNum (lump,PU_LEVEL); blockmap = blockmaplump+4; count = W_LumpLength (lump)/2; for (i=0 ; i<count ; i++) blockmaplump[i] = LITTLESHORT(blockmaplump[i]); #endif bmaporgx = blockmaplump[0]<<FRACBITS; bmaporgy = blockmaplump[1]<<FRACBITS; bmapwidth = blockmaplump[2]; bmapheight = blockmaplump[3]; /* clear out mobj chains */ count = sizeof(*blocklinks)* bmapwidth*bmapheight; blocklinks = Z_Malloc (count,PU_LEVEL, 0); D_memset (blocklinks, 0, count); }
// // R_LoadVoxelResource // // Loads a .vox-format voxel model into an rvoxelmodel_t structure. // rvoxelmodel_t *R_LoadVoxelResource(int lumpnum) { rvoxelmodel_t *model = NULL; byte *buffer = NULL, *rover = NULL; int lumplen = W_LumpLength(lumpnum); int xsize, ysize, zsize, voxsize; int i; // minimum size test if(lumplen < 12) return NULL; // cache the lump rover = buffer = (byte *)(wGlobalDir.cacheLumpNum(lumpnum, PU_STATIC)); // get sizes xsize = SwapLong(*(int32_t *)rover); rover += 4; ysize = SwapLong(*(int32_t *)rover); rover += 4; zsize = SwapLong(*(int32_t *)rover); rover += 4; voxsize = xsize*ysize*zsize; // true size test if(lumplen < 12 + voxsize + 768) { Z_ChangeTag(buffer, PU_CACHE); return NULL; } // create the model and its voxel buffer model = (rvoxelmodel_t *)(Z_Calloc(1, sizeof(rvoxelmodel_t), PU_RENDERER, NULL)); model->voxels = (byte *)(Z_Calloc(voxsize, sizeof(byte), PU_RENDERER, NULL)); model->xsize = xsize; model->ysize = ysize; model->zsize = zsize; // get voxel data memcpy(model->voxels, rover, voxsize); rover += voxsize; // get original palette data memcpy(model->palette, rover, 768); // transform palette data into 0-255 range // TODO: verify color component order for(i = 0; i < 768; i++) model->palette[i] <<= 2; // TODO: run V_FindBestColor to create translated palette? // done with lump Z_ChangeTag(buffer, PU_CACHE); return model; }
static void I_UploadNewPalette(int pal) { // This is used to replace the current 256 colour cmap with a new one // Used by 256 colour PseudoColor modes // Array of SDL_Color structs used for setting the 256-colour palette static SDL_Color* colours; static int cachedgamma; static size_t num_pals; if ((colours == NULL) || (cachedgamma != usegamma)) { int pplump = W_GetNumForName("PLAYPAL"); int gtlump = (W_CheckNumForName)("GAMMATBL",ns_prboom); register const byte * palette = W_CacheLumpNum(pplump); register const byte * const gtable = (const byte *)W_CacheLumpNum(gtlump) + 256*(cachedgamma = usegamma); register int i; num_pals = W_LumpLength(pplump) / (3*256); num_pals *= 256; if (!colours) { // First call - allocate and prepare colour array colours = malloc(sizeof(SDL_Color)*num_pals); } // set the colormap entries for (i=0 ; (size_t)i<num_pals ; i++) { colours[i].r = gtable[palette[0]]; colours[i].g = gtable[palette[1]]; colours[i].b = gtable[palette[2]]; palette += 3; } W_UnlockLumpNum(pplump); W_UnlockLumpNum(gtlump); num_pals/=256; } #ifdef RANGECHECK if ((size_t)pal >= num_pals) I_Error("I_UploadNewPalette: Palette number out of range (%d>=%d)", pal, num_pals); #endif // store the colors to the current display //SDL_SetColors(SDL_GetVideoSurface(), colours+256*pal, 0, 256); u32 i; for(i = 0; i < 256; i++) { u8 r, g, b; r = (u8)colours[i+256*pal].r; g = (u8)colours[i+256*pal].g; b = (u8)colours[i+256*pal].b; // Jefklak 20/11/06 - also update lower screen palette BG_PALETTE[i]=RGB8(r,g,b); if(!gen_console_enable) BG_PALETTE_SUB[i]=RGB8(r,g,b); } }
static void getsfx (struct sfxinfo_struct *sfx) { Uint32 samplerate; Uint32 length ,expanded_length; Uint8 *data; Uint32 new_size = 0; Mix_Chunk *chunk; data = (Uint8 *)W_CacheLumpNum(sfx->lumpnum, PU_STATIC); // [Russell] - ICKY QUICKY HACKY SPACKY *I HATE THIS SOUND MANAGEMENT SYSTEM!* // get the lump size, shouldn't this be filled in elsewhere? sfx->length = W_LumpLength(sfx->lumpnum); // [Russell] is it not a doom sound lump? if (((data[1] << 8) | data[0]) != 3) { chunk = (Mix_Chunk *)Z_Malloc(sizeof(Mix_Chunk), PU_STATIC, NULL); chunk->allocated = 1; chunk->abuf = perform_sdlmix_conv(data, sfx->length, &new_size); chunk->alen = new_size; chunk->volume = MIX_MAX_VOLUME; sfx->data = chunk; Z_ChangeTag(data, PU_CACHE); return; } samplerate = (data[3] << 8) | data[2]; length = (data[5] << 8) | data[4]; // [Russell] - Ignore doom's sound format length info // if the lump is longer than the value, fixes exec.wad's ssg length = (sfx->length - 8 > length) ? sfx->length - 8 : length; expanded_length = (uint32_t) ((((uint64_t) length) * mixer_freq) / samplerate); // Double up twice: 8 -> 16 bit and mono -> stereo expanded_length *= 4; chunk = (Mix_Chunk *)Z_Malloc(sizeof(Mix_Chunk), PU_STATIC, NULL); chunk->allocated = 1; chunk->alen = expanded_length; chunk->abuf = (Uint8 *)Z_Malloc(expanded_length, PU_STATIC, &chunk->abuf); chunk->volume = MIX_MAX_VOLUME; ExpandSoundData((unsigned char *)data + 8, samplerate, length, chunk); sfx->data = chunk; Z_ChangeTag(data, PU_CACHE); }