Skip to content
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

Fix processes' toggle buttons not matching their actual state #5632

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

dligr
Copy link
Contributor

@dligr dligr commented Oct 27, 2024

Brief Description of What This PR Does

Fixes process toggle buttons being de-synced from their processes' actual state.

Does so by making process displays get the toggle state directly from the process, instead of using a local variable. This also allows those states to be saved.

Also, makes TweakedProcesses' speed multipliers save when they are updated (e.g. when an organelle duplicates).

Related Issues

Fixes #5420

Progress Checklist

Note: before starting this checklist the PR should be marked as non-draft.

  • PR author has checked that this PR works as intended and doesn't
    break existing features:
    https://wiki.revolutionarygamesstudio.com/wiki/Testing_Checklist
    (this is important as to not waste the time of Thrive team
    members reviewing this PR)
  • Initial code review passed (this and further items should not be checked by the PR author)
  • Functionality is confirmed working by another person (see above checklist link)
  • Final code review is passed and code conforms to the
    styleguide.

Before merging all CI jobs should finish on this PR without errors, if
there are automatically detected style issues they should be fixed by
the PR author. Merging must follow our
styleguide.

@dligr dligr added the review label Oct 27, 2024
@dligr dligr added this to the Release 0.8.0 milestone Oct 27, 2024
@dligr dligr requested review from a team October 27, 2024 11:18
@dligr
Copy link
Contributor Author

dligr commented Oct 27, 2024

I have noticed while testing that process toggles don't work on cell colonies (at least, on other members of those colonies). I hope that it would be fine if I fixed it too with this PR.

@hhyyrylainen
Copy link
Member

It's most likely fine, but I have slight concern if that has understandability problems because #3207 is not done. But I guess in most situations where like for efficiency reasons players want to toggle processes it's fine as the colony compound distribution will make sure that other colony members can basically do the same processes as the lead cell.

Copy link
Member

@hhyyrylainen hhyyrylainen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a pretty good design for this problem and one that can fix the toggle states getting out of sync. What I have significant concerns about is the change of that one struct to a class which majorly changes all memory usage and allocations related to it, which is something I've relied on greatly in the process system for maximum efficiency. I think as a result the changes here need to be considered more.

src/gui_common/ChemicalEquation.cs Show resolved Hide resolved
src/microbe_stage/TweakedProcess.cs Outdated Show resolved Hide resolved
src/microbe_stage/StrictProcessDisplayInfoEquality.cs Outdated Show resolved Hide resolved
src/microbe_stage/systems/ProcessSystem.cs Outdated Show resolved Hide resolved
src/microbe_stage/ProcessStatistics.cs Outdated Show resolved Hide resolved
src/microbe_stage/ProcessStatistics.cs Outdated Show resolved Hide resolved
src/microbe_stage/ProcessStatistics.cs Outdated Show resolved Hide resolved
src/microbe_stage/ProcessStatistics.cs Outdated Show resolved Hide resolved

/// <summary>
/// The processes and their associated speed statistics
/// </summary>
/// <remarks>
/// <para>
/// This uses <see cref="BioProcess"/> rather than <see cref="TweakedProcess"/> as the key so that equality
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another point that I think is causing some pretty major architectural problems here. I didn't yet check every single place, that these changes impact, but my impression is that all of the code depending on the assumptions about the code that has been changed in this PR have not been updated yet.

@@ -50,7 +50,8 @@ public bool Equals(TweakedProcess other)
return false;

// ReSharper disable once CompareOfFloatsByEqualityOperator
return Rate == other.Rate && ReferenceEquals(Process, other.Process);
return Rate == other.Rate && SpeedMultiplier == other.SpeedMultiplier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding comparing the speed multiplier here, I think might break some grouping of process displays...

So I would remove this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's right, because if processes with different states are considered equal, then they aren't correctly updated on GUI, unless I'm missing something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you playtested and confirmed that is a bug? Kind of unhelpfully the process list detection uses equality to combine items, so too strict checking can result in a situation where duplicates get created into the process list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have play tested it without the speed multiplier check and processes' statuses didn't update.

Are you sure that too strict checking may result in duplicates? If I read the process list code right, then GUI-side processes (ChemicalEquations) that aren't equal to any of the display infos that it is given are simply removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true that if this isn't the type of equality used in the GUI combining (and that doesn't call this equality in turn), this should be fine. Though, the last time I tried to improve the process equality checks to be more accurate, I totally messed up the process speed panel to show each instance of a process separately (instead of keeping the functionality where all organelles are summed into one process of each type). I'll need to check this carefully when doing the next review (after the extra temporary memory use is solved).

@@ -32,6 +32,8 @@ namespace Systems;
[RuntimeCost(55)]
public sealed class ProcessSystem : AEntitySetSystem<float>
{
private static readonly Dictionary<BioProcess, float> TempSpeedMultipliers = new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this is a massive problem as ComputeActiveProcessList has to be thread safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be right to put all of ComputeActiveProcessList's code in a lock statement? Only a single thread would then be able to access the dictionary at a time, though that would worsen performance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't because this then becomes a bottleneck. If there truly is no way to avoid the temp memory, then the approach where the method caller must provide the working memory should be used (look at for example how the hex adding methods in the hex layout class require multiple working memory parameters to work).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

Process toggle buttons sometimes don't match process state
2 participants