1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 14:38:30 +02:00

Simplify inits/resets in entityclass/mapclass

Instead of using somewhat-obtuse for-loops to initialize or reset these
vectors, it takes up less lines of code and is clearer if we use
std::vector::resize() and std::vector::clear() instead.
This commit is contained in:
Misa 2020-05-19 16:41:29 -07:00 committed by Ethan Lee
parent de82918efd
commit e795fbb511
3 changed files with 22 additions and 51 deletions

View File

@ -78,10 +78,8 @@ void entityclass::init()
void entityclass::resetallflags() void entityclass::resetallflags()
{ {
for (int i = 0; i < 100; i++) flags.clear();
{ flags.resize(100);
flags[i] = false;
}
} }
int entityclass::swncolour( int t ) int entityclass::swncolour( int t )

View File

@ -59,32 +59,16 @@ mapclass::mapclass()
vmult.push_back(int(i * 40)); vmult.push_back(int(i * 40));
} }
//We create a blank map //We create a blank map
for (int j = 0; j < 30; j++) contents.resize(40 * 30);
{
for (int i = 0; i < 40; i++)
{
contents.push_back(0);
}
}
for (int j = 0; j < 20; j++) roomdeaths.resize(20 * 20);
{ roomdeathsfinal.resize(20 * 20);
for (int i = 0; i < 20; i++) explored.resize(20 * 20);
{
areamap.push_back(0);
roomdeaths.push_back(0);
roomdeathsfinal.push_back(0);
explored.push_back(0);
}
}
tileset = 0; tileset = 0;
initmapdata(); initmapdata();
for (int i = 0; i < 8; i++) specialnames.resize(8);
{
specialnames.push_back(std::string());
}
resetnames(); resetnames();
//Areamap starts at 100,100 and extends 20x20 //Areamap starts at 100,100 and extends 20x20
@ -110,7 +94,6 @@ mapclass::mapclass()
2,2,2,2,2,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0, 2,2,2,2,2,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,
2,2,2,2,2,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0, 2,2,2,2,2,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,
}; };
areamap.clear();
areamap.insert(areamap.end(), tmap, tmap+400); areamap.insert(areamap.end(), tmap, tmap+400);
} }
@ -143,13 +126,8 @@ void mapclass::settrinket(int x, int y)
void mapclass::resetmap() void mapclass::resetmap()
{ {
//clear the explored area of the map //clear the explored area of the map
for (int j = 0; j < 20; j++) explored.clear();
{ explored.resize(20 * 20);
for (int i = 0; i < 20; i++)
{
explored[i + (j * 20)] = 0;
}
}
} }
void mapclass::resetnames() void mapclass::resetnames()

View File

@ -3536,15 +3536,12 @@ void scriptclass::hardreset()
map.scrolldir = 0; map.scrolldir = 0;
map.customshowmm=true; map.customshowmm=true;
for (j = 0; j < 20; j++) map.roomdeaths.clear();
{ map.roomdeaths.resize(20 * 20);
for (i = 0; i < 20; i++) map.roomdeathsfinal.clear();
{ map.roomdeathsfinal.resize(20 * 20);
map.roomdeaths[i + (j * 20)] = 0; map.explored.clear();
map.roomdeathsfinal[i + (j * 20)] = 0; map.explored.resize(20 * 20);
map.explored[i + (j * 20)] = 0;
}
}
//entityclass //entityclass
obj.nearelephant = false; obj.nearelephant = false;
obj.upsetmode = false; obj.upsetmode = false;
@ -3554,20 +3551,18 @@ void scriptclass::hardreset()
obj.trophytype = 0; obj.trophytype = 0;
obj.altstates = 0; obj.altstates = 0;
for (i = 0; i < 100; i++) obj.flags.clear();
{ obj.flags.resize(100);
obj.flags[i] = false;
}
for (i = 0; i < 6; i++){ for (i = 0; i < 6; i++){
obj.customcrewmoods[i]=1; obj.customcrewmoods[i]=1;
} }
for (i = 0; i < 100; i++) obj.collect.clear();
{ obj.collect.resize(100);
obj.collect[i] = false; obj.customcollect.clear();
obj.customcollect[i] = false; obj.customcollect.resize(100);
} i = 100; //previously a for-loop iterating over collect/customcollect set this to 100
if (obj.getplayer() > -1){ if (obj.getplayer() > -1){
obj.entities[obj.getplayer()].tile = 0; obj.entities[obj.getplayer()].tile = 0;