Skip to content

Commit

Permalink
Merge pull request scp-fs2open#5982 from Goober5000/issue_5980
Browse files Browse the repository at this point in the history
address issue 5980
  • Loading branch information
Goober5000 committed Feb 8, 2024
2 parents d34570a + 8a3b36d commit 8e98cdd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
18 changes: 12 additions & 6 deletions code/starfield/starfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3011,14 +3011,20 @@ bool stars_background_empty(const background_t &bg)
// Goober5000
void stars_pack_backgrounds()
{
// remove all empty backgrounds
Backgrounds.erase(
std::remove_if(Backgrounds.begin(), Backgrounds.end(), stars_background_empty),
Backgrounds.end());
size_t remove_count = 0;

// remove all empty backgrounds, with a caveat:
// in FRED, make sure we always have at least one background
if (Fred_running && Backgrounds.empty())
stars_add_blank_background(true);
// (note: older code removed all blank backgrounds and re-added one if necessary; but that method caused flag changes to be lost)
Backgrounds.erase(
std::remove_if(Backgrounds.begin(), Backgrounds.end(), [&](const background_t& bg) {
if (stars_background_empty(bg)) {
if (Fred_running && ++remove_count == Backgrounds.size())
return false; // cancel the last removal if FRED is running and if the last removal would result in all backgrounds being removed (i.e. all were blank)
return true;
}
return false;
}), Backgrounds.end());
}

static void render_environment(int i, vec3d *eye_pos, matrix *new_orient, fov_t new_zoom)
Expand Down
21 changes: 15 additions & 6 deletions fred2/missionsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,9 +977,7 @@ int CFred_mission_save::save_bitmaps()
}

// save our flags
if (Mission_save_format == FSO_FORMAT_RETAIL) {
MessageBox(nullptr, "Warning: Background flags (including the fixed-angles-in-mission-file flag) are not supported in retail. The sun and bitmap angles will be loaded differently by previous versions.", "Incompatibility with retail mission format", MB_OK);
} else if (background->flags.any_set()) {
if (Mission_save_format == FSO_FORMAT_STANDARD && background->flags.any_set()) {
if (optional_string_fred("+Flags:")) {
parse_comments();
} else {
Expand All @@ -996,7 +994,6 @@ int CFred_mission_save::save_bitmaps()
for (j = 0; j < background->suns.size(); j++) {
starfield_list_entry *sle = &background->suns[j];


// filename
required_string_fred("$Sun:");
parse_comments();
Expand All @@ -1006,7 +1003,7 @@ int CFred_mission_save::save_bitmaps()
required_string_fred("+Angles:");
parse_comments();
angles ang = sle->ang;
if (!background->flags[Starfield::Background_Flags::Corrected_angles_in_mission_file])
if (Mission_save_format != FSO_FORMAT_STANDARD || !background->flags[Starfield::Background_Flags::Corrected_angles_in_mission_file])
stars_uncorrect_background_sun_angles(&ang);
fout(" %f %f %f", ang.p, ang.b, ang.h);

Expand All @@ -1029,7 +1026,7 @@ int CFred_mission_save::save_bitmaps()
required_string_fred("+Angles:");
parse_comments();
angles ang = sle->ang;
if (!background->flags[Starfield::Background_Flags::Corrected_angles_in_mission_file])
if (Mission_save_format != FSO_FORMAT_STANDARD || !background->flags[Starfield::Background_Flags::Corrected_angles_in_mission_file])
stars_uncorrect_background_bitmap_angles(&ang);
fout(" %f %f %f", ang.p, ang.b, ang.h);

Expand Down Expand Up @@ -2609,6 +2606,18 @@ int CFred_mission_save::save_mission_file(const char *pathname)
}
strcat_s(savepath, "saving.xxx");

// only display this warning once, and only when the user explicitly saves, as opposed to autosave
static bool Displayed_retail_background_warning = false;
if (Mission_save_format != FSO_FORMAT_STANDARD && !Displayed_retail_background_warning) {
for (const auto &bg : Backgrounds) {
if (bg.flags[Starfield::Background_Flags::Corrected_angles_in_mission_file]) {
MessageBox(nullptr, "Warning: Background flags (including the fixed-angles-in-mission-file flag) are not supported in retail. The sun and bitmap angles will be loaded differently by previous versions.", "Incompatibility with retail mission format", MB_OK);
Displayed_retail_background_warning = true;
break;
}
}
}

save_mission_internal(savepath);

if (!err) {
Expand Down
26 changes: 18 additions & 8 deletions qtfred/src/mission/missionsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,7 @@ int CFred_mission_save::save_bitmaps()
}

// save our flags
if (save_format == MissionFormat::RETAIL) {
_viewport->dialogProvider->showButtonDialog(DialogType::Warning,
"Incompatibility with retail mission format",
"Warning: Background flags (including the fixed-angles-in-mission-file flag) are not supported in retail. The sun and bitmap angles will be loaded differently by previous versions.",
{ DialogButton::Ok });
} else if (background->flags.any_set()) {
if (save_format == MissionFormat::STANDARD && background->flags.any_set()) {
if (optional_string_fred("+Flags:")) {
parse_comments();
} else {
Expand All @@ -1023,7 +1018,7 @@ int CFred_mission_save::save_bitmaps()
required_string_fred("+Angles:");
parse_comments();
angles ang = sle->ang;
if (!background->flags[Starfield::Background_Flags::Corrected_angles_in_mission_file])
if (save_format != MissionFormat::STANDARD || !background->flags[Starfield::Background_Flags::Corrected_angles_in_mission_file])
stars_uncorrect_background_sun_angles(&ang);
fout(" %f %f %f", ang.p, ang.b, ang.h);

Expand All @@ -1046,7 +1041,7 @@ int CFred_mission_save::save_bitmaps()
required_string_fred("+Angles:");
parse_comments();
angles ang = sle->ang;
if (!background->flags[Starfield::Background_Flags::Corrected_angles_in_mission_file])
if (save_format != MissionFormat::STANDARD || !background->flags[Starfield::Background_Flags::Corrected_angles_in_mission_file])
stars_uncorrect_background_bitmap_angles(&ang);
fout(" %f %f %f", ang.p, ang.b, ang.h);

Expand Down Expand Up @@ -2508,6 +2503,21 @@ int CFred_mission_save::save_mission_file(const char* pathname_in)
}
strcat_s(savepath, "saving.xxx");

// only display this warning once, and only when the user explicitly saves, as opposed to autosave
static bool Displayed_retail_background_warning = false;
if (save_format != MissionFormat::STANDARD && !Displayed_retail_background_warning) {
for (const auto &bg : Backgrounds) {
if (bg.flags[Starfield::Background_Flags::Corrected_angles_in_mission_file]) {
_viewport->dialogProvider->showButtonDialog(DialogType::Warning,
"Incompatibility with retail mission format",
"Warning: Background flags (including the fixed-angles-in-mission-file flag) are not supported in retail. The sun and bitmap angles will be loaded differently by previous versions.",
{ DialogButton::Ok });
Displayed_retail_background_warning = true;
break;
}
}
}

save_mission_internal(savepath);

if (!err) {
Expand Down

0 comments on commit 8e98cdd

Please sign in to comment.