diff --git a/docs/rh-log.txt b/docs/rh-log.txt index b9d01f3b5..a39d02a22 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,13 @@ +May 3, 2006 +- Removed -bpal parameter. Blood's blood.pal is loaded from blood.rff, and + its tiles are loaded from the same directory. +- RFF files now load their entire directories into the lumplist. +- Added char * and const char * type coversions for FString, so FStrings can be + freely passed to functions expecting C strings. (Except varargs functions, + which still require manually fetching the C string out of it.) +- Renamed the name class to FName. +- Renamed the string class to FString to emphasize that it is not std::string. + May 3, 2006 (Changes by Graf Zahl) - Removed doom.x, heretic.x and strife.x from the SVN repository. These are generated files. diff --git a/src/b_game.cpp b/src/b_game.cpp index 87bcaeb79..2cb6e0edb 100644 --- a/src/b_game.cpp +++ b/src/b_game.cpp @@ -488,21 +488,21 @@ void DCajunMaster::ForgetBots () bool DCajunMaster::LoadBots () { - string tmp; + FString tmp; bool gotteam = false; bglobal.ForgetBots (); #ifndef unix tmp = progdir; tmp += "zcajun/" BOTFILENAME; - if (!FileExists (tmp.GetChars())) + if (!FileExists (tmp)) { DPrintf ("No " BOTFILENAME ", so no bots\n"); return false; } #else tmp = GetUserFile (BOTFILENAME); - if (!FileExists (tmp.GetChars())) + if (!FileExists (tmp)) { if (!FileExists (SHARE_DIR BOTFILENAME)) { @@ -515,7 +515,7 @@ bool DCajunMaster::LoadBots () #endif else { - SC_OpenFile (tmp.GetChars()); + SC_OpenFile (tmp); } while (SC_GetString ()) diff --git a/src/c_cmds.cpp b/src/c_cmds.cpp index 23c21d995..b523d9b2d 100644 --- a/src/c_cmds.cpp +++ b/src/c_cmds.cpp @@ -633,9 +633,9 @@ CCMD (load) Printf ("cannot load during a network game\n"); return; } - string fname = argv[1]; + FString fname = argv[1]; DefaultExtension (fname, ".zds"); - G_LoadGame (fname.GetChars()); + G_LoadGame (fname); } //========================================================================== @@ -668,9 +668,38 @@ CCMD (save) Printf ("player is dead in a single-player game\n"); return; } - string fname = argv[1]; + FString fname = argv[1]; DefaultExtension (fname, ".zds"); - G_SaveGame (fname.GetChars(), argv.argc() > 2 ? argv[2] : argv[1]); + G_SaveGame (fname, argv.argc() > 2 ? argv[2] : argv[1]); +} + +//========================================================================== +// +// CCMD wdir +// +// Lists the contents of a loaded wad file. +// +//========================================================================== + +CCMD (wdir) +{ + if (argv.argc() != 2) + { + Printf ("usage: wdir \n"); + return; + } + int wadnum = Wads.CheckIfWadLoaded (argv[1]); + if (wadnum < 0) + { + Printf ("%s must be loaded to view its directory.\n", argv[1]); + } + for (int i = 0; i < Wads.GetNumLumps(); ++i) + { + if (Wads.GetLumpFile(i) == wadnum) + { + Printf ("%s\n", Wads.GetLumpFullName(i)); + } + } } //----------------------------------------------------------------------------- diff --git a/src/c_console.cpp b/src/c_console.cpp index 21f7e1740..189fbfc67 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -236,7 +236,7 @@ struct TextQueue TextQueue *Next; bool bNotify; int PrintLevel; - string Text; + FString Text; }; TextQueue *EnqueuedText, **EnqueuedTextTail = &EnqueuedText; @@ -257,11 +257,11 @@ void DequeueConsoleText () TextQueue *next = queued->Next; if (queued->bNotify) { - C_AddNotifyString (queued->PrintLevel, queued->Text.GetChars()); + C_AddNotifyString (queued->PrintLevel, queued->Text); } else { - AddToConsole (queued->PrintLevel, queued->Text.GetChars()); + AddToConsole (queued->PrintLevel, queued->Text); } delete queued; queued = next; @@ -452,10 +452,10 @@ void C_AddNotifyString (int printlevel, const char *source) if (addtype == APPENDLINE && NotifyStrings[NUMNOTIFIES-1].printlevel == printlevel) { - string str; + FString str; str.Format("%s%s", NotifyStrings[NUMNOTIFIES-1].text, source); - lines = V_BreakLines (width, str.GetChars()); + lines = V_BreakLines (width, str); } else { @@ -715,9 +715,9 @@ int VPrintf (int printlevel, const char *format, va_list parms) if (gameisdead) return 0; - string outline; + FString outline; outline.VFormat (format, parms); - return PrintString (printlevel, outline.GetChars()); + return PrintString (printlevel, outline); } int STACK_ARGS Printf (int printlevel, const char *format, ...) @@ -1100,12 +1100,12 @@ void C_DrawConsole () // Make a copy of the command line, in case an input event is handled // while we draw the console and it changes. CmdLine[2+CmdLine[0]] = 0; - string command((char *)&CmdLine[2+CmdLine[259]]); + FString command((char *)&CmdLine[2+CmdLine[259]]); int cursorpos = CmdLine[1] - CmdLine[259]; screen->DrawChar (CR_ORANGE, left, bottomline, '\x1c', TAG_DONE); screen->DrawText (CR_ORANGE, left + ConFont->GetCharWidth(0x1c), bottomline, - command.GetChars(), TAG_DONE); + command, TAG_DONE); if (cursoron) { diff --git a/src/cmdlib.cpp b/src/cmdlib.cpp index 84259769c..8124d5174 100644 --- a/src/cmdlib.cpp +++ b/src/cmdlib.cpp @@ -144,7 +144,7 @@ void DefaultExtension (char *path, const char *extension) strcat (path, extension); } -void DefaultExtension (string &path, const char *extension) +void DefaultExtension (FString &path, const char *extension) { char *src = &path[int(path.Len())-1]; diff --git a/src/cmdlib.h b/src/cmdlib.h index 70705d430..930a81972 100644 --- a/src/cmdlib.h +++ b/src/cmdlib.h @@ -33,7 +33,7 @@ extern char progdir[1024]; void FixPathSeperator (char *path); void DefaultExtension (char *path, const char *extension); -void DefaultExtension (string &path, const char *extension); +void DefaultExtension (FString &path, const char *extension); void ExtractFilePath (const char *path, char *dest); void ExtractFileBase (const char *path, char *dest); diff --git a/src/configfile.cpp b/src/configfile.cpp index ff2663f81..3f4647871 100644 --- a/src/configfile.cpp +++ b/src/configfile.cpp @@ -128,7 +128,7 @@ void FConfigFile::ClearConfig () LastSectionPtr = &Sections; } -void FConfigFile::ChangePathName (const string &pathname) +void FConfigFile::ChangePathName (const char *pathname) { PathName = pathname; } @@ -306,7 +306,7 @@ FConfigFile::FConfigEntry *FConfigFile::NewConfigEntry ( void FConfigFile::LoadConfigFile (void (*nosechandler)(const char *pathname, FConfigFile *config, void *userdata), void *userdata) { - FILE *file = fopen (PathName.GetChars(), "r"); + FILE *file = fopen (PathName, "r"); bool succ; if (file == NULL) @@ -319,7 +319,7 @@ void FConfigFile::LoadConfigFile (void (*nosechandler)(const char *pathname, FCo { // First valid line did not define a section if (nosechandler != NULL) { - nosechandler (PathName.GetChars(), this, userdata); + nosechandler (PathName, this, userdata); } } } @@ -399,7 +399,7 @@ char *FConfigFile::ReadLine (char *string, int n, void *file) const void FConfigFile::WriteConfigFile () const { - FILE *file = fopen (PathName.GetChars(), "w"); + FILE *file = fopen (PathName, "w"); FConfigSection *section; FConfigEntry *entry; diff --git a/src/configfile.h b/src/configfile.h index 5c98cf02a..c06a0ba0f 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -58,7 +58,7 @@ public: void SetValueForKey (const char *key, const char *value, bool duplicates=false); const char *GetPathName () const { return PathName.GetChars(); } - void ChangePathName (const string &path); + void ChangePathName (const char *path); void LoadConfigFile (void (*nosechandler)(const char *pathname, FConfigFile *config, void *userdata), void *userdata); void WriteConfigFile () const; @@ -90,7 +90,7 @@ private: FConfigSection **LastSectionPtr; FConfigSection *CurrentSection; FConfigEntry *CurrentEntry; - string PathName; + FString PathName; FConfigSection *FindSection (const char *name) const; FConfigEntry *FindEntry (FConfigSection *section, const char *key) const; diff --git a/src/d_main.cpp b/src/d_main.cpp index 79556b44e..2473a758a 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1598,7 +1598,7 @@ static EIWADType IdentifyVersion (void) else if (*value == '~' && (*(value + 1) == 0 || *(value + 1) == '/')) { string homepath = GetUserFile (*(value + 1) ? value + 2 : value + 1); - CheckIWAD (homepath.GetChars(), wads); + CheckIWAD (homepath, wads); } #endif else @@ -1726,7 +1726,7 @@ static const char *BaseFileSearch (const char *file, const char *ext, bool lookf if (stricmp (key, "Path") == 0) { const char *dir; - string homepath; + FString homepath; if (*value == '$') { @@ -1743,7 +1743,7 @@ static const char *BaseFileSearch (const char *file, const char *ext, bool lookf else if (*value == '~' && (*(value + 1) == 0 || *(value + 1) == '/')) { homepath = GetUserFile (*(value + 1) ? value + 2 : value + 1); - dir = homepath.GetChars(); + dir = homepath; } #endif else @@ -1765,9 +1765,9 @@ static const char *BaseFileSearch (const char *file, const char *ext, bool lookf // Retry, this time with a default extension if (ext != NULL) { - string tmp = file; + FString tmp = file; DefaultExtension (tmp, ext); - return BaseFileSearch (tmp.GetChars(), NULL); + return BaseFileSearch (tmp, NULL); } return NULL; } diff --git a/src/d_net.cpp b/src/d_net.cpp index 51d2e0beb..e417f76a6 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -89,7 +89,7 @@ int P_StartScript (AActor *who, line_t *where, int script, char *map, bool backS extern byte *demo_p; // [RH] Special "ticcmds" get recorded in demos extern char savedescription[SAVESTRINGSIZE]; -extern string savegamefile; +extern FString savegamefile; extern short consistancy[MAXPLAYERS][BACKUPTICS]; @@ -2193,7 +2193,7 @@ void Net_DoCommand (int type, byte **stream, int player) // Paths sent over the network will be valid for the system that sent // the save command. For other systems, the path needs to be changed. char *fileonly = savegamefile.GetChars(); - char *slash = strrchr (savegamefile.GetChars(), '\\'); + char *slash = strrchr (fileonly, '\\'); if (slash != NULL) { fileonly = slash + 1; diff --git a/src/f_finale.cpp b/src/f_finale.cpp index c346063e8..e88aa6707 100644 --- a/src/f_finale.cpp +++ b/src/f_finale.cpp @@ -67,7 +67,7 @@ static int FinaleSequence; static SBYTE FadeDir; static bool FinaleHasPic; -static string FinaleText; +static FString FinaleText; static size_t FinaleTextLen; static char *FinaleFlat; diff --git a/src/farchive.cpp b/src/farchive.cpp index 853f46431..90a954c62 100644 --- a/src/farchive.cpp +++ b/src/farchive.cpp @@ -916,7 +916,7 @@ FArchive &FArchive::operator<< (double &w) return *this; } -FArchive &FArchive::operator<< (name &n) +FArchive &FArchive::operator<< (FName &n) { // In an archive, a "name" is a string that might be stored multiple times, // so it is only stored once. It is still treated as a normal string. In the // rest of the game, a name is a unique identifier for a number. @@ -926,7 +926,7 @@ FArchive &FArchive::operator<< (name &n) } else { - n = name(ReadName()); + n = FName(ReadName()); } return *this; } diff --git a/src/farchive.h b/src/farchive.h index fbb7443b5..9e79e4273 100644 --- a/src/farchive.h +++ b/src/farchive.h @@ -178,7 +178,7 @@ virtual void Read (void *mem, unsigned int len); FArchive& operator<< (float &f); FArchive& operator<< (double &d); FArchive& operator<< (char *&str); - FArchive& operator<< (name &n); + FArchive& operator<< (FName &n); FArchive& SerializePointer (void *ptrbase, BYTE **ptr, DWORD elemSize); FArchive& SerializeObject (DObject *&object, TypeInfo *type); FArchive& WriteObject (DObject *obj); diff --git a/src/g_game.cpp b/src/g_game.cpp index e8d76d5b8..b9bbfb57f 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -183,7 +183,7 @@ int turnheld; // for accelerative turning int mousex; int mousey; -string savegamefile; +FString savegamefile; char savedescription[SAVESTRINGSIZE]; // [RH] Name of screenshot file to generate (usually NULL) @@ -194,8 +194,8 @@ int bodyqueslot; void R_ExecuteSetViewSize (void); -string savename; -string BackupSaveName; +FString savename; +FString BackupSaveName; bool SendLand; const AInventory *SendItemUse, *SendItemDrop; @@ -599,7 +599,7 @@ void G_BuildTiccmd (ticcmd_t *cmd) { sendsave = false; Net_WriteByte (DEM_SAVEGAME); - Net_WriteString (savegamefile.GetChars()); + Net_WriteString (savegamefile); Net_WriteString (savedescription); savegamefile = ""; } @@ -1484,7 +1484,7 @@ static bool CheckSingleWad (char *name, bool &printRequires, bool printwarn) { return true; } - if (!Wads.CheckIfWadLoaded (name)) + if (Wads.CheckIfWadLoaded (name) < 0) { if (printwarn) { @@ -1734,9 +1734,9 @@ void G_SaveGame (const char *filename, const char *description) sendsave = true; } -string G_BuildSaveName (const char *prefix, int slot) +FString G_BuildSaveName (const char *prefix, int slot) { - string name; + FString name; const char *leader; const char *slash = ""; diff --git a/src/g_game.h b/src/g_game.h index 939969108..31eac02a9 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -60,7 +60,7 @@ BOOL G_Responder (event_t* ev); void G_ScreenShot (char *filename); -string G_BuildSaveName (const char *prefix, int slot); +FString G_BuildSaveName (const char *prefix, int slot); struct PNGHandle; bool G_CheckSaveGameWads (PNGHandle *png, bool printwarn); diff --git a/src/g_level.cpp b/src/g_level.cpp index 7d855de0b..a75e71a14 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -115,7 +115,7 @@ SDWORD ACS_GlobalVars[NUM_GLOBALVARS]; TAutoGrowArray ACS_GlobalArrays[NUM_GLOBALVARS]; extern bool netdemo; -extern string BackupSaveName; +extern FString BackupSaveName; BOOL savegamerestore; @@ -895,7 +895,7 @@ static void ParseMapInfoLower (MapInfoHandler *handlers, *so = sa; SC_SetCMode(true); SC_MustGetString(); - sa->Type = name(sc_String); + sa->Type = FName(sc_String); SC_CheckString(","); SC_MustGetString(); strlwr(sc_String); diff --git a/src/g_level.h b/src/g_level.h index 61128e17d..ae3c2aa00 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -107,7 +107,7 @@ class FBehavior; struct FSpecialAction { - name Type; // this is initialized before the actors... + FName Type; // this is initialized before the actors... BYTE Action; WORD Args[5]; // must allow 16 bit tags for 666 & 667! FSpecialAction *Next; diff --git a/src/g_shared/a_keys.cpp b/src/g_shared/a_keys.cpp index 828b27095..75233fc64 100644 --- a/src/g_shared/a_keys.cpp +++ b/src/g_shared/a_keys.cpp @@ -168,18 +168,18 @@ static void PrintMessage (const char *str) { if (str != NULL) { - string temp; + FString temp; if (strchr (str, '$')) { // The message or part of it is from the LANGUAGE lump - string name; + FString name; size_t part1 = strcspn (str, "$"); - temp = string(str, part1); + temp = FString(str, part1); size_t part2 = strcspn (str + part1 + 1, "$"); - name = string(str + part1 + 1, part2); + name = FString(str + part1 + 1, part2); temp += GStrings(name.GetChars()); if (str[part1 + 1 + part2] == '$') diff --git a/src/g_shared/a_pickups.cpp b/src/g_shared/a_pickups.cpp index bd4ea65c0..71b95dab5 100644 --- a/src/g_shared/a_pickups.cpp +++ b/src/g_shared/a_pickups.cpp @@ -823,18 +823,18 @@ static void PrintPickupMessage (const char *str) { if (str != NULL) { - string temp; + FString temp; if (strchr (str, '$')) { // The message or part of it is from the LANGUAGE lump - string name; + FString name; size_t part1 = strcspn (str, "$"); - temp = string(str, part1); + temp = FString(str, part1); size_t part2 = strcspn (str + part1 + 1, "$"); - name = string(str + part1 + 1, part2); + name = FString(str + part1 + 1, part2); temp += GStrings(name.GetChars()); if (str[part1 + 1 + part2] == '$') diff --git a/src/g_shared/a_soundsequence.cpp b/src/g_shared/a_soundsequence.cpp index 9b13e15d3..ac11da254 100644 --- a/src/g_shared/a_soundsequence.cpp +++ b/src/g_shared/a_soundsequence.cpp @@ -131,7 +131,7 @@ void ASoundSequence::Destroy () void ASoundSequence::PostBeginPlay () { - name slot = SN_GetSequenceSlot (args[0], SEQ_ENVIRONMENT); + FName slot = SN_GetSequenceSlot (args[0], SEQ_ENVIRONMENT); if (slot != NAME_None) { // This is a slotted sound, so add it to the master for that slot diff --git a/src/gameconfigfile.cpp b/src/gameconfigfile.cpp index 08dbc604d..70c500f4f 100644 --- a/src/gameconfigfile.cpp +++ b/src/gameconfigfile.cpp @@ -74,7 +74,7 @@ char *WeaponSection; FGameConfigFile::FGameConfigFile () { - string pathname; + FString pathname; bMigrating = false; pathname = GetConfigPath (true); @@ -504,14 +504,14 @@ void FGameConfigFile::ArchiveGlobalData () C_ArchiveCVars (this, 3); } -string FGameConfigFile::GetConfigPath (bool tryProg) +FString FGameConfigFile::GetConfigPath (bool tryProg) { char *pathval; - string path; + FString path; pathval = Args.CheckValue ("-config"); if (pathval != NULL) - return string(pathval); + return FString(pathval); #ifndef unix path = NULL; @@ -606,7 +606,7 @@ void FGameConfigFile::AddAutoexec (DArgs *list, const char *game) // with a default autoexec.cfg file present. if (!SetSection (section)) { - string path; + FString path; #ifndef unix if (Args.CheckParm ("-cdrom")) @@ -748,6 +748,6 @@ void FGameConfigFile::SetupWeaponList (const char *gamename) CCMD (whereisini) { - string path = GameConfig->GetConfigPath (false); + FString path = GameConfig->GetConfigPath (false); Printf ("%s\n", path.GetChars()); } diff --git a/src/gameconfigfile.h b/src/gameconfigfile.h index c4a1f3924..06548c54d 100644 --- a/src/gameconfigfile.h +++ b/src/gameconfigfile.h @@ -49,7 +49,7 @@ public: void ArchiveGlobalData (); void ArchiveGameData (const char *gamename); void AddAutoexec (DArgs *list, const char *gamename); - string GetConfigPath (bool tryProg); + FString GetConfigPath (bool tryProg); void ReadNetVars (); protected: diff --git a/src/info.h b/src/info.h index 53653a0dc..02cb5a3f0 100644 --- a/src/info.h +++ b/src/info.h @@ -353,7 +353,7 @@ enum struct FStateName { FState *AActor::*State; - name Name; + FName Name; }; #if _MSC_VER diff --git a/src/m_menu.cpp b/src/m_menu.cpp index d863c0b99..dd60b3885 100644 --- a/src/m_menu.cpp +++ b/src/m_menu.cpp @@ -75,7 +75,7 @@ struct FSaveGameNode : public Node { char Title[SAVESTRINGSIZE]; - string Filename; + FString Filename; bool bOldVersion; bool bMissingWads; }; @@ -611,7 +611,7 @@ void M_ReadSaveStrings () { void *filefirst; findstate_t c_file; - string filter; + FString filter; filter = G_BuildSaveName ("*.zds", -1); filefirst = I_FindFirst (filter.GetChars(), &c_file); @@ -620,8 +620,8 @@ void M_ReadSaveStrings () do { // I_FindName only returns the file's name and not its full path - string filepath = G_BuildSaveName (I_FindName(&c_file), -1); - FILE *file = fopen (filepath.GetChars(), "rb"); + FString filepath = G_BuildSaveName (I_FindName(&c_file), -1); + FILE *file = fopen (filepath, "rb"); if (file != NULL) { @@ -1204,21 +1204,21 @@ void M_DoSave (FSaveGameNode *node) else { // Find an unused filename and save as that - string filename; + FString filename; int i; FILE *test; for (i = 0;; ++i) { filename = G_BuildSaveName ("save", i); - test = fopen (filename.GetChars(), "rb"); + test = fopen (filename, "rb"); if (test == NULL) { break; } fclose (test); } - G_SaveGame (filename.GetChars(), savegamestring); + G_SaveGame (filename, savegamestring); } M_ClearMenus (); BorderNeedRefresh = screen->GetPageCount (); diff --git a/src/m_misc.cpp b/src/m_misc.cpp index bdb13e085..f0f7e5f6e 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -296,13 +296,13 @@ static long ParseCommandLine (const char *args, int *argc, char **argv) #ifdef unix -string GetUserFile (string file, bool nodir) +zstring GetUserFile (const char *file, bool nodir) { char *home = getenv ("HOME"); if (home == NULL || *home == '\0') I_FatalError ("Please set your HOME environment variable"); - string path = home; + zstring path = home; if (path[path.Len()-1] != '/') path += nodir ? "/" : "/.zdoom"; else if (!nodir) @@ -311,9 +311,9 @@ string GetUserFile (string file, bool nodir) if (!nodir) { struct stat info; - if (stat (path.GetChars(), &info) == -1) + if (stat (path, &info) == -1) { - if (mkdir (path.GetChars(), S_IRUSR | S_IWUSR | S_IXUSR) == -1) + if (mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR) == -1) { I_FatalError ("Failed to create %s directory:\n%s", path.GetChars(), strerror (errno)); @@ -517,9 +517,9 @@ void WritePNGfile (FILE *file, const DCanvas *canvas, const PalEntry *palette) // // M_ScreenShot // -static BOOL FindFreeName (string &fullname, const char *extension) +static BOOL FindFreeName (FString &fullname, const char *extension) { - string lbmname; + FString lbmname; int i; for (i = 0; i <= 9999; i++) @@ -537,7 +537,7 @@ static BOOL FindFreeName (string &fullname, const char *extension) void M_ScreenShot (char *filename) { FILE *file; - string autoname; + FString autoname; bool writepcx = (stricmp (screenshot_type, "pcx") == 0); // PNG is the default // find a file name to save it to diff --git a/src/m_misc.h b/src/m_misc.h index 20862229e..d369a6c38 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -43,6 +43,6 @@ void M_LoadDefaults (); void STACK_ARGS M_SaveDefaults (); void M_SaveCustomKeys (FConfigFile *config, char *section, char *subsection); -string GetUserFile (string path, bool nodir=false); +FString GetUserFile (const char *path, bool nodir=false); #endif diff --git a/src/name.cpp b/src/name.cpp index 738328988..7245a5db0 100644 --- a/src/name.cpp +++ b/src/name.cpp @@ -10,16 +10,16 @@ static const char *PredefinedNames[] = #undef xx }; -int name::Buckets[name::HASH_SIZE]; -TArray name::NameArray; -bool name::Inited; +int FName::Buckets[FName::HASH_SIZE]; +TArray FName::NameArray; +bool FName::Inited; -name::MainName::MainName (int next) +FName::MainName::MainName (int next) : NextHash(next) { } -int name::FindName (const char *text, bool noCreate) +int FName::FindName (const char *text, bool noCreate) { if (!Inited) InitBuckets (); @@ -56,7 +56,7 @@ int name::FindName (const char *text, bool noCreate) return index; } -void name::InitBuckets () +void FName::InitBuckets () { size_t i; diff --git a/src/name.h b/src/name.h index 9c6a01f7d..82c9bf566 100644 --- a/src/name.h +++ b/src/name.h @@ -11,41 +11,41 @@ enum ENamedName #undef xx }; -class name +class FName { public: - name () : Index(0) {} - name (const char *text) { Index = FindName (text, false); } - name (const string &text) { Index = FindName (text.GetChars(), false); } - name (const char *text, bool noCreate) { Index = FindName (text, noCreate); } - name (const string &text, bool noCreate) { Index = FindName (text.GetChars(), noCreate); } - name (const name &other) { Index = other.Index; } - name (ENamedName index) { Index = index; } - // ~name () {} // Names can be added but never removed. + FName () : Index(0) {} + FName (const char *text) { Index = FindName (text, false); } + FName (const FString &text) { Index = FindName (text.GetChars(), false); } + FName (const char *text, bool noCreate) { Index = FindName (text, noCreate); } + FName (const FString &text, bool noCreate) { Index = FindName (text.GetChars(), noCreate); } + FName (const FName &other) { Index = other.Index; } + FName (ENamedName index) { Index = index; } + // ~FName () {} // Names can be added but never removed. int GetIndex() const { return Index; } operator int() const { return Index; } - const string &GetText() const { return NameArray[Index].Text; } + const FString &GetText() const { return NameArray[Index].Text; } const char *GetChars() const { return NameArray[Index].Text.GetChars(); } - name &operator = (const char *text) { Index = FindName (text, false); return *this; } - name &operator = (const string &text) { Index = FindName (text.GetChars(), false); return *this; } - name &operator = (const name &other) { Index = other.Index; return *this; } - name &operator = (ENamedName index) { Index = index; return *this; } + FName &operator = (const char *text) { Index = FindName (text, false); return *this; } + FName &operator = (const FString &text) { Index = FindName (text.GetChars(), false); return *this; } + FName &operator = (const FName &other) { Index = other.Index; return *this; } + FName &operator = (ENamedName index) { Index = index; return *this; } int SetName (const char *text, bool noCreate) { return Index = FindName (text, false); } - int SetName (const string &text, bool noCreate) { return Index = FindName (text.GetChars(), false); } + int SetName (const FString &text, bool noCreate) { return Index = FindName (text.GetChars(), false); } bool IsValidName() const { return (unsigned int)Index < NameArray.Size(); } // Note that the comparison operators compare the names' indices, not // their text, so they cannot be used to do a lexicographical sort. - bool operator == (const name &other) const { return Index == other.Index; } - bool operator != (const name &other) const { return Index != other.Index; } - bool operator < (const name &other) const { return Index < other.Index; } - bool operator <= (const name &other) const { return Index <= other.Index; } - bool operator > (const name &other) const { return Index > other.Index; } - bool operator >= (const name &other) const { return Index >= other.Index; } + bool operator == (const FName &other) const { return Index == other.Index; } + bool operator != (const FName &other) const { return Index != other.Index; } + bool operator < (const FName &other) const { return Index < other.Index; } + bool operator <= (const FName &other) const { return Index <= other.Index; } + bool operator > (const FName &other) const { return Index > other.Index; } + bool operator >= (const FName &other) const { return Index >= other.Index; } bool operator == (ENamedName index) const { return Index == index; } bool operator != (ENamedName index) const { return Index != index; } @@ -64,7 +64,7 @@ private: MainName (int next); MainName (const MainName &other) : Text(other.Text), NextHash(other.NextHash) {} MainName () {} - string Text; + FString Text; int NextHash; void *operator new (size_t size, MainName *addr) @@ -91,11 +91,11 @@ private: } template<> friend void ConstructInTArray (MainName *dst, const MainName &src) { - new (dst) name::MainName(src); + new (dst) FName::MainName(src); } template<> friend void ConstructEmptyInTArray (MainName *dst) { - new (dst) name::MainName; + new (dst) FName::MainName; } #else template friend inline bool NeedsDestructor (); @@ -106,20 +106,20 @@ private: }; #ifdef __GNUC__ -template<> inline bool NeedsDestructor () { return true; } +template<> inline bool NeedsDestructor () { return true; } -template<> inline void CopyForTArray (name::MainName &dst, name::MainName &src) +template<> inline void CopyForTArray (FName::MainName &dst, FName::MainName &src) { dst.NextHash = src.NextHash; CopyForTArray (dst.Text, src.Text); } -template<> inline void ConstructInTArray (name::MainName *dst, const name::MainName &src) +template<> inline void ConstructInTArray (FName::MainName *dst, const FName::MainName &src) { - new (dst) name::MainName(src); + new (dst) FName::MainName(src); } -template<> inline void ConstructEmptyInTArray (name::MainName *dst) +template<> inline void ConstructEmptyInTArray (FName::MainName *dst) { - new (dst) name::MainName; + new (dst) FName::MainName; } #endif diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index 204044c3e..8f824204d 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -2367,7 +2367,7 @@ void A_BossDeath (AActor *actor) FSpecialAction *sa = level.info->specialactions; while (sa) { - if (name(actor->GetClass()->Name+1) == sa->Type) + if (FName(actor->GetClass()->Name+1) == sa->Type) { if (!checked && !CheckBossDeath(actor)) { diff --git a/src/r_data.cpp b/src/r_data.cpp index b7030f282..c57b8c7aa 100644 --- a/src/r_data.cpp +++ b/src/r_data.cpp @@ -2727,11 +2727,57 @@ void R_InitTextures (void) void R_InitBuildTiles () { - int numartfiles; + int numartfiles = 0; char artfile[] = "tilesXXX.art"; int lumpnum; - for (numartfiles = 0; numartfiles < 1000; numartfiles++) + lumpnum = Wads.CheckNumForFullName ("blood.pal"); + if (lumpnum >= 0) + { + // Blood's tiles are external resources. (Why did they do it like that?) + FString rffpath = Wads.GetWadFullName (Wads.GetLumpFile (lumpnum)); + int slashat = rffpath.LastIndexOf ('/'); + if (slashat >= 0) + { + rffpath.Resize (slashat + 1); + } + else + { + rffpath += '/'; + } + + for (; numartfiles < 1000; numartfiles++) + { + artfile[5] = numartfiles / 100 + '0'; + artfile[6] = numartfiles / 10 % 10 + '0'; + artfile[7] = numartfiles % 10 + '0'; + + FString artpath = rffpath; + artpath += artfile; + + FILE *f = fopen (artpath, "rb"); + if (f == NULL) + { + break; + } + + // BADBAD: This memory is never explicitly deleted except when the + // version number is wrong. + int len = Q_filelength (f); + BYTE *art = new BYTE[len]; + if (fread (art, 1, len, f) != len || LittleLong(*(DWORD *)art) != 1) + { + delete[] art; + } + else + { + TexMan.AddTiles (art); + } + fclose (f); + } + } + + for (; numartfiles < 1000; numartfiles++) { artfile[5] = numartfiles / 100 + '0'; artfile[6] = numartfiles / 10 % 10 + '0'; @@ -2750,10 +2796,11 @@ void R_InitBuildTiles () if (LittleLong(*(DWORD *)art) != 1) { delete[] art; - break; } - - TexMan.AddTiles (art); + else + { + TexMan.AddTiles (art); + } } } @@ -2776,8 +2823,8 @@ void R_SetDefaultColormap (const char *name) BYTE unremap[256]; BYTE remap[256]; - // [RH] If using BUILD's palette.dat, generate the colormap - if (Args.CheckParm ("-bpal") || Wads.CheckNumForFullName("palette.dat")) + // [RH] If using BUILD's palette, generate the colormap + if (Wads.CheckNumForFullName("palette.dat") >= 0 || Wads.CheckNumForFullName("blood.pal") >= 0) { Printf ("Make colormap\n"); FDynamicColormap foo; diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index e8ca473a4..4591b6efc 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -944,11 +944,11 @@ static void S_AddSNDINFO (int lump) case SI_MusicVolume: { SC_MustGetString(); - string musname (sc_String); + FString musname (sc_String); SC_MustGetFloat(); FMusicVolume *mv = (FMusicVolume *)Malloc (sizeof(*mv) + musname.Len()); mv->Volume = sc_Float; - strcpy (mv->MusicName, musname.GetChars()); + strcpy (mv->MusicName, musname); mv->Next = MusicVolumes; MusicVolumes = mv; } diff --git a/src/s_sndseq.cpp b/src/s_sndseq.cpp index 6b85a2b1a..5492bd93d 100644 --- a/src/s_sndseq.cpp +++ b/src/s_sndseq.cpp @@ -150,9 +150,9 @@ private: static void AssignTranslations (int seq, seqtype_t type); static void AssignHexenTranslations (void); -static void AddSequence (int curseq, name seqname, name slot, int stopsound, const TArray &ScriptTemp); +static void AddSequence (int curseq, FName seqname, FName slot, int stopsound, const TArray &ScriptTemp); static int FindSequence (const char *searchname); -static int FindSequence (name seqname); +static int FindSequence (FName seqname); static bool TwiddleSeqNum (int &sequence, seqtype_t type); // PUBLIC DATA DEFINITIONS ------------------------------------------------- @@ -265,7 +265,7 @@ void DSeqNode::Serialize (FArchive &arc) } else { - name seqName; + FName seqName; int delayTics = 0, id; float volume; int atten = ATTN_NORM; @@ -336,7 +336,7 @@ void DSeqNode::AddChoice (int seqnum, seqtype_t type) } } -name DSeqNode::GetSequenceName () const +FName DSeqNode::GetSequenceName () const { return Sequences[m_Sequence]->SeqName; } @@ -435,8 +435,8 @@ void S_ParseSndSeq (int levellump) TArray ScriptTemp; int lastlump, lump; char seqtype = ':'; - name seqname; - name slot; + FName seqname; + FName slot; int stopsound; int delaybase; float volumebase; @@ -519,7 +519,7 @@ void S_ParseSndSeq (int levellump) SC_MustGetNumber(); ScriptTemp.Push (sc_Number); SC_MustGetString(); - ScriptTemp.Push (name(sc_String)); + ScriptTemp.Push (FName(sc_String)); } continue; } @@ -646,13 +646,13 @@ void S_ParseSndSeq (int levellump) AssignHexenTranslations (); } -static void AddSequence (int curseq, name seqname, name slot, int stopsound, const TArray &ScriptTemp) +static void AddSequence (int curseq, FName seqname, FName slot, int stopsound, const TArray &ScriptTemp) { Sequences[curseq] = (FSoundSequence *)Malloc (sizeof(FSoundSequence) + sizeof(DWORD)*ScriptTemp.Size()); Sequences[curseq]->SeqName = seqname; Sequences[curseq]->Slot = slot; Sequences[curseq]->StopSound = stopsound; - memcpy (Sequences[curseq]->Script, &ScriptTemp[0], sizeof(int)*ScriptTemp.Size()); + memcpy (Sequences[curseq]->Script, &ScriptTemp[0], sizeof(DWORD)*ScriptTemp.Size()); Sequences[curseq]->Script[ScriptTemp.Size()] = MakeCommand(SS_CMD_END, 0); } @@ -801,7 +801,7 @@ DSeqNode *SN_StartSequence (AActor *actor, const char *seqname, int modenum) return NULL; } -DSeqNode *SN_StartSequence (AActor *actor, name seqname, int modenum) +DSeqNode *SN_StartSequence (AActor *actor, FName seqname, int modenum) { int seqnum = FindSequence (seqname); if (seqnum >= 0) @@ -833,7 +833,7 @@ DSeqNode *SN_StartSequence (polyobj_t *poly, const char *seqname, int modenum) static int FindSequence (const char *searchname) { - name seqname (searchname, true); + FName seqname (searchname, true); if (seqname != NAME_None) { @@ -842,7 +842,7 @@ static int FindSequence (const char *searchname) return -1; } -static int FindSequence (name seqname) +static int FindSequence (FName seqname) { int i; @@ -1163,7 +1163,7 @@ ptrdiff_t SN_GetSequenceOffset (int sequence, SDWORD *sequencePtr) // //========================================================================== -name SN_GetSequenceSlot (int sequence, seqtype_t type) +FName SN_GetSequenceSlot (int sequence, seqtype_t type) { if (TwiddleSeqNum (sequence, type)) { diff --git a/src/s_sndseq.h b/src/s_sndseq.h index 79b1ed5fa..d8f0bb040 100644 --- a/src/s_sndseq.h +++ b/src/s_sndseq.h @@ -28,7 +28,7 @@ public: void Tick (); void ChangeData (int seqOffset, int delayTics, float volume, int currentSoundID); void AddChoice (int seqnum, seqtype_t type); - name GetSequenceName() const; + FName GetSequenceName() const; virtual void MakeSound () {} virtual void MakeLoopedSound () {} @@ -70,8 +70,8 @@ private: struct FSoundSequence { - name SeqName; - name Slot; + FName SeqName; + FName Slot; int StopSound; SDWORD Script[1]; // + more until end of sequence script }; @@ -79,7 +79,7 @@ struct FSoundSequence void S_ParseSndSeq (int levellump); DSeqNode *SN_StartSequence (AActor *mobj, int sequence, seqtype_t type, int modenum, bool nostop=false); DSeqNode *SN_StartSequence (AActor *mobj, const char *name, int modenum); -DSeqNode *SN_StartSequence (AActor *mobj, name seqname, int modenum); +DSeqNode *SN_StartSequence (AActor *mobj, FName seqname, int modenum); DSeqNode *SN_StartSequence (sector_t *sector, int sequence, seqtype_t type, int modenum, bool nostop=false); DSeqNode *SN_StartSequence (sector_t *sector, const char *name, int modenum); DSeqNode *SN_StartSequence (polyobj_t *poly, int sequence, seqtype_t type, int modenum, bool nostop=false); @@ -92,7 +92,7 @@ ptrdiff_t SN_GetSequenceOffset (int sequence, SDWORD *sequencePtr); void SN_DoStop (void *); void SN_ChangeNodeData (int nodeNum, int seqOffset, int delayTics, float volume, int currentSoundID); -name SN_GetSequenceSlot (int sequence, seqtype_t type); +FName SN_GetSequenceSlot (int sequence, seqtype_t type); bool SN_IsMakingLoopingSound (sector_t *sector); #endif //__S_SNDSEQ_H__ diff --git a/src/s_sound.cpp b/src/s_sound.cpp index d7b87046c..f60476ac7 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -265,8 +265,8 @@ void S_NoiseDebug (void) BorderNeedRefresh = screen->GetPageCount (); } -static string LastLocalSndInfo; -static string LastLocalSndSeq; +static FString LastLocalSndInfo; +static FString LastLocalSndSeq; void S_AddLocalSndInfo(int lump); //========================================================================== diff --git a/src/sc_man.cpp b/src/sc_man.cpp index 60c0bfc7e..c52dc6151 100644 --- a/src/sc_man.cpp +++ b/src/sc_man.cpp @@ -62,7 +62,7 @@ char *sc_ScriptsDir = ""; // PRIVATE DATA DEFINITIONS ------------------------------------------------ -static string ScriptName; +static FString ScriptName; static char *ScriptBuffer; static char *ScriptPtr; static char *ScriptEndPtr; @@ -737,7 +737,7 @@ BOOL SC_Compare (const char *text) void STACK_ARGS SC_ScriptError (const char *message, ...) { - string composed; + FString composed; if (message == NULL) { @@ -785,7 +785,7 @@ struct SavedScript BOOL sc_Crossed; BOOL sc_FileScripts; - string * ScriptName; + FString *ScriptName; char *ScriptBuffer; char *ScriptPtr; char *ScriptEndPtr; @@ -809,7 +809,7 @@ void SC_SaveScriptState() ss.sc_End = sc_End; ss.sc_Crossed = sc_Crossed; ss.sc_FileScripts = sc_FileScripts; - ss.ScriptName = ::new string(ScriptName); + ss.ScriptName = ::new FString(ScriptName); ss.ScriptBuffer = ScriptBuffer; ss.ScriptPtr = ScriptPtr; ss.ScriptEndPtr = ScriptEndPtr; diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index 6b2e8b0e4..e2d1eea44 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -264,7 +264,7 @@ protected: int WavePipe[2]; pid_t ChildProcess; #endif - string CommandLine; + FString CommandLine; size_t LoopPos; static bool FillStream (SoundStream *stream, void *buff, int len, void *userdata); diff --git a/src/stringtable.cpp b/src/stringtable.cpp index 84419a78a..db4323e61 100644 --- a/src/stringtable.cpp +++ b/src/stringtable.cpp @@ -225,10 +225,10 @@ void FStringTable::LoadLanguage (int lumpnum, DWORD code, bool exactMatch, int p continue; } - string strName (sc_String); + FString strName (sc_String); SC_MustGetStringName ("="); SC_MustGetString (); - string strText (sc_String, ProcessEscapes (sc_String)); + FString strText (sc_String, ProcessEscapes (sc_String)); SC_MustGetString (); while (!SC_Compare (";")) { diff --git a/src/thingdef.cpp b/src/thingdef.cpp index 42e559e9d..3734831c5 100644 --- a/src/thingdef.cpp +++ b/src/thingdef.cpp @@ -1951,7 +1951,7 @@ void ParseActorProperties (Baggage &bag) // about the property. info = bag.Info->Class; - string propname = sc_String; + FString propname = sc_String; if (sc_String[0]!='-' && sc_String[0]!='+') { @@ -2806,7 +2806,7 @@ static void ActorFlagSetOrReset (AActor *defaults, Baggage &bag) } else { - string part1 = sc_String; + FString part1 = sc_String; const char *part2 = NULL; if (SC_CheckString (".")) { @@ -3046,18 +3046,18 @@ static void WeaponAmmoGive2 (AWeapon *defaults, Baggage &bag) // This class is for storing a name inside a const TypeInfo* field without // generating compiler warnings. It does not manipulate data in any other // way. -class fuglyname : public name +class fuglyname : public FName { public: - fuglyname() : name() {} - fuglyname(const char *foo) : name(foo) {} + fuglyname() : FName() {} + fuglyname(const char *foo) : FName(foo) {} operator const TypeInfo *() { return reinterpret_cast(size_t(int(*this))); } fuglyname &operator= (const TypeInfo *foo) { - name *p = this; + FName *p = this; *p = ENamedName(reinterpret_cast(foo)); return *this; } diff --git a/src/v_palette.cpp b/src/v_palette.cpp index 4700dfd6d..b0549a119 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -298,27 +298,41 @@ static int STACK_ARGS sortforremap2 (const void *a, const void *b) } } -static void FixBuildPalette (BYTE *pal) +static bool FixBuildPalette (BYTE *opal, int lump, bool blood) { - int c; + if (Wads.LumpLength (lump) < 768) + { + return false; + } + FMemLump data = Wads.ReadLump (lump); + const BYTE *ipal = (const BYTE *)data.GetMem(); + // Reverse the palette because BUILD used entry 255 as // transparent, but we use 0 as transparent. - for (c = 0; c < 768/2; c += 3) + + for (int c = 0; c < 768/2; c += 3) { - BYTE temp[3] = + if (!blood) { - (pal[c] << 2) | (pal[c] >> 4), - (pal[c+1] << 2) | (pal[c+1] >> 4), - (pal[c+2] << 2) | (pal[c+2] >> 4) - }; - pal[c] = (pal[765-c] << 2) | (pal[765-c] >> 4); - pal[c+1] = (pal[766-c] << 2) | (pal[766-c] >> 4); - pal[c+2] = (pal[767-c] << 2) | (pal[767-c] >> 4); - pal[765-c] = temp[0]; - pal[766-c] = temp[1]; - pal[767-c] = temp[2]; + opal[765-c] = (ipal[0] << 2) | (ipal[0] >> 4); + opal[766-c] = (ipal[1] << 2) | (ipal[1] >> 4); + opal[767-c] = (ipal[2] << 2) | (ipal[2] >> 4); + opal[c] = (ipal[765-c] << 2) | (ipal[765-c] >> 4); + opal[c+1] = (ipal[766-c] << 2) | (ipal[766-c] >> 4); + opal[c+2] = (ipal[767-c] << 2) | (ipal[767-c] >> 4); + } + else + { + opal[c] = ipal[765-c]; + opal[c+1] = ipal[766-c]; + opal[c+2] = ipal[767-c]; + opal[765-c] = ipal[c]; + opal[766-c] = ipal[c+1]; + opal[767-c] = ipal[c+2]; + } } + return true; } void InitPalette () @@ -326,36 +340,16 @@ void InitPalette () BYTE pal[768]; BYTE *shade; int c; - const char *buildPal; bool usingBuild = false; + int lump; - buildPal = Args.CheckValue ("-bpal"); - if (buildPal != NULL) + if ((lump = Wads.CheckNumForFullName ("palette.dat")) >= 0 && Wads.LumpLength (lump) >= 768) { - int f = open (buildPal, O_BINARY | O_RDONLY); - if (f >= 0) - { - if (read (f, pal, 768) == 768) - { - FixBuildPalette (pal); - usingBuild = true; - } - close (f); - } + usingBuild = FixBuildPalette (pal, lump, false); } - else + else if ((lump = Wads.CheckNumForFullName ("blood.pal")) >= 0 && Wads.LumpLength (lump) >= 768) { - int lump = Wads.CheckNumForFullName ("palette.dat"); - - if (lump >= 0 && Wads.LumpLength (lump) >= 768) - { - FWadLump data = Wads.OpenLumpNum (lump); - if (data.Read (pal, 768) == 768) - { - FixBuildPalette (pal); - usingBuild = true; - } - } + usingBuild = FixBuildPalette (pal, lump, true); } if (!usingBuild) @@ -369,7 +363,7 @@ void InitPalette () ColorMatcher.SetPalette ((DWORD *)GPalette.BaseColors); // The BUILD engine already has a transparent color, so it doesn't need any remapping. - if (buildPal == NULL) + if (!usingBuild) { if (GPalette.Remap[0] == 0) { // No duplicates, so settle for something close to color 0 diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 5f2d92b53..4614d9e9e 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -84,13 +84,13 @@ union MergedHeader // struct FWadCollection::LumpRecord { - char name[8]; char * fullname; // only valid for files loaded from a .zip file + char name[9]; + short wadnum; + WORD flags; int position; int size; int namespc; - short wadnum; - WORD flags; int compressedsize; }; @@ -370,7 +370,6 @@ void FWadCollection::AddFile (const char *filename, const char * data, int lengt { // This is a Blood RFF file rfflump_t *lumps, *rff_p; - int skipped = 0; header.rff.NumLumps = LittleLong(header.rff.NumLumps); header.rff.DirOfs = LittleLong(header.rff.DirOfs); @@ -397,25 +396,31 @@ void FWadCollection::AddFile (const char *filename, const char * data, int lengt } else { - //lump_p->namespc = ns_bloodmisc; - --NumLumps; - ++skipped; - continue; + lump_p->namespc = ns_global; } + uppercopy (lump_p->name, rff_p->Name); + lump_p->name[8] = 0; lump_p->wadnum = (WORD)NumWads; lump_p->position = LittleLong(rff_p->FilePos); lump_p->size = LittleLong(rff_p->Size); lump_p->flags = (rff_p->Flags & 0x10) >> 4; - lump_p->fullname = NULL; - lump_p->compressedsize=-1; + lump_p->compressedsize = -1; + + // Rearrange the name and extension in a part of the lump record + // that I don't have any use for in order to cnstruct the fullname. + rff_p->Name[8] = '\0'; + sprintf ((char *)rff_p->IDontKnow, "%s.", rff_p->Name); + rff_p->Name[0] = '\0'; + strcat ((char *)rff_p->IDontKnow, rff_p->Extension); + lump_p->fullname = copystring ((char *)rff_p->IDontKnow); + if (strstr ((char *)rff_p->IDontKnow, "TILE")) + rff_p = rff_p; + lump_p++; } + Printf (" (%ld files)", header.rff.NumLumps); delete[] lumps; - if (skipped != 0) - { - LumpInfo = (LumpRecord *)Realloc (LumpInfo, NumLumps*sizeof(LumpRecord)); - } } else if (header.magic[0] == GRP_ID_0 && header.magic[1] == GRP_ID_1 && header.magic[2] == GRP_ID_2) { @@ -440,12 +445,14 @@ void FWadCollection::AddFile (const char *filename, const char * data, int lengt grp_p->Name[12] = '\0'; // Be sure filename is null-terminated lump_p->fullname = copystring(grp_p->Name); uppercopy (lump_p->name, grp_p->Name); + lump_p->name[8] = 0; lump_p->compressedsize = -1; lump_p->flags = 0; lump_p->namespc = ns_global; lump_p++; } Printf (" (%ld files)", header.grp.NumLumps); + delete[] lumps; } else if (header.magic[0] == ZIP_ID) { @@ -539,6 +546,7 @@ void FWadCollection::AddFile (const char *filename, const char * data, int lengt char * dot = strrchr(base,'.'); if (dot) *dot=0; uppercopy(lump_p->name, base); + lump_p->name[8] = 0; lump_p->fullname = copystring(name); lump_p->position = LittleLong(zip_fh->dwFileOffset) + sizeof(FZipLocalHeader) + LittleShort(zip_fh->wFileNameSize); lump_p->size = zip_fh->dwSize; @@ -621,6 +629,7 @@ void FWadCollection::AddFile (const char *filename, const char * data, int lengt { // [RH] Convert name to uppercase during copy uppercopy (lump_p->name, fileinfo->Name); + lump_p->name[8] = 0; lump_p->wadnum = (WORD)NumWads; lump_p->position = LittleLong(fileinfo->FilePos); lump_p->size = LittleLong(fileinfo->Size); @@ -699,10 +708,11 @@ void FWadCollection::AddFile (const char *filename, const char * data, int lengt // Returns true if the specified wad is loaded, false otherwise. // If a fully-qualified path is specified, then the wad must match exactly. // Otherwise, any wad with that name will work, whatever its path. +// Returns the wads index if found, or -1 if not. // //========================================================================== -bool FWadCollection::CheckIfWadLoaded (const char *name) +int FWadCollection::CheckIfWadLoaded (const char *name) { unsigned int i; @@ -712,7 +722,7 @@ bool FWadCollection::CheckIfWadLoaded (const char *name) { if (stricmp (GetWadFullName (i), name) == 0) { - return true; + return i; } } } @@ -722,11 +732,11 @@ bool FWadCollection::CheckIfWadLoaded (const char *name) { if (stricmp (GetWadName (i), name) == 0) { - return true; + return i; } } } - return false; + return -1; } //========================================================================== @@ -1476,6 +1486,24 @@ void FWadCollection::GetLumpName (char *to, int lump) const uppercopy (to, LumpInfo[lump].name); } +//========================================================================== +// +// FWadCollection :: GetLumpFullName +// +// Returns the lump's full name if it has one or its short name if not. +// +//========================================================================== + +const char *FWadCollection::GetLumpFullName (int lump) const +{ + if ((size_t)lump >= NumLumps) + return NULL; + else if (LumpInfo[lump].fullname != NULL) + return LumpInfo[lump].fullname; + else + return LumpInfo[lump].name; +} + //========================================================================== // // GetLumpNamespace diff --git a/src/w_wad.h b/src/w_wad.h index 9bd6fd64c..3e21308d0 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -146,7 +146,7 @@ public: void InitMultipleFiles (wadlist_t **filenames); void AddFile (const char *filename, const char * data=NULL,int length=-1); - bool CheckIfWadLoaded (const char *name); + int CheckIfWadLoaded (const char *name); const char *GetWadName (int wadnum) const; const char *GetWadFullName (int wadnum) const; @@ -181,6 +181,7 @@ public: int LumpLength (int lump) const; int GetLumpOffset (int lump) const; // [RH] Returns offset of lump in the wadfile void GetLumpName (char *to, int lump) const; // [RH] Copies the lump name to to using uppercopy + const char *GetLumpFullName (int lump) const; // [RH] Returns the lump's full name int GetLumpFile (int lump) const; // [RH] Returns wadnum for a specified lump int GetLumpNamespace (int lump) const; // [RH] Returns the namespace a lump belongs to bool CheckLumpName (int lump, const char *name) const; // [RH] Returns true if the names match diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index 02be9cab1..754879e85 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -665,10 +665,3 @@ CCMD (crashout) { *(int *)0 = 0; } - -#include "zstring.h" -TArray Foo; -void bar (string &h, int *&a) -{ - Foo.Push (h); -} diff --git a/src/zstring.cpp b/src/zstring.cpp index f40bda918..5137ab344 100644 --- a/src/zstring.cpp +++ b/src/zstring.cpp @@ -4,32 +4,32 @@ #include "zstring.h" -string::string (size_t len) +FString::FString (size_t len) { Chars = Pond.Alloc (this, len); } -string::string (const char *copyStr) +FString::FString (const char *copyStr) { size_t len = strlen (copyStr); Chars = Pond.Alloc (this, len); StrCopy (Chars, copyStr, len); } -string::string (const char *copyStr, size_t len) +FString::FString (const char *copyStr, size_t len) { Chars = Pond.Alloc (this, len); StrCopy (Chars, copyStr, len); } -string::string (char oneChar) +FString::FString (char oneChar) { Chars = Pond.Alloc (this, 1); Chars[0] = oneChar; Chars[1] = '\0'; } -string::string (const string &head, const string &tail) +FString::FString (const FString &head, const FString &tail) { size_t len1 = head.Len(); size_t len2 = tail.Len(); @@ -38,7 +38,7 @@ string::string (const string &head, const string &tail) StrCopy (Chars + len1, tail); } -string::string (const string &head, const char *tail) +FString::FString (const FString &head, const char *tail) { size_t len1 = head.Len(); size_t len2 = strlen (tail); @@ -47,7 +47,7 @@ string::string (const string &head, const char *tail) StrCopy (Chars + len1, tail, len2); } -string::string (const string &head, char tail) +FString::FString (const FString &head, char tail) { size_t len1 = head.Len(); Chars = Pond.Alloc (this, len1 + 1); @@ -56,7 +56,7 @@ string::string (const string &head, char tail) Chars[len1+1] = '\0'; } -string::string (const char *head, const string &tail) +FString::FString (const char *head, const FString &tail) { size_t len1 = strlen (head); size_t len2 = tail.Len(); @@ -65,7 +65,7 @@ string::string (const char *head, const string &tail) StrCopy (Chars + len1, tail); } -string::string (const char *head, const char *tail) +FString::FString (const char *head, const char *tail) { size_t len1 = strlen (head); size_t len2 = strlen (tail); @@ -74,7 +74,7 @@ string::string (const char *head, const char *tail) StrCopy (Chars + len1, tail, len2); } -string::string (char head, const string &tail) +FString::FString (char head, const FString &tail) { size_t len2 = tail.Len(); Chars = Pond.Alloc (this, 1 + len2); @@ -82,7 +82,7 @@ string::string (char head, const string &tail) StrCopy (Chars + 1, tail); } -string::~string () +FString::~FString () { if (Chars != NULL) { @@ -91,7 +91,7 @@ string::~string () } } -string &string::operator = (const string &other) +FString &FString::operator = (const FString &other) { if (Chars != NULL) { @@ -109,7 +109,7 @@ string &string::operator = (const string &other) return *this; } -string &string::operator = (const char *copyStr) +FString &FString::operator = (const char *copyStr) { if (Chars != NULL) { @@ -137,7 +137,7 @@ string &string::operator = (const char *copyStr) return *this; } -void string::Format (const char *fmt, ...) +void FString::Format (const char *fmt, ...) { va_list arglist; va_start (arglist, fmt); @@ -145,7 +145,7 @@ void string::Format (const char *fmt, ...) va_end (arglist); } -void string::VFormat (const char *fmt, va_list arglist) +void FString::VFormat (const char *fmt, va_list arglist) { if (Chars != NULL) { @@ -155,41 +155,41 @@ void string::VFormat (const char *fmt, va_list arglist) StringFormat::VWorker (FormatHelper, this, fmt, arglist); } -int string::FormatHelper (void *data, const char *cstr, int len) +int FString::FormatHelper (void *data, const char *cstr, int len) { - string *str = (string *)data; + FString *str = (FString *)data; size_t len1 = str->Len(); str->Chars = Pond.Realloc (str, str->Chars, len1 + len); StrCopy (str->Chars + len1, cstr, len); return len; } -string string::operator + (const string &tail) const +FString FString::operator + (const FString &tail) const { - return string (*this, tail); + return FString (*this, tail); } -string string::operator + (const char *tail) const +FString FString::operator + (const char *tail) const { - return string (*this, tail); + return FString (*this, tail); } -string operator + (const char *head, const string &tail) +FString operator + (const char *head, const FString &tail) { - return string (head, tail); + return FString (head, tail); } -string string::operator + (char tail) const +FString FString::operator + (char tail) const { - return string (*this, tail); + return FString (*this, tail); } -string operator + (char head, const string &tail) +FString operator + (char head, const FString &tail) { - return string (head, tail); + return FString (head, tail); } -string &string::operator += (const string &tail) +FString &FString::operator += (const FString &tail) { size_t len1 = Len(); size_t len2 = tail.Len(); @@ -198,7 +198,7 @@ string &string::operator += (const string &tail) return *this; } -string &string::operator += (const char *tail) +FString &FString::operator += (const char *tail) { size_t len1 = Len(); size_t len2 = strlen(tail); @@ -207,7 +207,7 @@ string &string::operator += (const char *tail) return *this; } -string &string::operator += (char tail) +FString &FString::operator += (char tail) { size_t len1 = Len(); Chars = Pond.Realloc (this, Chars, len1 + 1); @@ -216,46 +216,55 @@ string &string::operator += (char tail) return *this; } -string string::Left (size_t numChars) const +void FString::Resize (long newlen) +{ + if (newlen >= 0) + { + Chars = Pond.Realloc (this, Chars, newlen); + Chars[newlen] = '\0'; + } +} + +FString FString::Left (size_t numChars) const { size_t len = Len(); if (len < numChars) { numChars = len; } - return string (Chars, numChars); + return FString (Chars, numChars); } -string string::Right (size_t numChars) const +FString FString::Right (size_t numChars) const { size_t len = Len(); if (len < numChars) { numChars = len; } - return string (Chars + len - numChars, numChars); + return FString (Chars + len - numChars, numChars); } -string string::Mid (size_t pos, size_t numChars) const +FString FString::Mid (size_t pos, size_t numChars) const { size_t len = Len(); if (pos >= len) { - return string(""); + return FString(""); } if (pos + numChars > len) { numChars = len - pos; } - return string (Chars + pos, numChars); + return FString (Chars + pos, numChars); } -long string::IndexOf (const string &substr, long startIndex) const +long FString::IndexOf (const FString &substr, long startIndex) const { return IndexOf (substr.Chars, startIndex); } -long string::IndexOf (const char *substr, long startIndex) const +long FString::IndexOf (const char *substr, long startIndex) const { if (startIndex > 0 && Len() <= (size_t)startIndex) { @@ -269,7 +278,7 @@ long string::IndexOf (const char *substr, long startIndex) const return long(str - Chars); } -long string::IndexOf (char subchar, long startIndex) const +long FString::IndexOf (char subchar, long startIndex) const { if (startIndex > 0 && Len() <= (size_t)startIndex) { @@ -283,12 +292,12 @@ long string::IndexOf (char subchar, long startIndex) const return long(str - Chars); } -long string::IndexOfAny (const string &charset, long startIndex) const +long FString::IndexOfAny (const FString &charset, long startIndex) const { return IndexOfAny (charset.Chars, startIndex); } -long string::IndexOfAny (const char *charset, long startIndex) const +long FString::IndexOfAny (const char *charset, long startIndex) const { if (startIndex > 0 && Len() <= (size_t)startIndex) { @@ -302,32 +311,32 @@ long string::IndexOfAny (const char *charset, long startIndex) const return long(brk - Chars); } -long string::LastIndexOf (const string &substr) const +long FString::LastIndexOf (const FString &substr) const { return LastIndexOf (substr.Chars, long(Len()), substr.Len()); } -long string::LastIndexOf (const char *substr) const +long FString::LastIndexOf (const char *substr) const { return LastIndexOf (substr, long(Len()), strlen(substr)); } -long string::LastIndexOf (char subchar) const +long FString::LastIndexOf (char subchar) const { return LastIndexOf (subchar, long(Len())); } -long string::LastIndexOf (const string &substr, long endIndex) const +long FString::LastIndexOf (const FString &substr, long endIndex) const { return LastIndexOf (substr.Chars, endIndex, substr.Len()); } -long string::LastIndexOf (const char *substr, long endIndex) const +long FString::LastIndexOf (const char *substr, long endIndex) const { return LastIndexOf (substr, endIndex, strlen(substr)); } -long string::LastIndexOf (char subchar, long endIndex) const +long FString::LastIndexOf (char subchar, long endIndex) const { if ((size_t)endIndex > Len()) { @@ -343,7 +352,7 @@ long string::LastIndexOf (char subchar, long endIndex) const return -1; } -long string::LastIndexOf (const char *substr, long endIndex, size_t substrlen) const +long FString::LastIndexOf (const char *substr, long endIndex, size_t substrlen) const { if ((size_t)endIndex > Len()) { @@ -360,22 +369,22 @@ long string::LastIndexOf (const char *substr, long endIndex, size_t substrlen) c return -1; } -long string::LastIndexOfAny (const string &charset) const +long FString::LastIndexOfAny (const FString &charset) const { return LastIndexOfAny (charset.Chars, long(Len())); } -long string::LastIndexOfAny (const char *charset) const +long FString::LastIndexOfAny (const char *charset) const { return LastIndexOfAny (charset, long(Len())); } -long string::LastIndexOfAny (const string &charset, long endIndex) const +long FString::LastIndexOfAny (const FString &charset, long endIndex) const { return LastIndexOfAny (charset.Chars, endIndex); } -long string::LastIndexOfAny (const char *charset, long endIndex) const +long FString::LastIndexOfAny (const char *charset, long endIndex) const { if ((size_t)endIndex > Len()) { @@ -391,7 +400,7 @@ long string::LastIndexOfAny (const char *charset, long endIndex) const return -1; } -void string::ToUpper () +void FString::ToUpper () { size_t max = Len(); for (size_t i = 0; i < max; ++i) @@ -400,7 +409,7 @@ void string::ToUpper () } } -void string::ToLower () +void FString::ToLower () { size_t max = Len(); for (size_t i = 0; i < max; ++i) @@ -409,7 +418,7 @@ void string::ToLower () } } -void string::SwapCase () +void FString::SwapCase () { size_t max = Len(); for (size_t i = 0; i < max; ++i) @@ -425,7 +434,7 @@ void string::SwapCase () } } -void string::StripLeft () +void FString::StripLeft () { size_t max = Len(), i, j; for (i = 0; i < max; ++i) @@ -440,12 +449,12 @@ void string::StripLeft () Pond.Realloc (this, Chars, j-1); } -void string::StripLeft (const string &charset) +void FString::StripLeft (const FString &charset) { return StripLeft (charset.Chars); } -void string::StripLeft (const char *charset) +void FString::StripLeft (const char *charset) { size_t max = Len(), i, j; for (i = 0; i < max; ++i) @@ -460,7 +469,7 @@ void string::StripLeft (const char *charset) Pond.Realloc (this, Chars, j-1); } -void string::StripRight () +void FString::StripRight () { size_t max = Len(), i; for (i = max - 1; i-- > 0; ) @@ -472,12 +481,12 @@ void string::StripRight () Pond.Realloc (this, Chars, i+1); } -void string::StripRight (const string &charset) +void FString::StripRight (const FString &charset) { return StripRight (charset.Chars); } -void string::StripRight (const char *charset) +void FString::StripRight (const char *charset) { size_t max = Len(), i; for (i = max - 1; i-- > 0; ) @@ -489,7 +498,7 @@ void string::StripRight (const char *charset) Pond.Realloc (this, Chars, i+1); } -void string::StripLeftRight () +void FString::StripLeftRight () { size_t max = Len(), i, j, k; for (i = 0; i < max; ++i) @@ -510,12 +519,12 @@ void string::StripLeftRight () Pond.Realloc (this, Chars, k); } -void string::StripLeftRight (const string &charset) +void FString::StripLeftRight (const FString &charset) { return StripLeft (charset.Chars); } -void string::StripLeftRight (const char *charset) +void FString::StripLeftRight (const char *charset) { size_t max = Len(), i, j, k; for (i = 0; i < max; ++i) @@ -536,17 +545,17 @@ void string::StripLeftRight (const char *charset) Pond.Realloc (this, Chars, k); } -void string::Insert (size_t index, const string &instr) +void FString::Insert (size_t index, const FString &instr) { Insert (index, instr.Chars, instr.Len()); } -void string::Insert (size_t index, const char *instr) +void FString::Insert (size_t index, const char *instr) { Insert (index, instr, strlen(instr)); } -void string::Insert (size_t index, const char *instr, size_t instrlen) +void FString::Insert (size_t index, const char *instr, size_t instrlen) { size_t mylen = Len(); if (index > mylen) @@ -565,7 +574,7 @@ void string::Insert (size_t index, const char *instr, size_t instrlen) } } -void string::ReplaceChars (char oldchar, char newchar) +void FString::ReplaceChars (char oldchar, char newchar) { size_t i, j; for (i = 0, j = Len(); i < j; ++i) @@ -577,7 +586,7 @@ void string::ReplaceChars (char oldchar, char newchar) } } -void string::ReplaceChars (const char *oldcharset, char newchar) +void FString::ReplaceChars (const char *oldcharset, char newchar) { size_t i, j; for (i = 0, j = Len(); i < j; ++i) @@ -589,7 +598,7 @@ void string::ReplaceChars (const char *oldcharset, char newchar) } } -void string::StripChars (char killchar) +void FString::StripChars (char killchar) { size_t read, write, mylen; for (read = write = 0, mylen = Len(); read < mylen; ++read) @@ -603,7 +612,7 @@ void string::StripChars (char killchar) Pond.Realloc (this, Chars, write); } -void string::StripChars (const char *killchars) +void FString::StripChars (const char *killchars) { size_t read, write, mylen; for (read = write = 0, mylen = Len(); read < mylen; ++read) @@ -617,12 +626,12 @@ void string::StripChars (const char *killchars) Pond.Realloc (this, Chars, write); } -void string::MergeChars (char merger) +void FString::MergeChars (char merger) { MergeChars (merger, merger); } -void string::MergeChars (char merger, char newchar) +void FString::MergeChars (char merger, char newchar) { size_t read, write, mylen; for (read = write = 0, mylen = Len(); read < mylen; ) @@ -643,7 +652,7 @@ void string::MergeChars (char merger, char newchar) Pond.Realloc (this, Chars, write); } -void string::MergeChars (const char *charset, char newchar) +void FString::MergeChars (const char *charset, char newchar) { size_t read, write, mylen; for (read = write = 0, mylen = Len(); read < mylen; ) @@ -664,27 +673,27 @@ void string::MergeChars (const char *charset, char newchar) Pond.Realloc (this, Chars, write); } -void string::Substitute (const string &oldstr, const string &newstr) +void FString::Substitute (const FString &oldstr, const FString &newstr) { return Substitute (oldstr.Chars, newstr.Chars, oldstr.Len(), newstr.Len()); } -void string::Substitute (const char *oldstr, const string &newstr) +void FString::Substitute (const char *oldstr, const FString &newstr) { return Substitute (oldstr, newstr.Chars, strlen(oldstr), newstr.Len()); } -void string::Substitute (const string &oldstr, const char *newstr) +void FString::Substitute (const FString &oldstr, const char *newstr) { return Substitute (oldstr.Chars, newstr, oldstr.Len(), strlen(newstr)); } -void string::Substitute (const char *oldstr, const char *newstr) +void FString::Substitute (const char *oldstr, const char *newstr) { return Substitute (oldstr, newstr, strlen(oldstr), strlen(newstr)); } -void string::Substitute (const char *oldstr, const char *newstr, size_t oldstrlen, size_t newstrlen) +void FString::Substitute (const char *oldstr, const char *newstr, size_t oldstrlen, size_t newstrlen) { for (size_t checkpt = 0; checkpt < Len(); ) { @@ -708,7 +717,7 @@ void string::Substitute (const char *oldstr, const char *newstr, size_t oldstrle } } -bool string::IsInt () const +bool FString::IsInt () const { // String must match: [whitespace] [{+ | –}] [0 [{ x | X }]] [digits] [whitespace] @@ -767,7 +776,7 @@ octdigits = [0-7]; return yych == '\0'; } -bool string::IsFloat () const +bool FString::IsFloat () const { // String must match: [whitespace] [sign] [digits] [.digits] [ {d | D | e | E}[sign]digits] [whitespace] /* This state machine is based on a simplification of re2c's output for this input: @@ -818,34 +827,34 @@ digits = [0-9]; return yych == '\0'; } -long string::ToLong (int base) const +long FString::ToLong (int base) const { return strtol (Chars, NULL, base); } -unsigned long string::ToULong (int base) const +unsigned long FString::ToULong (int base) const { return strtoul (Chars, NULL, base); } -double string::ToDouble () const +double FString::ToDouble () const { return strtod (Chars, NULL); } -string::StringHeader *string::GetHeader () const +FString::StringHeader *FString::GetHeader () const { if (Chars == NULL) return NULL; return (StringHeader *)(Chars - sizeof(StringHeader)); } -void string::StrCopy (char *to, const char *from, size_t len) +void FString::StrCopy (char *to, const char *from, size_t len) { memcpy (to, from, len*sizeof(char)); to[len] = 0; } -void string::StrCopy (char *to, const string &from) +void FString::StrCopy (char *to, const FString &from) { StrCopy (to, from.Chars, from.Len()); } diff --git a/src/zstring.h b/src/zstring.h index 5ccc21fa0..b9fd13da1 100644 --- a/src/zstring.h +++ b/src/zstring.h @@ -7,66 +7,69 @@ #include "tarray.h" //#define NOPOOLS -class string +class FString { public: - string () : Chars(NULL) {} + FString () : Chars(NULL) {} // Copy constructors - string (const string &other) { Chars = NULL; *this = other; } - string (const char *copyStr); - string (const char *copyStr, size_t copyLen); - string (char oneChar); + FString (const FString &other) { Chars = NULL; *this = other; } + FString (const char *copyStr); + FString (const char *copyStr, size_t copyLen); + FString (char oneChar); // Concatenation constructors - string (const string &head, const string &tail); - string (const string &head, const char *tail); - string (const string &head, char tail); - string (const char *head, const string &tail); - string (const char *head, const char *tail); - string (char head, const string &tail); + FString (const FString &head, const FString &tail); + FString (const FString &head, const char *tail); + FString (const FString &head, char tail); + FString (const char *head, const FString &tail); + FString (const char *head, const char *tail); + FString (char head, const FString &tail); - ~string (); + ~FString (); + + operator char *() { return Chars; } + operator const char *() const { return Chars; } char *GetChars() const { return Chars; } char &operator[] (int index) { return Chars[index]; } char &operator[] (size_t index) { return Chars[index]; } - string &operator = (const string &other); - string &operator = (const char *copyStr); + FString &operator = (const FString &other); + FString &operator = (const char *copyStr); - string operator + (const string &tail) const; - string operator + (const char *tail) const; - string operator + (char tail) const; - friend string operator + (const char *head, const string &tail); - friend string operator + (char head, const string &tail); + FString operator + (const FString &tail) const; + FString operator + (const char *tail) const; + FString operator + (char tail) const; + friend FString operator + (const char *head, const FString &tail); + friend FString operator + (char head, const FString &tail); - string &operator += (const string &tail); - string &operator += (const char *tail); - string &operator += (char tail); + FString &operator += (const FString &tail); + FString &operator += (const char *tail); + FString &operator += (char tail); - string Left (size_t numChars) const; - string Right (size_t numChars) const; - string Mid (size_t pos, size_t numChars) const; + FString Left (size_t numChars) const; + FString Right (size_t numChars) const; + FString Mid (size_t pos, size_t numChars) const; - long IndexOf (const string &substr, long startIndex=0) const; + long IndexOf (const FString &substr, long startIndex=0) const; long IndexOf (const char *substr, long startIndex=0) const; long IndexOf (char subchar, long startIndex=0) const; - long IndexOfAny (const string &charset, long startIndex=0) const; + long IndexOfAny (const FString &charset, long startIndex=0) const; long IndexOfAny (const char *charset, long startIndex=0) const; - long LastIndexOf (const string &substr) const; + long LastIndexOf (const FString &substr) const; long LastIndexOf (const char *substr) const; long LastIndexOf (char subchar) const; - long LastIndexOf (const string &substr, long endIndex) const; + long LastIndexOf (const FString &substr, long endIndex) const; long LastIndexOf (const char *substr, long endIndex) const; long LastIndexOf (char subchar, long endIndex) const; long LastIndexOf (const char *substr, long endIndex, size_t substrlen) const; - long LastIndexOfAny (const string &charset) const; + long LastIndexOfAny (const FString &charset) const; long LastIndexOfAny (const char *charset) const; - long LastIndexOfAny (const string &charset, long endIndex) const; + long LastIndexOfAny (const FString &charset, long endIndex) const; long LastIndexOfAny (const char *charset, long endIndex) const; void ToUpper (); @@ -74,18 +77,18 @@ public: void SwapCase (); void StripLeft (); - void StripLeft (const string &charset); + void StripLeft (const FString &charset); void StripLeft (const char *charset); void StripRight (); - void StripRight (const string &charset); + void StripRight (const FString &charset); void StripRight (const char *charset); void StripLeftRight (); - void StripLeftRight (const string &charset); + void StripLeftRight (const FString &charset); void StripLeftRight (const char *charset); - void Insert (size_t index, const string &instr); + void Insert (size_t index, const FString &instr); void Insert (size_t index, const char *instr); void Insert (size_t index, const char *instr, size_t instrlen); @@ -99,9 +102,9 @@ public: void MergeChars (char merger, char newchar); void MergeChars (const char *charset, char newchar); - void Substitute (const string &oldstr, const string &newstr); - void Substitute (const char *oldstr, const string &newstr); - void Substitute (const string &oldstr, const char *newstr); + void Substitute (const FString &oldstr, const FString &newstr); + void Substitute (const char *oldstr, const FString &newstr); + void Substitute (const FString &oldstr, const char *newstr); void Substitute (const char *oldstr, const char *newstr); void Substitute (const char *oldstr, const char *newstr, size_t oldstrlen, size_t newstrlen); @@ -117,19 +120,21 @@ public: size_t Len() const { return Chars == NULL ? 0 : ((StringHeader *)(Chars - sizeof(StringHeader)))->Len; } bool IsEmpty() const { return Len() == 0; } - int Compare (const string &other) const { return strcmp (Chars, other.Chars); } + void Resize (long newlen); + + int Compare (const FString &other) const { return strcmp (Chars, other.Chars); } int Compare (const char *other) const { return strcmp (Chars, other); } - int CompareNoCase (const string &other) const { return stricmp (Chars, other.Chars); } + int CompareNoCase (const FString &other) const { return stricmp (Chars, other.Chars); } int CompareNoCase (const char *other) const { return stricmp (Chars, other); } protected: struct StringHeader { #ifndef NOPOOLS - string *Owner; // string this char array belongs to + FString *Owner; // FString this char array belongs to #endif - size_t Len; // Length of string, excluding terminating null + size_t Len; // Length of FString, excluding terminating null }; struct Pool; struct PoolGroup @@ -140,83 +145,83 @@ protected: Pool *FindPool (char *chars) const; static StringHeader *GetHeader (char *chars); #endif - char *Alloc (string *owner, size_t len); - char *Realloc (string *owner, char *chars, size_t newlen); + char *Alloc (FString *owner, size_t len); + char *Realloc (FString *owner, char *chars, size_t newlen); void Free (char *chars); }; - string (size_t len); + FString (size_t len); StringHeader *GetHeader () const; static int FormatHelper (void *data, const char *str, int len); static void StrCopy (char *to, const char *from, size_t len); - static void StrCopy (char *to, const string &from); + static void StrCopy (char *to, const FString &from); static PoolGroup Pond; char *Chars; #ifndef __GNUC__ - template<> friend bool NeedsDestructor () { return true; } + template<> friend bool NeedsDestructor () { return true; } - template<> friend void CopyForTArray (string &dst, string &src) + template<> friend void CopyForTArray (FString &dst, FString &src) { // When a TArray is resized, we just need to update the Owner, because // the old copy is going to go away very soon. No need to call the // destructor, either, because full ownership is transferred to the - // new string. + // new FString. char *chars = src.Chars; dst.Chars = chars; if (chars != NULL) { - ((string::StringHeader *)(chars - sizeof(string::StringHeader)))->Owner = &dst; + ((FString::StringHeader *)(chars - sizeof(FString::StringHeader)))->Owner = &dst; } } - template<> friend void ConstructInTArray (string *dst, const string &src) + template<> friend void ConstructInTArray (FString *dst, const FString &src) { - new (dst) string(src); + new (dst) FString(src); } - template<> friend void ConstructEmptyInTArray (string *dst) + template<> friend void ConstructEmptyInTArray (FString *dst) { - new (dst) string; + new (dst) FString; } #else - template friend inline void CopyForTArray (string &dst, string &src); - template friend inline void ConstructInTArray (string *dst, const string &src); - template friend inline void ConstructEmptyInTArray (string *dst); + template friend inline void CopyForTArray (FString &dst, FString &src); + template friend inline void ConstructInTArray (FString *dst, const FString &src); + template friend inline void ConstructEmptyInTArray (FString *dst); #endif private: - void *operator new (size_t size, string *addr) + void *operator new (size_t size, FString *addr) { return addr; } - void operator delete (void *, string *) + void operator delete (void *, FString *) { } }; #ifdef __GNUC__ -template<> inline bool NeedsDestructor () { return true; } -template<> inline void CopyForTArray (string &dst, string &src) +template<> inline bool NeedsDestructor () { return true; } +template<> inline void CopyForTArray (FString &dst, FString &src) { // When a TArray is resized, we just need to update the Owner, because // the old copy is going to go away very soon. No need to call the // destructor, either, because full ownership is transferred to the - // new string. + // new FString. char *chars = src.Chars; dst.Chars = chars; if (chars != NULL) { - ((string::StringHeader *)(chars - sizeof(string::StringHeader)))->Owner = &dst; + ((FString::StringHeader *)(chars - sizeof(FString::StringHeader)))->Owner = &dst; } } -template<> inline void ConstructInTArray (string *dst, const string &src) +template<> inline void ConstructInTArray (FString *dst, const FString &src) { - new (dst) string(src); + new (dst) FString(src); } -template<> inline void ConstructEmptyInTArray (string *dst) +template<> inline void ConstructEmptyInTArray (FString *dst) { - new (dst) string; + new (dst) FString; } #endif diff --git a/src/zstringpool.cpp b/src/zstringpool.cpp index e82d432af..855319ac0 100644 --- a/src/zstringpool.cpp +++ b/src/zstringpool.cpp @@ -4,12 +4,12 @@ #include "zstring.h" -string::PoolGroup string::Pond; +FString::PoolGroup FString::Pond; #ifndef NOPOOLS -struct string::Pool +struct FString::Pool { - // The pool's performance (and thus the string class's performance) is + // The pool's performance (and thus the FString class's performance) is // controlled via these two constants. A small pool size will result // in more frequent garbage collection, while a large pool size will // result in longer garbage collection. A large pool can also end up @@ -17,7 +17,7 @@ struct string::Pool // is ideal. Similarly, making the granularity too big will also result // in more frequent garbage collection. But if you do a lot of // concatenation with the += operator, then a large granularity is good - // because it gives the string more room to grow without needing to + // because it gives the FString more room to grow without needing to // be reallocated. // // Note that the granularity must be a power of 2. The pool size need @@ -27,7 +27,7 @@ struct string::Pool Pool (size_t minSize); ~Pool (); - char *Alloc (string *owner, size_t len); + char *Alloc (FString *owner, size_t len); char *Realloc (char *chars, size_t newlen); void Free (char *chars); void MergeFreeBlocks (StringHeader *block); @@ -48,7 +48,7 @@ struct string::Pool // guarantee it will be constructed before any strings that need it. // Instead, we rely on the loader to initialize Pools to NULL for us. -string::PoolGroup::~PoolGroup () +FString::PoolGroup::~PoolGroup () { int count = 0; Pool *pool = Pools, *next; @@ -62,7 +62,7 @@ string::PoolGroup::~PoolGroup () Pools = NULL; } -char *string::PoolGroup::Alloc (string *owner, size_t len) +char *FString::PoolGroup::Alloc (FString *owner, size_t len) { char *mem; Pool *pool, *best, **prev, **bestprev; @@ -70,7 +70,7 @@ char *string::PoolGroup::Alloc (string *owner, size_t len) // If no pools, create one if (Pools == NULL) { - Pools = new string::Pool (len); + Pools = new FString::Pool (len); } // Try to allocate space from an existing pool @@ -114,8 +114,8 @@ char *string::PoolGroup::Alloc (string *owner, size_t len) } else { - // No pools were large enough to hold the string, so create a new one - pool = new string::Pool (len); + // No pools were large enough to hold the FString, so create a new one + pool = new FString::Pool (len); pool->Next = Pools; Pools = pool; mem = pool->Alloc (owner, len); @@ -123,7 +123,7 @@ char *string::PoolGroup::Alloc (string *owner, size_t len) return mem; } -char *string::PoolGroup::Realloc (string *owner, char *chars, size_t newlen) +char *FString::PoolGroup::Realloc (FString *owner, char *chars, size_t newlen) { if (chars == NULL) { @@ -148,13 +148,13 @@ char *string::PoolGroup::Realloc (string *owner, char *chars, size_t newlen) return newchars; } -void string::PoolGroup::Free (char *chars) +void FString::PoolGroup::Free (char *chars) { Pool *pool = FindPool (chars); pool->Free (chars); } -string::Pool *string::PoolGroup::FindPool (char *chars) const +FString::Pool *FString::PoolGroup::FindPool (char *chars) const { Pool *pool = Pools; while (pool != NULL) @@ -168,12 +168,12 @@ string::Pool *string::PoolGroup::FindPool (char *chars) const return pool; } -string::StringHeader *string::PoolGroup::GetHeader (char *chars) +FString::StringHeader *FString::PoolGroup::GetHeader (char *chars) { return (StringHeader *)(chars - sizeof(StringHeader)); } -string::Pool::Pool (size_t minSize) +FString::Pool::Pool (size_t minSize) { if (minSize < POOL_SIZE) { @@ -191,7 +191,7 @@ string::Pool::Pool (size_t minSize) GenerationNum = 0; } -string::Pool::~Pool () +FString::Pool::~Pool () { if (PoolData != NULL) { @@ -219,7 +219,7 @@ string::Pool::~Pool () } } -char *string::Pool::Alloc (string *owner, size_t len) +char *FString::Pool::Alloc (FString *owner, size_t len) { if (NextAlloc == (StringHeader *)MaxAlloc) { @@ -244,7 +244,7 @@ char *string::Pool::Alloc (string *owner, size_t len) return NULL; } -char *string::Pool::Realloc (char *chars, size_t newlen) +char *FString::Pool::Realloc (char *chars, size_t newlen) { size_t needlen = RoundLen (newlen); StringHeader *oldhead = (StringHeader *)(chars - sizeof(StringHeader)); @@ -266,11 +266,11 @@ char *string::Pool::Realloc (char *chars, size_t newlen) return chars; } - // If there is free space after this string, try to grow into it. + // If there is free space after this FString, try to grow into it. StringHeader *nexthead = (StringHeader *)((char *)oldhead + oldtruelen); if (nexthead < (StringHeader *)MaxAlloc && nexthead->Owner == NULL) { - // Make sure there's only one free block past this string + // Make sure there's only one free block past this FString MergeFreeBlocks (nexthead); // Is there enough room to grow? if (oldtruelen + nexthead->Len >= needlen) @@ -282,7 +282,7 @@ char *string::Pool::Realloc (char *chars, size_t newlen) StringHeader *nextnewhead = (StringHeader *)((char *)oldhead + needlen); nextnewhead->Owner = NULL; nextnewhead->Len = newfreelen; - // If this is the last string in the pool, then the NextAlloc marker also needs to move + // If this is the last FString in the pool, then the NextAlloc marker also needs to move if (nexthead == NextAlloc) { NextAlloc = nextnewhead; @@ -297,7 +297,7 @@ char *string::Pool::Realloc (char *chars, size_t newlen) char *newchars = Alloc (oldhead->Owner, newlen); if (newchars != NULL) { - string::StrCopy (newchars, chars, oldhead->Len); + FString::StrCopy (newchars, chars, oldhead->Len); Free (chars); return newchars; } @@ -306,7 +306,7 @@ char *string::Pool::Realloc (char *chars, size_t newlen) return NULL; } -void string::Pool::Free (char *chars) +void FString::Pool::Free (char *chars) { StringHeader *head = (StringHeader *)(chars - sizeof(StringHeader)); size_t truelen = RoundLen (head->Len); @@ -318,7 +318,7 @@ void string::Pool::Free (char *chars) MergeFreeBlocks (head); } -void string::Pool::MergeFreeBlocks (StringHeader *head) +void FString::Pool::MergeFreeBlocks (StringHeader *head) { StringHeader *block; @@ -344,17 +344,17 @@ void string::Pool::MergeFreeBlocks (StringHeader *head) } } -bool string::Pool::BigEnough (size_t len) const +bool FString::Pool::BigEnough (size_t len) const { return FreeSpace >= RoundLen (len); } -size_t string::Pool::RoundLen (size_t len) const +size_t FString::Pool::RoundLen (size_t len) const { return (len + 1 + sizeof(StringHeader) + BLOCK_GRANULARITY - 1) & ~(BLOCK_GRANULARITY - 1); } -void string::Pool::CollectGarbage (bool noGenerations) +void FString::Pool::CollectGarbage (bool noGenerations) { // This is a generational garbage collector. The space occupied by strings from // the first two generations will not be collected unless noGenerations is set true. @@ -404,7 +404,7 @@ void string::Pool::CollectGarbage (bool noGenerations) } } #else -char *string::PoolGroup::Alloc (string *owner, size_t len) +char *FString::PoolGroup::Alloc (FString *owner, size_t len) { char *mem = (char *)malloc (len + 1 + sizeof(StringHeader)); StringHeader *head = (StringHeader *)mem; @@ -413,7 +413,7 @@ char *string::PoolGroup::Alloc (string *owner, size_t len) return mem; } -char *string::PoolGroup::Realloc (string *owner, char *chars, size_t newlen) +char *FString::PoolGroup::Realloc (FString *owner, char *chars, size_t newlen) { if (chars == NULL) { @@ -427,7 +427,7 @@ char *string::PoolGroup::Realloc (string *owner, char *chars, size_t newlen) return (char *)head + sizeof(StringHeader); } -void string::PoolGroup::Free (char *chars) +void FString::PoolGroup::Free (char *chars) { free (chars - sizeof(StringHeader)); }