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

Turn crew rescued/mood vectors into arrays

Since they're always fixed-size, they don't need to be dynamically-sized
vectors.

entityclass::customcrewmoods is now a proper bool instead of an int now,
and I replaced the hardcoded constant 6 with a static const int Game
attribute to make it easier to change.
This commit is contained in:
Misa 2020-07-02 18:10:52 -07:00 committed by Ethan Lee
parent cd3869f974
commit 1258eb7bf4
5 changed files with 30 additions and 102 deletions

View file

@ -67,10 +67,7 @@ void entityclass::init()
altstates = 0; altstates = 0;
for (int i = 0; i < 6; i++) SDL_memset(customcrewmoods, true, sizeof(customcrewmoods));
{
customcrewmoods[i]=1;
}
flags.resize(100); flags.resize(100);
collect.resize(100); collect.resize(100);

View file

@ -207,7 +207,7 @@ public:
int customplatformtile; int customplatformtile;
bool customwarpmode, customwarpmodevon, customwarpmodehon; bool customwarpmode, customwarpmodevon, customwarpmodehon;
std::string customscript; std::string customscript;
int customcrewmoods[6]; bool customcrewmoods[Game::numcrew];
}; };
extern entityclass obj; extern entityclass obj;

View file

@ -209,9 +209,9 @@ void Game::init(void)
} }
customcol=0; customcol=0;
crewstats.resize(6); SDL_memset(crewstats, false, sizeof(crewstats));
tele_crewstats.resize(6); SDL_memset(tele_crewstats, false, sizeof(tele_crewstats));
quick_crewstats.resize(6); SDL_memset(quick_crewstats, false, sizeof(quick_crewstats));
SDL_memset(besttimes, -1, sizeof(besttimes)); SDL_memset(besttimes, -1, sizeof(besttimes));
SDL_memset(bestframes, -1, sizeof(bestframes)); SDL_memset(bestframes, -1, sizeof(bestframes));
SDL_memset(besttrinkets, -1, sizeof(besttrinkets)); SDL_memset(besttrinkets, -1, sizeof(besttrinkets));
@ -4589,20 +4589,22 @@ void Game::unlocknum( int t )
savestats(); savestats();
} }
#define LOAD_ARRAY(ARRAY_NAME) \ #define LOAD_ARRAY_RENAME(ARRAY_NAME, DEST) \
if (pKey == #ARRAY_NAME) \ if (pKey == #ARRAY_NAME) \
{ \ { \
std::string TextString = pText; \ std::string TextString = pText; \
if (TextString.length()) \ if (TextString.length()) \
{ \ { \
std::vector<std::string> values = split(TextString, ','); \ std::vector<std::string> values = split(TextString, ','); \
for (size_t i = 0; i < SDL_min(SDL_arraysize(ARRAY_NAME), values.size()); i++) \ for (size_t i = 0; i < SDL_min(SDL_arraysize(DEST), values.size()); i++) \
{ \ { \
ARRAY_NAME[i] = atoi(values[i].c_str()); \ DEST[i] = atoi(values[i].c_str()); \
} \ } \
} \ } \
} }
#define LOAD_ARRAY(ARRAY_NAME) LOAD_ARRAY_RENAME(ARRAY_NAME, ARRAY_NAME)
void Game::loadstats() void Game::loadstats()
{ {
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
@ -5377,19 +5379,7 @@ void Game::loadquick()
} }
} }
if (pKey == "crewstats") LOAD_ARRAY(crewstats)
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
crewstats.clear();
for(size_t i = 0; i < values.size(); i++)
{
crewstats.push_back(atoi(values[i].c_str()));
}
}
}
if (pKey == "collect") if (pKey == "collect")
{ {
@ -5604,32 +5594,9 @@ void Game::customloadquick(std::string savfile)
} }
} }
if (pKey == "moods") LOAD_ARRAY_RENAME(moods, obj.customcrewmoods)
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
for(size_t i = 0; i < 6; i++)
{
obj.customcrewmoods[i]=atoi(values[i].c_str());
}
}
}
if (pKey == "crewstats") LOAD_ARRAY(crewstats)
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
crewstats.clear();
for(size_t i = 0; i < values.size(); i++)
{
crewstats.push_back(atoi(values[i].c_str()));
}
}
}
if (pKey == "collect") if (pKey == "collect")
{ {
@ -5864,19 +5831,7 @@ void Game::loadsummary()
map.finalstretch = atoi(pText); map.finalstretch = atoi(pText);
} }
if (pKey == "crewstats") LOAD_ARRAY_RENAME(crewstats, tele_crewstats)
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
tele_crewstats.clear();
for(size_t i = 0; i < values.size(); i++)
{
tele_crewstats.push_back(atoi(values[i].c_str()));
}
}
}
} }
tele_gametime = giventimestring(l_hours,l_minute, l_second); tele_gametime = giventimestring(l_hours,l_minute, l_second);
@ -5953,19 +5908,7 @@ void Game::loadsummary()
map.finalstretch = atoi(pText); map.finalstretch = atoi(pText);
} }
if (pKey == "crewstats") LOAD_ARRAY_RENAME(crewstats, quick_crewstats)
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
quick_crewstats.clear();
for(size_t i = 0; i < values.size(); i++)
{
quick_crewstats.push_back(atoi(values[i].c_str()));
}
}
}
} }
@ -6037,7 +5980,7 @@ void Game::savetele()
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string crewstatsString; std::string crewstatsString;
for(size_t i = 0; i < crewstats.size(); i++ ) for(size_t i = 0; i < SDL_arraysize(crewstats); i++ )
{ {
crewstatsString += help.String(crewstats[i]) + ","; crewstatsString += help.String(crewstats[i]) + ",";
} }
@ -6233,7 +6176,7 @@ void Game::savequick()
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string crewstatsString; std::string crewstatsString;
for(size_t i = 0; i < crewstats.size(); i++ ) for(size_t i = 0; i < SDL_arraysize(crewstats); i++ )
{ {
crewstatsString += help.String(crewstats[i]) + ","; crewstatsString += help.String(crewstats[i]) + ",";
} }
@ -6422,7 +6365,7 @@ void Game::customsavequick(std::string savfile)
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string moods; std::string moods;
for(int i = 0; i < 6; i++ ) for(size_t i = 0; i < SDL_arraysize(obj.customcrewmoods); i++ )
{ {
moods += help.String(obj.customcrewmoods[i]) + ","; moods += help.String(obj.customcrewmoods[i]) + ",";
} }
@ -6431,7 +6374,7 @@ void Game::customsavequick(std::string savfile)
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string crewstatsString; std::string crewstatsString;
for(size_t i = 0; i < crewstats.size(); i++ ) for(size_t i = 0; i < SDL_arraysize(crewstats); i++ )
{ {
crewstatsString += help.String(crewstats[i]) + ","; crewstatsString += help.String(crewstats[i]) + ",";
} }
@ -6653,19 +6596,7 @@ void Game::loadtele()
} }
} }
if (pKey == "crewstats") LOAD_ARRAY(crewstats)
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
crewstats.clear();
for(size_t i = 0; i < values.size(); i++)
{
crewstats.push_back(atoi(values[i].c_str()));
}
}
}
if (pKey == "collect") if (pKey == "collect")
{ {
@ -7646,7 +7577,7 @@ void Game::swnpenalty()
int Game::crewrescued() int Game::crewrescued()
{ {
int temp = 0; int temp = 0;
for (size_t i = 0; i < crewstats.size(); i++) for (size_t i = 0; i < SDL_arraysize(crewstats); i++)
{ {
if (crewstats[i]) if (crewstats[i])
{ {

View file

@ -196,7 +196,6 @@ public:
//Menu interaction stuff //Menu interaction stuff
bool mapheld; bool mapheld;
int menupage; int menupage;
//public var crewstats:Array = new Array();
int lastsaved; int lastsaved;
int deathcounts; int deathcounts;
@ -278,15 +277,16 @@ public:
bool inintermission; bool inintermission;
std::vector<bool> crewstats; static const int numcrew = 6;
bool crewstats[numcrew];
bool alarmon; bool alarmon;
int alarmdelay; int alarmdelay;
bool blackout; bool blackout;
std::vector<bool> tele_crewstats; bool tele_crewstats[numcrew];
std::vector<bool> quick_crewstats; bool quick_crewstats[numcrew];
static const int numunlock = 25; static const int numunlock = 25;
bool unlock[numunlock]; bool unlock[numunlock];

View file

@ -1366,8 +1366,8 @@ void scriptclass::run()
} }
else if (words[0] == "ifcrewlost") else if (words[0] == "ifcrewlost")
{ {
int crewmate = ss_toi(words[1]); size_t crewmate = ss_toi(words[1]);
if (crewmate >= 0 && crewmate < (int) game.crewstats.size() && game.crewstats[crewmate]==false) if (crewmate < SDL_arraysize(game.crewstats) && game.crewstats[crewmate]==false)
{ {
load(words[2]); load(words[2]);
position--; position--;
@ -3570,7 +3570,7 @@ void scriptclass::hardreset()
game.nodeathmode = false; game.nodeathmode = false;
game.nocutscenes = false; game.nocutscenes = false;
for (i = 0; i < 6; i++) for (i = 0; i < (int) SDL_arraysize(game.crewstats); i++)
{ {
game.crewstats[i] = false; game.crewstats[i] = false;
} }
@ -3704,8 +3704,8 @@ void scriptclass::hardreset()
obj.flags.clear(); obj.flags.clear();
obj.flags.resize(100); obj.flags.resize(100);
for (i = 0; i < 6; i++){ for (i = 0; i < (int) SDL_arraysize(obj.customcrewmoods); i++){
obj.customcrewmoods[i]=1; obj.customcrewmoods[i]=true;
} }
obj.collect.clear(); obj.collect.clear();