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: Cache ScriptConfig for the slot in constructor #10531

Conversation

SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Mar 2, 2023

Motivation / Problem

GSConfigWindow seems to mix usage of this->gs_config and GameConfig::GetConfig(). And ScriptListWindow could also cache ScriptConfig for the slot in constructor instead calling GetConfig() everytime. Then the static function can be removed. #10458 (review)

While at it, maybe also invalidate debug window (to show/hide break string), but the invalidate code of that window doesn't really do anything in that regard. #10458 (comment) , #10458 (comment)

Possible programmatic simplification Game and Script OnClick handlers. #10458 (comment)

Description

Limitations

When changing ai_developer_tools, the invalidate call on the Debug Window doesn't really show or hide the break box (to do).

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@2TallTyler 2TallTyler added the needs review: Script API Review requested from GS/AI expert label Mar 3, 2023
Copy link
Member

@2TallTyler 2TallTyler left a comment

Choose a reason for hiding this comment

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

It would be nice to see these changes split into commits that explain what you're changing and why. We have a PR template and commit naming convention for a reason, but you've ignored the template and crammed unrelated changes into your commit. Your current commit title is perfect for the caching change, but code simplification and fixes to previous PRs should have their own commits (so to be clear, this PR should have at least 3 commits for the changes it contains).

Here's a useful article about commit messages that might help you figure out how to structure them.

I'd also encourage you to use the PR template. The code and commit message tell me that you're caching the ScriptConfig, but I can't read your mind to understand why. Does caching make something faster? Is it more consistent with other parts of the code? Is the new InvalidateWindowData() call to fix something in a previous PR? If you explain this in the Problem / Motivation section, I don't have to guess, and can review your PR much more effectively. This doesn't need a long backstory and test cases for each change, just help me understand your motivation behind the change. 🙂

@@ -779,7 +779,7 @@ cat = SC_EXPERT
var = gui.ai_developer_tools
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def = false
post_cb = [](auto) { InvalidateWindowClassesData(WC_SCRIPT_SETTINGS); }
post_cb = [](auto) { InvalidateWindowClassesData(WC_SCRIPT_SETTINGS); InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GS); InvalidateWindowClassesData(WC_SCRIPT_DEBUG); }
Copy link
Member

Choose a reason for hiding this comment

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

Why is this being changed now? Was it missed in #10058?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GS) was missing in #10058
InvalidateWindowClassesData(WC_SCRIPT_DEBUG) is added to supposedly show or hide the debug break box when ai_developer_tools setting change, though the invalidate code doesn't really do that yet.

Copy link
Member

Choose a reason for hiding this comment

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

I'm going to mark the PR as a draft until you resolve that, just so it's clear that it's not ready for review. Once you fix it, you can mark it ready for review again.

@SamuXarick SamuXarick force-pushed the simplify-script-gui-related-functions branch from a02f9a4 to 6cb1ffe Compare March 3, 2023 19:02
Copy link
Member

@2TallTyler 2TallTyler left a comment

Choose a reason for hiding this comment

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

Can I suggest more descriptive commit names? Remember, people looking through the commit history can't see at a glance while files were changed:

  • Codechange: Simplify code in some parts -> Codechange: Simplify script GUI OnClick handlers
  • Fix: Typos -> Fix: Typos in AI and script GUI

src/script/script_gui.cpp Outdated Show resolved Hide resolved
@SamuXarick SamuXarick force-pushed the simplify-script-gui-related-functions branch from 6cb1ffe to 0579bdb Compare March 3, 2023 21:29
@2TallTyler 2TallTyler marked this pull request as draft March 5, 2023 13:52
@2TallTyler 2TallTyler added the work: minor details This Pull Request has some minor details left to do label Mar 5, 2023
@SamuXarick SamuXarick force-pushed the simplify-script-gui-related-functions branch from 0579bdb to bc4d9ce Compare March 10, 2023 15:38
@SamuXarick SamuXarick force-pushed the simplify-script-gui-related-functions branch from bc4d9ce to 100f8b0 Compare March 10, 2023 16:06
@2TallTyler
Copy link
Member

This is a solution in search of a problem. The new code is not any cleaner and doesn't seem more performant. If you can show some data that says otherwise, I'm happy to reopen. 😄

I'd be happy to see a PR of your commit that fixes the typos though, those are always welcome. 😉

@2TallTyler 2TallTyler closed this Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review: Script API Review requested from GS/AI expert work: minor details This Pull Request has some minor details left to do
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants