add GetChars() accessors to many FString uses where const char* is wanted.

By no means complete, it's just a start to get rid of that automatic type conversion operator.
This commit is contained in:
Christoph Oelckers 2023-10-03 14:27:13 +02:00
commit 1717ff47b2
28 changed files with 92 additions and 97 deletions

View file

@ -429,14 +429,14 @@ void FKeyBindings::ArchiveBindings(FConfigFile *f, const char *matchcmd)
f->ClearKey(ConfigKeyName(i));
}
}
else if (matchcmd == nullptr || stricmp(Binds[i], matchcmd) == 0)
else if (matchcmd == nullptr || Binds[i].CompareNoCase(matchcmd) == 0)
{
if (Binds[i][0] == '\1')
{
Binds[i] = "";
continue;
}
f->SetValueForKey(ConfigKeyName(i), Binds[i]);
f->SetValueForKey(ConfigKeyName(i), Binds[i].GetChars());
if (matchcmd != nullptr)
{ // If saving a specific command, set a marker so that
// it does not get saved in the general binding list.
@ -465,7 +465,7 @@ int FKeyBindings::GetKeysForCommand (const char *cmd, int *first, int *second)
while (i < NUM_KEYS && c < 2)
{
if (stricmp (cmd, Binds[i]) == 0)
if (stricmp (cmd, Binds[i].GetChars()) == 0)
{
if (c++ == 0)
*first = i;
@ -490,7 +490,7 @@ TArray<int> FKeyBindings::GetKeysForCommand (const char *cmd)
while (i < NUM_KEYS)
{
if (stricmp (cmd, Binds[i]) == 0)
if (stricmp (cmd, Binds[i].GetChars()) == 0)
{
result.Push(i);
}
@ -511,7 +511,7 @@ void FKeyBindings::UnbindACommand (const char *str)
for (i = 0; i < NUM_KEYS; i++)
{
if (!stricmp (str, Binds[i]))
if (!stricmp (str, Binds[i].GetChars()))
{
Binds[i] = "";
}
@ -538,7 +538,7 @@ void FKeyBindings::DefaultBind(const char *keyname, const char *cmd)
}
for (int i = 0; i < NUM_KEYS; ++i)
{
if (!Binds[i].IsEmpty() && stricmp (Binds[i], cmd) == 0)
if (!Binds[i].IsEmpty() && stricmp (Binds[i].GetChars(), cmd) == 0)
{ // This command is already bound to a key.
return;
}

View file

@ -412,8 +412,8 @@ public:
const char *operator= (const char *stringrep)
{ UCVarValue val; val.String = const_cast<char *>(stringrep); SetGenericRep (val, CVAR_String); return stringrep; }
inline operator const char * () const { return mValue; }
inline const char *operator *() const { return mValue; }
inline operator const char * () const { return mValue.GetChars(); }
inline const char *operator *() const { return mValue.GetChars(); }
protected:
virtual void DoSet (UCVarValue value, ECVarType type);

View file

@ -165,10 +165,7 @@ bool FStringTable::readMacros(int lumpnum)
for (unsigned i = 1; i < data.Size(); i++)
{
auto macroname = data[i][0];
auto language = data[i][1];
if (macroname.IsEmpty() || language.IsEmpty()) continue;
FStringf combined_name("%s/%s", language.GetChars(), macroname.GetChars());
FName name = combined_name.GetChars();
FName name = macroname.GetChars();
StringMacro macro;
@ -446,9 +443,8 @@ void FStringTable::InsertString(int lumpnum, int langid, FName label, const FStr
break;
}
FString macroname(te.strings[0].GetChars() + index + 2, endindex - index - 2);
FStringf lookupstr("%s/%s", strlangid, macroname.GetChars());
FStringf replacee("@[%s]", macroname.GetChars());
FName lookupname(lookupstr.GetChars(), true);
FName lookupname(macroname.GetChars(), true);
auto replace = allMacros.CheckKey(lookupname);
for (int i = 0; i < 4; i++)
{

View file

@ -898,7 +898,7 @@ const char *FDInputJoystick::GetAxisName(int axis)
{
if (unsigned(axis) < Axes.Size())
{
return Axes[axis].Name;
return Axes[axis].Name.GetChars();
}
return "Invalid";
}

View file

@ -738,7 +738,7 @@ void MainWindow::FlushBufferedConsoleStuff()
{
for (unsigned i = 0; i < bufferedConsoleStuff.Size(); i++)
{
DoPrintStr(bufferedConsoleStuff[i]);
DoPrintStr(bufferedConsoleStuff[i].GetChars());
}
bufferedConsoleStuff.Clear();
}

View file

@ -1242,8 +1242,8 @@ int FRawPS2Manager::DeviceSort(const void *a, const void *b)
if (lex == 0)
{
// Skip device part of the ID and sort the connection part
const char *ca = strchr(ha->DeviceID, '#');
const char *cb = strchr(hb->DeviceID, '#');
const char *ca = strchr(ha->DeviceID.GetChars(), '#');
const char *cb = strchr(hb->DeviceID.GetChars(), '#');
const char *ea, *eb;
// The last bit looks like a controller number. Strip it out to be safe
// if this is a multi-controller adapter.

View file

@ -91,7 +91,7 @@ bool IsPortable()
// A portable INI means that this storage location should also be portable if the file can be written to.
FStringf path("%s" GAMENAMELOWERCASE "_portable.ini", progdir.GetChars());
if (FileExists(path))
if (FileExists(path.GetChars()))
{
file = CreateFile(path.WideString().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
@ -145,7 +145,7 @@ FString M_GetAppDataPath(bool create)
path += "/" GAMENAMELOWERCASE;
if (create)
{
CreatePath(path);
CreatePath(path.GetChars());
}
return path;
}
@ -167,7 +167,7 @@ FString M_GetCachePath(bool create)
path += "/zdoom/cache";
if (create)
{
CreatePath(path);
CreatePath(path.GetChars());
}
return path;
}
@ -217,7 +217,7 @@ FString M_GetOldConfigPath(int& type)
}
path << GAMENAMELOWERCASE "-" << FString(uname) << ".ini";
type = 0;
if (FileExists(path))
if (FileExists(path.GetChars()))
return path;
}
@ -226,7 +226,7 @@ FString M_GetOldConfigPath(int& type)
path = GetKnownFolder(CSIDL_APPDATA, FOLDERID_RoamingAppData, true);
path += "/" GAME_DIR "/" GAMENAMELOWERCASE ".ini";
type = 1;
if (FileExists(path))
if (FileExists(path.GetChars()))
return path;
return "";
@ -283,9 +283,9 @@ FString M_GetConfigPath(bool for_reading)
// Construct a user-specific config name
FString path = GetKnownFolder(CSIDL_APPDATA, FOLDERID_Documents, true);
path += "/My Games/" GAME_DIR;
CreatePath(path);
CreatePath(path.GetChars());
path += "/" GAMENAMELOWERCASE ".ini";
if (!for_reading || FileExists(path))
if (!for_reading || FileExists(path.GetChars()))
return path;
// No config was found in the accepted locations.
@ -305,7 +305,7 @@ FString M_GetConfigPath(bool for_reading)
isportable = true;
}
}
bool res = MoveFileExW(WideString(oldpath).c_str(), WideString(path).c_str(), MOVEFILE_COPY_ALLOWED);
bool res = MoveFileExW(WideString(oldpath.GetChars()).c_str(), WideString(path.GetChars()).c_str(), MOVEFILE_COPY_ALLOWED);
if (res) return path;
else return oldpath; // if we cannot move, just use the config where it was. It won't be written back, though and never be used again if a new one gets saved.
}
@ -314,7 +314,7 @@ FString M_GetConfigPath(bool for_reading)
// If we are reading the config file, check if it exists. If not, fallback to base version.
if (for_reading)
{
if (!FileExists(path))
if (!FileExists(path.GetChars()))
{
path = progdir;
path << GAMENAMELOWERCASE ".ini";
@ -351,7 +351,7 @@ FString M_GetScreenshotsPath()
path = GetKnownFolder(CSIDL_MYPICTURES, FOLDERID_Pictures, true);
path << "/Screenshots/" GAMENAME "/";
}
CreatePath(path);
CreatePath(path.GetChars());
return path;
}
@ -402,7 +402,7 @@ FString M_GetDocumentsPath()
// I assume since this isn't a standard folder, it doesn't have a localized name either.
path = GetKnownFolder(CSIDL_PERSONAL, FOLDERID_Documents, true);
path << "/My Games/" GAMENAME "/";
CreatePath(path);
CreatePath(path.GetChars());
}
return path;
}

View file

@ -409,9 +409,9 @@ BOOL CALLBACK IWADBoxCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
ctrl = GetDlgItem(hDlg, IDC_IWADLIST);
for (i = 0; i < NumWads; i++)
{
const char *filepart = strrchr(WadList[i].Path, '/');
const char *filepart = strrchr(WadList[i].Path.GetChars(), '/');
if (filepart == NULL)
filepart = WadList[i].Path;
filepart = WadList[i].Path.GetChars();
else
filepart++;

View file

@ -119,7 +119,7 @@ static FString CalcProgramBinaryChecksum(const FString &vertex, const FString &f
static FString CreateProgramCacheName(bool create)
{
FString path = M_GetCachePath(create);
if (create) CreatePath(path);
if (create) CreatePath(path.GetChars());
path << "/shadercache.zdsc";
return path;
}
@ -135,7 +135,7 @@ static void LoadShaders()
{
FString path = CreateProgramCacheName(false);
FileReader fr;
if (!fr.OpenFile(path))
if (!fr.OpenFile(path.GetChars()))
I_Error("Could not open shader file");
char magic[4];
@ -176,7 +176,7 @@ static void LoadShaders()
static void SaveShaders()
{
FString path = CreateProgramCacheName(true);
std::unique_ptr<FileWriter> fw(FileWriter::Open(path));
std::unique_ptr<FileWriter> fw(FileWriter::Open(path.GetChars()));
if (fw)
{
uint32_t count = (uint32_t)ShaderCache.size();
@ -234,7 +234,7 @@ bool FShader::Configure(const char* name, const char* vert_prog_lump, const char
void FShader::LoadVariant()
{
//mDefinesBase
Load(mName.GetChars(), mVertProg, mFragProg, mFragProg2, mLightProg, mDefinesBase);
Load(mName.GetChars(), mVertProg.GetChars(), mFragProg.GetChars(), mFragProg2.GetChars(), mLightProg.GetChars(), mDefinesBase.GetChars());
}
bool FShader::Load(const char * name, const char * vert_prog_lump_, const char * frag_prog_lump_, const char * proc_prog_lump_, const char * light_fragprog_, const char * defines)
@ -381,11 +381,11 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
i_data += "#define NPOT_EMULATION\nuniform vec2 uNpotEmulation;\n";
#endif
int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump, 0);
int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump.GetChars(), 0);
if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump.GetChars());
auto vp_data = fileSystem.ReadFile(vp_lump);
int fp_lump = fileSystem.CheckNumForFullName(frag_prog_lump, 0);
int fp_lump = fileSystem.CheckNumForFullName(frag_prog_lump.GetChars(), 0);
if (fp_lump == -1) I_Error("Unable to load '%s'", frag_prog_lump.GetChars());
auto fp_data = fileSystem.ReadFile(fp_lump);
@ -418,9 +418,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
{
fp_comb << "#line 1\n";
if (*proc_prog_lump != '#')
if (proc_prog_lump[0] != '#')
{
int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump);
int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump.GetChars());
if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump.GetChars());
auto ppf = fileSystem.ReadFile(pp_lump);
FString pp_data = GetStringFromLump(pp_lump);
@ -485,7 +485,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
if (light_fragprog.Len())
{
int pp_lump = fileSystem.CheckNumForFullName(light_fragprog, 0);
int pp_lump = fileSystem.CheckNumForFullName(light_fragprog.GetChars(), 0);
if (pp_lump == -1) I_Error("Unable to load '%s'", light_fragprog.GetChars());
fp_comb << GetStringFromLump(pp_lump) << "\n";
}
@ -722,8 +722,7 @@ bool FShader::Bind(ShaderFlavourData& flavour)
//Printf("Shader: %s, %08x %s", mFragProg2.GetChars(), tag, variantConfig.GetChars());
Load(mName.GetChars(), mVertProg, mFragProg, mFragProg2, mLightProg, mDefinesBase + variantConfig);
Load(mName.GetChars(), mVertProg.GetChars(), mFragProg.GetChars(), mFragProg2.GetChars(), mLightProg.GetChars(), (mDefinesBase + variantConfig).GetChars());
variants.insert(std::make_pair(tag, cur));
}
else

View file

@ -165,7 +165,7 @@ void FShaderProgram::Link(const char *name)
glUseProgram(mProgram);
for (auto &uni : samplerstobind)
{
auto index = glGetUniformLocation(mProgram, uni.first);
auto index = glGetUniformLocation(mProgram, uni.first.GetChars());
if (index >= 0)
{
glUniform1i(index, uni.second);
@ -266,8 +266,8 @@ void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program
FString prolog = Uniforms.CreateDeclaration("Uniforms", PresentUniforms::Desc());
mShader.reset(new FShaderProgram());
mShader->Compile(FShaderProgram::Vertex, "shaders_gles/pp/screenquad.vp", prolog, 330);
mShader->Compile(FShaderProgram::Fragment, vtx_shader_name, prolog, 330);
mShader->Compile(FShaderProgram::Vertex, "shaders_gles/pp/screenquad.vp", prolog.GetChars(), 330);
mShader->Compile(FShaderProgram::Fragment, vtx_shader_name, prolog.GetChars(), 330);
mShader->Link(program_name);
mShader->Bind();
Uniforms.Init();

View file

@ -40,7 +40,7 @@
VkRenderPassManager::VkRenderPassManager(VulkanRenderDevice* fb) : fb(fb)
{
FString path = M_GetCachePath(true);
CreatePath(path);
CreatePath(path.GetChars());
CacheFilename = path + "/pipelinecache.zdpc";
PipelineCacheBuilder builder;
@ -49,7 +49,7 @@ VkRenderPassManager::VkRenderPassManager(VulkanRenderDevice* fb) : fb(fb)
try
{
FileReader fr;
if (fr.OpenFile(CacheFilename))
if (fr.OpenFile(CacheFilename.GetChars()))
{
std::vector<uint8_t> data;
data.resize(fr.GetLength());
@ -71,7 +71,7 @@ VkRenderPassManager::~VkRenderPassManager()
try
{
auto data = PipelineCache->GetCacheData();
std::unique_ptr<FileWriter> fw(FileWriter::Open(CacheFilename));
std::unique_ptr<FileWriter> fw(FileWriter::Open(CacheFilename.GetChars()));
if (fw)
fw->Write(data.data(), data.size());
}

View file

@ -67,7 +67,7 @@ void VkPPShader::Reset()
FString VkPPShader::LoadShaderCode(const FString &lumpName, const FString &defines, int version)
{
int lump = fileSystem.CheckNumForFullName(lumpName);
int lump = fileSystem.CheckNumForFullName(lumpName.GetChars());
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName.GetChars());
auto sp = fileSystem.ReadFile(lump);
FString code = GetStringFromLump(lump);

View file

@ -73,12 +73,12 @@ bool VkShaderManager::CompileNextShader()
{
// user shaders
const FString& name = ExtractFileBase(usershaders[i].shader);
const FString& name = ExtractFileBase(usershaders[i].shader.GetChars());
FString defines = defaultshaders[usershaders[i].shaderType].Defines + usershaders[i].defines;
VkShaderProgram prog;
prog.vert = LoadVertShader(name, mainvp, defines);
prog.frag = LoadFragShader(name, mainfp, usershaders[i].shader, defaultshaders[usershaders[i].shaderType].lightfunc, defines, true, compilePass == GBUFFER_PASS);
prog.vert = LoadVertShader(name, mainvp, defines.GetChars());
prog.frag = LoadFragShader(name, mainfp, usershaders[i].shader.GetChars(), defaultshaders[usershaders[i].shaderType].lightfunc, defines.GetChars(), true, compilePass == GBUFFER_PASS);
mMaterialShaders[compilePass].push_back(std::move(prog));
compileIndex++;

View file

@ -1394,7 +1394,7 @@ FxExpression *FxColorCast::Resolve(FCompileContext &ctx)
}
else
{
FxExpression *x = new FxConstant(V_GetColor(constval.GetString(), &ScriptPosition), ScriptPosition);
FxExpression *x = new FxConstant(V_GetColor(constval.GetString().GetChars(), &ScriptPosition), ScriptPosition);
delete this;
return x;
}
@ -1474,7 +1474,7 @@ FxExpression *FxSoundCast::Resolve(FCompileContext &ctx)
if (basex->isConstant())
{
ExpVal constval = static_cast<FxConstant *>(basex)->GetValue();
FxExpression *x = new FxConstant(S_FindSound(constval.GetString()), ScriptPosition);
FxExpression *x = new FxConstant(S_FindSound(constval.GetString().GetChars()), ScriptPosition);
delete this;
return x;
}
@ -1552,7 +1552,7 @@ FxExpression *FxFontCast::Resolve(FCompileContext &ctx)
else if ((basex->ValueType == TypeString || basex->ValueType == TypeName) && basex->isConstant())
{
ExpVal constval = static_cast<FxConstant *>(basex)->GetValue();
FFont *font = V_GetFont(constval.GetString());
FFont *font = V_GetFont(constval.GetString().GetChars());
// Font must exist. Most internal functions working with fonts do not like null pointers.
// If checking is needed scripts will have to call Font.GetFont themselves.
if (font == nullptr)

View file

@ -528,7 +528,7 @@ void CreatePath(const char *fn)
{
FString name(fn);
name += '/';
DoCreatePath(name);
DoCreatePath(name.GetChars());
}
else
{
@ -805,13 +805,13 @@ FString ExpandEnvVars(const char *searchpathstring)
if (length != 0)
{
FString varname = FString(dollar + 1, length);
if (stricmp(varname, "progdir") == 0)
if (varname.Compare("progdir") == 0)
{
out += progdir;
}
else
{
char *varvalue = getenv(varname);
char *varvalue = getenv(varname.GetChars());
if ( (varvalue != NULL) && (strlen(varvalue) != 0) )
{
out += varvalue;

View file

@ -85,7 +85,7 @@ FConfigFile::FConfigFile (const FConfigFile &other)
Sections = CurrentSection = NULL;
LastSectionPtr = &Sections;
CurrentEntry = NULL;
ChangePathName (other.PathName);
ChangePathName (other.PathName.GetChars());
*this = other;
OkayToWrite = other.OkayToWrite;
FileExisted = other.FileExisted;
@ -134,7 +134,7 @@ FConfigFile &FConfigFile::operator = (const FConfigFile &other)
while (fromsection != NULL)
{
fromentry = fromsection->RootEntry;
tosection = NewConfigSection (fromsection->SectionName);
tosection = NewConfigSection (fromsection->SectionName.GetChars());
while (fromentry != NULL)
{
NewConfigEntry (tosection, fromentry->Key, fromentry->Value);
@ -602,7 +602,7 @@ void FConfigFile::LoadConfigFile ()
bool succ;
FileExisted = false;
if (!file.OpenFile (PathName))
if (!file.OpenFile (PathName.GetChars()))
{
return;
}
@ -739,7 +739,7 @@ FConfigFile::FConfigEntry *FConfigFile::ReadMultiLineValue(FileReader *file, FCo
// Append this line to the value.
value << readbuf;
}
return NewConfigEntry(section, key, value);
return NewConfigEntry(section, key, value.GetChars());
}
//====================================================================
@ -787,7 +787,7 @@ bool FConfigFile::WriteConfigFile () const
return true;
}
FileWriter *file = FileWriter::Open (PathName);
FileWriter *file = FileWriter::Open (PathName.GetChars());
FConfigSection *section;
FConfigEntry *entry;

View file

@ -146,7 +146,7 @@ void D_AddWildFile(std::vector<std::string>& wadfiles, const char* value, const
auto path = ExtractFilePath(value);
auto name = ExtractFileBase(value, true);
if (path.IsEmpty()) path = ".";
if (FileSys::ScanDirectory(list, path, name, true))
if (FileSys::ScanDirectory(list, path.GetChars(), name.GetChars(), true))
{
for(auto& entry : list)
{
@ -178,7 +178,7 @@ void D_AddConfigFiles(std::vector<std::string>& wadfiles, const char* section, c
{
// D_AddWildFile resets config's position, so remember it
config->GetPosition(pos);
D_AddWildFile(wadfiles, ExpandEnvVars(value), extension, config);
D_AddWildFile(wadfiles, ExpandEnvVars(value).GetChars(), extension, config);
// Reset config's position to get next wad
config->SetPosition(pos);
}
@ -230,7 +230,7 @@ const char* BaseFileSearch(const char* file, const char* ext, bool lookfirstinpr
if (lookfirstinprogdir)
{
BFSwad.Format("%s%s%s", progdir.GetChars(), progdir.Back() == '/' ? "" : "/", file);
if (DirEntryExists(BFSwad))
if (DirEntryExists(BFSwad.GetChars()))
{
return BFSwad.GetChars();
}
@ -257,7 +257,7 @@ const char* BaseFileSearch(const char* file, const char* ext, bool lookfirstinpr
if (dir.IsNotEmpty())
{
BFSwad.Format("%s%s%s", dir.GetChars(), dir.Back() == '/' ? "" : "/", file);
if (DirEntryExists(BFSwad))
if (DirEntryExists(BFSwad.GetChars()))
{
return BFSwad.GetChars();
}
@ -271,7 +271,7 @@ const char* BaseFileSearch(const char* file, const char* ext, bool lookfirstinpr
{
FString tmp = file;
DefaultExtension(tmp, ext);
return BaseFileSearch(tmp, nullptr, lookfirstinprogdir, config);
return BaseFileSearch(tmp.GetChars(), nullptr, lookfirstinprogdir, config);
}
return nullptr;
}