Merge branch 'render_imagepath'

This commit is contained in:
Chris Beck 2014-10-22 18:32:37 -04:00
commit 7ade343718
7 changed files with 52 additions and 1 deletions

View file

@ -178,6 +178,7 @@ commandline_options::commandline_options ( int argc, char** argv ) :
("nomusic", "runs the game without music.")
("nosound", "runs the game without sounds and music.")
("path", "prints the path to the data directory and exits.")
("render-image", po::value<two_strings>()->multitoken(), "takes two arguments: <image> <output>. Like screenshot, but instead of a map, takes a valid wesnoth 'image path string' with image path functions, and outputs to a windows .bmp file")
("rng-seed", po::value<unsigned int>(), "seeds the random number generator with number <arg>. Example: --rng-seed 0")
("screenshot", po::value<two_strings>()->multitoken(), "takes two arguments: <map> <output>. Saves a screenshot of <map> to <output> without initializing a screen. Editor must be compiled in for this to work.")
("server,s", po::value<std::string>()->implicit_value(std::string()), "connects to the host <arg> if specified or to the first host in your preferences.")
@ -410,6 +411,11 @@ commandline_options::commandline_options ( int argc, char** argv ) :
rng_seed = vm["rng-seed"].as<unsigned int>();
if (vm.count("scenario"))
multiplayer_scenario = vm["scenario"].as<std::string>();
if (vm.count("render-image"))
{
render_image = vm["render-image"].as<two_strings>().get<0>();
render_image_dst = vm["render-image"].as<two_strings>().get<1>();
}
if (vm.count("screenshot"))
{
screenshot = true;

View file

@ -170,6 +170,10 @@ public:
boost::optional<std::string> username;
/// Non-empty if --password was given on the command line. Forces Wesnoth to use this network password.
boost::optional<std::string> password;
/// Image path to render. First parameter after --render-image
boost::optional<std::string> render_image;
/// Output file to put rendered image path in. Optional second parameter after --render-image
boost::optional<std::string> render_image_dst;
/// True if --screenshot was given on the command line. Starts Wesnoth in screenshot mode.
bool screenshot;
/// Map file to make a screenshot of. First parameter given after --screenshot.

View file

@ -566,6 +566,34 @@ bool game_launcher::play_screenshot_mode()
return false;
}
bool game_launcher::play_render_image_mode()
{
if(!cmdline_opts_.render_image) {
return true;
}
state_.classification().campaign_type = game_classification::MULTIPLAYER;
DBG_GENERAL << "Current campaign type: " << state_.classification().campaign_type << std::endl;
try {
resources::config_manager->
load_game_config_for_game(state_.classification());
} catch(config::error& e) {
std::cerr << "Error loading game config: " << e.what() << std::endl;
return false;
}
std::string outfile = cmdline_opts_.render_image->substr(0, std::min(8ul,cmdline_opts_.render_image->length())) + ".bmp";
if (cmdline_opts_.render_image_dst) {
outfile = *cmdline_opts_.render_image_dst;
}
image::save_image(*cmdline_opts_.render_image, outfile);
return false;
}
bool game_launcher::is_loading() const
{
return !game::load_game_exception::game.empty();

View file

@ -65,6 +65,7 @@ public:
bool play_test();
bool play_screenshot_mode();
bool play_render_image_mode();
int unit_test();
bool is_loading() const;

View file

@ -1190,6 +1190,12 @@ bool precached_file_exists(const std::string& file)
return false;
}
void save_image(const locator & i_locator, const std::string & filename)
{
surface surf = get_image(i_locator);
SDL_SaveBMP(surf, filename.c_str());
}
std::string describe_versions()
{
std::stringstream ss;

View file

@ -249,6 +249,8 @@ namespace image {
bool precached_file_exists(const std::string& file);
std::string describe_versions();
void save_image(const locator& i_locator, const std::string& outfile);
}
#endif

View file

@ -431,7 +431,7 @@ static int process_command_args(const commandline_options& cmdline_opts) {
if(cmdline_opts.rng_seed) {
srand(*cmdline_opts.rng_seed);
}
if(cmdline_opts.screenshot) {
if(cmdline_opts.screenshot || cmdline_opts.render_image) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_setenv("SDL_VIDEODRIVER", "dummy", 1);
#else
@ -643,6 +643,10 @@ static int do_gameloop(int argc, char** argv)
return 0;
}
if(game->play_render_image_mode() == false) {
return 0;
}
recorder.clear();
//Start directly a campaign