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

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

@ -70,8 +70,8 @@ void entityclass::init()
SDL_memset(customcrewmoods, true, sizeof(customcrewmoods)); SDL_memset(customcrewmoods, true, sizeof(customcrewmoods));
resetallflags(); resetallflags();
collect.resize(100); SDL_memset(collect, false, sizeof(collect));
customcollect.resize(100); SDL_memset(customcollect, false, sizeof(customcollect));
} }
void entityclass::resetallflags() void entityclass::resetallflags()
@ -1391,7 +1391,7 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
//Check if it's already been collected //Check if it's already been collected
entity.para = vx; entity.para = vx;
if (!INBOUNDS(vx, collect) || collect[vx]) return; if (!INBOUNDS_ARR(vx, collect) || collect[(int) vx]) return;
break; break;
case 9: //Something Shiny case 9: //Something Shiny
entity.rule = 3; entity.rule = 3;
@ -1406,7 +1406,7 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
//Check if it's already been collected //Check if it's already been collected
entity.para = vx; entity.para = vx;
if (collect[vx]) return; if (collect[(int) vx]) return;
break; break;
case 10: //Savepoint case 10: //Savepoint
entity.rule = 3; entity.rule = 3;
@ -1602,7 +1602,7 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
//Check if it's already been collected //Check if it's already been collected
entity.para = vx; entity.para = vx;
if (INBOUNDS(vx, collect) && !collect[ (vx)]) return; if (INBOUNDS_ARR(vx, collect) && !collect[(int) vx]) return;
break; break;
case 23: //SWN Enemies case 23: //SWN Enemies
//Given a different behavior, these enemies are especially for SWN mode and disappear outside the screen. //Given a different behavior, these enemies are especially for SWN mode and disappear outside the screen.
@ -1935,7 +1935,7 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
//Check if it's already been collected //Check if it's already been collected
entity.para = vx; entity.para = vx;
if (!INBOUNDS(vx, customcollect) || customcollect[vx]) return; if (!INBOUNDS_ARR(vx, customcollect) || customcollect[(int) vx]) return;
break; break;
case 56: //Custom enemy case 56: //Custom enemy
entity.rule = 1; entity.rule = 1;
@ -2517,7 +2517,7 @@ bool entityclass::updateentities( int i )
if (entities[i].state == 1) if (entities[i].state == 1)
{ {
music.playef(4); music.playef(4);
collect[entities[i].para] = true; collect[(int) entities[i].para] = true;
return removeentity(i); return removeentity(i);
} }
@ -2526,9 +2526,9 @@ bool entityclass::updateentities( int i )
//wait for collision //wait for collision
if (entities[i].state == 1) if (entities[i].state == 1)
{ {
if (INBOUNDS(entities[i].para, collect)) if (INBOUNDS_ARR(entities[i].para, collect))
{ {
collect[entities[i].para] = true; collect[(int) entities[i].para] = true;
} }
if (game.intimetrial) if (game.intimetrial)
@ -3159,9 +3159,9 @@ bool entityclass::updateentities( int i )
} }
else if (entities[i].state == 1) else if (entities[i].state == 1)
{ {
if (INBOUNDS(entities[i].para, customcollect)) if (INBOUNDS_ARR(entities[i].para, customcollect))
{ {
customcollect[entities[i].para] = true; customcollect[(int) entities[i].para] = true;
} }
if (game.intimetrial) if (game.intimetrial)

View file

@ -183,8 +183,8 @@ public:
std::vector<blockclass> blocks; std::vector<blockclass> blocks;
bool flags[100]; bool flags[100];
std::vector<bool> collect; bool collect[100];
std::vector<bool> customcollect; bool customcollect[100];
bool skipblocks, skipdirblocks; bool skipblocks, skipdirblocks;

View file

@ -5369,19 +5369,7 @@ void Game::loadquick()
LOAD_ARRAY(crewstats) LOAD_ARRAY(crewstats)
if (pKey == "collect") LOAD_ARRAY_RENAME(collect, obj.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()));
}
}
}
if (pKey == "finalmode") if (pKey == "finalmode")
{ {
@ -5574,33 +5562,9 @@ void Game::customloadquick(std::string savfile)
LOAD_ARRAY(crewstats) LOAD_ARRAY(crewstats)
if (pKey == "collect") LOAD_ARRAY_RENAME(collect, obj.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()));
}
}
}
if (pKey == "customcollect") LOAD_ARRAY_RENAME(customcollect, obj.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()));
}
}
}
if (pKey == "finalmode") if (pKey == "finalmode")
{ {
@ -5965,7 +5929,7 @@ void Game::savetele()
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string collect; 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]) + ","; collect += help.String((int) obj.collect[i]) + ",";
} }
@ -6161,7 +6125,7 @@ void Game::savequick()
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string collect; 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]) + ","; collect += help.String((int) obj.collect[i]) + ",";
} }
@ -6359,7 +6323,7 @@ void Game::customsavequick(std::string savfile)
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string collect; 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]) + ","; collect += help.String((int) obj.collect[i]) + ",";
} }
@ -6368,7 +6332,7 @@ void Game::customsavequick(std::string savfile)
msgs->LinkEndChild( msg ); msgs->LinkEndChild( msg );
std::string customcollect; 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]) + ","; customcollect += help.String((int) obj.customcollect[i]) + ",";
} }
@ -6562,19 +6526,7 @@ void Game::loadtele()
LOAD_ARRAY(crewstats) LOAD_ARRAY(crewstats)
if (pKey == "collect") LOAD_ARRAY_RENAME(collect, obj.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()));
}
}
}
if (pKey == "finalmode") if (pKey == "finalmode")
{ {
@ -7562,7 +7514,7 @@ void Game::resetgameclock()
int Game::trinkets() int Game::trinkets()
{ {
int temp = 0; 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]) if (obj.collect[i])
{ {
@ -7575,7 +7527,7 @@ int Game::trinkets()
int Game::crewmates() int Game::crewmates()
{ {
int temp = 0; 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]) if (obj.customcollect[i])
{ {

View file

@ -1959,8 +1959,8 @@ void scriptclass::run()
music.haltdasmusik(); music.haltdasmusik();
music.playef(3); music.playef(3);
int trinket = ss_toi(words[1]); size_t trinket = ss_toi(words[1]);
if (trinket >= 0 && trinket < (int) obj.collect.size()) if (trinket < SDL_arraysize(obj.collect))
{ {
obj.collect[trinket] = true; obj.collect[trinket] = true;
} }
@ -3707,10 +3707,8 @@ void scriptclass::hardreset()
obj.customcrewmoods[i]=true; obj.customcrewmoods[i]=true;
} }
obj.collect.clear(); SDL_memset(obj.collect, false, sizeof(obj.collect));
obj.collect.resize(100); SDL_memset(obj.customcollect, false, sizeof(obj.customcollect));
obj.customcollect.clear();
obj.customcollect.resize(100);
i = 100; //previously a for-loop iterating over collect/customcollect set this to 100 i = 100; //previously a for-loop iterating over collect/customcollect set this to 100
int theplayer = obj.getplayer(); int theplayer = obj.getplayer();

View file

@ -16,6 +16,7 @@ bool is_positive_num(const std::string& str, bool hex);
bool endsWith(const std::string& str, const std::string& suffix); bool endsWith(const std::string& str, const std::string& suffix);
#define INBOUNDS(index, vector) ((int) index >= 0 && (int) index < (int) vector.size()) #define INBOUNDS(index, vector) ((int) index >= 0 && (int) index < (int) vector.size())
#define INBOUNDS_ARR(index, array) ((int) index >= 0 && (int) index < (int) SDL_arraysize(array))
#define WHINE_ONCE(message) \ #define WHINE_ONCE(message) \
static bool whine = true; \ static bool whine = true; \