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

Codechange: use more C++11 in script-related functions #8432

Merged
merged 1 commit into from Dec 25, 2020

Conversation

TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Dec 25, 2020

Motivation / Problem

When trying to read the AI code (emphasis on trying), I run into a lot of very hard to read statements that can be solved by using a bit of auto and for (.. : ..) constructions.

Description

Well .. it uses C++11 now.

Limitations

  • Only did matches for iter in script, ai and game folder.

@frosch123
Copy link
Member

  • No, there is no find with default value like python's dict.get().
  • More const is better, but sometimes hurts readability. Make your own judgement whether you can still read the code.
  • Looks like GetConfigList never returns nullptr, so the return type should be "const ScriptConfigItemList&".

Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

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

There are contains functions (which could cover most of the find cases)... but not until C++20
https://en.cppreference.com/w/cpp/container/map/contains

Could write helpers I suppose...

src/script/script_info.cpp Show resolved Hide resolved
src/script/script_scanner.cpp Outdated Show resolved Hide resolved
@TrueBrain TrueBrain marked this pull request as ready for review December 25, 2020 18:30
Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

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

My issues fixed

@TrueBrain TrueBrain merged commit f66baa4 into OpenTTD:master Dec 25, 2020
@TrueBrain TrueBrain deleted the ai_cplusplus branch December 25, 2020 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants