1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Turn time trial stat vectors into plain arrays

These are the besttimes, besttrinkets, bestlives, and bestrank
attributes of Game. bestframes was already a plain array.

As these are always fixed-sized, there's no reason for them to be
vectors. Also, I put their size in a static const int so it's easy to
change how many of them there are.
This commit is contained in:
Misa 2020-07-02 17:09:30 -07:00 committed by Ethan Lee
parent 56f06bd853
commit cd3869f974
2 changed files with 20 additions and 67 deletions

View file

@ -212,11 +212,11 @@ void Game::init(void)
crewstats.resize(6); crewstats.resize(6);
tele_crewstats.resize(6); tele_crewstats.resize(6);
quick_crewstats.resize(6); quick_crewstats.resize(6);
besttimes.resize(6, -1); SDL_memset(besttimes, -1, sizeof(besttimes));
SDL_memset(bestframes, -1, sizeof(bestframes)); SDL_memset(bestframes, -1, sizeof(bestframes));
besttrinkets.resize(6, -1); SDL_memset(besttrinkets, -1, sizeof(besttrinkets));
bestlives.resize(6, -1); SDL_memset(bestlives, -1, sizeof(bestlives));
bestrank.resize(6, -1); SDL_memset(bestrank, -1, sizeof(bestrank));
crewstats[0] = true; crewstats[0] = true;
lastsaved = 0; lastsaved = 0;
@ -4564,7 +4564,7 @@ void Game::deletestats()
unlock[i] = false; unlock[i] = false;
unlocknotify[i] = false; unlocknotify[i] = false;
} }
for (int i = 0; i < 6; i++) for (int i = 0; i < numtrials; i++)
{ {
besttimes[i] = -1; besttimes[i] = -1;
bestframes[i] = -1; bestframes[i] = -1;
@ -4643,65 +4643,17 @@ void Game::loadstats()
LOAD_ARRAY(unlocknotify) LOAD_ARRAY(unlocknotify)
if (pKey == "besttimes") LOAD_ARRAY(besttimes)
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
besttimes.clear();
for(size_t i = 0; i < values.size(); i++)
{
besttimes.push_back(atoi(values[i].c_str()));
}
}
}
LOAD_ARRAY(bestframes) LOAD_ARRAY(bestframes)
if (pKey == "besttrinkets") LOAD_ARRAY(besttrinkets)
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
besttrinkets.clear();
for(size_t i = 0; i < values.size(); i++)
{
besttrinkets.push_back(atoi(values[i].c_str()));
}
}
}
if (pKey == "bestlives") LOAD_ARRAY(bestlives)
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
bestlives.clear();
for(size_t i = 0; i < values.size(); i++)
{
bestlives.push_back(atoi(values[i].c_str()));
}
}
}
if (pKey == "bestrank") LOAD_ARRAY(bestrank)
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
bestrank.clear();
for(size_t i = 0; i < values.size(); i++)
{
bestrank.push_back(atoi(values[i].c_str()));
}
}
}
@ -4964,7 +4916,7 @@ void Game::savestats()
dataNode->LinkEndChild( msg ); dataNode->LinkEndChild( msg );
std::string s_besttimes; std::string s_besttimes;
for(size_t i = 0; i < besttimes.size(); i++ ) for(size_t i = 0; i < SDL_arraysize(besttimes); i++ )
{ {
s_besttimes += help.String(besttimes[i]) + ","; s_besttimes += help.String(besttimes[i]) + ",";
} }
@ -4973,7 +4925,7 @@ void Game::savestats()
dataNode->LinkEndChild( msg ); dataNode->LinkEndChild( msg );
std::string s_bestframes; std::string s_bestframes;
for (size_t i = 0; i < sizeof(bestframes) / sizeof(int); i++) for (size_t i = 0; i < SDL_arraysize(bestframes); i++)
{ {
s_bestframes += help.String(bestframes[i]) + ","; s_bestframes += help.String(bestframes[i]) + ",";
} }
@ -4982,7 +4934,7 @@ void Game::savestats()
dataNode->LinkEndChild( msg ); dataNode->LinkEndChild( msg );
std::string s_besttrinkets; std::string s_besttrinkets;
for(size_t i = 0; i < besttrinkets.size(); i++ ) for(size_t i = 0; i < SDL_arraysize(besttrinkets); i++ )
{ {
s_besttrinkets += help.String(besttrinkets[i]) + ","; s_besttrinkets += help.String(besttrinkets[i]) + ",";
} }
@ -4991,7 +4943,7 @@ void Game::savestats()
dataNode->LinkEndChild( msg ); dataNode->LinkEndChild( msg );
std::string s_bestlives; std::string s_bestlives;
for(size_t i = 0; i < bestlives.size(); i++ ) for(size_t i = 0; i < SDL_arraysize(bestlives); i++ )
{ {
s_bestlives += help.String(bestlives[i]) + ","; s_bestlives += help.String(bestlives[i]) + ",";
} }
@ -5000,7 +4952,7 @@ void Game::savestats()
dataNode->LinkEndChild( msg ); dataNode->LinkEndChild( msg );
std::string s_bestrank; std::string s_bestrank;
for(size_t i = 0; i < bestrank.size(); i++ ) for(size_t i = 0; i < SDL_arraysize(bestrank); i++ )
{ {
s_bestrank += help.String(bestrank[i]) + ","; s_bestrank += help.String(bestrank[i]) + ",";
} }

View file

@ -297,11 +297,12 @@ public:
int bestgamedeaths; int bestgamedeaths;
std::vector<int>besttimes; static const int numtrials = 6;
int bestframes[6]; int besttimes[numtrials];
std::vector<int>besttrinkets; int bestframes[numtrials];
std::vector<int>bestlives; int besttrinkets[numtrials];
std::vector<int> bestrank; int bestlives[numtrials];
int bestrank[numtrials];
std::string tele_gametime; std::string tele_gametime;
int tele_trinkets; int tele_trinkets;