forked from jaildesigner-jailgames/jaildoctors_dilemma
Optimizaciones de código
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
// Constructor
|
||||
Asset::Asset(std::string path)
|
||||
{
|
||||
mExecutablePath = path;
|
||||
longest_name = 0;
|
||||
executablePath = path;
|
||||
longestName = 0;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -16,21 +16,25 @@ Asset::~Asset()
|
||||
void Asset::add(std::string file, enum assetType type, bool required)
|
||||
{
|
||||
item_t temp;
|
||||
temp.file = mExecutablePath + "/.." + file;
|
||||
temp.file = executablePath + "/.." + file;
|
||||
temp.type = type;
|
||||
temp.required = required;
|
||||
mFileList.push_back(temp);
|
||||
fileList.push_back(temp);
|
||||
|
||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
||||
longest_name = SDL_max(longest_name, filename.size());
|
||||
longestName = SDL_max(longestName, filename.size());
|
||||
}
|
||||
|
||||
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
||||
std::string Asset::get(std::string text)
|
||||
{
|
||||
for (int i = 0; i < mFileList.size(); i++)
|
||||
if (mFileList[i].file.find(text) != std::string::npos)
|
||||
return mFileList[i].file;
|
||||
for (auto f : fileList)
|
||||
{
|
||||
if (f.file.find(text) != std::string::npos)
|
||||
{
|
||||
return f.file;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Warning: file %s not found\n", text.c_str());
|
||||
return "";
|
||||
@@ -44,31 +48,43 @@ bool Asset::check()
|
||||
printf("\n** Checking files.\n");
|
||||
|
||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||
for (int type = 0; type < maxAssetType; type++)
|
||||
for (int type = 0; type < maxAssetType; ++type)
|
||||
{
|
||||
// Comprueba si hay ficheros de ese tipo
|
||||
bool any = false;
|
||||
|
||||
for (int i = 0; i < mFileList.size(); i++)
|
||||
if ((mFileList[i].required) && (mFileList[i].type == type))
|
||||
for (auto f : fileList)
|
||||
{
|
||||
if ((f.required) && (f.type == type))
|
||||
{
|
||||
any = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Si hay ficheros de ese tipo, comprueba si existen
|
||||
if (any)
|
||||
{
|
||||
printf("\n>> %s FILES\n", getTypeName(type).c_str());
|
||||
|
||||
for (int i = 0; i < mFileList.size(); i++)
|
||||
if ((mFileList[i].required) && (mFileList[i].type == type))
|
||||
success &= checkFile(mFileList[i].file);
|
||||
for (auto f : fileList)
|
||||
{
|
||||
if ((f.required) && (f.type == type))
|
||||
{
|
||||
success &= checkFile(f.file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resultado
|
||||
if (success)
|
||||
{
|
||||
printf("\n** All files OK.\n\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\n** A file is missing. Exiting.\n\n");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -83,14 +99,14 @@ bool Asset::checkFile(std::string path)
|
||||
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(path.c_str(), "r+b");
|
||||
|
||||
if (file != NULL)
|
||||
if (file != nullptr)
|
||||
{
|
||||
result = "OK";
|
||||
success = true;
|
||||
SDL_RWclose(file);
|
||||
}
|
||||
|
||||
const std::string s = "Checking file %-" + std::to_string(longest_name) + "s [" + result + "]\n";
|
||||
const std::string s = "Checking file %-" + std::to_string(longestName) + "s [" + result + "]\n";
|
||||
printf(s.c_str(), filename.c_str());
|
||||
|
||||
return success;
|
||||
@@ -104,30 +120,39 @@ std::string Asset::getTypeName(int type)
|
||||
case bitmap:
|
||||
return "BITMAP";
|
||||
break;
|
||||
|
||||
case music:
|
||||
return "MUSIC";
|
||||
break;
|
||||
|
||||
case sound:
|
||||
return "SOUND";
|
||||
break;
|
||||
|
||||
case font:
|
||||
return "FONT";
|
||||
break;
|
||||
|
||||
case lang:
|
||||
return "LANG";
|
||||
break;
|
||||
|
||||
case data:
|
||||
return "DATA";
|
||||
break;
|
||||
|
||||
case room:
|
||||
return "ROOM";
|
||||
break;
|
||||
|
||||
case enemy:
|
||||
return "ENEMY";
|
||||
break;
|
||||
|
||||
case item:
|
||||
return "ITEM";
|
||||
break;
|
||||
|
||||
default:
|
||||
return "ERROR";
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user