Skip to content

Hex layout optimization#6793

Open
xfractalino wants to merge 3 commits intomasterfrom
hex-layout-optimization
Open

Hex layout optimization#6793
xfractalino wants to merge 3 commits intomasterfrom
hex-layout-optimization

Conversation

@xfractalino
Copy link
Contributor

Brief Description of What This PR Does

Avoiding deep-cloning for the organelle layout and hex layouts in general by using temporary pooled memory for diffs only.

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.

mutation.MutatedSpecies.Organelles.Approve(true);
}

mutation.MutatedSpecies.Organelles.Approve(false);
Copy link
Member

Choose a reason for hiding this comment

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

Should this be in an else clause? Because now if the if is true above then we first all Approve and then Approve false.

return existingHexes.Contains(item);
}

public void Approve(bool isApproved = true)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this method named Approve? Doesn't calling Approve(false) mean that this is rejected? I think for clarity it would be nicer to have two methods: Approve and Reject without any parameters each.


IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
Copy link
Member

Choose a reason for hiding this comment

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

This causes boxing due to the way the enumerator is implemented. Hopefully this is not called much?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this shouldn't be called at all.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe a GD.PrintErr warning about the performance implications then? (if in the future this somehow ends up being called)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also happens in the current HexLayout implementation, by the way, also in the standard GetEnumerator (which is used in 66 places, Rider tells me)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But there's a comment with a TODO about this very issue.

Copy link
Member

Choose a reason for hiding this comment

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

I think this case is different, because this is a struct so any allocated enumerator will have a copy of the struct data and not just a reference to the data. So I kind of think that this is a slightly more problematic situation than a simple lightweight enumerator allocation. But I admit I don't fully know how structs having an enumerator function in them behave.

@xfractalino xfractalino force-pushed the hex-layout-optimization branch from 2bcd594 to 48f85e9 Compare March 11, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants