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

Unify all queries to map size to map.getwidth and map.getheight

It's becoming pretty clear that the size of the map is important enough
to be queried a lot, but each time it's something like `map.custommode ?
map.customwidth : 20` and `map.custommode ? map.customheight : 20` which
is not ideal because of copy-pasting.

Furthermore, even `map.customwidth` and `map.customheight` are just
duplicates of `cl.mapwidth` and `cl.mapheight`, which are only set in
`customlevelclass::generatecustomminimap`. This is a bit annoying if you
want to, say, add checks that depend on the width and height of the
custom map in `mapclass::initcustommapdata`, but `map.customwidth` and
`map.customheight` are out of date because `generatecustomminimap`
hasn't been called yet. And doing the ternary there requires a `#ifndef
NO_CUSTOM_LEVELS` to reference `cl.mapwidth` and `cl.mapheight` which is
just awful.

So I'm axing `map.customwidth` and `map.customheight`, and I'm axing all
the ternaries that are duplicating the source of truth in
`MapRenderData`. Instead, there will just be one function to call for
the width and height, `mapclass::getwidth` and `mapclass::getheight`,
and everyone can simply call those without needing to do ternaries or
duplication.
This commit is contained in:
Misa 2022-11-30 13:35:14 -08:00
parent d183ea6367
commit de38b6b55c
4 changed files with 38 additions and 19 deletions

View file

@ -1483,15 +1483,12 @@ bool customlevelclass::save(const std::string& _path)
void customlevelclass::generatecustomminimap(void) void customlevelclass::generatecustomminimap(void)
{ {
map.customwidth = mapwidth;
map.customheight = mapheight;
map.customzoom = 1; map.customzoom = 1;
if (map.customwidth <= 10 && map.customheight <= 10) if (mapwidth <= 10 && mapheight <= 10)
{ {
map.customzoom = 2; map.customzoom = 2;
} }
if (map.customwidth <= 5 && map.customheight <= 5) if (mapwidth <= 5 && mapheight <= 5)
{ {
map.customzoom = 4; map.customzoom = 4;
} }
@ -1500,16 +1497,16 @@ void customlevelclass::generatecustomminimap(void)
switch (map.customzoom) switch (map.customzoom)
{ {
case 4: case 4:
map.custommmxoff = 24 * (5 - map.customwidth); map.custommmxoff = 24 * (5 - mapwidth);
map.custommmyoff = 18 * (5 - map.customheight); map.custommmyoff = 18 * (5 - mapheight);
break; break;
case 2: case 2:
map.custommmxoff = 12 * (10 - map.customwidth); map.custommmxoff = 12 * (10 - mapwidth);
map.custommmyoff = 9 * (10 - map.customheight); map.custommmyoff = 9 * (10 - mapheight);
break; break;
default: default:
map.custommmxoff = 6 * (20 - map.customwidth); map.custommmxoff = 6 * (20 - mapwidth);
map.custommmyoff = int(4.5 * (20 - map.customheight)); map.custommmyoff = int(4.5 * (20 - mapheight));
break; break;
} }

View file

@ -48,7 +48,6 @@ mapclass::mapclass(void)
custommode=false; custommode=false;
custommodeforreal=false; custommodeforreal=false;
customwidth=20; customheight=20;
custommmxoff=0; custommmyoff=0; custommmxsize=0; custommmysize=0; custommmxoff=0; custommmyoff=0; custommmxsize=0; custommmysize=0;
customzoom=0; customzoom=0;
customshowmm=true; customshowmm=true;
@ -109,6 +108,30 @@ const int mapclass::areamap[] = {
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,
}; };
int mapclass::getwidth(void)
{
#ifndef NO_CUSTOM_LEVELS
if (custommode)
{
return cl.mapwidth;
}
#endif
return 20;
}
int mapclass::getheight(void)
{
#ifndef NO_CUSTOM_LEVELS
if (custommode)
{
return cl.mapheight;
}
#endif
return 20;
}
int mapclass::intpol(int a, int b, float c) int mapclass::intpol(int a, int b, float c)
{ {
return static_cast<int>(a + ((b - a) * c)); return static_cast<int>(a + ((b - a) * c));

View file

@ -23,6 +23,10 @@ class mapclass
public: public:
mapclass(void); mapclass(void);
int getwidth(void);
int getheight(void);
int intpol(int a, int b, float c); int intpol(int a, int b, float c);
void setteleporter(int x, int y); void setteleporter(int x, int y);
@ -129,7 +133,6 @@ public:
//Variables for playing custom levels //Variables for playing custom levels
bool custommode; bool custommode;
bool custommodeforreal; bool custommodeforreal;
int customwidth, customheight;
int custommmxoff, custommmyoff, custommmxsize, custommmysize; int custommmxoff, custommmyoff, custommmxsize, custommmysize;
int customzoom; int customzoom;
bool customshowmm; bool customshowmm;

View file

@ -26,8 +26,6 @@ static int tb;
struct MapRenderData struct MapRenderData
{ {
int width;
int height;
int zoom; int zoom;
int xoff; int xoff;
int yoff; int yoff;
@ -2055,8 +2053,6 @@ static MapRenderData getmaprenderdata()
{ {
MapRenderData data; MapRenderData data;
data.width = map.custommode ? map.customwidth : 20;
data.height = map.custommode ? map.customheight : 20;
data.zoom = map.custommode ? map.customzoom : 1; data.zoom = map.custommode ? map.customzoom : 1;
data.xoff = map.custommode ? map.custommmxoff : 0; data.xoff = map.custommode ? map.custommmxoff : 0;
data.yoff = map.custommode ? map.custommmyoff : 0; data.yoff = map.custommode ? map.custommmyoff : 0;
@ -2102,9 +2098,9 @@ static void rendermapfog(void)
{ {
const MapRenderData data = getmaprenderdata(); const MapRenderData data = getmaprenderdata();
for (int j = 0; j < data.height; j++) for (int j = 0; j < map.getheight(); j++)
{ {
for (int i = 0; i < data.width; i++) for (int i = 0; i < map.getwidth(); i++)
{ {
if (!map.isexplored(i, j)) if (!map.isexplored(i, j))
{ {