Turn obj.collect and obj.customcollect into plain arrays

Since they're always fixed-size, there's no need for them to be vectors.

Also added an INBOUNDS_ARR() macro to do bounds checks with plain
arrays.
This commit is contained in:
Misa
2020-07-02 19:17:32 -07:00
committed by Ethan Lee
parent 62203efb2c
commit 0664eac7fc
5 changed files with 28 additions and 77 deletions

View File

@@ -5369,19 +5369,7 @@ void Game::loadquick()
LOAD_ARRAY(crewstats)
if (pKey == "collect")
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
obj.collect.clear();
for(size_t i = 0; i < values.size(); i++)
{
obj.collect.push_back((bool) atoi(values[i].c_str()));
}
}
}
LOAD_ARRAY_RENAME(collect, obj.collect)
if (pKey == "finalmode")
{
@@ -5574,33 +5562,9 @@ void Game::customloadquick(std::string savfile)
LOAD_ARRAY(crewstats)
if (pKey == "collect")
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
obj.collect.clear();
for(size_t i = 0; i < values.size(); i++)
{
obj.collect.push_back((bool) atoi(values[i].c_str()));
}
}
}
LOAD_ARRAY_RENAME(collect, obj.collect)
if (pKey == "customcollect")
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
obj.customcollect.clear();
for(size_t i = 0; i < values.size(); i++)
{
obj.customcollect.push_back((bool) atoi(values[i].c_str()));
}
}
}
LOAD_ARRAY_RENAME(customcollect, obj.customcollect)
if (pKey == "finalmode")
{
@@ -5965,7 +5929,7 @@ void Game::savetele()
msgs->LinkEndChild( msg );
std::string collect;
for(size_t i = 0; i < obj.collect.size(); i++ )
for(size_t i = 0; i < SDL_arraysize(obj.collect); i++ )
{
collect += help.String((int) obj.collect[i]) + ",";
}
@@ -6161,7 +6125,7 @@ void Game::savequick()
msgs->LinkEndChild( msg );
std::string collect;
for(size_t i = 0; i < obj.collect.size(); i++ )
for(size_t i = 0; i < SDL_arraysize(obj.collect); i++ )
{
collect += help.String((int) obj.collect[i]) + ",";
}
@@ -6359,7 +6323,7 @@ void Game::customsavequick(std::string savfile)
msgs->LinkEndChild( msg );
std::string collect;
for(size_t i = 0; i < obj.collect.size(); i++ )
for(size_t i = 0; i < SDL_arraysize(obj.collect); i++ )
{
collect += help.String((int) obj.collect[i]) + ",";
}
@@ -6368,7 +6332,7 @@ void Game::customsavequick(std::string savfile)
msgs->LinkEndChild( msg );
std::string customcollect;
for(size_t i = 0; i < obj.customcollect.size(); i++ )
for(size_t i = 0; i < SDL_arraysize(obj.customcollect); i++ )
{
customcollect += help.String((int) obj.customcollect[i]) + ",";
}
@@ -6562,19 +6526,7 @@ void Game::loadtele()
LOAD_ARRAY(crewstats)
if (pKey == "collect")
{
std::string TextString = (pText);
if(TextString.length())
{
std::vector<std::string> values = split(TextString,',');
obj.collect.clear();
for(size_t i = 0; i < values.size(); i++)
{
obj.collect.push_back((bool) atoi(values[i].c_str()));
}
}
}
LOAD_ARRAY_RENAME(collect, obj.collect)
if (pKey == "finalmode")
{
@@ -7562,7 +7514,7 @@ void Game::resetgameclock()
int Game::trinkets()
{
int temp = 0;
for (size_t i = 0; i < obj.collect.size(); i++)
for (size_t i = 0; i < SDL_arraysize(obj.collect); i++)
{
if (obj.collect[i])
{
@@ -7575,7 +7527,7 @@ int Game::trinkets()
int Game::crewmates()
{
int temp = 0;
for (size_t i = 0; i < obj.customcollect.size(); i++)
for (size_t i = 0; i < SDL_arraysize(obj.customcollect); i++)
{
if (obj.customcollect[i])
{