huge cleanup and conversion of most string handling (especially paths) to unicode

please note: format strings must be %hs for char* arguments and %ls for
wchar_t*

This was SVN commit r7161.
This commit is contained in:
janwas
2009-11-03 21:46:35 +00:00
parent a46f3432f3
commit 8a52113e60
317 changed files with 2517 additions and 2588 deletions
+24 -35
View File
@@ -31,7 +31,7 @@
#include "ps/CLogger.h"
#include "ps/Filesystem.h"
#define LOG_CATEGORY "graphics"
#define LOG_CATEGORY L"graphics"
CTextureManager::CTextureManager():
m_LastGroupIndex(0)
@@ -74,7 +74,7 @@ CTextureEntry* CTextureManager::FindTexture(const CStr& tag_)
return m_TextureEntries[i];
}
LOG(CLogger::Warning, LOG_CATEGORY, "TextureManager: Couldn't find terrain %s", tag.c_str());
LOG(CLogger::Warning, LOG_CATEGORY, L"TextureManager: Couldn't find terrain %hs", tag.c_str());
return 0;
}
@@ -83,12 +83,12 @@ CTextureEntry* CTextureManager::FindTexture(Handle handle)
return CTextureEntry::GetByHandle(handle);
}
CTerrainPropertiesPtr CTextureManager::GetPropertiesFromFile(const CTerrainPropertiesPtr& props, const char* path)
CTerrainPropertiesPtr CTextureManager::GetPropertiesFromFile(const CTerrainPropertiesPtr& props, const VfsPath& pathname)
{
return CTerrainProperties::FromXML(props, path);
return CTerrainProperties::FromXML(props, pathname);
}
CTextureEntry *CTextureManager::AddTexture(const CTerrainPropertiesPtr& props, const CStr& path)
CTextureEntry *CTextureManager::AddTexture(const CTerrainPropertiesPtr& props, const VfsPath& path)
{
CTextureEntry *entry = new CTextureEntry(props, path);
m_TextureEntries.push_back(entry);
@@ -111,89 +111,78 @@ void CTextureManager::DeleteTexture(CTextureEntry* entry)
// jw: indeed this is inefficient and RecurseDirectory should be implemented
// via VFSUtil::EnumFiles, but it works fine and "only" takes 25ms for
// typical maps. therefore, we'll leave it for now.
void CTextureManager::LoadTextures(const CTerrainPropertiesPtr& props, const char* dir)
void CTextureManager::LoadTextures(const CTerrainPropertiesPtr& props, const VfsPath& path)
{
VfsPaths pathnames;
if(fs_util::GetPathnames(g_VFS, dir, 0, pathnames) < 0)
if(fs_util::GetPathnames(g_VFS, path, 0, pathnames) < 0)
return;
for(size_t i = 0; i < pathnames.size(); i++)
{
const char* texture_name = pathnames[i].string().c_str();
// skip files that obviously aren't textures.
// note: this loop runs for each file in dir, even .xml;
// we should skip those to avoid spurious "texture load failed".
// we can't use FindFile's filter param because new texture formats
// may later be added and that interface doesn't support specifying
// multiple extensions.
if(!tex_is_known_extension(texture_name))
if(!tex_is_known_extension(pathnames[i]))
continue;
// build name of associated xml file (i.e. replace extension)
char xml_name[PATH_MAX+5]; // add room for .XML
strcpy_s(xml_name, PATH_MAX, texture_name);
const char* ext = path_extension(texture_name);
SAFE_STRCPY(xml_name + (ext-texture_name), "xml");
VfsPath pathnameXML = fs::change_extension(pathnames[i], L".xml");
CTerrainPropertiesPtr myprops;
// Has XML file -> attempt to load properties
if (FileExists(xml_name))
if (FileExists(pathnameXML))
{
myprops = GetPropertiesFromFile(props, xml_name);
myprops = GetPropertiesFromFile(props, pathnameXML);
if (myprops)
LOG(CLogger::Normal, LOG_CATEGORY, "CTextureManager: Successfully loaded override xml %s for texture %s", xml_name, texture_name);
LOG(CLogger::Normal, LOG_CATEGORY, L"CTextureManager: Successfully loaded override xml %ls for texture %ls", pathnameXML.string().c_str(), pathnames[i].string().c_str());
}
// Error or non-existant xml file -> use parent props
if (!myprops)
myprops = props;
AddTexture(myprops, texture_name);
AddTexture(myprops, pathnames[i]);
}
}
void CTextureManager::RecurseDirectory(const CTerrainPropertiesPtr& parentProps, const char* cur_dir_path)
void CTextureManager::RecurseDirectory(const CTerrainPropertiesPtr& parentProps, const VfsPath& path)
{
//LOG(CLogger::Normal, LOG_CATEGORY, "CTextureManager::RecurseDirectory(%s)", path.c_str());
//LOG(CLogger::Normal, LOG_CATEGORY, L"CTextureManager::RecurseDirectory(%ls)", path.string().c_str());
CTerrainPropertiesPtr props;
// Load terrains.xml first, if it exists
char fn[PATH_MAX];
snprintf(fn, PATH_MAX, "%s%s", cur_dir_path, "terrains.xml");
fn[PATH_MAX-1] = '\0';
if (FileExists(fn))
props = GetPropertiesFromFile(parentProps, fn);
VfsPath pathname = path/L"terrains.xml";
if (FileExists(pathname))
props = GetPropertiesFromFile(parentProps, pathname);
// No terrains.xml, or read failures -> use parent props (i.e.
if (!props)
{
LOG(CLogger::Normal, LOG_CATEGORY,
"CTextureManager::RecurseDirectory(%s): no terrains.xml (or errors while loading) - using parent properties", cur_dir_path);
LOG(CLogger::Normal, LOG_CATEGORY, L"CTextureManager::RecurseDirectory(%ls): no terrains.xml (or errors while loading) - using parent properties", path.string().c_str());
props = parentProps;
}
// Recurse once for each subdirectory
DirectoryNames subdirectoryNames;
(void)g_VFS->GetDirectoryEntries(cur_dir_path, 0, &subdirectoryNames);
(void)g_VFS->GetDirectoryEntries(path, 0, &subdirectoryNames);
for (size_t i=0;i<subdirectoryNames.size();i++)
{
char subdirectoryPath[PATH_MAX];
path_append(subdirectoryPath, cur_dir_path, subdirectoryNames[i].c_str(), PATH_APPEND_SLASH);
VfsPath subdirectoryPath = path/subdirectoryNames[i]/L"/"; // (VFS paths must end with a slash)
RecurseDirectory(props, subdirectoryPath);
}
LoadTextures(props, cur_dir_path);
LoadTextures(props, path);
}
int CTextureManager::LoadTerrainTextures()
{
RecurseDirectory(CTerrainPropertiesPtr(), "art/textures/terrain/types/");
RecurseDirectory(CTerrainPropertiesPtr(), L"art/textures/terrain/types/");
return 0;
}
CTerrainGroup *CTextureManager::FindGroup(const CStr& name)
CTerrainGroup* CTextureManager::FindGroup(const CStr& name)
{
TerrainGroupMap::const_iterator it=m_TerrainGroups.find(name);
if (it != m_TerrainGroups.end())