Skip to content

[GEN][ZH] Fix ThingTemplate copying to prevent mismatch with mod maps and quickstart #1234

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xezon
Copy link

@xezon xezon commented Jul 6, 2025

This change fixes #856 and is an alternative implementation to #1194.

TODO

  • Replicate in Generals
  • Test against replays in VC6

@xezon xezon added this to the Stability fixes milestone Jul 6, 2025
@xezon xezon added Bug Something is not working right, typically is user facing Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Stability Concerns stability of the runtime labels Jul 6, 2025
@@ -42,8 +42,14 @@
#undef SPARSEMATCH_DEBUG
#endif

typedef UnsignedInt SparseMatchFinderFlags;

Choose a reason for hiding this comment

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

Is this needed? Unless I'm missing something, I think it'd be better to get rid of this typedef.

Copy link
Author

Choose a reason for hiding this comment

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

This is the imgui style of declaring enums for flags.

The reason for this is that

SparseMatchFinderFlags flags = flagName1 | flagName2;

does not work if SparseMatchFinderFlags is an enum. And it is bad to use int for flag types, because it is more difficult to follow what this flag type is then.

Choose a reason for hiding this comment

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

It would work if you do it inside the enum itself (flags1 = flagName1 | flagName2), which may not be feasible for larger enums, but fair enough.

public:


//-------------------------------------------------------------------------------------------------
SparseMatchFinder() {}

Choose a reason for hiding this comment

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

Is it necessary to define the constructor?

Choose a reason for hiding this comment

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

Technically we should define a destructor if we're following the rule of 3, but in this case it'd be empty and C++98 doesn't support the default keyword.

Copy link
Author

Choose a reason for hiding this comment

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

There was a compile error when I did not add it. So I added that.

SparseMatchFinder() {}
SparseMatchFinder(const SparseMatchFinder& other)
{
*this = other;

Choose a reason for hiding this comment

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

Shouldn't the copy flag be checked here as well?

Copy link
Author

Choose a reason for hiding this comment

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

It is checked in the assignment operator (which this calls).

Choose a reason for hiding this comment

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

Ah right.

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 little awkward to have the copy constructor call the copy assignment operator and also potentially slightly inefficient if the data is copied. I'd propose this instead:

SparseMatchFinder(const SparseMatchFinder& other) : 
	m_bestMatches((FLAGS & SparseMatchFinderFlags_NoCopy) == 0 ? MatchMap() : other.m_bestMatches)
{}

Copy link
Author

@xezon xezon Jul 6, 2025

Choose a reason for hiding this comment

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

If this construction was more simple then I would agree, but I think in this case it is easier to just write the code once for simpler C++ code. std::map does not allocate anything on default construction and there should be no worry about inefficiency - if the function was even called.

@xezon xezon requested a review from Caball009 July 6, 2025 20:26
@Caball009
Copy link

The code looks alright. I can verify tomorrow whether the original issue is still fixed, although I don't see no reason why that wouldn't be the case.

I hope someone can run this against a large number of replays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working right, typically is user facing Gen Relates to Generals Major Severity: Minor < Major < Critical < Blocker Stability Concerns stability of the runtime ZH Relates to Zero Hour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mismatches when using -quickstart
2 participants