From 75ed9f96315548807f45cab4bcbf4b3335d1226d Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 16 Apr 2021 23:12:32 -0700 Subject: [PATCH] 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. --- desktop_version/src/Entity.cpp | 4 ++-- desktop_version/src/Entity.h | 6 ++---- desktop_version/src/Map.cpp | 16 ++++++++-------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/desktop_version/src/Entity.cpp b/desktop_version/src/Entity.cpp index e334fec9..026b02ba 100644 --- a/desktop_version/src/Entity.cpp +++ b/desktop_version/src/Entity.cpp @@ -1148,7 +1148,7 @@ void entityclass::removetrigger( int t ) } } -void entityclass::copylinecross( int t ) +void entityclass::copylinecross(std::vector& 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& linecrosskludge, int t, int s) { if (!INBOUNDS_VEC(t, entities) || !INBOUNDS_VEC(s, linecrosskludge)) { diff --git a/desktop_version/src/Entity.h b/desktop_version/src/Entity.h index 309e02a0..26caf7b7 100644 --- a/desktop_version/src/Entity.h +++ b/desktop_version/src/Entity.h @@ -66,9 +66,9 @@ public: void removetrigger(int t); - void copylinecross(int t); + void copylinecross(std::vector& linecrosskludge, int t); - void revertlinecross(int t, int s); + void revertlinecross(std::vector& 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 entities; - std::vector linecrosskludge; - int k; diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index 180e1427..09d2cd93 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -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 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); } } }