-
Notifications
You must be signed in to change notification settings - Fork 178
fix persistent variables and containers #7192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
0f0de2a to
ef67aec
Compare
ef67aec to
adbfb8a
Compare
Storage of persistent variables had been broken since scp-fs2open#1631 -- the player-persistent variable code would inadvertently not run if there were no campaign-persistent variables. Additionally, there were several places where the persistent variable logic was hard to follow, which could have hidden other related bugs. This fixes the check and cleans up and consolidates the relevant functions.
adbfb8a to
98ecb98
Compare
jg18
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still reading, but adding a few thoughts.
code/mission/missioncampaign.cpp
Outdated
| } | ||
| if (store_red_alert) { | ||
| for (auto& current_rav : Campaign.red_alert_variables) { | ||
| Campaign.persistent_variables.push_back(current_rav); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably check for naming collisions between existing persistent variables and the RA variables we're adding. Ditto for containers.
code/mission/missioncampaign.cpp
Outdated
| } else if (any(persistence_type & ContainerType::SAVE_ON_MISSION_PROGRESS) && | ||
| any(container.type & persistence_type) && container.is_eternal()) { | ||
| // we might need to save some eternal player-persistent containers | ||
| if (!any(container.type & persistence_type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use none() instead of !any().
jg18
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still studying, but one concern.
| int num_mission_variables = sexp_campaign_file_variable_count(); | ||
| int num_sexp_variables = sexp_variable_count(); | ||
| for (int i = 0; i < num_sexp_variables; i++) { | ||
| if (!(Sexp_variables[i].type & persistence_type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code assumes all "set" variables are packed to the left in Sexp_variables. Can we be 110% sure that will always be true?
I suggest
for (int i = 0; i < MAX_SEXP_VARIABLES; i++) {
if (!(Sexp_variables[i].type & (SEXP_VARIABLE_SET | persistence_type))) {
continue;
}
Storage of persistent variables had been broken since #1631 -- the player-persistent variable code would inadvertently not run if there were no campaign-persistent variables. Additionally, there were several places where the persistent variable logic was hard to follow, which could have hidden other related bugs. This fixes the check and cleans up and consolidates the relevant functions.