Skip to content

Commit

Permalink
Add current video settings to the game_config::full_build_report.
Browse files Browse the repository at this point in the history
Backport of 11f96b3
  • Loading branch information
Pentarctagon committed Jun 9, 2020
1 parent bcabb9d commit 7a5361d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/build_info.cpp
Expand Up @@ -22,6 +22,7 @@
#include "formatter.hpp"
#include "gettext.hpp"
#include "serialization/unicode.hpp"
#include "video.hpp"

#include <algorithm>
#include <fstream>
Expand Down Expand Up @@ -481,7 +482,11 @@ std::string full_build_report()
<< '\n'
<< report_heading("Features")
<< '\n'
<< game_config::optional_features_report();
<< game_config::optional_features_report()
<< '\n'
<< report_heading("Current video settings")
<< '\n'
<< CVideo::video_settings_report();

return o.str();
}
Expand Down
25 changes: 25 additions & 0 deletions src/video.cpp
Expand Up @@ -132,6 +132,31 @@ CVideo::~CVideo()
LOG_DP << "called SDL_Quit()\n";
}

std::string CVideo::video_settings_report()
{
if (singleton_ == nullptr) return "No video initialized.\n";
if (singleton_->non_interactive())
return "Initialized but non-interactive.\n";
sdl::window* win = singleton_->get_window();
if (!win) return "Interactive but no SDL window.\n";
std::ostringstream o;
o << "Current pixel resolution: "
<< singleton_->get_width() << "x" << singleton_->get_height()
<< '\n'
<< "Refresh rate: " << singleton_->current_refresh_rate()
<< '\n';
float hdpi, vdpi;
int returncode = SDL_GetDisplayDPI(win->get_display_index(),
nullptr, &hdpi, &vdpi);
if (returncode != 0) {
o << "SDL not supplying dots per inch.\n";
} else {
o << "SDL reports: " << hdpi << "x" << vdpi
<< " dots per inch.\n";
}
return o.str();
}

bool CVideo::non_interactive() const
{
return fake_interactive ? false : (window == nullptr);
Expand Down
2 changes: 2 additions & 0 deletions src/video.hpp
Expand Up @@ -45,6 +45,8 @@ class CVideo
return *singleton_;
}

static std::string video_settings_report();

/***** ***** ***** ***** Unit test-related functions ***** ***** ****** *****/

void make_fake();
Expand Down

0 comments on commit 7a5361d

Please sign in to comment.