forked from 0ad/0ad
Range-based for for VfsPath loops.
This was SVN commit r16893.
This commit is contained in:
parent
540cf75794
commit
c5eb9b7bb7
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -219,23 +219,23 @@ public:
|
||||
}
|
||||
|
||||
bool loaded = false;
|
||||
for (VfsPaths::const_iterator it = pathnames.begin(); it != pathnames.end(); ++it)
|
||||
for (const VfsPath& path : pathnames)
|
||||
{
|
||||
LOGMESSAGE("Loading skeleton definitions from '%s'", it->string8());
|
||||
LOGMESSAGE("Loading skeleton definitions from '%s'", path.string8());
|
||||
// Set the filename for the logger to report
|
||||
set_logger(ColladaLog, const_cast<void*>(static_cast<const void*>(&(*it))));
|
||||
set_logger(ColladaLog, const_cast<void*>(static_cast<const void*>(&path)));
|
||||
|
||||
CVFSFile skeletonFile;
|
||||
if (skeletonFile.Load(m_VFS, *it) != PSRETURN_OK)
|
||||
if (skeletonFile.Load(m_VFS, path) != PSRETURN_OK)
|
||||
{
|
||||
LOGERROR("Failed to read skeleton defintions from '%s'", it->string8());
|
||||
LOGERROR("Failed to read skeleton defintions from '%s'", path.string8());
|
||||
continue;
|
||||
}
|
||||
|
||||
int ok = set_skeleton_definitions((const char*)skeletonFile.GetBuffer(), (int)skeletonFile.GetBufferSize());
|
||||
if (ok < 0)
|
||||
{
|
||||
LOGERROR("Failed to load skeleton definitions from '%s'", it->string8());
|
||||
LOGERROR("Failed to load skeleton definitions from '%s'", path.string8());
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -280,14 +280,14 @@ public:
|
||||
m_skeletonHashes.reserve(paths.size()*2);
|
||||
|
||||
CFileInfo fileInfo;
|
||||
for (VfsPaths::const_iterator it = paths.begin(); it != paths.end(); ++it)
|
||||
for (const VfsPath& path : paths)
|
||||
{
|
||||
// This will cause an assertion failure if *it doesn't exist,
|
||||
// because fileinfo is not a NULL pointer, which is annoying but that
|
||||
// should never happen, unless there really is a problem
|
||||
if (m_VFS->GetFileInfo(*it, &fileInfo) != INFO::OK)
|
||||
if (m_VFS->GetFileInfo(path, &fileInfo) != INFO::OK)
|
||||
{
|
||||
LOGERROR("Failed to stat '%s' for DAE caching", it->string8());
|
||||
LOGERROR("Failed to stat '%s' for DAE caching", path.string8());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -304,8 +304,8 @@ public:
|
||||
m_skeletonHashInvalidated = false;
|
||||
}
|
||||
|
||||
for (std::vector<u64>::const_iterator it = m_skeletonHashes.begin(); it != m_skeletonHashes.end(); ++it)
|
||||
hash.Update((const u8*)&(*it), sizeof(*it));
|
||||
for (const u64& h : m_skeletonHashes)
|
||||
hash.Update((const u8*)&h, sizeof(h));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -1470,18 +1470,18 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::un
|
||||
{
|
||||
VfsPaths pathnames;
|
||||
vfs::GetPathnames(g_VFS, directory, L"*.js", pathnames);
|
||||
for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
|
||||
for (const VfsPath& path : pathnames)
|
||||
{
|
||||
// Only load new files (so when the insert succeeds)
|
||||
if (Paths.insert(*it).second)
|
||||
if (Paths.insert(path).second)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_ScriptInterface->LoadGlobalScriptFile(*it);
|
||||
m_ScriptInterface->LoadGlobalScriptFile(path);
|
||||
}
|
||||
catch (PSERROR_Scripting& e)
|
||||
{
|
||||
LOGERROR("GUI: Error executing script %s: %s", (*it).string8(), e.what());
|
||||
LOGERROR("GUI: Error executing script %s: %s", path.string8(), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -264,15 +264,14 @@ std::vector<std::string> CTemplateLoader::FindPlaceableTemplates(const std::stri
|
||||
if (vfs::GetPathnames(g_VFS, templatePath / (directoryPath + "/"), fileFilter.c_str(), filenames) != INFO::OK)
|
||||
continue;
|
||||
|
||||
for (VfsPaths::iterator it = filenames.begin(); it != filenames.end(); ++it)
|
||||
for (const VfsPath& filename : filenames)
|
||||
{
|
||||
VfsPath filename = *it;
|
||||
// Strip the .xml extension
|
||||
VfsPath pathstem = filename.ChangeExtension(L"");
|
||||
// Strip the root from the path
|
||||
std::wstring name = pathstem.string().substr(ARRAY_SIZE(TEMPLATE_ROOT) - 1);
|
||||
|
||||
templates.push_back(std::string(name.begin(), name.end()));
|
||||
templates.emplace_back(name.begin(), name.end());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -514,21 +514,17 @@ void CPostprocManager::ApplyPostproc()
|
||||
std::vector<CStrW> CPostprocManager::GetPostEffects()
|
||||
{
|
||||
std::vector<CStrW> effects;
|
||||
|
||||
|
||||
const VfsPath path(L"shaders/effects/postproc/");
|
||||
|
||||
|
||||
VfsPaths pathnames;
|
||||
if(vfs::GetPathnames(g_VFS, path, 0, pathnames) < 0)
|
||||
if (vfs::GetPathnames(g_VFS, path, 0, pathnames) < 0)
|
||||
LOGERROR("Error finding Post effects in '%s'", path.string8());
|
||||
|
||||
for(size_t i = 0; i < pathnames.size(); i++)
|
||||
{
|
||||
if (pathnames[i].Extension() != L".xml")
|
||||
continue;
|
||||
|
||||
effects.push_back(pathnames[i].Basename().string());
|
||||
}
|
||||
|
||||
for (const VfsPath& path : pathnames)
|
||||
if (path.Extension() == L".xml")
|
||||
effects.push_back(path.Basename().string());
|
||||
|
||||
// Add the default "null" effect to the list.
|
||||
effects.push_back(L"default");
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -461,14 +461,12 @@ bool ScriptInterface::LoadGlobalScripts()
|
||||
// Load and execute *.js in the global scripts directory
|
||||
VfsPaths pathnames;
|
||||
vfs::GetPathnames(g_VFS, L"globalscripts/", L"*.js", pathnames);
|
||||
for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
|
||||
{
|
||||
if (!LoadGlobalScriptFile(*it))
|
||||
for (const VfsPath& path : pathnames)
|
||||
if (!LoadGlobalScriptFile(path))
|
||||
{
|
||||
LOGERROR("LoadGlobalScripts: Failed to load script %s", it->string8());
|
||||
LOGERROR("LoadGlobalScripts: Failed to load script %s", path.string8());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
JS::RootedValue proto(m->m_cx);
|
||||
|
@ -187,13 +187,12 @@ bool CSimulation2Impl::LoadScripts(CComponentManager& componentManager, std::set
|
||||
return false;
|
||||
|
||||
bool ok = true;
|
||||
for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
|
||||
for (const VfsPath& path : pathnames)
|
||||
{
|
||||
VfsPath filename = *it;
|
||||
if (loadedScripts)
|
||||
loadedScripts->insert(filename);
|
||||
LOGMESSAGE("Loading simulation script '%s'", filename.string8());
|
||||
if (!componentManager.LoadScript(filename))
|
||||
loadedScripts->insert(path);
|
||||
LOGMESSAGE("Loading simulation script '%s'", path.string8());
|
||||
if (!componentManager.LoadScript(path))
|
||||
ok = false;
|
||||
}
|
||||
return ok;
|
||||
|
@ -252,11 +252,11 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
|
||||
for (const VfsPath& path : pathnames)
|
||||
{
|
||||
if (!m_ScriptInterface->LoadGlobalScriptFile(*it))
|
||||
if (!m_ScriptInterface->LoadGlobalScriptFile(path))
|
||||
{
|
||||
LOGERROR("Failed to load script %s", it->string8());
|
||||
LOGERROR("Failed to load script %s", path.string8());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2015 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -66,7 +66,7 @@ public:
|
||||
|
||||
VfsPaths paths;
|
||||
TS_ASSERT_OK(vfs::GetPathnames(g_VFS, L"simulation/components/tests/", L"test_*.js", paths));
|
||||
for (size_t i = 0; i < paths.size(); ++i)
|
||||
for (const VfsPath& path : paths)
|
||||
{
|
||||
CSimContext context;
|
||||
CComponentManager componentManager(context, g_ScriptRuntime, true);
|
||||
@ -79,7 +79,7 @@ public:
|
||||
componentManager.LoadComponentTypes();
|
||||
|
||||
load_script(componentManager.GetScriptInterface(), L"simulation/components/tests/setup.js");
|
||||
load_script(componentManager.GetScriptInterface(), paths[i]);
|
||||
load_script(componentManager.GetScriptInterface(), path);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user