-
Notifications
You must be signed in to change notification settings - Fork 78
[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
base: main
Are you sure you want to change the base?
Conversation
@@ -42,8 +42,14 @@ | |||
#undef SPARSEMATCH_DEBUG | |||
#endif | |||
|
|||
typedef UnsignedInt SparseMatchFinderFlags; |
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.
Is this needed? Unless I'm missing something, I think it'd be better to get rid of this typedef
.
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.
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.
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.
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() {} |
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.
Is it necessary to define the constructor?
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.
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.
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.
There was a compile error when I did not add it. So I added that.
SparseMatchFinder() {} | ||
SparseMatchFinder(const SparseMatchFinder& other) | ||
{ | ||
*this = other; |
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.
Shouldn't the copy flag be checked here as well?
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.
It is checked in the assignment operator (which this calls).
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.
Ah right.
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.
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)
{}
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.
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.
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. |
This change fixes #856 and is an alternative implementation to #1194.
TODO