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;
}