Kill off some usages of c_str.

Also changes some function params, but this is ok.
Some simplifications were also able to be made (ie. killing off strcmps with ==, etc).
This commit is contained in:
Lioncash
2014-03-12 15:33:41 -04:00
parent dccc6d8b47
commit a82675b7d5
170 changed files with 812 additions and 704 deletions

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <string>
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
@ -79,10 +81,9 @@ void ContinueGFXDebugger()
}
void GFXDebuggerBase::DumpPixelShader(const char* path)
void GFXDebuggerBase::DumpPixelShader(const std::string& path)
{
char filename[MAX_PATH];
sprintf(filename, "%sdump_ps.txt", path);
const std::string filename = StringFromFormat("%sdump_ps.txt", path.c_str());
std::string output;
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
@ -111,51 +112,50 @@ void GFXDebuggerBase::DumpPixelShader(const char* path)
File::WriteStringToFile(output, filename);
}
void GFXDebuggerBase::DumpVertexShader(const char* path)
void GFXDebuggerBase::DumpVertexShader(const std::string& path)
{
char filename[MAX_PATH];
sprintf(filename, "%sdump_vs.txt", path);
const std::string filename = StringFromFormat("%sdump_vs.txt", path.c_str());
File::CreateEmptyFile(filename);
/// File::WriteStringToFile(GenerateVertexShaderCode(g_nativeVertexFmt->m_components, g_ActiveConfig.backend_info.APIType), filename);
}
void GFXDebuggerBase::DumpPixelShaderConstants(const char* path)
void GFXDebuggerBase::DumpPixelShaderConstants(const std::string& path)
{
// TODO
}
void GFXDebuggerBase::DumpVertexShaderConstants(const char* path)
void GFXDebuggerBase::DumpVertexShaderConstants(const std::string& path)
{
// TODO
}
void GFXDebuggerBase::DumpTextures(const char* path)
void GFXDebuggerBase::DumpTextures(const std::string& path)
{
// TODO
}
void GFXDebuggerBase::DumpFrameBuffer(const char* path)
void GFXDebuggerBase::DumpFrameBuffer(const std::string& path)
{
// TODO
}
void GFXDebuggerBase::DumpGeometry(const char* path)
void GFXDebuggerBase::DumpGeometry(const std::string& path)
{
// TODO
}
void GFXDebuggerBase::DumpVertexDecl(const char* path)
void GFXDebuggerBase::DumpVertexDecl(const std::string& path)
{
// TODO
}
void GFXDebuggerBase::DumpMatrices(const char* path)
void GFXDebuggerBase::DumpMatrices(const std::string& path)
{
// TODO
}
void GFXDebuggerBase::DumpStats(const char* path)
void GFXDebuggerBase::DumpStats(const std::string& path)
{
// TODO
}

View File

@ -4,6 +4,8 @@
#pragma once
#include <string>
class GFXDebuggerBase
{
public:
@ -13,19 +15,20 @@ public:
virtual void OnPause() {};
virtual void OnContinue() {};
void DumpPixelShader(const char* path);
void DumpVertexShader(const char* path);
void DumpPixelShaderConstants(const char* path);
void DumpVertexShaderConstants(const char* path);
void DumpTextures(const char* path);
void DumpFrameBuffer(const char* path);
void DumpGeometry(const char* path);
void DumpVertexDecl(const char* path);
void DumpMatrices(const char* path);
void DumpStats(const char* path);
void DumpPixelShader(const std::string& path);
void DumpVertexShader(const std::string& path);
void DumpPixelShaderConstants(const std::string& path);
void DumpVertexShaderConstants(const std::string& path);
void DumpTextures(const std::string& path);
void DumpFrameBuffer(const std::string& path);
void DumpGeometry(const std::string& path);
void DumpVertexDecl(const std::string& path);
void DumpMatrices(const std::string& path);
void DumpStats(const std::string& path);
};
enum PauseEvent {
enum PauseEvent
{
NOT_PAUSE = 0,
NEXT_FRAME = 1<<0,
NEXT_FLUSH = 1<<1,

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <string>
#include <windows.h>
#include "Core/ConfigManager.h"
@ -22,8 +23,6 @@ WNDCLASSEX wndClass;
const TCHAR m_szClassName[] = _T("DolphinEmuWnd");
int g_winstyle;
static volatile bool s_sizing;
static const int TITLE_TEXT_BUF_SIZE = 1024;
TCHAR m_titleTextBuffer[TITLE_TEXT_BUF_SIZE];
static const int WM_SETTEXT_CUSTOM = WM_USER + WM_SETTEXT;
bool IsSizing()
@ -193,27 +192,11 @@ void SetSize(int width, int height)
MoveWindow(m_hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE);
}
void SetWindowText(const TCHAR* text)
void SetWindowText(const std::string& text)
{
// the simple way.
// we don't do this because it's a blocking call and the GUI thread might be waiting for us.
//::SetWindowText(m_hWnd, text);
// copy to m_titleTextBuffer in such a way that
// it remains null-terminated and without garbage data at every point in time,
// in case another thread reads it while we're doing this.
for (int i = 0; i < TITLE_TEXT_BUF_SIZE-1; ++i)
{
m_titleTextBuffer[i+1] = 0;
TCHAR c = text[i];
m_titleTextBuffer[i] = c;
if (!c)
break;
}
// the OS doesn't allow posting WM_SETTEXT,
// so we post our own message and convert it to that in WndProc
PostMessage(m_hWnd, WM_SETTEXT_CUSTOM, 0, (LPARAM)m_titleTextBuffer);
PostMessage(m_hWnd, WM_SETTEXT_CUSTOM, 0, (LPARAM)text.c_str());
}
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <string>
#include <windows.h>
namespace EmuWindow
@ -13,6 +14,6 @@ void Close();
void SetSize(int displayWidth, int displayHeight);
bool IsSizing();
void OSDMenu(WPARAM wParam);
void SetWindowText(const TCHAR* text);
void SetWindowText(const std::string& text);
}

