int FWadCollection::FindLump (const char *name, int *lastlump, bool anyns) { union { char name8[8]; uint64_t qname; }; LumpRecord *lump_p; uppercopy (name8, name); assert(lastlump != NULL && *lastlump >= 0); lump_p = &LumpInfo[*lastlump]; while (lump_p < &LumpInfo[NumLumps]) { FResourceLump *lump = lump_p->lump; if ((anyns || lump->Namespace == ns_global) && lump->qwName == qname) { int lump = int(lump_p - &LumpInfo[0]); *lastlump = lump + 1; return lump; } lump_p++; } *lastlump = NumLumps; return -1; }
static int WriteSIDEDEFS (FILE *file) { mapsidedef_t msd; for (int i = 0; i < numsides; ++i) { msd.textureoffset = LittleShort(short(sides[i].GetTextureXOffset(side_t::mid) >> FRACBITS)); msd.rowoffset = LittleShort(short(sides[i].GetTextureYOffset(side_t::mid) >> FRACBITS)); msd.sector = LittleShort(short(sides[i].sector - sectors)); uppercopy (msd.toptexture, GetTextureName (sides[i].GetTexture(side_t::top))); uppercopy (msd.bottomtexture, GetTextureName (sides[i].GetTexture(side_t::bottom))); uppercopy (msd.midtexture, GetTextureName (sides[i].GetTexture(side_t::mid))); fwrite (&msd, sizeof(msd), 1, file); } return numsides * sizeof(msd); }
void FWadCollection::GetLumpName (char *to, int lump) const { if ((size_t)lump >= NumLumps) *to = 0; else uppercopy (to, LumpInfo[lump].lump->Name); }
void gl_ParseSkybox() { int facecount=0; SC_MustGetString(); FSkyBox * sb = new FSkyBox; uppercopy(sb->Name, sc_String); sb->Name[8]=0; SC_MustGetStringName("{"); while (!SC_CheckString("}")) { SC_MustGetString(); if (facecount<6) { sb->faces[facecount] = TexMan[TexMan.GetTexture(sc_String, FTexture::TEX_Wall, FTextureManager::TEXMAN_TryAny|FTextureManager::TEXMAN_Overridable)]; } facecount++; } if (facecount != 3 && facecount != 6) { SC_ScriptError("%s: Skybox definition requires either 3 or 6 faces", sb->Name); } sb->SetSize(); TexMan.AddTexture(sb); FGLTexture * gltex = FGLTexture::ValidateTexture(sb); gltex->bSkybox=true; }
void gl_ParseSkybox(FScanner &sc) { int facecount=0; sc.MustGetString(); FSkyBox * sb = new FSkyBox; uppercopy(sb->Name, sc.String); sb->Name[8]=0; if (sc.CheckString("fliptop")) { sb->fliptop = true; } sc.MustGetStringName("{"); while (!sc.CheckString("}")) { sc.MustGetString(); if (facecount<6) { sb->faces[facecount] = TexMan[TexMan.GetTexture(sc.String, FTexture::TEX_Wall, FTextureManager::TEXMAN_TryAny|FTextureManager::TEXMAN_Overridable)]; } facecount++; } if (facecount != 3 && facecount != 6) { sc.ScriptError("%s: Skybox definition requires either 3 or 6 faces", sb->Name); } sb->SetSize(); TexMan.AddTexture(sb); }
int FWadCollection::CheckNumForName (const char *name, int space, int wadnum, bool exact) { FResourceLump *lump; union { char uname[8]; uint64_t qname; }; uint32_t i; if (wadnum < 0) { return CheckNumForName (name, space); } uppercopy (uname, name); i = FirstLumpIndex[LumpNameHash (uname) % NumLumps]; // If exact is true if will only find lumps in the same WAD, otherwise // also those in earlier WADs. while (i != NULL_INDEX && (lump = LumpInfo[i].lump, lump->qwName != qname || lump->Namespace != space || (exact? (LumpInfo[i].wadnum != wadnum) : (LumpInfo[i].wadnum > wadnum)) )) { i = NextLumpIndex[i]; } return i != NULL_INDEX ? i : -1; }
void FWadCollection::InitHashChains (void) { char name[8]; unsigned int i, j; // Mark all buckets as empty memset (FirstLumpIndex, 255, NumLumps*sizeof(FirstLumpIndex[0])); memset (NextLumpIndex, 255, NumLumps*sizeof(NextLumpIndex[0])); memset (FirstLumpIndex_FullName, 255, NumLumps*sizeof(FirstLumpIndex_FullName[0])); memset (NextLumpIndex_FullName, 255, NumLumps*sizeof(NextLumpIndex_FullName[0])); // Now set up the chains for (i = 0; i < (unsigned)NumLumps; i++) { uppercopy (name, LumpInfo[i].lump->Name); j = LumpNameHash (name) % NumLumps; NextLumpIndex[i] = FirstLumpIndex[j]; FirstLumpIndex[j] = i; // Do the same for the full paths if (LumpInfo[i].lump->FullName.IsNotEmpty()) { j = MakeKey(LumpInfo[i].lump->FullName) % NumLumps; NextLumpIndex_FullName[i] = FirstLumpIndex_FullName[j]; FirstLumpIndex_FullName[j] = i; } } }
static int WriteSECTORS (FILE *file) { mapsector_t ms; for (int i = 0; i < numsectors; ++i) { ms.floorheight = LittleShort(short(sectors[i].GetPlaneTexZF(sector_t::floor))); ms.ceilingheight = LittleShort(short(sectors[i].GetPlaneTexZF(sector_t::ceiling))); uppercopy (ms.floorpic, GetTextureName (sectors[i].GetTexture(sector_t::floor))); uppercopy (ms.ceilingpic, GetTextureName (sectors[i].GetTexture(sector_t::ceiling))); ms.lightlevel = LittleShort((short)sectors[i].lightlevel); ms.special = LittleShort(sectors[i].special); ms.tag = LittleShort(tagManager.GetFirstSectorTag(§ors[i])); fwrite (&ms, sizeof(ms), 1, file); } return numsectors * sizeof(ms); }
level_info_t *FindLevelInfo (const char *mapname) { int i; if ((i = FindWadLevelInfo (mapname)) > -1) return &wadlevelinfos[i]; else { if (TheDefaultLevelInfo.LevelName.IsEmpty()) { uppercopy(TheDefaultLevelInfo.skypic1, "SKY1"); uppercopy(TheDefaultLevelInfo.skypic2, "SKY1"); TheDefaultLevelInfo.LevelName = "Unnamed"; } return &TheDefaultLevelInfo; } }
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; } }
static int ParseLumpName(FScanner &scanner, char *buffer) { scanner.MustGetToken(TK_StringConst); if (strlen(scanner.String) > 8) { scanner.ScriptError("String too long. Maximum size is 8 characters."); return 0; } uppercopy(buffer, scanner.String); return 1; }
void FResourceLump::LumpNameSetup(const char *iname) { const char *lname = strrchr(iname,'/'); lname = (lname == NULL) ? iname : lname + 1; FString base = lname; base = base.Left(base.LastIndexOf('.')); uppercopy(Name, base); Name[8] = 0; FullName = copystring(iname); // Map some directories to WAD namespaces. // Note that some of these namespaces don't exist in WADS. // CheckNumForName will handle any request for these namespaces accordingly. Namespace = !strncmp(iname, "flats/", 6) ? ns_flats : !strncmp(iname, "textures/", 9) ? ns_newtextures : !strncmp(iname, "hires/", 6) ? ns_hires : !strncmp(iname, "sprites/", 8) ? ns_sprites : !strncmp(iname, "voxels/", 7) ? ns_voxels : !strncmp(iname, "colormaps/", 10) ? ns_colormaps : !strncmp(iname, "acs/", 4) ? ns_acslibrary : !strncmp(iname, "voices/", 7) ? ns_strifevoices : !strncmp(iname, "patches/", 8) ? ns_patches : !strncmp(iname, "graphics/", 9) ? ns_graphics : !strncmp(iname, "sounds/", 7) ? ns_sounds : !strncmp(iname, "music/", 6) ? ns_music : !strncmp(iname, "userdata/", 9) ? ns_userdata : !strncmp(iname, "hitmaps/", 9) ? ns_hitmaps : !strchr(iname, '/') ? ns_global : -1; // Anything that is not in one of these subdirectories or the main directory // should not be accessible through the standard WAD functions but only through // the ones which look for the full name. if (Namespace == -1) { memset(Name, 0, 8); } // Since '\' can't be used as a file name's part inside a ZIP // we have to work around this for sprites because it is a valid // frame character. else if (Namespace == ns_sprites || Namespace == ns_voxels) { char *c; while ((c = (char*)memchr(Name, '^', 8))) { *c = '\\'; } } }
void gl_ParseVavoomSkybox() { int lump = Wads.CheckNumForName("SKYBOXES"); if (lump < 0) return; FScanner sc(lump); while (sc.GetString()) { int facecount=0; int maplump = -1; FSkyBox * sb = new FSkyBox; uppercopy(sb->Name, sc.String); sb->Name[8]=0; sb->fliptop = true; sc.MustGetStringName("{"); while (!sc.CheckString("}")) { if (facecount<6) { sc.MustGetStringName("{"); sc.MustGetStringName("map"); sc.MustGetString(); maplump = Wads.CheckNumForFullName(sc.String, true); if (maplump==-1) Printf("Texture '%s' not found in Vavoom skybox '%s'\n", sc.String, sb->Name); FTextureID tex = TexMan.FindTextureByLumpNum(maplump); if (!tex.isValid()) { tex = TexMan.CreateTexture(maplump, FTexture::TEX_MiscPatch); } sb->faces[facecount] = TexMan[tex]; sc.MustGetStringName("}"); } facecount++; } if (facecount != 6) { sc.ScriptError("%s: Skybox definition requires 6 faces", sb->Name); } sb->SetSize(); TexMan.AddTexture(sb); } }
int FWadCollection::CheckNumForName (const char *name, int space) { union { char uname[8]; uint64_t qname; }; uint32_t i; if (name == NULL) { return -1; } // Let's not search for names that are longer than 8 characters and contain path separators // They are almost certainly full path names passed to this function. if (strlen(name) > 8 && strpbrk(name, "/.")) { return -1; } uppercopy (uname, name); i = FirstLumpIndex[LumpNameHash (uname) % NumLumps]; while (i != NULL_INDEX) { FResourceLump *lump = LumpInfo[i].lump; if (lump->qwName == qname) { if (lump->Namespace == space) break; // If the lump is from one of the special namespaces exclusive to Zips // the check has to be done differently: // If we find a lump with this name in the global namespace that does not come // from a Zip return that. WADs don't know these namespaces and single lumps must // work as well. if (space > ns_specialzipdirectory && lump->Namespace == ns_global && !(lump->Flags & LUMPF_ZIPFILE)) break; } i = NextLumpIndex[i]; } return i != NULL_INDEX ? i : -1; }
bool FWadFile::Open(bool quiet) { wadinfo_t header; Reader->Read(&header, sizeof(header)); NumLumps = LittleLong(header.NumLumps); header.InfoTableOfs = LittleLong(header.InfoTableOfs); wadlump_t *fileinfo = new wadlump_t[NumLumps]; Reader->Seek (header.InfoTableOfs, SEEK_SET); Reader->Read (fileinfo, NumLumps * sizeof(wadlump_t)); Lumps = new FUncompressedLump[NumLumps]; if (!quiet) Printf(", %d lumps\n", NumLumps); for(DWORD i = 0; i < NumLumps; i++) { uppercopy (Lumps[i].Name, fileinfo[i].Name); Lumps[i].Name[8] = 0; Lumps[i].Owner = this; Lumps[i].Position = LittleLong(fileinfo[i].FilePos); Lumps[i].LumpSize = LittleLong(fileinfo[i].Size); Lumps[i].Namespace = ns_global; Lumps[i].Flags = 0; Lumps[i].FullName = NULL; } if (!quiet) // don't bother with namespaces here. We won't need them. { SetNamespace("S_START", "S_END", ns_sprites); SetNamespace("F_START", "F_END", ns_flats, true); SetNamespace("C_START", "C_END", ns_colormaps); SetNamespace("A_START", "A_END", ns_acslibrary); SetNamespace("TX_START", "TX_END", ns_newtextures); SetNamespace("V_START", "V_END", ns_strifevoices); SetNamespace("HI_START", "HI_END", ns_hires); SetNamespace("VX_START", "VX_END", ns_voxels); SkinHack(); } delete [] fileinfo; return true; }
bool FLumpFile::Open(bool quiet) { FString name(ExtractFileBase (Filename)); Lumps = new FUncompressedLump[1]; // must use array allocator uppercopy(Lumps->Name, name); Lumps->Name[8] = 0; Lumps->Owner = this; Lumps->Position = 0; Lumps->LumpSize = Reader->GetLength(); Lumps->Namespace = ns_global; Lumps->Flags = 0; Lumps->FullName = NULL; NumLumps = 1; if (!quiet) { Printf("\n"); } return true; }
FTexture::FTexture (const char *name, int lumpnum) : LeftOffset(0), TopOffset(0), WidthBits(0), HeightBits(0), xScale(FRACUNIT), yScale(FRACUNIT), SourceLump(lumpnum), UseType(TEX_Any), bNoDecals(false), bNoRemap0(false), bWorldPanning(false), bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), Rotations(0xFFFF), Width(0), Height(0), WidthMask(0), Native(NULL) { if (name != NULL) { uppercopy(Name, name); } else if (lumpnum < 0) { *Name = 0; } else { Wads.GetLumpName (Name, lumpnum); Name[8] = 0; } }
// // G_ParseMapInfo // Parses the MAPINFO lumps of all loaded WADs and generates // data for wadlevelinfos and wadclusterinfos. // void G_ParseMapInfo (void) { int lump, lastlump = 0; level_pwad_info_t defaultinfo; level_pwad_info_t *levelinfo; int levelindex; cluster_info_t *clusterinfo; int clusterindex; DWORD levelflags; while ((lump = W_FindLump ("MAPINFO", &lastlump)) != -1) { SetLevelDefaults (&defaultinfo); SC_OpenLumpNum (lump, "MAPINFO"); while (SC_GetString ()) { switch (SC_MustMatchString (MapInfoTopLevel)) { case MITL_DEFAULTMAP: SetLevelDefaults (&defaultinfo); ParseMapInfoLower (MapHandlers, MapInfoMapLevel, &defaultinfo, NULL, 0); break; case MITL_MAP: // map <MAPNAME> <Nice Name> levelflags = defaultinfo.flags; SC_MustGetString (); if (IsNum (sc_String)) { // MAPNAME is a number, assume a Hexen wad int map = atoi (sc_String); sprintf (sc_String, "MAP%02d", map); SKYFLATNAME[5] = 0; HexenHack = true; // Hexen levels are automatically nointermission // and even lighting and no auto sound sequences levelflags |= LEVEL_NOINTERMISSION | LEVEL_EVENLIGHTING | LEVEL_SNDSEQTOTALCTRL; } levelindex = FindWadLevelInfo (sc_String); if (levelindex == -1) { levelindex = numwadlevelinfos++; wadlevelinfos = (level_pwad_info_t *)Realloc (wadlevelinfos, sizeof(level_pwad_info_t)*numwadlevelinfos); } levelinfo = wadlevelinfos + levelindex; memcpy (levelinfo, &defaultinfo, sizeof(*levelinfo)); uppercopy (levelinfo->mapname, sc_String); SC_MustGetString (); ReplaceString (&levelinfo->level_name, sc_String); // Set up levelnum now so that the Teleport_NewMap specials // in hexen.wad work without modification. if (!strnicmp (levelinfo->mapname, "MAP", 3) && levelinfo->mapname[5] == 0) { int mapnum = atoi (levelinfo->mapname + 3); if (mapnum >= 1 && mapnum <= 99) levelinfo->levelnum = mapnum; } ParseMapInfoLower (MapHandlers, MapInfoMapLevel, levelinfo, NULL, levelflags); break; case MITL_CLUSTERDEF: // clusterdef <clusternum> SC_MustGetNumber (); clusterindex = FindWadClusterInfo (sc_Number); if (clusterindex == -1) { clusterindex = numwadclusterinfos++; wadclusterinfos = (cluster_info_t *)Realloc (wadclusterinfos, sizeof(cluster_info_t)*numwadclusterinfos); memset (wadclusterinfos + clusterindex, 0, sizeof(cluster_info_t)); } clusterinfo = wadclusterinfos + clusterindex; clusterinfo->cluster = sc_Number; ParseMapInfoLower (ClusterHandlers, MapInfoClusterLevel, NULL, clusterinfo, 0); break; } } SC_Close (); } }
static void ParseMapInfoLower (MapInfoHandler *handlers, const char *strings[], level_pwad_info_t *levelinfo, cluster_info_t *clusterinfo, DWORD flags) { int entry; MapInfoHandler *handler; byte *info; info = levelinfo ? (byte *)levelinfo : (byte *)clusterinfo; while (SC_GetString ()) { if (SC_MatchString (MapInfoTopLevel) != -1) { SC_UnGet (); break; } entry = SC_MustMatchString (strings); handler = handlers + entry; switch (handler->type) { case MITYPE_IGNORE: break; case MITYPE_EATNEXT: SC_MustGetString (); break; case MITYPE_INT: SC_MustGetNumber (); *((int *)(info + handler->data1)) = sc_Number; break; case MITYPE_FLOAT: SC_MustGetFloat (); *((float *)(info + handler->data1)) = sc_Float; break; case MITYPE_COLOR: { SC_MustGetString (); std::string string = V_GetColorStringByName (sc_String); if (string.length()) { *((DWORD *)(info + handler->data1)) = V_GetColorFromString (NULL, string.c_str()); } else { *((DWORD *)(info + handler->data1)) = V_GetColorFromString (NULL, sc_String); } } break; case MITYPE_MAPNAME: SC_MustGetString (); if (IsNum (sc_String)) { int map = atoi (sc_String); sprintf (sc_String, "MAP%02d", map); } strncpy ((char *)(info + handler->data1), sc_String, 8); break; case MITYPE_LUMPNAME: SC_MustGetString (); uppercopy ((char *)(info + handler->data1), sc_String); break; case MITYPE_SKY: SC_MustGetString (); // get texture name; uppercopy ((char *)(info + handler->data1), sc_String); SC_MustGetFloat (); // get scroll speed //if (HexenHack) //{ // *((fixed_t *)(info + handler->data2)) = sc_Number << 8; //} //else //{ // *((fixed_t *)(info + handler->data2)) = (fixed_t)(sc_Float * 65536.0f); //} break; case MITYPE_SETFLAG: flags |= handler->data1; break; case MITYPE_SCFLAGS: flags = (flags & handler->data2) | handler->data1; break; case MITYPE_CLUSTER: SC_MustGetNumber (); *((int *)(info + handler->data1)) = sc_Number; if (HexenHack) { cluster_info_t *clusterH = FindClusterInfo (sc_Number); if (clusterH) clusterH->flags |= CLUSTER_HUB; } break; case MITYPE_STRING: SC_MustGetString (); ReplaceString ((const char **)(info + handler->data1), sc_String); break; case MITYPE_CSTRING: SC_MustGetString (); strncpy ((char *)(info + handler->data1), sc_String, handler->data2); *((char *)(info + handler->data1 + handler->data2)) = '\0'; break; } } if (levelinfo) levelinfo->flags = flags; else clusterinfo->flags = flags; }
FTexture * FTexture::CreateTexture (const char *name, int lumpnum, int usetype) { FTexture *tex = CreateTexture(lumpnum, usetype); if (tex != NULL && name != NULL) uppercopy(tex->Name, name); return tex; }
void FMapInfoParser::ParseLumpOrTextureName(char *name) { sc.MustGetString(); uppercopy(name, sc.String); name[8]=0; }