porymap/src/core/maplayout.cpp
garak 37fcfba829 use static (And const where applicable) regular expression objects
the speed increase here is noticable since the work of creating a regex object is only done once per session
2023-01-17 13:15:07 -05:00

34 lines
976 B
C++

#include "maplayout.h"
#include <QRegularExpression>
QString MapLayout::layoutConstantFromName(QString mapName) {
// Transform map names of the form 'GraniteCave_B1F` into layout constants like 'LAYOUT_GRANITE_CAVE_B1F'.
static const QRegularExpression caseChange("([a-z])([A-Z])");
QString nameWithUnderscores = mapName.replace(caseChange, "\\1_\\2");
QString withMapAndUppercase = "LAYOUT_" + nameWithUnderscores.toUpper();
static const QRegularExpression underscores("_+");
QString constantName = withMapAndUppercase.replace(underscores, "_");
// Handle special cases.
// SSTidal should be SS_TIDAL, rather than SSTIDAL
constantName = constantName.replace("SSTIDAL", "SS_TIDAL");
return constantName;
}
int MapLayout::getWidth() {
return width;
}
int MapLayout::getHeight() {
return height;
}
int MapLayout::getBorderWidth() {
return border_width;
}
int MapLayout::getBorderHeight() {
return border_height;
}