1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-17 01:58:29 +02: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)
{
map.customwidth = mapwidth;
map.customheight = mapheight;
map.customzoom = 1;
if (map.customwidth <= 10 && map.customheight <= 10)
if (mapwidth <= 10 && mapheight <= 10)
{
map.customzoom = 2;
}
if (map.customwidth <= 5 && map.customheight <= 5)
if (mapwidth <= 5 && mapheight <= 5)
{
map.customzoom = 4;
}
@ -1500,16 +1497,16 @@ void customlevelclass::generatecustomminimap(void)
switch (map.customzoom)
{
case 4:
map.custommmxoff = 24 * (5 - map.customwidth);
map.custommmyoff = 18 * (5 - map.customheight);
map.custommmxoff = 24 * (5 - mapwidth);
map.custommmyoff = 18 * (5 - mapheight);
break;
case 2:
map.custommmxoff = 12 * (10 - map.customwidth);
map.custommmyoff = 9 * (10 - map.customheight);
map.custommmxoff = 12 * (10 - mapwidth);
map.custommmyoff = 9 * (10 - mapheight);
break;
default:
map.custommmxoff = 6 * (20 - map.customwidth);
map.custommmyoff = int(4.5 * (20 - map.customheight));
map.custommmxoff = 6 * (20 - mapwidth);
map.custommmyoff = int(4.5 * (20 - mapheight));
break;
}

View File

@ -48,7 +48,6 @@ mapclass::mapclass(void)
custommode=false;
custommodeforreal=false;
customwidth=20; customheight=20;
custommmxoff=0; custommmyoff=0; custommmxsize=0; custommmysize=0;
customzoom=0;
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,
};
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)
{
return static_cast<int>(a + ((b - a) * c));

View File

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

View File

@ -26,8 +26,6 @@ static int tb;
struct MapRenderData
{
int width;
int height;
int zoom;
int xoff;
int yoff;
@ -2055,8 +2053,6 @@ static MapRenderData getmaprenderdata()
{
MapRenderData data;
data.width = map.custommode ? map.customwidth : 20;
data.height = map.custommode ? map.customheight : 20;
data.zoom = map.custommode ? map.customzoom : 1;
data.xoff = map.custommode ? map.custommmxoff : 0;
data.yoff = map.custommode ? map.custommmyoff : 0;
@ -2102,9 +2098,9 @@ static void rendermapfog(void)
{
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))
{