void CPipeManager::CheckGoalpipes()
{
// Find all calls to goalpipes
string path = gEnv->pSystem->GetRootFolder();
path += "Game/Scripts";
// Collect all scrip files.
CryLog("- Collecting files...");
std::vector<string> files;
GetScriptFiles(path, files);
// Scan used goalpipes.
std::vector<CheckFuncCall> pipesUsedCalls;
CheckFuncCallScanDef useFuncs[] = {
{ 0, "SelectPipe" },
{ 0, "InsertSubpipe" },
};
CryLog("- Scanning used pipes...");
for (unsigned i = 0, ni = files.size(); i < ni; ++i)
ScanFileForFunctionCalls(files[i].c_str(), (int)i, pipesUsedCalls, useFuncs, 2);
// Scan created goalpipes
std::vector<CheckFuncCall> pipesCreatedCalls;
CheckFuncCallScanDef createFuncs[] = {
{ 0, "CreateGoalPipe" },
{ 0, "BeginGoalPipe" },
{ 0, "PushGoal" },
{ 0, "EndGoalPipe" },
};
CryLog("- Scanning created pipes...");
for (unsigned i = 0, ni = files.size(); i < ni; ++i)
ScanFileForFunctionCalls(files[i].c_str(), (int)i, pipesCreatedCalls, createFuncs, 4);
// Parse pipes
CheckPipeMap createdPipes;
ParseGoalpipes(pipesCreatedCalls, files, createdPipes);
// Parse pipe usage
ParsePipeUsage(pipesUsedCalls, files, createdPipes);
// Check embedded pipes
for (CheckPipeMap::iterator it = createdPipes.begin(), end = createdPipes.end(); it != end; ++it)
{
CheckGoalpipe* pipe = it->second;
if (pipe->embeddedPipes.empty()) continue;
// The pipe is used, mark the embedded pipes as used too.
if (!pipe->usedInFile.empty())
MarkUsedEmbeddedPipe(pipe, createdPipes, files);
}
CryLog("\n");
// Create a list of pipes per file for more intuitive output.
std::vector<std::vector<CheckGoalpipe*> > unusedGoalsPerFile;
unusedGoalsPerFile.resize(files.size());
int unusedCount = 0;
for (CheckPipeMap::iterator it = createdPipes.begin(), end = createdPipes.end(); it != end; ++it)
{
CheckGoalpipe* pipe = it->second;
if (pipe->usedInFile.empty())
{
unusedGoalsPerFile[pipe->fileId].push_back(pipe);
unusedCount++;
}
}
// Output unused golapipes.
for (unsigned i = 0, ni = unusedGoalsPerFile.size(); i < ni; ++i)
{
std::vector<CheckGoalpipe*>& pipes = unusedGoalsPerFile[i];
if (pipes.empty()) continue;
CryLog("%d ununsed pipes in %s", pipes.size(), files[i].c_str());
for (unsigned j = 0, nj = pipes.size(); j < nj; ++j)
CryLog(" %s", pipes[j]->name.c_str());
}
CryLog("\n");
CryLog("Unused goalpipes: %d of %d", unusedCount, createdPipes.size());
// Cleanup
for (CheckPipeMap::iterator it = createdPipes.begin(), end = createdPipes.end(); it != end; ++it)
delete it->second;
}