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

src/debug_menu.cpp: split functions from void debug() #73428

Merged
merged 1 commit into from
May 3, 2024

Conversation

Brambor
Copy link
Contributor

@Brambor Brambor commented May 1, 2024

Summary

None

Purpose of change

#73400 failed because void debug() is too long (among other things)
https://github.com/CleverRaven/Cataclysm-DDA/actions/runs/8889143243/job/24407971501?pr=73400#step:9:938

Make the void debug() considerably shorter so the next person does not have to deal with this when they are nice enough to add something to the debug menu.

Describe the solution

Made a simple Python function

my_str = ""  # Paste the huge case statement here

split_by = "\n        case"
res = []
for case in my_str.split(split_by):
	lines = case.splitlines()
	res.append((len(lines), lines[0]))
res.sort()
running_total = 0
for r in res:
	running_total += r[0]
	print(r, running_total)

and ran it on the huge switch in the debug menu. It shows the biggest case statements (by line count), output:

(...)
(12, ' debug_menu_index::REVEAL_MAP: {') 293
(14, ' debug_menu_index::ACTIVATE_EOC: {') 307
(14, ' debug_menu_index::PRINT_FACTION_INFO: {') 321
(14, ' debug_menu_index::QUICK_SETUP: {') 335
(14, ' debug_menu_index::VEHICLE_DELETE: {') 349
(14, ' debug_menu_index::WRITE_TIMED_EVENTS: {') 363
# Solved the below
(15, ' debug_menu_index::GENERATE_EFFECT_LIST:') 378
(15, ' debug_menu_index::WRITE_CITY_LIST: {') 393
(15, ' debug_menu_index::WRITE_GLOBAL_VARS: {') 408
(16, ' debug_menu_index::UNLOCK_ALL:') 424
(17, ' debug_menu_index::EDIT_GLOBAL_VARS: {') 441
(17, ' debug_menu_index::SET_AUTOMOVE: {') 458
(18, ' debug_menu_index::GAME_REPORT: {') 476
(19, ' debug_menu_index::GEN_SOUND: {') 495
(19, ' debug_menu_index::SPAWN_NPC: {') 514
(20, ' debug_menu_index::MAP_EXTRA: {') 534
(21, ' debug_menu_index::PRINT_NPC_MAGIC: {') 555
(21, ' debug_menu_index::WIND_DIRECTION: {') 576
(23, ' debug_menu_index::WIND_SPEED: {') 599
(24, ' debug_menu_index::SHOW_SOUND: {') 623
(24, ' debug_menu_index::VEHICLE_BATTERY_CHARGE: {') 647
(26, ' debug_menu_index::DAMAGE_SELF: {') 673
(26, ' debug_menu_index::VEHICLE_EXPORT: {') 699
(30, ' debug_menu_index::CHANGE_WEATHER: {') 729
(32, ' debug_menu_index::IMPORT_FOLLOWER: {') 761
(36, ' debug_menu_index::KILL_AREA: {') 797
(38, ' debug_menu_index::BLEED_SELF: {') 835

Then I made these cases into static void functions starting at the bottom of this list and making my way up. It is a straightforward task, the only changes are fixing aliases: player_character for get_avatar(), and here for get_map() and return in one case.

This PR is refactoring, except for debug_menu_index::GEN_SOUND, which doesn't return from the void debug() function, so it runs here.invalidate_map_cache( here.get_abs_sub().z() ); on last line.

Describe alternatives you've considered

Do more or less. Ask, whether this is a correct solution before doing it.

Testing

  • Compile.
  • Run the game.
  • Check (some of) the debug functions. They still work.
    • sound still works image

Additional context

this is refactoring, except for `debug_menu_index::GEN_SOUND`,
which doesn't return from the `void debug()` function,
so it runs `here.invalidate_map_cache( here.get_abs_sub().z() );` on last line.
@github-actions github-actions bot added the [C++] Changes (can be) made in C++. Previously named `Code` label May 1, 2024
@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) labels May 1, 2024
@Brambor
Copy link
Contributor Author

Brambor commented May 1, 2024

Clang tidy test was fixed in

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label May 1, 2024
@akrieger akrieger merged commit 4cffe59 into CleverRaven:master May 3, 2024
45 of 55 checks passed
@Brambor Brambor deleted the debug-split branch May 3, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants