-
Notifications
You must be signed in to change notification settings - Fork 79
[GEN][ZH] Fix ThingTemplate copying to prevent multiplayer 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?
[GEN][ZH] Fix ThingTemplate copying to prevent multiplayer mismatch with mod maps and quickstart #1234
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,14 @@ | |
#undef SPARSEMATCH_DEBUG | ||
#endif | ||
|
||
typedef UnsignedInt SparseMatchFinderFlags; | ||
enum SparseMatchFinderFlags_ CPP_11(: SparseMatchFinderFlags) | ||
{ | ||
SparseMatchFinderFlags_NoCopy = 1<<0, | ||
}; | ||
|
||
//------------------------------------------------------------------------------------------------- | ||
template<class MATCHABLE, class BITSET> | ||
template<class MATCHABLE, class BITSET, SparseMatchFinderFlags FLAGS = 0> | ||
class SparseMatchFinder | ||
{ | ||
private: | ||
|
@@ -185,9 +191,29 @@ class SparseMatchFinder | |
return result; | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------- | ||
public: | ||
|
||
|
||
//------------------------------------------------------------------------------------------------- | ||
SparseMatchFinder() {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(const SparseMatchFinder& other) | ||
{ | ||
*this = other; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
//------------------------------------------------------------------------------------------------- | ||
SparseMatchFinder& operator=(const SparseMatchFinder& other) | ||
{ | ||
if CONSTEXPR ((FLAGS & SparseMatchFinderFlags_NoCopy) == 0) | ||
{ | ||
if (this != &other) | ||
{ | ||
m_bestMatches = other.m_bestMatches; | ||
} | ||
} | ||
return *this; | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------- | ||
void clear() | ||
{ | ||
|
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
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.