View File

@ -4,6 +4,7 @@
#include <algorithm>
#include <cstring>
#include <string>
#include <utility>
#include <SOIL/SOIL.h>
@ -19,16 +20,14 @@ namespace HiresTextures
std::map<std::string, std::string> textureMap;
void Init(const char *gameCode)
void Init(const std::string& gameCode)
{
textureMap.clear();
CFileSearch::XStringVector Directories;
//Directories.push_back(File::GetUserPath(D_HIRESTEXTURES_IDX));
char szDir[MAX_PATH];
sprintf(szDir, "%s%s", File::GetUserPath(D_HIRESTEXTURES_IDX).c_str(), gameCode);
Directories.push_back(std::string(szDir));
std::string szDir = StringFromFormat("%s%s", File::GetUserPath(D_HIRESTEXTURES_IDX).c_str(), gameCode.c_str());
Directories.push_back(szDir);
for (u32 i = 0; i < Directories.size(); i++)
{
@ -39,31 +38,34 @@ void Init(const char *gameCode)
if (entry.isDirectory)
{
bool duplicate = false;
for (auto& Directory : Directories)
{
if (strcmp(Directory.c_str(), entry.physicalName.c_str()) == 0)
if (Directory == entry.physicalName)
{
duplicate = true;
break;
}
}
if (!duplicate)
Directories.push_back(entry.physicalName.c_str());
Directories.push_back(entry.physicalName);
}
}
}
CFileSearch::XStringVector Extensions;
Extensions.push_back("*.png");
Extensions.push_back("*.bmp");
Extensions.push_back("*.tga");
Extensions.push_back("*.dds");
Extensions.push_back("*.jpg"); // Why not? Could be useful for large photo-like textures
CFileSearch::XStringVector Extensions = {
"*.png",
"*.bmp",
"*.tga",
"*.dds",
"*.jpg" // Why not? Could be useful for large photo-like textures
};
CFileSearch FileSearch(Extensions, Directories);
const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames();
char code[MAX_PATH];
sprintf(code, "%s_", gameCode);
const std::string code = StringFromFormat("%s_", gameCode.c_str());
if (rFilenames.size() > 0)
{
@ -72,32 +74,30 @@ void Init(const char *gameCode)
std::string FileName;
SplitPath(rFilename, nullptr, &FileName, nullptr);
if (FileName.substr(0, strlen(code)).compare(code) == 0 && textureMap.find(FileName) == textureMap.end())
if (FileName.substr(0, code.length()).compare(code) == 0 && textureMap.find(FileName) == textureMap.end())
textureMap.insert(std::map<std::string, std::string>::value_type(FileName, rFilename));
}
}
}
bool HiresTexExists(const char* filename)
bool HiresTexExists(const std::string& filename)
{
std::string key(filename);
return textureMap.find(key) != textureMap.end();
return textureMap.find(filename) != textureMap.end();
}
PC_TexFormat GetHiresTex(const char *fileName, unsigned int *pWidth, unsigned int *pHeight, unsigned int *required_size, int texformat, unsigned int data_size, u8 *data)
PC_TexFormat GetHiresTex(const std::string& filename, unsigned int* pWidth, unsigned int* pHeight, unsigned int* required_size, int texformat, unsigned int data_size, u8* data)
{
std::string key(fileName);
if (textureMap.find(key) == textureMap.end())
if (textureMap.find(filename) == textureMap.end())
return PC_TEX_FMT_NONE;
int width;
int height;
int channels;
u8 *temp = SOIL_load_image(textureMap[key].c_str(), &width, &height, &channels, SOIL_LOAD_RGBA);
u8 *temp = SOIL_load_image(textureMap[filename].c_str(), &width, &height, &channels, SOIL_LOAD_RGBA);
if (temp == nullptr)
{
ERROR_LOG(VIDEO, "Custom texture %s failed to load", textureMap[key].c_str());
ERROR_LOG(VIDEO, "Custom texture %s failed to load", textureMap[filename].c_str());
return PC_TEX_FMT_NONE;
}
@ -136,7 +136,7 @@ PC_TexFormat GetHiresTex(const char *fileName, unsigned int *pWidth, unsigned in
break;
}
INFO_LOG(VIDEO, "Loading custom texture from %s", textureMap[key].c_str());
INFO_LOG(VIDEO, "Loading custom texture from %s", textureMap[filename].c_str());
cleanup:
SOIL_free_image_data(temp);
return returnTex;

View File

@ -5,13 +5,14 @@
#pragma once
#include <map>
#include <string>
#include "VideoCommon/TextureDecoder.h"
#include "VideoCommon/VideoCommon.h"
namespace HiresTextures
{
void Init(const char *gameCode);
bool HiresTexExists(const char *filename);
PC_TexFormat GetHiresTex(const char *fileName, unsigned int *pWidth, unsigned int *pHeight, unsigned int *required_size, int texformat, unsigned int data_size, u8 *data);
void Init(const std::string& gameCode);
bool HiresTexExists(const std::string& filename);
PC_TexFormat GetHiresTex(const std::string& fileName, unsigned int* pWidth, unsigned int* pHeight, unsigned int* required_size, int texformat, unsigned int data_size, u8* data);
};

View File

@ -119,9 +119,9 @@ void VideoBackendHardware::Video_EndField()
}
}
void VideoBackendHardware::Video_AddMessage(const char* pstr, u32 milliseconds)
void VideoBackendHardware::Video_AddMessage(const std::string& msg, u32 milliseconds)
{
OSD::AddMessage(pstr, milliseconds);
OSD::AddMessage(msg, milliseconds);
}
void VideoBackendHardware::Video_ClearMessages()
@ -130,9 +130,9 @@ void VideoBackendHardware::Video_ClearMessages()
}
// Screenshot
bool VideoBackendHardware::Video_Screenshot(const char *_szFilename)
bool VideoBackendHardware::Video_Screenshot(const std::string& filename)
{
Renderer::SetScreenshot(_szFilename);
Renderer::SetScreenshot(filename.c_str());
return true;
}

