Skip to content

Commit

Permalink
Don't populate sdf_names needlessly
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Mar 3, 2025
1 parent 8fc0d09 commit 2e05188
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/scenario/scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,3 +605,11 @@ std::string cScenario::get_feature_flag(std::string flag) {
if(iter == this->feature_flags.end()) return "";
return iter->second;
}

std::string cScenario::get_sdf_name(int col, int row) {
if(sdf_names.find(col) == sdf_names.end())
return "";
if(sdf_names[col].find(row) == sdf_names[col].end())
return "";
return sdf_names[col][row];
}
2 changes: 2 additions & 0 deletions src/scenario/scenario.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class cScenario {
std::vector<std::string> ic_names;
std::vector<std::string> itf_names;
std::map<int, std::map<int, std::string>> sdf_names;
std::string get_sdf_name(int col, int row);

bool adjust_diff;
bool is_legacy;
fs::path scen_file; // transient
Expand Down
2 changes: 1 addition & 1 deletion src/scenedit/scen.fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void writeScenarioToXml(ticpp::Printer&& data, cScenario& scenario) {
}
for(int x = 0; x < SDF_COLUMNS; x++) {
for(int y = 0; y < SDF_ROWS; y++) {
if(scenario.sdf_names[x][y].empty()) continue;
if(scenario.get_sdf_name(x, y).empty()) continue;
data.OpenElement("sdf");
data.PushAttribute("row", x);
data.PushAttribute("col", y);
Expand Down
5 changes: 3 additions & 2 deletions src/scenedit/scen.sdfpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void cStuffDonePicker::fill_names() {
location sdf = viewport;
sdf.x += x;
sdf.y += y;
field.setText(scenario.sdf_names[sdf.x][sdf.y]);
field.setText(scenario.get_sdf_name(sdf.x, sdf.y));
if(x == 0) {
// Add row labels
row_labels->getChild("row", 0, y).setTextToNum(sdf.y);
Expand All @@ -139,7 +139,8 @@ void cStuffDonePicker::save_names() {
location sdf = viewport;
sdf.x += x;
sdf.y += y;
scenario.sdf_names[sdf.x][sdf.y] = field.getText();
if(!field.getText().empty())
scenario.sdf_names[sdf.x][sdf.y] = field.getText();
}
}
}
Expand Down

0 comments on commit 2e05188

Please sign in to comment.