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

Add game information report and SDL screenshot (#2) #30313

Merged
merged 33 commits into from
May 11, 2019
Merged

Add game information report and SDL screenshot (#2) #30313

merged 33 commits into from
May 11, 2019

Conversation

neitsa
Copy link
Contributor

@neitsa neitsa commented May 8, 2019

Summary

SUMMARY: Features "Add game information report and SDL screenshot."

Purpose of change

(Note: this is a replay of #30244 after having messed up my branch)

Describe the solution

Following Night-Pryanik and DracoGriffin suggestions the debug menu is visible from the main menu under some circumstances:

  • if (and only if) the debug menu has a bound key, then the whole menu is visible from the main menu:

debug_bound_key

  • If the debug menu has no bound key then only a specific portion of the menu is shown:

debug_no_bound_key


  • Add a "Generate Game Report" option in the Debug > Info menu.

The report , as of now, looks like this:

- OS: Windows [64-bit]
- Game Version: 0.D-2546-g2ac90b3f96-dirty
- Graphics Version: Tiles
- Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    Filthy Clothing [filthy_morale],
    Generic Guns [generic_guns],
    Icecoon's Arsenal [ew_pack],
    Modular Turrets [modular_turrets],
    Salvaged Robots [Salvaged_Robots],
    Crazy Cataclysm [crazy_cataclysm],
    Alternative Map Key [alt_map_key],
    Mapgen Demo [mapgen_demo],
    Disable Religious Texts [no_religious_Texts],
    No Fungal Monsters [No_Fungi],
    Classes and Scenarios Mod [more_classes_scenarios],
    Manual Bionic Installation [manualbionicinstall],
    Safe Autodoc [safeautodoc],
    StatsThroughSkills [StatsThroughSkills]
]

Except for the mod list, all the other information are collected through compiler defines, it's obviously not perfect but:

  1. it does not rely on an external lib.
  2. It's almost a no-brainer and doesn't require reinventing the wheel

The above report is written to the debug.log file and in the clipboard (for SDL).


  • Add a "Save screenshot" option in the debug menu.

I intended to do it for bug reporting, but while coding it I thought that taking a screenshot while the process heap might be in a bad shape was a probably bad idea. The code was there so I left it.

The screen shot is basically a copy of the SDL viewport (so, not the screen, just the game view) translated into a PNG. The file is saved into the game save world, into a "screenshots" folder.

So if your current workd is named Amidon the screenshots are in /save/Amidon/screenshots.

The naming scheme of the screenshots is: [<character_name>]_YYYY-MM-DD_HH-MM-SS_<GMT_OFFSET>

So for example:

  • [Julian 'Fish' Willis]_2019-05-04_15-49-08_+0100

The date format is similar to ISO 8601, except for some characters that are replaced because they are not allowed on some file systems.

I also added a function (filesystem.[h,cpp]) that filters possible invalid characters from the player name when building the filename.

Describe alternatives you've considered

N/A.

Additional context

In the end I'd like to do a semi-automatic reporting:

  • include debug.log (with the above game info report)
  • include screenshot at time of crash?
  • include game save file
  • include meaningful stack trace
  • include meaningful dump / core.
  • zip everything

I'd also like to get more information about the system, like the distribution and its version for Unices (e.g. Ubuntu 18.04) and the Major and Minor versions for Windows (e.g. Windows 10 1809).

@ZhilkinSerg ZhilkinSerg self-assigned this May 8, 2019
neitsa added 2 commits May 8, 2019 15:44
- Check if the SDL copy to clipboard function error-ed or not.
- Manual astyle...
@ifreund ifreund added <Enhancement / Feature> New features, or enhancements on existing [C++] Changes (can be) made in C++. Previously named `Code` SDL: Tiles / Sound Tiles visual interface and sounds. labels May 8, 2019
neitsa added 6 commits May 8, 2019 16:31
- Remove check on world validity. The world is already playing at this point.
- Name it take_screenshot() in game.[h; cpp].

- This is the only location where we can access the SDL renderer (except catatiles.cpp but it's really more meaningful in sdltiles.cpp).
@neitsa
Copy link
Contributor Author

neitsa commented May 8, 2019

Integrated all suggestions from #30244. I think it's ready for review now.

@neitsa neitsa marked this pull request as ready for review May 8, 2019 17:00
@neitsa
Copy link
Contributor Author

neitsa commented May 8, 2019

Side note: for an unknown reason both Astyle 3.1 and 3.0.1 (windows binaries) fail to format the very end of the debug_menu.cpp file... I couldn't understand why they both failed and I had to format everything manually.

neitsa added 9 commits May 8, 2019 22:12
- Remove unused header.
- It is fine to have it outside since it returns false if SDL/TILES are not used.
- Otherwise the code in game.cpp can't find it.
- It returns false if TILES is not defined
- Remove obsolete function comment.
- As sdltiles is the only file where the renderer can be accessed, but obviously is only usable when TILES is defined, you can only use save_screenshot() if SDL is defined.

- Make it so that game::take_screenshot() returns false if TILES is not defined.
@neitsa
Copy link
Contributor Author

neitsa commented May 9, 2019

It compiles :) there's an error on a test but this PR didn't touch any core game components.

Copy link
Contributor

@codemime codemime left a comment

Choose a reason for hiding this comment

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

Overall looks good.

src/debug.cpp Outdated Show resolved Hide resolved
src/debug.cpp Outdated
return string_format( "%s [%s]", mod->name(), mod->ident.str() );
} );

auto result = join( mod_names, ",\n " );
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point in the trailing blanks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

4 spaces before the mod name:

- Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    Filthy Clothing [filthy_morale],
    ...
]

It acts like a tabulation but I never liked \t because it looks different depending on the font you use, unless it is a fixed font... A pet peeve of mine.

I prefer to have the mod names with a slight offset, it looks better in my opinion.

src/debug.cpp Outdated Show resolved Hide resolved
src/cata_tiles.cpp Outdated Show resolved Hide resolved
src/cata_tiles.cpp Outdated Show resolved Hide resolved
src/debug.cpp Outdated Show resolved Hide resolved
src/debug_menu.cpp Outdated Show resolved Hide resolved
src/debug.cpp Outdated Show resolved Hide resolved
src/game.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@ZhilkinSerg ZhilkinSerg left a comment

Choose a reason for hiding this comment

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

Some minor style fixups required for consistency with the rest of the code.

neitsa and others added 4 commits May 10, 2019 10:55
Co-Authored-By: ZhilkinSerg <[email protected]>
Co-Authored-By: ZhilkinSerg <[email protected]>
Co-Authored-By: ZhilkinSerg <[email protected]>
Co-Authored-By: ZhilkinSerg <[email protected]>
@neitsa
Copy link
Contributor Author

neitsa commented May 10, 2019

Thank you for your review!

// Get the key for an action, used in the action menu to give each action the
// hotkey it is bound to.
// We ignore bindings to '?' because that will already do something else in
// this menu (open the menu keybindings).
long hotkey_for_action( action_id action )
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't return values properly for function keys, e.g. if debug action is set for F10, hotkey_for_action would return -1, thus rendering debug menu unavailable (tested on Windows with VS and MSYS).

Copy link
Contributor Author

@neitsa neitsa May 10, 2019

Choose a reason for hiding this comment

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

Yep you're right, I can confirm this behavior, functions keys are not understood by keys_bound_to. Hmmm I don't know exactly what should be the next step here...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the check that returns the bound key from keys_bound_to (which returns nothing at the moment):

Cataclysm-DDA/src/input.cpp

Lines 667 to 670 in f2df59c

if( events_event.type == CATA_INPUT_KEYBOARD && events_event.sequence.size() == 1 &&
events_event.sequence.front() < 0xFF && isprint( events_event.sequence.front() ) ) {
result.push_back( static_cast<char>( events_event.sequence.front() ) );
}

The above comparison with F9 bound to the debug menu:

  • events_event.type == CATA_INPUT_KEYBOARD: true
  • events_event.sequence.size() == 1: true
  • events_event.sequence.front() < 0xFF: false (0x111 for F9 for ex.)
  • isprint( events_event.sequence.front(): false (0x111 is not printable)

So technically there's a bound key but the check enforces that it must be a 8-bit key code and be printable...

Is it worth a new function or a patch? should I kill this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can address this in another PR. It is not your fault and this function behavior existed before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok understood! Thanks for your feedback. I'll try to address this in another PR as you suggested. Thank you!

@kevingranade kevingranade merged commit 2ce1bfa into CleverRaven:master May 11, 2019
@ZhilkinSerg ZhilkinSerg removed their assignment May 11, 2019
@neitsa neitsa deleted the feature/game_info branch May 12, 2019 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` <Enhancement / Feature> New features, or enhancements on existing SDL: Tiles / Sound Tiles visual interface and sounds.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide the ability to copy relevant version & config info from game.
5 participants