View File

@ -56,8 +56,8 @@ void DrawMessages()
alpha <<= 24;
g_renderer->RenderText(it->str.c_str(), left + 1, top + 1, 0x000000 | alpha);
g_renderer->RenderText(it->str.c_str(), left, top, 0xffff30 | alpha);
g_renderer->RenderText(it->str, left + 1, top + 1, 0x000000 | alpha);
g_renderer->RenderText(it->str, left, top, 0xffff30 | alpha);
top += 15;
if (time_left <= 0)

View File

@ -238,7 +238,7 @@ bool Renderer::CalculateTargetSize(unsigned int framebuffer_width, unsigned int
return false;
}
void Renderer::SetScreenshot(const char *filename)
void Renderer::SetScreenshot(const std::string& filename)
{
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
s_sScreenshotName = filename;
@ -343,11 +343,11 @@ void Renderer::DrawDebugText()
}
// Render a shadow
g_renderer->RenderText(final_cyan.c_str(), 21, 21, 0xDD000000);
g_renderer->RenderText(final_yellow.c_str(), 21, 21, 0xDD000000);
g_renderer->RenderText(final_cyan, 21, 21, 0xDD000000);
g_renderer->RenderText(final_yellow, 21, 21, 0xDD000000);
//and then the text
g_renderer->RenderText(final_cyan.c_str(), 20, 20, 0xFF00FFFF);
g_renderer->RenderText(final_yellow.c_str(), 20, 20, 0xFFFFFF00);
g_renderer->RenderText(final_cyan, 20, 20, 0xFF00FFFF);
g_renderer->RenderText(final_yellow, 20, 20, 0xFFFFFF00);
}
// TODO: remove

View File

@ -90,10 +90,10 @@ public:
static float EFBToScaledYf(float y) { return y * ((float)GetTargetHeight() / (float)EFB_HEIGHT); }
// Random utilities
static void SetScreenshot(const char *filename);
static void SetScreenshot(const std::string& filename);
static void DrawDebugText();
virtual void RenderText(const char* pstr, int left, int top, u32 color) = 0;
virtual void RenderText(const std::string& text, int left, int top, u32 color) = 0;
virtual void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z) = 0;
virtual void ReinterpretPixelData(unsigned int convtype) = 0;

