use nested map for SDF names to save stack space.

Update semantics of the SDF array to (row, column) form to match
the picker space

Fix #674
This commit is contained in:
2025-03-05 09:24:50 -06:00
committed by Celtic Minstrel
parent 3d48cb14e7
commit 90d5e1b778
8 changed files with 52 additions and 38 deletions

View File

@@ -46,19 +46,19 @@ bool cStuffDonePicker::handle_scroll(std::string item_hit) {
if(item_hit == "up") {
if(viewport.y > 0) viewport.y -= rows;
} else if(item_hit == "down") {
if(viewport.y < scenario.sdf_names[0].size() - rows) viewport.y += rows;
if(viewport.y < SDF_ROWS - rows) viewport.y += rows;
} else if(item_hit == "left") {
if(viewport.x > 0) viewport.x -= cols;
} else if(item_hit == "right") {
if(viewport.x < scenario.sdf_names.size() - cols) viewport.x += cols;
if(viewport.x < SDF_COLUMNS - cols) viewport.x += cols;
}
if(viewport.x == 0) dlog["left"].hide();
else dlog["left"].show();
if(viewport.y == 0) dlog["up"].hide();
else dlog["up"].show();
if(viewport.x >= scenario.sdf_names.size() - cols) dlog["right"].hide();
if(viewport.x >= SDF_COLUMNS - cols) dlog["right"].hide();
else dlog["right"].show();
if(viewport.y >= scenario.sdf_names[0].size() - rows) dlog["down"].hide();
if(viewport.y >= SDF_ROWS - rows) dlog["down"].hide();
else dlog["down"].show();
fill_names();
if(!item_hit.empty()) select_active();
@@ -106,40 +106,43 @@ location cStuffDonePicker::run() {
}
void cStuffDonePicker::clamp_sdf() {
chosen_sdf.x = minmax(0, scenario.sdf_names.size() - 1, chosen_sdf.x);
chosen_sdf.y = minmax(0, scenario.sdf_names[0].size() - 1, chosen_sdf.y);
// Note: x and y in chosen_sdf are actually (c,r)
chosen_sdf.x = minmax(0, SDF_COLUMNS - 1, chosen_sdf.x);
chosen_sdf.y = minmax(0, SDF_ROWS - 1, chosen_sdf.y);
viewport.x = cols * floor(chosen_sdf.x / float(cols));
viewport.y = rows * floor(chosen_sdf.y / float(rows));
}
void cStuffDonePicker::fill_names() {
for(int x = 0; x < cols; x++) {
for(int y = 0; y < rows; y++) {
auto& field = grid->getChild("name", x, y);
for(int c = 0; c < cols; c++) {
for(int r = 0; r < rows; r++) {
auto& field = grid->getChild("name", c, r);
// Note: x and y in sdf are actually (c,r)
location sdf = viewport;
sdf.x += x;
sdf.y += y;
field.setText(scenario.sdf_names[sdf.x][sdf.y]);
if(x == 0) {
sdf.x += c;
sdf.y += r;
field.setText(scenario.get_sdf_name(sdf.y, sdf.x));
if(c == 0) {
// Add row labels
row_labels->getChild("row", 0, y).setTextToNum(sdf.y);
row_labels->getChild("row", 0, r).setTextToNum(sdf.y);
}
if(y == 0) {
if(r == 0) {
// Add column labels
col_labels->getChild("col", x, 0).setTextToNum(sdf.x);
col_labels->getChild("col", c, 0).setTextToNum(sdf.x);
}
}
}
}
void cStuffDonePicker::save_names() {
for(int x = 0; x < cols; x++) {
for(int y = 0; y < rows; y++) {
auto& field = grid->getChild("name", x, y);
for(int c = 0; c < cols; c++) {
for(int r = 0; r < rows; r++) {
auto& field = grid->getChild("name", c, r);
location sdf = viewport;
sdf.x += x;
sdf.y += y;
scenario.sdf_names[sdf.x][sdf.y] = field.getText();
sdf.x += c;
sdf.y += r;
if(!field.getText().empty())
scenario.sdf_names[sdf.y][sdf.x] = field.getText();
}
}
}