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

@@ -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));