View File

@ -47,7 +47,7 @@ TextureCache::TextureCache()
TexDecoder_SetTexFmtOverlayOptions(g_ActiveConfig.bTexFmtOverlayEnable, g_ActiveConfig.bTexFmtOverlayCenter);
if (g_ActiveConfig.bHiresTextures && !g_ActiveConfig.bDumpTextures)
HiresTextures::Init(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());
HiresTextures::Init(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID);
SetHash64Function(g_ActiveConfig.bHiresTextures || g_ActiveConfig.bDumpTextures);
@ -89,7 +89,7 @@ void TextureCache::OnConfigChanged(VideoConfig& config)
g_texture_cache->Invalidate();
if (g_ActiveConfig.bHiresTextures)
HiresTextures::Init(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());
HiresTextures::Init(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID);
SetHash64Function(g_ActiveConfig.bHiresTextures || g_ActiveConfig.bDumpTextures);
TexDecoder_SetTexFmtOverlayOptions(g_ActiveConfig.bTexFmtOverlayEnable, g_ActiveConfig.bTexFmtOverlayCenter);
@ -290,8 +290,8 @@ void TextureCache::DumpTexture(TCacheEntryBase* entry, unsigned int level)
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID;
// make sure that the directory exists
if (false == File::Exists(szDir) || false == File::IsDirectory(szDir))
File::CreateDir(szDir.c_str());
if (!File::Exists(szDir) || !File::IsDirectory(szDir))
File::CreateDir(szDir);
// For compatibility with old texture packs, don't print the LOD index for level 0.
// TODO: TLUT format should actually be stored in filename? :/
@ -421,8 +421,8 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
// TODO: Don't we need to force texture decoding to RGBA8 for dynamic EFB copies?
// TODO: Actually, it should be enough if the internal texture format matches...
if ((entry->type == TCET_NORMAL &&
width == entry->virtual_width &&
height == entry->virtual_height &&
width == entry->virtual_width &&
height == entry->virtual_height &&
full_format == entry->format &&
entry->num_mipmaps > maxlevel) ||
(entry->type == TCET_EC_DYNAMIC &&

View File

@ -72,7 +72,7 @@ public:
virtual void EmuStateChange(EMUSTATE_CHANGE) = 0;
virtual void UpdateFPSDisplay(const char*) = 0;
virtual void UpdateFPSDisplay(const std::string&) = 0;
virtual unsigned int PeekMessages() = 0;
@ -96,9 +96,9 @@ public:
virtual u32 Video_AccessEFB(EFBAccessType, u32, u32, u32) = 0;
virtual u32 Video_GetQueryResult(PerfQueryType type) = 0;
virtual void Video_AddMessage(const char* pstr, unsigned int milliseconds) = 0;
virtual void Video_AddMessage(const std::string& msg, unsigned int milliseconds) = 0;
virtual void Video_ClearMessages() = 0;
virtual bool Video_Screenshot(const char* filename) = 0;
virtual bool Video_Screenshot(const std::string& filename) = 0;
virtual void Video_SetRendering(bool bEnabled) = 0;
@ -146,9 +146,9 @@ class VideoBackendHardware : public VideoBackend
u32 Video_AccessEFB(EFBAccessType, u32, u32, u32) override;
u32 Video_GetQueryResult(PerfQueryType type) override;
void Video_AddMessage(const char* pstr, unsigned int milliseconds) override;
void Video_AddMessage(const std::string& pstr, unsigned int milliseconds) override;
void Video_ClearMessages() override;
bool Video_Screenshot(const char* filename) override;
bool Video_Screenshot(const std::string& filename) override;
void Video_SetRendering(bool bEnabled) override;

View File

@ -39,7 +39,7 @@ VideoConfig::VideoConfig()
backend_info.bSupports3DVision = false;
}
void VideoConfig::Load(const char *ini_file)
void VideoConfig::Load(const std::string& ini_file)
{
IniFile iniFile;
iniFile.Load(ini_file);
@ -217,7 +217,7 @@ void VideoConfig::VerifyValidity()
if (!backend_info.bSupportsPixelLighting) bEnablePixelLighting = false;
}
void VideoConfig::Save(const char *ini_file)
void VideoConfig::Save(const std::string& ini_file)
{
IniFile iniFile;
iniFile.Load(ini_file);

View File

@ -50,10 +50,10 @@ class IniFile;
struct VideoConfig
{
VideoConfig();
void Load(const char *ini_file);
void Load(const std::string& ini_file);
void GameIniLoad();
void VerifyValidity();
void Save(const char *ini_file);
void Save(const std::string& ini_file);
void UpdateProjectionHack();
bool IsVSync();