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

Remove hard-coded framecount for linking progress animation. #628

Merged
merged 1 commit into from
Feb 12, 2020

Conversation

Deledrius
Copy link
Member

This fixes a long-standing crash which could occur if using a different resource.dat than one the client was hard-coded to expect. Previously, the number of frames was dictated at compile-time. This change allows the plProgressMgr to query for the list of resources, find the ones matching the given pattern, and subsequently use that sorted list as the IDs from which it builds and cycles the animation.

{
std::vector<ST::string> names;

for (auto resource : ClientResources)
Copy link
Member

Choose a reason for hiding this comment

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

I believe that this makes an unnecessary copy of the string. We may prefer const auto&

Copy link
Member Author

Choose a reason for hiding this comment

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

I wish I were better at seeing these myself.

fImageRotation[i] = ST::format("xLoading_Linking.{02}.png", i);
// Find linking-animation frame IDs and store the sorted list
std::regex re("xLoading_Linking\\.[0-9]+?\\.png");
for (auto name : plClientResMgr::Instance().getResourceNames()) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe that this makes an unnecessary copy of the string. We may prefer const auto&

// Find linking-animation frame IDs and store the sorted list
std::regex re("xLoading_Linking\\.[0-9]+?\\.png");
for (auto name : plClientResMgr::Instance().getResourceNames()) {
if (std::regex_match(name.to_std_string(), re))
Copy link
Member

Choose a reason for hiding this comment

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

You can avoid the conversion to std::string here by using std::regex_match(name.begin(), name.end(), re) instead

Copy link
Member Author

Choose a reason for hiding this comment

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

Excellent, I didn't see that option when I was looking at the regex matches. I was hoping to write something a bit better here.

fImageRotation[i] = ST::format("xLoading_Linking.{02}.png", i);
// Find linking-animation frame IDs and store the sorted list
std::regex re("xLoading_Linking\\.[0-9]+?\\.png");
for (auto name : plClientResMgr::Instance().getResourceNames()) {
Copy link
Member

Choose a reason for hiding this comment

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

const auto& name to avoid copying...

Copy link
Member Author

Choose a reason for hiding this comment

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

I wish I were better at seeing these myself.

{
std::vector<ST::string> names;

for (auto resource : ClientResources)
Copy link
Member

Choose a reason for hiding this comment

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

const auto& resource to avoid copies (if applicable)

return fImageRotation[index];
else
return fImageRotation[0];
return fImageRotation[index % (fImageRotation.size() - 1)];
Copy link
Member

Choose a reason for hiding this comment

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

% doesn't protect against negative indexes... I'd suggest either making this unsigned or keeping the old behavior (with the non-hard-coded size)

Copy link
Member Author

Choose a reason for hiding this comment

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

I must have been thinking of this backwards. Thanks.

Copy link
Member Author

@Deledrius Deledrius Feb 12, 2020

Choose a reason for hiding this comment

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

The old method doesn't protect against negatives, either. Yikes.

As far as I can tell, the code at both ends of the function call are checking that we don't exceed our bounds, and there should never be a reason to play the animation in reverse. But I'd rather it be solid against such a usage.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is std::clamp available for our usage? Would that be appropriate?

Copy link
Member

Choose a reason for hiding this comment

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

std::clamp was added in C++17--we are still using C++14.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, that's out then. :)

Copy link
Member

Choose a reason for hiding this comment

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

The old method doesn't protect against negatives, either. Yikes.

Ah, good point... Maybe not a big deal then.

@Hoikas Hoikas merged commit a0b9f6f into H-uru:master Feb 12, 2020
@Deledrius Deledrius deleted the smart_loading_anim branch February 12, 2020 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants