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

Move linecrosskludge off of entityclass

This is a temporary vector that only gets used in mapclass::gotoroom().
It's always guaranteed to be cleared, so it's safe to move it off.

I'm fine with using references here because, like, it's a C++ STL vector
anyway - when we switch away from the STL (which is a precondition for
moving to C), we'll be passing around raw pointers here instead, and
won't be using references here anyway.
This commit is contained in:
Misa 2021-04-16 23:12:32 -07:00 committed by Misa Elizabeth Kai
parent 382b83a54d
commit 75ed9f9631
3 changed files with 12 additions and 14 deletions

View File

@ -1148,7 +1148,7 @@ void entityclass::removetrigger( int t )
}
}
void entityclass::copylinecross( int t )
void entityclass::copylinecross(std::vector<entclass>& linecrosskludge, int t)
{
if (!INBOUNDS_VEC(t, entities))
{
@ -1159,7 +1159,7 @@ void entityclass::copylinecross( int t )
linecrosskludge.push_back(entities[t]);
}
void entityclass::revertlinecross( int t, int s )
void entityclass::revertlinecross(std::vector<entclass>& linecrosskludge, int t, int s)
{
if (!INBOUNDS_VEC(t, entities) || !INBOUNDS_VEC(s, linecrosskludge))
{

View File

@ -66,9 +66,9 @@ public:
void removetrigger(int t);
void copylinecross(int t);
void copylinecross(std::vector<entclass>& linecrosskludge, int t);
void revertlinecross(int t, int s);
void revertlinecross(std::vector<entclass>& linecrosskludge, int t, int s);
bool gridmatch(int p1, int p2, int p3, int p4, int p11, int p21, int p31, int p41);
@ -165,8 +165,6 @@ public:
std::vector<entclass> entities;
std::vector<entclass> linecrosskludge;
int k;

View File

@ -904,6 +904,7 @@ void mapclass::warpto(int rx, int ry , int t, int tx, int ty)
void mapclass::gotoroom(int rx, int ry)
{
int roomchangedir;
std::vector<entclass> linecrosskludge;
//First, destroy the current room
obj.removeallblocks();
@ -912,7 +913,6 @@ void mapclass::gotoroom(int rx, int ry)
game.oldreadytotele = 0;
//Ok, let's save the position of all lines on the screen
obj.linecrosskludge.clear();
for (size_t i = 0; i < obj.entities.size(); i++)
{
if (obj.entities[i].type == 9)
@ -921,7 +921,7 @@ void mapclass::gotoroom(int rx, int ry)
if (obj.entities[i].xp <= 0 || (obj.entities[i].xp + obj.entities[i].w) >= 312)
{
//it's on a screen edge
obj.copylinecross(i);
obj.copylinecross(linecrosskludge, i);
}
}
}
@ -1069,24 +1069,24 @@ void mapclass::gotoroom(int rx, int ry)
if (obj.entities[i].xp <= 0 || obj.entities[i].xp + obj.entities[i].w >= 312)
{
//it's on a screen edge
for (size_t j = 0; j < obj.linecrosskludge.size(); j++)
for (size_t j = 0; j < linecrosskludge.size(); j++)
{
if (obj.entities[i].yp == obj.linecrosskludge[j].yp)
if (obj.entities[i].yp == linecrosskludge[j].yp)
{
//y's match, how about x's?
//we're moving left:
if (roomchangedir == 0)
{
if (obj.entities[i].xp + obj.entities[i].w >= 312 && obj.linecrosskludge[j].xp <= 0)
if (obj.entities[i].xp + obj.entities[i].w >= 312 && linecrosskludge[j].xp <= 0)
{
obj.revertlinecross(i, j);
obj.revertlinecross(linecrosskludge, i, j);
}
}
else
{
if (obj.entities[i].xp <= 0 && obj.linecrosskludge[j].xp + obj.linecrosskludge[j].w >= 312)
if (obj.entities[i].xp <= 0 && linecrosskludge[j].xp + linecrosskludge[j].w >= 312)
{
obj.revertlinecross(i, j);
obj.revertlinecross(linecrosskludge, i, j);
}
}
}