FFont * V_GetFont(const char *name) { FFont *font = FFont::FindFont (name); if (font == NULL) { int lump = Wads.CheckNumForName (name); if (lump != -1) { char head[3]; { FWadLump lumpy = Wads.OpenLumpNum (lump); lumpy.Read (head, 3); } if (head[0] == 'F' && head[1] == 'O' && head[2] == 'N') { font = new FSingleLumpFont (name, lump); } } if (font == NULL) { int picnum = TexMan.CheckForTexture (name, FTexture::TEX_Any); if (picnum <= 0) { picnum = TexMan.AddPatch (name); } if (picnum > 0) { font = new FSingleLumpFont (name, -1); } } } return font; }
bool LumpRemapper::LoadMap() { if(loaded) return true; if(Wads.GetNumLumps() == 0) return false; int lump = Wads.GetNumForName(mapLumpName); if(lump == -1) { printf("\n"); return false; } FWadLump mapLump = Wads.OpenLumpNum(lump); char* mapData = new char[Wads.LumpLength(lump)]; mapLump.Read(mapData, Wads.LumpLength(lump)); Scanner sc(mapData, Wads.LumpLength(lump)); sc.SetScriptIdentifier(Wads.GetLumpFullName(lump)); delete[] mapData; ParseMap(sc); loaded = true; return true; }
void R_SetDefaultColormap (const char *name) { if (strnicmp (fakecmaps[0].name, name, 8) != 0) { int lump, i, j; BYTE map[256]; BYTE unremap[256]; BYTE remap[256]; lump = Wads.CheckNumForName (name, ns_colormaps); if (lump == -1) lump = Wads.CheckNumForName (name, ns_global); // [RH] If using BUILD's palette, generate the colormap if (lump == -1 || Wads.CheckNumForFullName("palette.dat") >= 0 || Wads.CheckNumForFullName("blood.pal") >= 0) { Printf ("Make colormap\n"); FDynamicColormap foo; foo.Color = 0xFFFFFF; foo.Fade = 0; foo.Maps = realcolormaps; foo.Desaturate = 0; foo.Next = NULL; foo.BuildLights (); } else { FWadLump lumpr = Wads.OpenLumpNum (lump); // [RH] The colormap may not have been designed for the specific // palette we are using, so remap it to match the current palette. memcpy (remap, GPalette.Remap, 256); memset (unremap, 0, 256); for (i = 0; i < 256; ++i) { unremap[remap[i]] = i; } // Mapping to color 0 is okay, because the colormap won't be used to // produce a masked texture. remap[0] = 0; for (i = 0; i < NUMCOLORMAPS; ++i) { BYTE *map2 = &realcolormaps[i*256]; lumpr.Read (map, 256); for (j = 0; j < 256; ++j) { map2[j] = remap[map[unremap[j]]]; } } } uppercopy (fakecmaps[0].name, name); fakecmaps[0].blend = 0; } }
void FFlatTexture::MakeTexture () { FWadLump lump = Wads.OpenLumpNum (SourceLump); Pixels = new BYTE[Width*Height]; long numread = lump.Read (Pixels, Width*Height); if (numread < Width*Height) { memset (Pixels + numread, 0xBB, Width*Height - numread); } FlipSquareBlockRemap (Pixels, Width, Height, GPalette.Remap); }
void FWadCollection::ReadLump (int lump, void *dest) { FWadLump lumpr = OpenLumpNum (lump); long size = lumpr.GetLength (); long numread = lumpr.Read (dest, size); if (numread != size) { I_Error ("W_ReadLump: only read %ld of %ld on lump %i\n", numread, size, lump); } }
void SD_ContinueMusic(const char* chunk, int startoffs) { SD_MusicOff(); if (MusicMode == smm_AdLib) { { // We need this scope to "delete" the lump before modifying the sqHack pointers. int lumpNum = Wads.CheckNumForName(chunk, ns_music); if(lumpNum == -1) return; SDL_LockMutex(audioMutex); FWadLump lump = Wads.OpenLumpNum(lumpNum); if(sqHackFreeable != NULL) delete[] sqHackFreeable; sqHack = new word[(Wads.LumpLength(lumpNum)/2)+1]; //+1 is just safety sqHackFreeable = sqHack; lump.Read(sqHack, Wads.LumpLength(lumpNum)); if(*sqHack == 0) sqHackLen = sqHackSeqLen = Wads.LumpLength(lumpNum); else sqHackLen = sqHackSeqLen = LittleShort(*sqHack++); sqHackPtr = sqHack; } if(startoffs >= sqHackLen) { SDL_UnlockMutex(audioMutex); Quit("SD_StartMusic: Illegal startoffs provided!"); } // fast forward to correct position // (needed to reconstruct the instruments) for(int i = 0; i < startoffs; i += 2) { byte reg = *(byte *)sqHackPtr; byte val = *(((byte *)sqHackPtr) + 1); if(reg >= 0xb1 && reg <= 0xb8) val &= 0xdf; // disable play note flag else if(reg == 0xbd) val &= 0xe0; // disable drum flags alOut(reg,val); sqHackPtr += 2; sqHackLen -= 4; } sqHackTime = 0; alTimeCount = 0; SDL_UnlockMutex(audioMutex); SD_MusicOn(); } }
void FTGATexture::MakeTexture () { BYTE PaletteMap[256]; FWadLump lump = Wads.OpenLumpNum (SourceLump); TGAHeader hdr; WORD w; BYTE r,g,b,a; BYTE * buffer; Pixels = new BYTE[Width*Height]; lump.Read(&hdr, sizeof(hdr)); lump.Seek(hdr.id_len, SEEK_CUR); hdr.width = LittleShort(hdr.width); hdr.height = LittleShort(hdr.height); hdr.cm_first = LittleShort(hdr.cm_first); hdr.cm_length = LittleShort(hdr.cm_length); if (hdr.has_cm) { memset(PaletteMap, 0, 256); for (int i = hdr.cm_first; i < hdr.cm_first + hdr.cm_length && i < 256; i++) { switch (hdr.cm_size) { case 15: case 16: lump >> w; r = (w & 0x001F) << 3; g = (w & 0x03E0) >> 2; b = (w & 0x7C00) >> 7; a = 255; break; case 24: lump >> b >> g >> r; a=255; break; case 32: lump >> b >> g >> r >> a; if ((hdr.img_desc&15)!=8) a=255; break; default: // should never happen r=g=b=a=0; break; } PaletteMap[i] = a>=128? ColorMatcher.Pick(r, g, b) : 0; } }
FString::FString (ELumpNum lumpnum) { FWadLump lumpr = Wads.OpenLumpNum ((int)lumpnum); long size = lumpr.GetLength (); AllocBuffer (1 + size); long numread = lumpr.Read (&Chars[0], size); Chars[size] = '\0'; if (numread != size) { I_Error ("ConstructStringFromLump: Only read %ld of %ld bytes on lump %i (%s)\n", numread, size, lumpnum, Wads.GetLumpFullName((int)lumpnum)); } }
//***************************************************************************** // void NETWORK_GenerateLumpMD5Hash( const int LumpNum, FString &MD5Hash ) { const int lumpSize = Wads.LumpLength (LumpNum); BYTE *pbData = new BYTE[lumpSize]; FWadLump lump = Wads.OpenLumpNum (LumpNum); // Dump the data from the lump into our data buffer. lump.Read (pbData, lumpSize); // Perform the checksum on our buffer, and free it. CMD5Checksum::GetMD5( pbData, lumpSize, MD5Hash ); delete[] pbData; }
static bool ShowText(const FString exitText, const FString flat, const FString music, ClusterInfo::ExitType type) { // Use cluster background if set. if(!flat.IsEmpty()) backgroundFlat = TexMan(flat); if(!backgroundFlat) // Get default if needed backgroundFlat = TexMan(gameinfo.FinaleFlat); switch(type) { case ClusterInfo::EXIT_MESSAGE: SD_PlaySound ("misc/1up"); Message (exitText); IN_ClearKeysDown (); IN_Ack (); return false; case ClusterInfo::EXIT_LUMP: { int lumpNum = Wads.CheckNumForName(exitText, ns_global); if(lumpNum != -1) { FWadLump lump = Wads.OpenLumpNum(lumpNum); char* text = new char[Wads.LumpLength(lumpNum)]; lump.Read(text, Wads.LumpLength(lumpNum)); if(!music.IsEmpty()) StartCPMusic(music); ShowArticle(text, !!(IWad::GetGame().Flags & IWad::HELPHACK)); delete[] text; } break; } default: if(!music.IsEmpty()) StartCPMusic(music); ShowArticle(exitText, !!(IWad::GetGame().Flags & IWad::HELPHACK)); break; } IN_ClearKeysDown(); if (MousePresent && IN_IsInputGrabbed()) IN_CenterMouse(); // Clear accumulated mouse movement return true; }
static void InitBoomColormaps () { // [RH] Try and convert BOOM colormaps into blending values. // This is a really rough hack, but it's better than // not doing anything with them at all (right?) uint32_t NumLumps = Wads.GetNumLumps(); realcolormaps.Maps = new uint8_t[256*NUMCOLORMAPS*fakecmaps.Size()]; SetDefaultColormap ("COLORMAP"); if (fakecmaps.Size() > 1) { uint8_t unremap[256], remap[256], mapin[256]; int i; unsigned j; memcpy (remap, GPalette.Remap, 256); memset (unremap, 0, 256); for (i = 0; i < 256; ++i) { unremap[remap[i]] = i; } remap[0] = 0; for (j = 1; j < fakecmaps.Size(); j++) { if (Wads.LumpLength (fakecmaps[j].lump) >= (NUMCOLORMAPS+1)*256) { int k, r; FWadLump lump = Wads.OpenLumpNum (fakecmaps[j].lump); uint8_t *const map = realcolormaps.Maps + NUMCOLORMAPS*256*j; for (k = 0; k < NUMCOLORMAPS; ++k) { uint8_t *map2 = &map[k*256]; lump.Read (mapin, 256); map2[0] = 0; for (r = 1; r < 256; ++r) { map2[r] = remap[mapin[unremap[r]]]; } } } } } }
/////////////////////////////////////////////////////////////////////////// // // SD_StartMusic() - starts playing the music pointed to // /////////////////////////////////////////////////////////////////////////// void SD_StartMusic(const char* chunk) { static const Instrument ChannelRelease = { 0, 0, 0x3F, 0x3F, 0xFF, 0xFF, 0xF, 0xF, 0, 0, 0, 0, 0, {0, 0, 0} }; SD_MusicOff(); if (MusicMode == smm_AdLib) { int lumpNum = Wads.CheckNumForName(chunk, ns_music); if(lumpNum == -1) return; SDL_LockMutex(audioMutex); for (int i = 0; i < OPL_CHANNELS; ++i) SDL_AlSetChanInst(&ChannelRelease, i); FWadLump lump = Wads.OpenLumpNum(lumpNum); if(sqHackFreeable != NULL) delete[] sqHackFreeable; sqHack = new word[(Wads.LumpLength(lumpNum)/2)+1]; //+1 is just safety sqHackFreeable = sqHack; lump.Read(sqHack, Wads.LumpLength(lumpNum)); if(*sqHack == 0) sqHackLen = sqHackSeqLen = Wads.LumpLength(lumpNum); else sqHackLen = sqHackSeqLen = LittleShort(*sqHack++); sqHackPtr = sqHack; sqHackTime = 0; alTimeCount = 0; SDL_UnlockMutex(audioMutex); SD_MusicOn(); } }
void FTextureManager::AddPatches (int lumpnum) { FWadLump *file = Wads.ReopenLumpNum (lumpnum); DWORD numpatches, i; char name[9]; *file >> numpatches; name[8] = 0; for (i = 0; i < numpatches; ++i) { file->Read (name, 8); if (CheckForTexture (name, FTexture::TEX_WallPatch, 0) == -1) { CreateTexture (Wads.CheckNumForName (name, ns_patches), FTexture::TEX_WallPatch); } //StartScreen->Progress(); } delete file; }
void R_InitColormaps () { // [RH] Try and convert BOOM colormaps into blending values. // This is a really rough hack, but it's better than // not doing anything with them at all (right?) FakeCmap cm; R_DeinitColormaps(); cm.name[0] = 0; cm.blend = 0; fakecmaps.Push(cm); uint32_t NumLumps = Wads.GetNumLumps(); for (uint32_t i = 0; i < NumLumps; i++) { if (Wads.GetLumpNamespace(i) == ns_colormaps) { char name[9]; name[8] = 0; Wads.GetLumpName (name, i); if (Wads.CheckNumForName (name, ns_colormaps) == (int)i) { strncpy(cm.name, name, 8); cm.blend = 0; cm.lump = i; fakecmaps.Push(cm); } } } int rr = 0, gg = 0, bb = 0; for(int x=0;x<256;x++) { rr += GPalette.BaseColors[x].r; gg += GPalette.BaseColors[x].g; bb += GPalette.BaseColors[x].b; } rr >>= 8; gg >>= 8; bb >>= 8; int palette_brightness = (rr*77 + gg*143 + bb*35) / 255; // To calculate the blend it will just average the colors of the first map if (fakecmaps.Size() > 1) { uint8_t map[256]; for (unsigned j = 1; j < fakecmaps.Size(); j++) { if (Wads.LumpLength (fakecmaps[j].lump) >= 256) { int k, r, g, b; FWadLump lump = Wads.OpenLumpNum (fakecmaps[j].lump); lump.Read(map, 256); r = g = b = 0; for (k = 0; k < 256; k++) { r += GPalette.BaseColors[map[k]].r; g += GPalette.BaseColors[map[k]].g; b += GPalette.BaseColors[map[k]].b; } r /= 256; g /= 256; b /= 256; // The calculated average is too dark so brighten it according to the palettes's overall brightness int maxcol = MAX<int>(MAX<int>(palette_brightness, r), MAX<int>(g, b)); fakecmaps[j].blend = PalEntry (255, r * 255 / maxcol, g * 255 / maxcol, b * 255 / maxcol); } } } // build default special maps (e.g. invulnerability) for (unsigned i = 0; i < countof(SpecialColormapParms); ++i) { AddSpecialColormap(SpecialColormapParms[i].Start[0], SpecialColormapParms[i].Start[1], SpecialColormapParms[i].Start[2], SpecialColormapParms[i].End[0], SpecialColormapParms[i].End[1], SpecialColormapParms[i].End[2]); } // desaturated colormaps. These are used for texture composition for(int m = 0; m < 31; m++) { uint8_t *shade = DesaturateColormap[m]; for (int c = 0; c < 256; c++) { int intensity = (GPalette.BaseColors[c].r * 77 + GPalette.BaseColors[c].g * 143 + GPalette.BaseColors[c].b * 37) / 256; int r = (GPalette.BaseColors[c].r * (31-m) + intensity *m) / 31; int g = (GPalette.BaseColors[c].g * (31-m) + intensity *m) / 31; int b = (GPalette.BaseColors[c].b * (31-m) + intensity *m) / 31; shade[c] = ColorMatcher.Pick(r, g, b); } } }
void FFontChar2::MakeTexture () { FWadLump lump = Wads.OpenLumpNum (SourceLump); int destSize = Width * Height; BYTE max = 255; // This is to "fix" bad fonts { BYTE buff[8]; lump.Read (buff, 4); if (buff[3] == '2') { lump.Read (buff, 7); max = buff[6]; lump.Seek (SourcePos - 11, SEEK_CUR); } else { lump.Seek (SourcePos - 4, SEEK_CUR); } } Pixels = new BYTE[destSize]; int runlen = 0, setlen = 0; BYTE setval = 0; // Shut up, GCC! BYTE *dest_p = Pixels; int dest_adv = Height; int dest_rew = destSize - 1; for (int y = Height; y != 0; --y) { for (int x = Width; x != 0; ) { if (runlen != 0) { BYTE color; lump >> color; *dest_p = MIN (color, max); if (SourceRemap != NULL) { *dest_p = SourceRemap[*dest_p]; } dest_p += dest_adv; x--; runlen--; } else if (setlen != 0) { *dest_p = setval; dest_p += dest_adv; x--; setlen--; } else { SBYTE code; lump >> code; if (code >= 0) { runlen = code + 1; } else if (code != -128) { BYTE color; lump >> color; setlen = (-code) + 1; setval = MIN (color, max); if (SourceRemap != NULL) { setval = SourceRemap[setval]; } } }
void R_InitColormaps () { // [RH] Try and convert BOOM colormaps into blending values. // This is a really rough hack, but it's better than // not doing anything with them at all (right?) FakeCmap cm; R_DeinitColormaps(); cm.name[0] = 0; cm.blend = 0; fakecmaps.Push(cm); DWORD NumLumps = Wads.GetNumLumps(); for (DWORD i = 0; i < NumLumps; i++) { if (Wads.GetLumpNamespace(i) == ns_colormaps) { char name[9]; name[8] = 0; Wads.GetLumpName (name, i); if (Wads.CheckNumForName (name, ns_colormaps) == (int)i) { strncpy(cm.name, name, 8); cm.blend = 0; cm.lump = i; fakecmaps.Push(cm); } } } realcolormaps = new BYTE[256*NUMCOLORMAPS*fakecmaps.Size()]; R_SetDefaultColormap ("COLORMAP"); if (fakecmaps.Size() > 1) { BYTE unremap[256], remap[256], mapin[256]; int i; unsigned j; memcpy (remap, GPalette.Remap, 256); memset (unremap, 0, 256); for (i = 0; i < 256; ++i) { unremap[remap[i]] = i; } remap[0] = 0; for (j = 1; j < fakecmaps.Size(); j++) { if (Wads.LumpLength (fakecmaps[j].lump) >= (NUMCOLORMAPS+1)*256) { int k, r, g, b; FWadLump lump = Wads.OpenLumpNum (fakecmaps[j].lump); BYTE *const map = realcolormaps + NUMCOLORMAPS*256*j; for (k = 0; k < NUMCOLORMAPS; ++k) { BYTE *map2 = &map[k*256]; lump.Read (mapin, 256); map2[0] = 0; for (r = 1; r < 256; ++r) { map2[r] = remap[mapin[unremap[r]]]; } } r = g = b = 0; for (k = 0; k < 256; k++) { r += GPalette.BaseColors[map[k]].r; g += GPalette.BaseColors[map[k]].g; b += GPalette.BaseColors[map[k]].b; } fakecmaps[j].blend = PalEntry (255, r/256, g/256, b/256); } } } NormalLight.Color = PalEntry (255, 255, 255); NormalLight.Fade = 0; NormalLight.Maps = realcolormaps; NormalLightHasFixedLights = R_CheckForFixedLights(realcolormaps); numfakecmaps = fakecmaps.Size(); // build default special maps (e.g. invulnerability) for (unsigned i = 0; i < countof(SpecialColormapParms); ++i) { AddSpecialColormap(SpecialColormapParms[i].Start[0], SpecialColormapParms[i].Start[1], SpecialColormapParms[i].Start[2], SpecialColormapParms[i].End[0], SpecialColormapParms[i].End[1], SpecialColormapParms[i].End[2]); } // desaturated colormaps. These are used for texture composition for(int m = 0; m < 31; m++) { BYTE *shade = DesaturateColormap[m]; for (int c = 0; c < 256; c++) { int intensity = (GPalette.BaseColors[c].r * 77 + GPalette.BaseColors[c].g * 143 + GPalette.BaseColors[c].b * 37) / 256; int r = (GPalette.BaseColors[c].r * (31-m) + intensity *m) / 31; int g = (GPalette.BaseColors[c].g * (31-m) + intensity *m) / 31; int b = (GPalette.BaseColors[c].b * (31-m) + intensity *m) / 31; shade[c] = ColorMatcher.Pick(r, g, b); } } }