Read MAX_MAP_DATA_SIZE
This commit is contained in:
parent
61b5654f14
commit
731fbce6af
5 changed files with 91 additions and 25 deletions
|
@ -277,7 +277,7 @@ private:
|
||||||
QString getDefaultMap();
|
QString getDefaultMap();
|
||||||
void setRecentMap(QString map_name);
|
void setRecentMap(QString map_name);
|
||||||
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
|
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
|
||||||
static bool mapDimensionsValid(int width, int height);
|
bool mapDimensionsValid(int width, int height);
|
||||||
|
|
||||||
void drawMapListIcons(QAbstractItemModel *model);
|
void drawMapListIcons(QAbstractItemModel *model);
|
||||||
void updateMapList();
|
void updateMapList();
|
||||||
|
|
|
@ -184,6 +184,13 @@ public:
|
||||||
static int getNumMetatilesTotal();
|
static int getNumMetatilesTotal();
|
||||||
static int getNumPalettesPrimary();
|
static int getNumPalettesPrimary();
|
||||||
static int getNumPalettesTotal();
|
static int getNumPalettesTotal();
|
||||||
|
static int getMaxMapDataSize();
|
||||||
|
static int getDefaultMapSize();
|
||||||
|
static int getMaxMapWidth();
|
||||||
|
static int getMaxMapHeight();
|
||||||
|
|
||||||
|
int getMapDataSize(int width, int height);
|
||||||
|
bool calculateDefaultMapSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateMapLayout(Map*);
|
void updateMapLayout(Map*);
|
||||||
|
@ -203,6 +210,8 @@ private:
|
||||||
static int num_metatiles_total;
|
static int num_metatiles_total;
|
||||||
static int num_pals_primary;
|
static int num_pals_primary;
|
||||||
static int num_pals_total;
|
static int num_pals_total;
|
||||||
|
static int max_map_data_size;
|
||||||
|
static int default_map_size;
|
||||||
|
|
||||||
QWidget *parent;
|
QWidget *parent;
|
||||||
|
|
||||||
|
|
|
@ -2291,9 +2291,8 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
|
||||||
heightSpinBox->setMinimum(1);
|
heightSpinBox->setMinimum(1);
|
||||||
bwidthSpinBox->setMinimum(1);
|
bwidthSpinBox->setMinimum(1);
|
||||||
bheightSpinBox->setMinimum(1);
|
bheightSpinBox->setMinimum(1);
|
||||||
// See below for explanation of maximum map dimensions
|
widthSpinBox->setMaximum(editor->project->getMaxMapWidth());
|
||||||
widthSpinBox->setMaximum(0x1E7);
|
heightSpinBox->setMaximum(editor->project->getMaxMapHeight());
|
||||||
heightSpinBox->setMaximum(0x1D1);
|
|
||||||
// Maximum based only on data type (u8) of map border width/height
|
// Maximum based only on data type (u8) of map border width/height
|
||||||
bwidthSpinBox->setMaximum(255);
|
bwidthSpinBox->setMaximum(255);
|
||||||
bheightSpinBox->setMaximum(255);
|
bheightSpinBox->setMaximum(255);
|
||||||
|
@ -2319,20 +2318,20 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
|
||||||
|
|
||||||
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
|
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
|
||||||
form.addRow(&buttonBox);
|
form.addRow(&buttonBox);
|
||||||
connect(&buttonBox, &QDialogButtonBox::accepted, [&dialog, &widthSpinBox, &heightSpinBox, &errorLabel](){
|
connect(&buttonBox, &QDialogButtonBox::accepted, [&dialog, &widthSpinBox, &heightSpinBox, &errorLabel, this](){
|
||||||
// Ensure width and height are an acceptable size.
|
// Ensure width and height are an acceptable size.
|
||||||
// The maximum number of metatiles in a map is the following:
|
// The maximum number of metatiles in a map is the following:
|
||||||
// max = (width + 15) * (height + 14)
|
// max = (width + 15) * (height + 14)
|
||||||
// This limit can be found in fieldmap.c in pokeruby/pokeemerald.
|
// This limit can be found in fieldmap.c in pokeruby/pokeemerald/pokefirered.
|
||||||
int realWidth = widthSpinBox->value() + 15;
|
int numMetatiles = editor->project->getMapDataSize(widthSpinBox->value(), heightSpinBox->value());
|
||||||
int realHeight = heightSpinBox->value() + 14;
|
int maxMetatiles = editor->project->getMaxMapDataSize();
|
||||||
int numMetatiles = realWidth * realHeight;
|
if (numMetatiles <= maxMetatiles) {
|
||||||
if (MainWindow::mapDimensionsValid(widthSpinBox->value(), heightSpinBox->value())) {
|
|
||||||
dialog.accept();
|
dialog.accept();
|
||||||
} else {
|
} else {
|
||||||
QString errorText = QString("Error: The specified width and height are too large.\n"
|
QString errorText = QString("Error: The specified width and height are too large.\n"
|
||||||
"The maximum map width and height is the following: (width + 15) * (height + 14) <= 10240\n"
|
"The maximum map width and height is the following: (width + 15) * (height + 14) <= %1\n"
|
||||||
"The specified map width and height was: (%1 + 15) * (%2 + 14) = %3")
|
"The specified map width and height was: (%2 + 15) * (%3 + 14) = %4")
|
||||||
|
.arg(maxMetatiles)
|
||||||
.arg(widthSpinBox->value())
|
.arg(widthSpinBox->value())
|
||||||
.arg(heightSpinBox->value())
|
.arg(heightSpinBox->value())
|
||||||
.arg(numMetatiles);
|
.arg(numMetatiles);
|
||||||
|
@ -2353,14 +2352,7 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::mapDimensionsValid(int width, int height) {
|
bool MainWindow::mapDimensionsValid(int width, int height) {
|
||||||
// Ensure width and height are an acceptable size.
|
return editor->project->getMapDataSize(width, height) <= editor->project->getMaxMapDataSize();
|
||||||
// The maximum number of metatiles in a map is the following:
|
|
||||||
// max = (width + 15) * (height + 14)
|
|
||||||
// This limit can be found in fieldmap.c in pokeruby/pokeemerald.
|
|
||||||
int realWidth = width + 15;
|
|
||||||
int realHeight = height + 14;
|
|
||||||
int numMetatiles = realWidth * realHeight;
|
|
||||||
return numMetatiles <= 0x2800;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_checkBox_smartPaths_stateChanged(int selected)
|
void MainWindow::on_checkBox_smartPaths_stateChanged(int selected)
|
||||||
|
|
|
@ -33,6 +33,8 @@ int Project::num_metatiles_primary = 512;
|
||||||
int Project::num_metatiles_total = 1024;
|
int Project::num_metatiles_total = 1024;
|
||||||
int Project::num_pals_primary = 6;
|
int Project::num_pals_primary = 6;
|
||||||
int Project::num_pals_total = 13;
|
int Project::num_pals_total = 13;
|
||||||
|
int Project::max_map_data_size = 10240; // 0x2800
|
||||||
|
int Project::default_map_size = 20;
|
||||||
|
|
||||||
Project::Project(QWidget *parent) : parent(parent)
|
Project::Project(QWidget *parent) : parent(parent)
|
||||||
{
|
{
|
||||||
|
@ -720,8 +722,8 @@ void Project::setNewMapLayout(Map* map) {
|
||||||
MapLayout *layout = new MapLayout();
|
MapLayout *layout = new MapLayout();
|
||||||
layout->id = MapLayout::layoutConstantFromName(map->name);
|
layout->id = MapLayout::layoutConstantFromName(map->name);
|
||||||
layout->name = QString("%1_Layout").arg(map->name);
|
layout->name = QString("%1_Layout").arg(map->name);
|
||||||
layout->width = "20";
|
layout->width = QString::number(getDefaultMapSize());
|
||||||
layout->height = "20";
|
layout->height = QString::number(getDefaultMapSize());
|
||||||
layout->border_width = DEFAULT_BORDER_WIDTH;
|
layout->border_width = DEFAULT_BORDER_WIDTH;
|
||||||
layout->border_height = DEFAULT_BORDER_HEIGHT;
|
layout->border_height = DEFAULT_BORDER_HEIGHT;
|
||||||
layout->border_path = QString("data/layouts/%1/border.bin").arg(map->name);
|
layout->border_path = QString("data/layouts/%1/border.bin").arg(map->name);
|
||||||
|
@ -2044,7 +2046,7 @@ QMap<QString, QStringList> Project::getTilesetLabels() {
|
||||||
|
|
||||||
bool Project::readTilesetProperties() {
|
bool Project::readTilesetProperties() {
|
||||||
QStringList definePrefixes;
|
QStringList definePrefixes;
|
||||||
definePrefixes << "NUM_";
|
definePrefixes << "NUM_" << "MAX_";
|
||||||
QString filename = "include/fieldmap.h";
|
QString filename = "include/fieldmap.h";
|
||||||
fileWatcher.addPath(root + "/" + filename);
|
fileWatcher.addPath(root + "/" + filename);
|
||||||
QMap<QString, int> defines = parser.readCDefines(filename, definePrefixes);
|
QMap<QString, int> defines = parser.readCDefines(filename, definePrefixes);
|
||||||
|
@ -2097,6 +2099,24 @@ bool Project::readTilesetProperties() {
|
||||||
logWarn(QString("Value for tileset property 'NUM_PALS_TOTAL' not found. Using default (%1) instead.")
|
logWarn(QString("Value for tileset property 'NUM_PALS_TOTAL' not found. Using default (%1) instead.")
|
||||||
.arg(Project::num_pals_total));
|
.arg(Project::num_pals_total));
|
||||||
}
|
}
|
||||||
|
it = defines.find("MAX_MAP_DATA_SIZE");
|
||||||
|
if (it != defines.end()) {
|
||||||
|
int min = getMapDataSize(1, 1);
|
||||||
|
if (it.value() >= min) {
|
||||||
|
Project::max_map_data_size = it.value();
|
||||||
|
calculateDefaultMapSize();
|
||||||
|
} else {
|
||||||
|
// must be large enough to support a 1x1 map
|
||||||
|
logWarn(QString("Value for map property 'MAX_MAP_DATA_SIZE' is %1, must be at least %2. Using default (%3) instead.")
|
||||||
|
.arg(it.value())
|
||||||
|
.arg(min)
|
||||||
|
.arg(Project::max_map_data_size));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logWarn(QString("Value for map property 'MAX_MAP_DATA_SIZE' not found. Using default (%1) instead.")
|
||||||
|
.arg(Project::max_map_data_size));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2541,3 +2561,48 @@ int Project::getNumPalettesTotal()
|
||||||
{
|
{
|
||||||
return Project::num_pals_total;
|
return Project::num_pals_total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Project::getMaxMapDataSize()
|
||||||
|
{
|
||||||
|
return Project::max_map_data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Project::getMapDataSize(int width, int height)
|
||||||
|
{
|
||||||
|
// + 15 and + 14 come from fieldmap.c in pokeruby/pokeemerald/pokefirered.
|
||||||
|
return (width + 15) * (height + 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Project::getDefaultMapSize()
|
||||||
|
{
|
||||||
|
return Project::default_map_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Project::getMaxMapWidth()
|
||||||
|
{
|
||||||
|
return (getMaxMapDataSize() / (1 + 14)) - 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Project::getMaxMapHeight()
|
||||||
|
{
|
||||||
|
return (getMaxMapDataSize() / (1 + 15)) - 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get largest possible square dimensions for a map up to maximum of 20x20 (arbitrary)
|
||||||
|
bool Project::calculateDefaultMapSize(){
|
||||||
|
int max = getMaxMapDataSize();
|
||||||
|
|
||||||
|
if (max >= getMapDataSize(20, 20)) {
|
||||||
|
default_map_size = 20;
|
||||||
|
} else if (max >= getMapDataSize(1, 1)) {
|
||||||
|
// Below equation derived from max >= (x + 15) * (x + 14)
|
||||||
|
// x^2 + 29x + (10 - max), then complete the square and simplify
|
||||||
|
default_map_size = qFloor((qSqrt(4 * getMaxMapDataSize() + 1) - 29) / 2);
|
||||||
|
} else {
|
||||||
|
logError(QString("'MAX_MAP_DATA_SIZE' of %1 is too small to support a 1x1 map. Must be at least %2.")
|
||||||
|
.arg(max)
|
||||||
|
.arg(getMapDataSize(1, 1)));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -67,8 +67,8 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
|
||||||
ui->comboBox_NewMap_Primary_Tileset->setDisabled(true);
|
ui->comboBox_NewMap_Primary_Tileset->setDisabled(true);
|
||||||
ui->comboBox_NewMap_Secondary_Tileset->setDisabled(true);
|
ui->comboBox_NewMap_Secondary_Tileset->setDisabled(true);
|
||||||
} else {
|
} else {
|
||||||
ui->spinBox_NewMap_Width->setValue(20);
|
ui->spinBox_NewMap_Width->setValue(project->getDefaultMapSize());
|
||||||
ui->spinBox_NewMap_Height->setValue(20);
|
ui->spinBox_NewMap_Height->setValue(project->getDefaultMapSize());
|
||||||
ui->spinBox_NewMap_BorderWidth->setValue(DEFAULT_BORDER_WIDTH);
|
ui->spinBox_NewMap_BorderWidth->setValue(DEFAULT_BORDER_WIDTH);
|
||||||
ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT);
|
ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue