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

Command list improvs #357

Merged

Conversation

EvidentlyCube
Copy link
Collaborator

@EvidentlyCube EvidentlyCube commented Nov 25, 2020

This depends on changes from #353.
Relevant thread

@mrimer
Copy link
Member

mrimer commented Nov 25, 2020

I've merged #353. Would you please rebase?

Copy link

@vittorioromeo vittorioromeo left a comment

Choose a reason for hiding this comment

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

Nice to see DROD being developed again. Some pedantic C++ stuff to improve code quality/readability. I'm not sure what C++ standard is targeted, but pretty much every platform in the world supports C++11 nowadays, and most support C++14 and C++17 as well.

@@ -130,6 +131,13 @@ void AsciiToUnicode(const std::string &str, WSTRING &wstr) {
AsciiToUnicode(str.c_str(), wstr);
}

//*****************************************************************************
const WSTRING AsciiToUnicode(const char *psz) {

Choose a reason for hiding this comment

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

Returning by const value doesn't really help here, assuming WSTRING is the same as this one.

Suggested change
const WSTRING AsciiToUnicode(const char *psz) {
WSTRING AsciiToUnicode(const char *psz) {

I would also look into [[nodiscard]] for function signatures like these. It is a C++17 feature but there are equivalent compiler-specific attributes since C++98. It produces a warning when the return value of AsciiToUnicode is discarded, avoidining mistakenly assuming that psz gets mutated rather than a new value being returned:

Suggested change
const WSTRING AsciiToUnicode(const char *psz) {
[[nodiscard]] WSTRING AsciiToUnicode(const char *psz) {

Choose a reason for hiding this comment

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

The [[nodiscard]] suggestion applies to pretty much every function here, or every function returning a value that should never be ignored.

Comment on lines 903 to 906
for (WSTRING::const_iterator it = source.begin(); it != source.end(); ++it)
lowercased += towlower(*it);

return lowercased;

Choose a reason for hiding this comment

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

C++11 range-based for is cleaner here:

Suggested change
for (WSTRING::const_iterator it = source.begin(); it != source.end(); ++it)
lowercased += towlower(*it);
return lowercased;
for (char c : source)
lowercased += towlower(c);
return lowercased;

}

//*****************************************************************************
const std::vector<WSTRING> WCSExplode(WSTRING const &source, WCHAR const delimiter)

Choose a reason for hiding this comment

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

Comment on lines 930 to 936
for (std::vector<WSTRING>::const_iterator iter = needles.begin(); iter < needles.end(); ++iter)
{
if (haystack.find(*iter) == WSTRING::npos)
return false;
}

return true;

Choose a reason for hiding this comment

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

From <algorithm>, C++11:

	return std::all_of(needles.begin(), needles.end(),
		[&haystack]
		{
			return haystack.find(*iter) != WSTRING::npos;
		});

Consider std::none_of as well, might be more readable due to the avoided negation in the body of the lambda expression.

Comment on lines 193 to 195
const UINT CCharacterDialogWidget::INDENT_PREFIX_SIZE = 6;
const UINT CCharacterDialogWidget::INDENT_TAB_SIZE = 3;
const UINT CCharacterDialogWidget::INDENT_IF_CONDITION_SIZE = 5;

Choose a reason for hiding this comment

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

If these are purely hardcoded constants, consider using a constexpr variable (C++11), or an inline constexpr variable if C++17 support is available. Just makes it more obvious and has a stronger guarantee that the value is purely known at compile-time.

@EvidentlyCube
Copy link
Collaborator Author

@SuperV1234 I am afraid we're currently not targeting C++11 :(.

@vittorioromeo
Copy link

@SuperV1234 I am afraid we're currently not targeting C++11 :(.

What platform is stopping you? Seems a bit of a weird decision in 2020.

@vittorioromeo
Copy link

@mrimer
Copy link
Member

mrimer commented Nov 27, 2020

@SuperV1234 I am afraid we're currently not targeting C++11 :(.

What platform is stopping you? Seems a bit of a weird decision in 2020.

Our current OS X development setup.

…f blocks + displaying a lot of commands now works faster because indenting now happens once instead once for each command
@EvidentlyCube
Copy link
Collaborator Author

@mrimer PR updated, I also fixed labels not having negative indent.

@@ -189,6 +190,9 @@ const UINT LIST_LINE_HEIGHT = 22;
const SURFACECOLOR PaleRed = {255, 192, 192};

std::map<UINT, UINT> CCharacterDialogWidget::speechLengthCache;
const UINT CCharacterDialogWidget::INDENT_PREFIX_SIZE = 8;
Copy link
Member

Choose a reason for hiding this comment

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

These constants should be consolidated with the analogous magic numbers featured elsewhere in the code, e.g., CCommandListBoxWidget.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mrimer I'm not quite sure what needs to be consolidated where. These constants appear to be grouped with the other ones in this file, and they don't appear to share a purpose with the ones in CCommandListBoxWidget. That file does have some constants littered about, but they are in the place where they're being used, so it doesn't seem like much of an 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 appreciate you looking into this. I possibly misinterpreted the values. IIRC, to me, it looked like there are identical dimension values in both places, e.g., 8 pixels for an indent size, that possibly need to remain in lockstep in both places for things to work correctly. If this isn't the case, I'm fine with leaving things as-is for now.

@Hypexion
Copy link
Contributor

Hypexion commented May 6, 2021

@mrimer In light of skell's departure from DROD development, could this be merged as-is? The feature is complete, and I can whip up a PR to move the magic number to live with its friends.

@mrimer
Copy link
Member

mrimer commented May 6, 2021

Merging. My last request can be applied as a follow-on PR.

@mrimer mrimer merged commit 279ab72 into CaravelGames:tss-5.2-dev May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants