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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8e20fd6
Replay work.
neitsa May 7, 2019
e23d520
Rework mods_loaded().
neitsa May 8, 2019
8dacccd
Remove function from cata_tiles (moved to game.[h,cpp])
neitsa May 8, 2019
909b702
Add save_screenshot function.
neitsa May 8, 2019
9ca5591
Change ensure_valid_file_name() with actually used parameter.
neitsa May 8, 2019
b0f04ce
[WIP] report and screenshot actual implementation.
neitsa May 8, 2019
812a32c
Astyle game.cpp.
neitsa May 8, 2019
92dc655
Add success and error message for screenshot.
neitsa May 8, 2019
b6eb8d0
Rework all menu options and entries selection.
neitsa May 8, 2019
6628a4f
Pass filename to screenshot function...
neitsa May 8, 2019
8a5028b
Add missing lambda param.
neitsa May 8, 2019
cf26131
Move save_screenshot() to sldtiles.cpp.
neitsa May 8, 2019
2b6dcef
Astyle.
neitsa May 8, 2019
e6d4b03
Move "quit to main menu" to debug only.
neitsa May 8, 2019
a53575a
Add guard for include.
neitsa May 8, 2019
b1698f6
Remove unused function parameters.
neitsa May 8, 2019
567b7d5
get save_screenshot() outside of 'TILES' definition.
neitsa May 8, 2019
fd93c7d
'extern'-ize save_screenshot().
neitsa May 8, 2019
5d1f793
typos.
neitsa May 8, 2019
2d39a0a
The save_screenshot() function can't be guarded by TILES define.
neitsa May 9, 2019
02487e9
Astyle.
neitsa May 9, 2019
382d209
Proper location outside TILES define.
neitsa May 9, 2019
1896f25
Proper location.
neitsa May 9, 2019
3468b89
silence compiler warning.
neitsa May 9, 2019
92a4324
Astyle.
neitsa May 9, 2019
2ba01d3
Linux clang and Apple clang do not agree on required lambda parameter…
neitsa May 9, 2019
a14359d
Fix differing parameter name in declaration and function comment.
neitsa May 10, 2019
0b708b3
Integrate codemime's review.
neitsa May 10, 2019
45ca9fc
Remove unused headers.
neitsa May 10, 2019
69d3cfa
Update src/debug.cpp
neitsa May 10, 2019
e5bb2b1
Update src/debug_menu.cpp
neitsa May 10, 2019
447f33c
Update src/debug.cpp
neitsa May 10, 2019
30d9ab0
Update src/game.cpp
neitsa May 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,6 @@ point get_delta_from_movement_direction( action_id act )
}
}

// 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!

{
auto is_valid_key = []( char key ) {
Expand Down Expand Up @@ -930,6 +926,7 @@ action_id handle_main_menu()
REGISTER_ACTION( ACTION_ACTIONMENU );
REGISTER_ACTION( ACTION_QUICKSAVE );
REGISTER_ACTION( ACTION_SAVE );
REGISTER_ACTION( ACTION_DEBUG );

int width = 0;
for( auto &entry : entries ) {
Expand Down
8 changes: 8 additions & 0 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ void load_keyboard_settings( std::map<char, action_id> &keymap,
*/
std::vector<char> keys_bound_to( action_id act );

/**
* Get the key for an action, used in the action menu to give each action the hotkey it is bound to.
* @param action Action ID to lookup in keymap.
* @returns the key code for the hotkey or -1 if no key is associated with the given action.
* @note 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 );

/**
* Lookup an action ID by its unique string identifier
*
Expand Down
97 changes: 97 additions & 0 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "color.h"
#include "optional.h"
#include "translations.h"
#include "worldfactory.h"
#include "mod_manager.h"

#if !defined(_MSC_VER)
#include <sys/time.h>
Expand Down Expand Up @@ -777,4 +779,99 @@ std::ostream &DebugLog( DebugLevel lev, DebugClass cl )
return nullStream;
}

std::string game_info::operating_system()
{
#if defined(__ANDROID__)
return "Android";
#elif defined(_WIN32)
return "Windows";
#elif defined(__linux__)
return "Linux";
#elif defined(unix) || defined(__unix__) || defined(__unix) || defined(__APPLE__) && defined(__MACH__) // unix; BSD; MacOs
#if defined(__APPLE__) && defined(__MACH__)
// The following include is **only** needed for the TARGET_xxx defines below and is only included if both of the above defines are true.
// The whole function only relying on compiler defines, it is probably more meaningful to include it here and not mingle with the
// headers at the top of the .cpp file.
#include <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR == 1
/* iOS in Xcode simulator */
return "iOS Simulator";
#elif TARGET_OS_IPHONE == 1
/* iOS on iPhone, iPad, etc. */
return "iOS";
#elif TARGET_OS_MAC == 1
/* OSX */
return "MacOs";
#endif // TARGET_IPHONE_SIMULATOR
#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
return "BSD";
#else
return "Unix";
#endif // __APPLE__
#else
return "Unknown";
#endif
}

std::string game_info::bitness()
{
if( sizeof( void * ) == 8 ) {
return "64-bit";
}

if( sizeof( void * ) == 4 ) {
return "32-bit";
}

return "Unknown";
}

std::string game_info::game_version()
{
return getVersionString();
}

std::string game_info::graphics_version()
{
#if defined(TILES)
return "Tiles";
#else
return "Curses";
#endif
}

std::string game_info::mods_loaded()
{
if( world_generator->active_world == nullptr ) {
return "No active world";
}

const std::vector<mod_id> &mod_ids = world_generator->active_world->active_mod_order;
if( mod_ids.empty() ) {
return "No loaded mods";
}

std::vector<std::string> mod_names;
mod_names.reserve( mod_ids.size() );
std::transform( mod_ids.begin(), mod_ids.end(),
std::back_inserter( mod_names ), []( const mod_id mod ) -> std::string {
// e.g. "Dark Days Ahead [dda]".
return string_format( "%s [%s]", mod->name(), mod->ident.str() );
} );

return join( mod_names, ",\n " ); // note: 4 spaces for a slight offset.
}

std::string game_info::game_report()
{
std::stringstream report;
report <<
"- OS: " << operating_system() << " [" << bitness() << "]\n" <<
"- Game Version: " << game_version() << "\n" <<
"- Graphics Version: " << graphics_version() << "\n" <<
"- Mods loaded: [\n " << mods_loaded() << "\n]\n";

return report.str();
}

// vim:tw=72:sw=4:fdm=marker:fdl=0:
25 changes: 25 additions & 0 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ inline void realDebugmsg( const char *const filename, const char *const line,
std::forward<Args>( args )... ) );
}

/**
* Used to generate game report information.
*/
namespace game_info
{
/** Return the name of the current operating system.
*/
std::string operating_system();
/** Return the "bitness" of the game (not necessarily of the operating system); either: 64-bit, 32-bit or Unknown.
*/
std::string bitness();
/** Return the game version, as in the entry screen.
*/
std::string game_version();
/** Return the underlying graphics version used by the game; either Tiles or Curses.
*/
std::string graphics_version();
/** Return a list of the loaded mods, including the mod full name and its id name in brackets, e.g. "Dark Days Ahead [dda]".
*/
std::string mods_loaded();
/** Generate a game report, including the information returned by all of the other functions.
*/
std::string game_report();
};

// Enumerations {{{1
// ---------------------------------------------------------------------

Expand Down
Loading