The Battle for Wesnoth  1.15.7+dev
wesnoth.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "addon/manager.hpp"
16 #include "build_info.hpp"
17 #include "commandline_argv.hpp"
18 #include "commandline_options.hpp" // for commandline_options, etc
19 #include "config.hpp" // for config, config::error, etc
20 #include "cursor.hpp" // for set, CURSOR_TYPE::NORMAL, etc
21 #include "editor/editor_main.hpp"
22 #include "filesystem.hpp" // for filesystem::file_exists, filesystem::io_exception, etc
23 #include "floating_label.hpp"
24 #include "font/error.hpp" // for error
25 #include "font/font_config.hpp" // for load_font_config, etc
26 #include "formula/formula.hpp" // for formula_error
27 #include "game_config.hpp" // for path, debug, debug_lua, etc
28 #include "game_config_manager.hpp" // for game_config_manager, etc
29 #include "game_end_exceptions.hpp"
30 #include "game_launcher.hpp" // for game_launcher, etc
31 #include "gettext.hpp"
32 #include "gui/core/event/handler.hpp" // for tmanager
35 #include "gui/dialogs/message.hpp" // for show_error_message
36 #include "gui/dialogs/title_screen.hpp" // for title_screen, etc
37 #include "gui/gui.hpp" // for init
38 #include "picture.hpp" // for flush_cache, etc
39 #include "log.hpp" // for LOG_STREAM, general, logger, etc
40 #include "preferences/general.hpp" // for core_id, etc
44 #include "sdl/exception.hpp" // for exception
45 #include "sdl/rect.hpp"
46 #include "serialization/binary_or_text.hpp" // for config_writer
47 #include "serialization/parser.hpp" // for read
48 #include "serialization/preprocessor.hpp" // for preproc_define, etc
50 #include "serialization/schema_validator.hpp" // for strict_validation_enabled and schema_validator
51 #include "sound.hpp" // for commit_music_changes, etc
52 #include "statistics.hpp" // for fresh_stats
53 #include "utils/functional.hpp"
54 #include "game_version.hpp" // for version_info
55 #include "video.hpp" // for CVideo
56 #include "wesconfig.h" // for PACKAGE
57 #include "widgets/button.hpp" // for button
58 #include "wml_exception.hpp" // for wml_exception
59 
60 #ifdef _WIN32
61 #include "log_windows.hpp"
62 
63 #include <float.h>
64 #endif // _WIN32
65 
66 #ifndef _MSC_VER
67 #include <fenv.h>
68 #endif // _MSC_VER
69 
70 #include <SDL2/SDL.h> // for SDL_Init, SDL_INIT_TIMER
71 
72 #include <boost/iostreams/categories.hpp> // for input, output
73 #include <boost/iostreams/copy.hpp> // for copy
74 #include <boost/iostreams/filter/bzip2.hpp> // for bzip2_compressor, etc
75 
76 #if defined(_MSC_VER)
77 #pragma warning(push)
78 #pragma warning(disable : 4456)
79 #pragma warning(disable : 4458)
80 #endif
81 
82 #include <boost/iostreams/filter/gzip.hpp> // for gzip_compressor, etc
83 
84 #if defined(_MSC_VER)
85 #pragma warning(pop)
86 #endif
87 
88 #include <boost/iostreams/filtering_stream.hpp> // for filtering_stream
89 #include <boost/program_options/errors.hpp> // for error
90 
91 #include <algorithm> // for transform
92 #include <cerrno> // for ENOMEM
93 #include <clocale> // for setlocale, LC_ALL, etc
94 #include <cstdio> // for remove, fprintf, stderr
95 #include <cstdlib> // for srand, exit
96 #include <ctime> // for time, ctime, std::time_t
97 #include <exception> // for exception
98 #include <fstream> // for operator<<, basic_ostream, etc
99 #include <iostream> // for cerr, cout
100 #include <vector>
101 
102 //#define NO_CATCH_AT_GAME_END
103 
104 #ifdef _WIN32
105 
106 #ifdef INADDR_ANY
107 #undef INADDR_ANY
108 #endif
109 
110 #ifdef INADDR_BROADCAST
111 #undef INADDR_BROADCAST
112 #endif
113 
114 #ifdef INADDR_NONE
115 #undef INADDR_NONE
116 #endif
117 
118 #include <windows.h>
119 
120 #endif // _WIN32
121 
122 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
123 #include "gui/widgets/debug.hpp"
124 #endif
125 
126 class end_level_exception;
127 namespace game
128 {
129 struct error;
130 }
131 
132 static lg::log_domain log_config("config");
133 #define LOG_CONFIG LOG_STREAM(info, log_config)
134 
135 #define LOG_GENERAL LOG_STREAM(info, lg::general())
136 
137 static lg::log_domain log_preprocessor("preprocessor");
138 #define LOG_PREPROC LOG_STREAM(info, log_preprocessor)
139 
140 // this is needed to allow identical functionality with clean refactoring
141 // play_game only returns on an error, all returns within play_game can
142 // be replaced with this
143 static void safe_exit(int res)
144 {
145  LOG_GENERAL << "exiting with code " << res << "\n";
146  exit(res);
147 }
148 
149 // maybe this should go in a util file somewhere?
150 template<typename filter>
151 static void encode(const std::string& input_file, const std::string& output_file)
152 {
153  try {
154  std::ifstream ifile(input_file.c_str(), std::ios_base::in | std::ios_base::binary);
155  ifile.peek(); // We need to touch the stream to set the eof bit
156 
157  if(!ifile.good()) {
158  std::cerr << "Input file " << input_file
159  << " is not good for reading. Exiting to prevent bzip2 from segfaulting\n";
160  safe_exit(1);
161  }
162 
163  std::ofstream ofile(output_file.c_str(), std::ios_base::out | std::ios_base::binary);
164 
165  boost::iostreams::filtering_stream<boost::iostreams::output> stream;
166  stream.push(filter());
167  stream.push(ofile);
168 
169  boost::iostreams::copy(ifile, stream);
170  ifile.close();
171 
172  safe_exit(remove(input_file.c_str()));
173  } catch(const filesystem::io_exception& e) {
174  std::cerr << "IO error: " << e.what() << "\n";
175  }
176 }
177 
178 template<typename filter>
179 static void decode(const std::string& input_file, const std::string& output_file)
180 {
181  try {
182  std::ofstream ofile(output_file.c_str(), std::ios_base::out | std::ios_base::binary);
183  std::ifstream ifile(input_file.c_str(), std::ios_base::in | std::ios_base::binary);
184 
185  boost::iostreams::filtering_stream<boost::iostreams::input> stream;
186  stream.push(filter());
187  stream.push(ifile);
188 
189  boost::iostreams::copy(stream, ofile);
190  ifile.close();
191 
192  safe_exit(remove(input_file.c_str()));
193  } catch(const filesystem::io_exception& e) {
194  std::cerr << "IO error: " << e.what() << "\n";
195  }
196 }
197 
198 static void gzip_encode(const std::string& input_file, const std::string& output_file)
199 {
200  encode<boost::iostreams::gzip_compressor>(input_file, output_file);
201 }
202 
203 static void gzip_decode(const std::string& input_file, const std::string& output_file)
204 {
205  decode<boost::iostreams::gzip_decompressor>(input_file, output_file);
206 }
207 
208 static void bzip2_encode(const std::string& input_file, const std::string& output_file)
209 {
210  encode<boost::iostreams::bzip2_compressor>(input_file, output_file);
211 }
212 
213 static void bzip2_decode(const std::string& input_file, const std::string& output_file)
214 {
215  decode<boost::iostreams::bzip2_decompressor>(input_file, output_file);
216 }
217 
218 static void handle_preprocess_command(const commandline_options& cmdline_opts)
219 {
220  preproc_map input_macros;
221 
222  if(cmdline_opts.preprocess_input_macros) {
223  std::string file = *cmdline_opts.preprocess_input_macros;
224  if(filesystem::file_exists(file) == false) {
225  std::cerr << "please specify an existing file. File " << file << " doesn't exist.\n";
226  return;
227  }
228 
229  std::cerr << SDL_GetTicks() << " Reading cached defines from: " << file << "\n";
230 
231  config cfg;
232 
233  try {
235  read(cfg, *stream);
236  } catch(const config::error& e) {
237  std::cerr << "Caught a config error while parsing file '" << file << "':\n" << e.message << std::endl;
238  }
239 
240  int read = 0;
241 
242  // use static preproc_define::read_pair(config) to make a object
243  for(const config::any_child& value : cfg.all_children_range()) {
244  const preproc_map::value_type def = preproc_define::read_pair(value.cfg);
245  input_macros[def.first] = def.second;
246  ++read;
247  }
248 
249  std::cerr << SDL_GetTicks() << " Read " << read << " defines.\n";
250  }
251 
252  const std::string resourceToProcess(*cmdline_opts.preprocess_path);
253  const std::string targetDir(*cmdline_opts.preprocess_target);
254 
255  uint32_t startTime = SDL_GetTicks();
256 
257  // If the users add the SKIP_CORE define we won't preprocess data/core
258  bool skipCore = false;
259  bool skipTerrainGFX = false;
260 
261  // The 'core_defines_map' is the one got from data/core macros
262  preproc_map defines_map(input_macros);
263 
264  if(cmdline_opts.preprocess_defines) {
265  // add the specified defines
266  for(const std::string& define : *cmdline_opts.preprocess_defines) {
267  if(define.empty()) {
268  std::cerr << "empty define supplied\n";
269  continue;
270  }
271 
272  LOG_PREPROC << "adding define: " << define << '\n';
273  defines_map.emplace(define, preproc_define(define));
274 
275  if(define == "SKIP_CORE") {
276  std::cerr << "'SKIP_CORE' defined.\n";
277  skipCore = true;
278  } else if(define == "NO_TERRAIN_GFX") {
279  std::cerr << "'NO_TERRAIN_GFX' defined." << std::endl;
280  skipTerrainGFX = true;
281  }
282  }
283  }
284 
285  // add the WESNOTH_VERSION define
286  defines_map["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str());
287 
288  std::cerr << "added " << defines_map.size() << " defines.\n";
289 
290  // preprocess core macros first if we don't skip the core
291  if(skipCore == false) {
292  std::cerr << "preprocessing common macros from 'data/core' ...\n";
293 
294  // process each folder explicitly to gain speed
295  preprocess_resource(game_config::path + "/data/core/macros", &defines_map);
296 
297  if(skipTerrainGFX == false) {
298  preprocess_resource(game_config::path + "/data/core/terrain-graphics", &defines_map);
299  }
300 
301  std::cerr << "acquired " << (defines_map.size() - input_macros.size()) << " 'data/core' defines.\n";
302  } else {
303  std::cerr << "skipped 'data/core'\n";
304  }
305 
306  // preprocess resource
307  std::cerr << "preprocessing specified resource: " << resourceToProcess << " ...\n";
308 
309  preprocess_resource(resourceToProcess, &defines_map, true, true, targetDir);
310  std::cerr << "acquired " << (defines_map.size() - input_macros.size()) << " total defines.\n";
311 
312  if(cmdline_opts.preprocess_output_macros) {
313  std::string outputFileName = "_MACROS_.cfg";
314  if(!cmdline_opts.preprocess_output_macros->empty()) {
315  outputFileName = *cmdline_opts.preprocess_output_macros;
316  }
317 
318  std::string outputPath = targetDir + "/" + outputFileName;
319 
320  std::cerr << "writing '" << outputPath << "' with " << defines_map.size() << " defines.\n";
321 
323  if(!out->fail()) {
324  config_writer writer(*out, false);
325 
326  for(auto& define_pair : defines_map) {
327  define_pair.second.write(writer, define_pair.first);
328  }
329  } else {
330  std::cerr << "couldn't open the file.\n";
331  }
332  }
333 
334  std::cerr << "preprocessing finished. Took " << SDL_GetTicks() - startTime << " ticks.\n";
335 }
336 
337 static int handle_validate_command(const std::string& file, abstract_validator& validator, const std::vector<std::string>& defines) {
338  preproc_map defines_map;
339  for(const std::string& define : defines) {
340  if(define.empty()) {
341  std::cerr << "empty define supplied\n";
342  continue;
343  }
344 
345  LOG_PREPROC << "adding define: " << define << '\n';
346  defines_map.emplace(define, preproc_define(define));
347  }
348  std::cout << "Validating " << file << " against schema " << validator.name_ << std::endl;
350  filesystem::scoped_istream stream = preprocess_file(file, &defines_map);
351  config result;
352  read(result, *stream, &validator);
353  if(lg::broke_strict()) {
354  std::cout << "validation failed\n";
355  } else {
356  std::cout << "validation succeeded\n";
357  }
358  return lg::broke_strict();
359 }
360 
361 /** Process commandline-arguments */
362 static int process_command_args(const commandline_options& cmdline_opts)
363 {
364  // Options that don't change behavior based on any others should be checked alphabetically below.
365 
366  if(cmdline_opts.log) {
367  for(const auto& log_pair : cmdline_opts.log.value()) {
368  const std::string log_domain = log_pair.second;
369  const int severity = log_pair.first;
370  if(!lg::set_log_domain_severity(log_domain, severity)) {
371  std::cerr << "unknown log domain: " << log_domain << '\n';
372  return 2;
373  }
374  }
375  }
376 
377  if(cmdline_opts.userconfig_dir) {
379  }
380 
381  if(cmdline_opts.userconfig_path) {
382  std::cout << filesystem::get_user_config_dir() << '\n';
383  return 0;
384  }
385 
386  if(cmdline_opts.userdata_dir) {
388  }
389 
390  if(cmdline_opts.userdata_path) {
391  std::cout << filesystem::get_user_data_dir() << '\n';
392  return 0;
393  }
394 
395  if(cmdline_opts.data_dir) {
396  const std::string datadir = *cmdline_opts.data_dir;
397 #ifdef _WIN32
398  // use c_str to ensure that index 1 points to valid element since c_str() returns null-terminated string
399  if(datadir.c_str()[1] == ':') {
400 #else
401  if(datadir[0] == '/') {
402 #endif
403  game_config::path = datadir;
404  } else {
405  game_config::path = filesystem::get_cwd() + '/' + datadir;
406  }
407 
409  std::cerr << "Overriding data directory with " << game_config::path << std::endl;
410 
412  std::cerr << "Could not find directory '" << game_config::path << "'\n";
413  throw config::error("directory not found");
414  }
415 
416  // don't update font as we already updating it in game ctor
417  // font_manager_.update_font_path();
418  }
419 
420  if(cmdline_opts.data_path) {
421  std::cout << game_config::path << '\n';
422  return 0;
423  }
424 
425  if(cmdline_opts.debug_lua) {
426  game_config::debug_lua = true;
427  }
428 
429  if(cmdline_opts.gunzip) {
430  const std::string input_file(*cmdline_opts.gunzip);
431  if(!filesystem::is_gzip_file(input_file)) {
432  std::cerr << "file '" << input_file << "'isn't a .gz file\n";
433  return 2;
434  }
435 
436  const std::string output_file(input_file, 0, input_file.length() - 3);
437  gzip_decode(input_file, output_file);
438  }
439 
440  if(cmdline_opts.bunzip2) {
441  const std::string input_file(*cmdline_opts.bunzip2);
442  if(!filesystem::is_bzip2_file(input_file)) {
443  std::cerr << "file '" << input_file << "'isn't a .bz2 file\n";
444  return 2;
445  }
446 
447  const std::string output_file(input_file, 0, input_file.length() - 4);
448  bzip2_decode(input_file, output_file);
449  }
450 
451  if(cmdline_opts.gzip) {
452  const std::string input_file(*cmdline_opts.gzip);
453  const std::string output_file(*cmdline_opts.gzip + ".gz");
454  gzip_encode(input_file, output_file);
455  }
456 
457  if(cmdline_opts.bzip2) {
458  const std::string input_file(*cmdline_opts.bzip2);
459  const std::string output_file(*cmdline_opts.bzip2 + ".bz2");
460  bzip2_encode(input_file, output_file);
461  }
462 
463  if(cmdline_opts.help) {
464  std::cout << cmdline_opts;
465  return 0;
466  }
467 
468  if(cmdline_opts.logdomains) {
469  std::cout << lg::list_logdomains(*cmdline_opts.logdomains);
470  return 0;
471  }
472 
473  if(cmdline_opts.log_precise_timestamps) {
475  }
476 
477  if(cmdline_opts.rng_seed) {
478  srand(*cmdline_opts.rng_seed);
479  }
480 
481  if(cmdline_opts.screenshot || cmdline_opts.render_image) {
482  SDL_setenv("SDL_VIDEODRIVER", "dummy", 1);
483  }
484 
485  if(cmdline_opts.strict_validation) {
487  }
488 
489  if(cmdline_opts.version) {
490  std::cout << "Battle for Wesnoth" << " " << game_config::wesnoth_version.str() << "\n\n";
491  std::cout << "Library versions:\n" << game_config::library_versions_report() << '\n';
492  std::cout << "Optional features:\n" << game_config::optional_features_report();
493 
494  return 0;
495  }
496 
497  if(cmdline_opts.report) {
498  std::cout << "\n========= BUILD INFORMATION =========\n\n" << game_config::full_build_report();
499  return 0;
500  }
501 
502  if(cmdline_opts.validate_schema) {
504  validator.set_create_exceptions(false); // Don't crash if there's an error, just go ahead anyway
505  return handle_validate_command(*cmdline_opts.validate_schema, validator, {});
506  }
507 
508  if(cmdline_opts.do_diff) {
509  config left, right;
510  std::ifstream in_left(cmdline_opts.diff_left);
511  std::ifstream in_right(cmdline_opts.diff_right);
512  read(left, in_left);
513  read(right, in_right);
514  std::ostream* os = &std::cout;
515  if(cmdline_opts.output_file) {
516  os = new std::ofstream(*cmdline_opts.output_file);
517  }
519  out.write(right.get_diff(left));
520  if(os != &std::cout) delete os;
521  return 0;
522  }
523 
524  if(cmdline_opts.do_patch) {
525  config base, diff;
526  std::ifstream in_base(cmdline_opts.diff_left);
527  std::ifstream in_diff(cmdline_opts.diff_right);
528  read(base, in_base);
529  read(diff, in_diff);
530  base.apply_diff(diff);
531  std::ostream* os = &std::cout;
532  if(cmdline_opts.output_file) {
533  os = new std::ofstream(*cmdline_opts.output_file);
534  }
536  out.write(base);
537  if(os != &std::cout) delete os;
538  return 0;
539  }
540 
541  // Options changing their behavior dependent on some others should be checked below.
542 
543  if(cmdline_opts.preprocess) {
544  handle_preprocess_command(cmdline_opts);
545  return 0;
546  }
547 
548  if(cmdline_opts.validate_wml) {
549  std::string schema_path;
550  if(cmdline_opts.validate_with) {
551  schema_path = *cmdline_opts.validate_with;
552  } else {
553  schema_path = filesystem::get_wml_location("schema/game_config.cfg");
554  }
555  schema_validation::schema_validator validator(schema_path);
556  validator.set_create_exceptions(false); // Don't crash if there's an error, just go ahead anyway
557  return handle_validate_command(*cmdline_opts.validate_wml, validator,
558  cmdline_opts.preprocess_defines.value_or<decltype(cmdline_opts.preprocess_defines)::value_type>({}));
559  }
560 
561  if(cmdline_opts.preprocess_defines || cmdline_opts.preprocess_input_macros || cmdline_opts.preprocess_path) {
562  // It would be good if this was supported for running tests too, possibly for other uses.
563  // For the moment show an error message instead of leaving the user wondering why it doesn't work.
564  std::cerr << "That --preprocess-* option is only supported when using --preprocess or --validate-wml.\n";
565  // Return an error status other than -1, because in our caller -1 means no error
566  return -2;
567  }
568 
569  // Not the most intuitive solution, but I wanted to leave current semantics for now
570  return -1;
571 }
572 
573 /**
574  * I would prefer to setup locale first so that early error
575  * messages can get localized, but we need the game_launcher
576  * initialized to have filesystem::get_intl_dir() to work. Note: setlocale()
577  * does not take GUI language setting into account.
578  */
579 static void init_locale()
580 {
581 #if defined _WIN32 || defined __APPLE__
582  setlocale(LC_ALL, "English");
583 #else
584  std::setlocale(LC_ALL, "C");
585 #endif
586 
587  const std::string& intl_dir = filesystem::get_intl_dir();
588 
589  translation::bind_textdomain(PACKAGE, intl_dir.c_str(), "UTF-8");
590  translation::bind_textdomain(PACKAGE "-lib", intl_dir.c_str(), "UTF-8");
592 }
593 
594 /**
595  * Print an alert and instructions to stderr about early initialization errors.
596  *
597  * This is provided as an aid for users dealing with potential data dir
598  * configuration issues. The first code to read core WML *has* the
599  * responsibility to call this function in the event of a problem, to inform
600  * the user of the most likely possible cause and suggest a course of action
601  * to solve the issue.
602  */
604 {
605  // NOTE: wrap output to 80 columns.
606  std::cerr << '\n'
607  << "An error at this point during initialization usually indicates that the data\n"
608  << "directory above was not correctly set or detected. Try passing the correct path\n"
609  << "in the command line with the --data-dir switch or as the only argument.\n";
610 }
611 
612 /**
613  * Handles the lua script command line arguments if present.
614  * This function will only run once.
615  */
617 {
618  static bool first_time = true;
619 
620  if(!first_time) {
621  return;
622  }
623 
624  first_time = false;
625 
626  if(!game->init_lua_script()) {
627  // std::cerr << "error when loading lua scripts at startup\n";
628  // std::cerr << "could not load lua script: " << *cmdline_opts.script_file << std::endl;
629  }
630 }
631 
632 #ifdef _MSC_VER
633 static void check_fpu()
634 {
635  uint32_t f_control;
636 
637  if(_controlfp_s(&f_control, 0, 0) == 0) {
638  uint32_t unused;
639  uint32_t rounding_mode = f_control & _MCW_RC;
640  uint32_t precision_mode = f_control & _MCW_PC;
641 
642  if(rounding_mode != _RC_NEAR) {
643  std::cerr << "Floating point rounding mode is currently '"
644  << ((rounding_mode == _RC_CHOP)
645  ? "chop"
646  : (rounding_mode == _RC_UP)
647  ? "up"
648  : (rounding_mode == _RC_DOWN)
649  ? "down"
650  : (rounding_mode == _RC_NEAR) ? "near" : "unknown")
651  << "' setting to 'near'\n";
652 
653  if(_controlfp_s(&unused, _RC_NEAR, _MCW_RC)) {
654  std::cerr << "failed to set floating point rounding type to 'near'\n";
655  }
656  }
657 
658 #ifndef _M_AMD64
659  if(precision_mode != _PC_53) {
660  std::cerr << "Floating point precision mode is currently '"
661  << ((precision_mode == _PC_53)
662  ? "double"
663  : (precision_mode == _PC_24)
664  ? "single"
665  : (precision_mode == _PC_64) ? "double extended" : "unknown")
666  << "' setting to 'double'\n";
667 
668  if(_controlfp_s(&unused, _PC_53, _MCW_PC)) {
669  std::cerr << "failed to set floating point precision type to 'double'\n";
670  }
671  }
672 #endif
673 
674  } else {
675  std::cerr << "_controlfp_s failed.\n";
676  }
677 }
678 #else
679 static void check_fpu()
680 {
681  switch(fegetround()) {
682  case FE_TONEAREST:
683  break;
684  case FE_DOWNWARD:
685  std::cerr << "Floating point precision mode is currently 'downward'";
686  goto reset_fpu;
687  case FE_TOWARDZERO:
688  std::cerr << "Floating point precision mode is currently 'toward-zero'";
689  goto reset_fpu;
690  case FE_UPWARD:
691  std::cerr << "Floating point precision mode is currently 'upward'";
692  goto reset_fpu;
693  default:
694  std::cerr << "Floating point precision mode is currently 'unknown'";
695  goto reset_fpu;
696  reset_fpu:
697  std::cerr << "setting to 'nearest'";
698  fesetround(FE_TONEAREST);
699  break;
700  }
701 }
702 #endif
703 
704 /**
705  * Setups the game environment and enters
706  * the titlescreen or game loops.
707  */
708 static int do_gameloop(const std::vector<std::string>& args)
709 {
710  srand(std::time(nullptr));
711 
712  commandline_options cmdline_opts = commandline_options(args);
714 
715  int finished = process_command_args(cmdline_opts);
716  if(finished != -1) {
717 #ifdef _WIN32
718  if(lg::using_own_console()) {
719  std::cerr << "Press enter to continue..." << std::endl;
720  std::cin.get();
721  }
722 #endif
723 
724  return finished;
725  }
726 
727  const auto game = std::make_unique<game_launcher>(cmdline_opts, args[0].c_str());
728  const int start_ticks = SDL_GetTicks();
729 
730  init_locale();
731 
732  bool res;
733 
734  // Do initialize fonts before reading the game config, to have game
735  // config error messages displayed. fonts will be re-initialized later
736  // when the language is read from the game config.
737  res = font::load_font_config();
738  if(res == false) {
739  std::cerr << "could not initialize fonts\n";
740  // The most common symptom of a bogus data dir path -- warn the user.
742  return 1;
743  }
744 
745  res = game->init_language();
746  if(res == false) {
747  std::cerr << "could not initialize the language\n";
748  return 1;
749  }
750 
751  res = game->init_video();
752  if(res == false) {
753  std::cerr << "could not initialize display\n";
754  return 1;
755  }
756 
757 
758  check_fpu();
759  const cursor::manager cursor_manager;
761 
762 #if(defined(_X11) && !defined(__APPLE__)) || defined(_WIN32)
763  SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
764 #endif
765 
766  gui2::init();
767  const gui2::event::manager gui_event_manager;
768 
769  game_config_manager config_manager(cmdline_opts, game->jump_to_editor());
770 
771  gui2::dialogs::loading_screen::display([&res, &config_manager]() {
773  res = config_manager.init_game_config(game_config_manager::NO_FORCE_RELOAD);
774 
775  if(res == false) {
776  std::cerr << "could not initialize game config\n";
777  return;
778  }
779 
781 
782  res = font::load_font_config();
783  if(res == false) {
784  std::cerr << "could not re-initialize fonts for the current language\n";
785  return;
786  }
787 
789 
791  });
792 
793  if(res == false) {
794  return 1;
795  }
796 
797  LOG_CONFIG << "time elapsed: " << (SDL_GetTicks() - start_ticks) << " ms\n";
798 
799  plugins_manager plugins_man(new application_lua_kernel);
800 
801  const plugins_context::reg_vec callbacks {
802  {"play_multiplayer", std::bind(&game_launcher::play_multiplayer, game.get(), game_launcher::MP_CONNECT)},
803  };
804 
805  const plugins_context::areg_vec accessors {
806  {"command_line", std::bind(&commandline_options::to_config, &cmdline_opts)},
807  };
808 
809  plugins_context plugins("titlescreen", callbacks, accessors);
810 
811  plugins.set_callback("exit", [](const config& cfg) { safe_exit(cfg["code"].to_int(0)); }, false);
812 
813  for(;;) {
814  // reset the TC, since a game can modify it, and it may be used
815  // by images in add-ons or campaigns dialogs
817 
819 
820  if(!game->is_loading()) {
821  const config& cfg = config_manager.game_config().child("titlescreen_music");
822  if(cfg) {
823  for(const config& i : cfg.child_range("music")) {
825  }
826 
827  config title_music_config;
828  title_music_config["name"] = game_config::title_music;
829  title_music_config["append"] = true;
830  title_music_config["immediate"] = true;
831  sound::play_music_config(title_music_config);
832  } else {
835  }
836  }
837 
838  handle_lua_script_args(&*game, cmdline_opts);
839 
840  plugins.play_slice();
841  plugins.play_slice();
842 
843  if(!cmdline_opts.unit_test.empty()) {
844  return static_cast<int>(game->unit_test());
845  }
846 
847  if(game->play_test() == false) {
848  return 0;
849  }
850 
851  if(game->play_screenshot_mode() == false) {
852  return 0;
853  }
854 
855  if(game->play_render_image_mode() == false) {
856  return 0;
857  }
858 
859  // Start directly a campaign
860  if(game->goto_campaign() == false) {
861  if(game->jump_to_campaign_id().empty())
862  continue; // Go to main menu
863  else
864  return 1; // we got an error starting the campaign from command line
865  }
866 
867  // Start directly a multiplayer
868  // Eventually with a specified server
869  if(game->goto_multiplayer() == false) {
870  continue; // Go to main menu
871  }
872 
873  // Start directly a commandline multiplayer game
874  if(game->play_multiplayer_commandline() == false) {
875  return 0;
876  }
877 
878  if(game->goto_editor() == false) {
879  return 0;
880  }
881 
882  const font::floating_label_context label_manager;
883 
885 
887 
888  // If loading a game, skip the titlescreen entirely
889  if(game->is_loading()) {
890  if(!game->load_game()) {
891  game->clear_loaded_game();
892  }
893 
894  game->launch_game(should_reload);
895  continue;
896  }
897 
899 
900  /*
901  * Quick explanation of the titlscreen loop:
902  *
903  * The dialog's redraw_background_ flag is initialized as true in the constructor, so the dialog will always
904  * display at least once when this loop is executed. Each time it's opened, the aforementioned flag is set to
905  * false, and any selection that results in leaving the dialog simply sets the window's retval and proceeds to
906  * the appropriate action.
907  *
908  * Certain actions (such as window resizing) set the flag to true, which allows the dialog to reopen with any
909  * layout changes such as those dictated by window resolution.
910  */
912  dlg.show();
913  }
914 
915  switch(dlg.get_retval()) {
917  LOG_GENERAL << "quitting game...\n";
918  return 0;
921  if(!game->play_multiplayer(game_launcher::MP_CONNECT)) {
922  continue;
923  }
924  break;
927  if(!game->play_multiplayer(game_launcher::MP_HOST)) {
928  continue;
929  }
930  break;
933  if(!game->play_multiplayer(game_launcher::MP_LOCAL)) {
934  continue;
935  }
936  break;
938  gui2::dialogs::loading_screen::display([&config_manager]() {
939  config_manager.reload_changed_game_config();
940  });
941  break;
943  game->start_editor();
944  break;
946  gui2::dialogs::end_credits::display();
947  break;
949  game->launch_game(should_reload);
950  break;
952  break;
953  }
954  }
955 }
956 
957 #ifndef _WIN32
959 {
960  exit(0);
961 }
962 #endif
963 
964 #ifdef _WIN32
965 #define error_exit(res) \
966  do { \
967  if(lg::using_own_console()) { \
968  std::cerr << "Press enter to continue..." << std::endl; \
969  std::cin.get(); \
970  } \
971  return res; \
972  } while(false)
973 #else
974 #define error_exit(res) return res
975 #endif
976 
977 #ifdef __APPLE__
978 extern "C" int wesnoth_main(int argc, char** argv);
979 int wesnoth_main(int argc, char** argv)
980 #else
981 int main(int argc, char** argv)
982 #endif
983 {
984  auto args = read_argv(argc, argv);
985  assert(!args.empty());
986 
987 #ifdef _WIN32
988  // Some switches force a Windows console to be attached to the process even
989  // if Wesnoth is an IMAGE_SUBSYSTEM_WINDOWS_GUI executable because they
990  // turn it into a CLI application. Also, --wconsole in particular attaches
991  // a console to a regular GUI game session.
992  //
993  // It's up to commandline_options later to handle these switches (other
994  // --wconsole) later and emit any applicable console output, but right here
995  // we need a rudimentary check for the switches in question to set up the
996  // console before proceeding any further.
997  for(const auto& arg : args) {
998  // Switches that don't take arguments
999  static const std::set<std::string> wincon_switches = {
1000  "--wconsole", "-h", "--help", "-v", "--version", "-R", "--report", "--logdomains",
1001  "--data-path", "--userdata-path", "--userconfig-path",
1002  };
1003 
1004  // Switches that take arguments, the switch may have the argument past
1005  // the first = character, or in a subsequent argv entry which we don't
1006  // care about -- we just want to see if the switch is there.
1007  static const std::set<std::string> wincon_arg_switches = {
1008  "-D", "--diff", "-p", "--preprocess", "-P", "--patch", "--render-image",
1009  "--screenshot", "-V", "--validate", "--validate-addon", "--validate-schema",
1010  };
1011 
1012  auto switch_matches_arg = [&arg](const std::string& sw) {
1013  const auto pos = arg.find('=');
1014  return pos == std::string::npos ? arg == sw : arg.substr(0, pos) == sw;
1015  };
1016 
1017  if(wincon_switches.find(arg) != wincon_switches.end() ||
1018  std::find_if(wincon_arg_switches.begin(), wincon_arg_switches.end(), switch_matches_arg) != wincon_arg_switches.end()) {
1020  break;
1021  }
1022  }
1023 
1025 #endif
1026 
1027  if(SDL_Init(SDL_INIT_TIMER) < 0) {
1028  fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
1029  return (1);
1030  }
1031 
1032 #ifndef _WIN32
1033  struct sigaction terminate_handler;
1034  terminate_handler.sa_handler = wesnoth_terminate_handler;
1035  terminate_handler.sa_flags = 0;
1036 
1037  sigemptyset(&terminate_handler.sa_mask);
1038  sigaction(SIGTERM, &terminate_handler, nullptr);
1039  sigaction(SIGINT, &terminate_handler, nullptr);
1040 #endif
1041 
1042  // Mac's touchpad generates touch events too.
1043  // Ignore them until Macs have a touchscreen: https://forums.libsdl.org/viewtopic.php?p=45758
1044 #if defined(__APPLE__) && !defined(__IPHONEOS__)
1045  SDL_EventState(SDL_FINGERMOTION, SDL_DISABLE);
1046  SDL_EventState(SDL_FINGERDOWN, SDL_DISABLE);
1047  SDL_EventState(SDL_FINGERUP, SDL_DISABLE);
1048 #endif
1049 
1050  // declare this here so that it will always be at the front of the event queue.
1051  events::event_context global_context;
1052 
1053  SDL_StartTextInput();
1054 
1055  try {
1056  std::cerr << "Battle for Wesnoth v" << game_config::revision << '\n';
1057  const std::time_t t = std::time(nullptr);
1058  std::cerr << "Started on " << ctime(&t) << "\n";
1059 
1060  const std::string& exe_dir = filesystem::get_exe_dir();
1061  if(!exe_dir.empty()) {
1062  // Try to autodetect the location of the game data dir. Note that
1063  // the root of the source tree currently doubles as the data dir.
1064  std::string auto_dir;
1065 
1066  // scons leaves the resulting binaries at the root of the source
1067  // tree by default.
1068  if(filesystem::file_exists(exe_dir + "/data/_main.cfg")) {
1069  auto_dir = exe_dir;
1070  }
1071  // cmake encourages creating a subdir at the root of the source
1072  // tree for the build, and the resulting binaries are found in it.
1073  else if(filesystem::file_exists(exe_dir + "/../data/_main.cfg")) {
1074  auto_dir = filesystem::normalize_path(exe_dir + "/..");
1075  }
1076  // In Windows debug builds, the EXE is placed away from the game data dir
1077  // (in projectfiles\VCx\Debug), but the working directory is set to the
1078  // game data dir. Thus, check if the working dir is the game data dir.
1079  else if(filesystem::file_exists(filesystem::get_cwd() + "/data/_main.cfg")) {
1080  auto_dir = filesystem::get_cwd();
1081  }
1082 
1083  if(!auto_dir.empty()) {
1084  std::cerr << "Automatically found a possible data directory at " << filesystem::sanitize_path(auto_dir) << '\n';
1085  game_config::path = auto_dir;
1086  }
1087  }
1088 
1089  const int res = do_gameloop(args);
1090  safe_exit(res);
1091  } catch(const boost::program_options::error& e) {
1092  std::cerr << "Error in command line: " << e.what() << '\n';
1093  error_exit(1);
1094  } catch(const CVideo::error& e) {
1095  std::cerr << "Could not initialize video.\n\n" << e.what() << "\n\nExiting.\n";
1096  error_exit(1);
1097  } catch(const font::error& e) {
1098  std::cerr << "Could not initialize fonts.\n\n" << e.what() << "\n\nExiting.\n";
1099  error_exit(1);
1100  } catch(const config::error& e) {
1101  std::cerr << e.message << "\n";
1102  error_exit(1);
1103  } catch(const gui::button::error&) {
1104  std::cerr << "Could not create button: Image could not be found\n";
1105  error_exit(1);
1106  } catch(const CVideo::quit&) {
1107  // just means the game should quit
1108  } catch(const return_to_play_side_exception&) {
1109  std::cerr << "caught return_to_play_side_exception, please report this bug (quitting)\n";
1110  } catch(const quit_game_exception&) {
1111  std::cerr << "caught quit_game_exception (quitting)\n";
1112  } catch(const wml_exception& e) {
1113  std::cerr << "WML exception:\nUser message: " << e.user_message << "\nDev message: " << e.dev_message << '\n';
1114  error_exit(1);
1115  } catch(const wfl::formula_error& e) {
1116  std::cerr << e.what() << "\n\nGame will be aborted.\n";
1117  error_exit(1);
1118  } catch(const sdl::exception& e) {
1119  std::cerr << e.what();
1120  error_exit(1);
1121  } catch(const game::error&) {
1122  // A message has already been displayed.
1123  error_exit(1);
1124  } catch(const std::bad_alloc&) {
1125  std::cerr << "Ran out of memory. Aborted.\n";
1126  error_exit(ENOMEM);
1127 #if !defined(NO_CATCH_AT_GAME_END)
1128  } catch(const std::exception& e) {
1129  // Try to catch unexpected exceptions.
1130  std::cerr << "Caught general '" << typeid(e).name() << "' exception:\n" << e.what() << std::endl;
1131  error_exit(1);
1132  } catch(const std::string& e) {
1133  std::cerr << "Caught a string thrown as an exception:\n" << e << std::endl;
1134  error_exit(1);
1135  } catch(const char* e) {
1136  std::cerr << "Caught a string thrown as an exception:\n" << e << std::endl;
1137  error_exit(1);
1138  } catch(...) {
1139  // Ensure that even when we terminate with `throw 42`, the exception
1140  // is caught and all destructors are actually called. (Apparently,
1141  // some compilers will simply terminate without calling destructors if
1142  // the exception isn't caught.)
1143  std::cerr << "Caught unspecified general exception. Terminating." << std::endl;
1144  error_exit(1);
1145 #endif
1146  }
1147 
1148  return 0;
1149 } // end main
void empty_playlist()
Definition: sound.cpp:611
Exception used to escape form the ai or ui code to playsingle_controller::play_side.
bool log_precise_timestamps
True if –log-precise was given on the command line. Shows timestamps in log with more precision...
utils::optional< std::string > validate_schema
Non-empty if –validate-schema was given on the command line. Makes Wesnoth validate a WML schema...
#define error_exit(res)
Definition: wesnoth.cpp:974
static void wesnoth_terminate_handler(int)
Definition: wesnoth.cpp:958
std::vector< Reg > reg_vec
Definition: context.hpp:39
void set_callback(const std::string &name, callback_function)
Definition: context.cpp:51
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:420
static int handle_validate_command(const std::string &file, abstract_validator &validator, const std::vector< std::string > &defines)
Definition: wesnoth.cpp:337
void bind_textdomain(const char *domain, const char *directory, const char *)
Definition: gettext.cpp:431
const_all_children_itors all_children_range() const
In-order iteration over all children.
Definition: config.cpp:921
bool using_own_console()
Returns true if a console was allocated by the Wesnoth process.
void write(const config &cfg)
void stop_music()
Definition: sound.cpp:556
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:175
std::string library_versions_report()
Produce a plain-text report of library versions suitable for stdout/stderr.
Definition: build_info.cpp:612
static void bzip2_encode(const std::string &input_file, const std::string &output_file)
Definition: wesnoth.cpp:208
static void bzip2_decode(const std::string &input_file, const std::string &output_file)
Definition: wesnoth.cpp:213
Interfaces for manipulating version numbers of engine, add-ons, etc.
utils::optional< std::vector< std::pair< int, std::string > > > log
Contains parsed arguments of –log-* (e.g.
static lg::log_domain log_preprocessor("preprocessor")
void set_team_colors(const std::vector< std::string > *colors)
set the team colors used by the TC image modification use a vector with one string for each team usin...
Definition: picture.cpp:708
Add a special kind of assert to validate whether the input from WML doesn&#39;t contain any problems that...
std::string optional_features_report()
Produce a plain-text report of features suitable for stdout/stderr.
Definition: build_info.cpp:617
static l_noret error(LoadState *S, const char *why)
Definition: lundump.cpp:39
void set_user_data_dir(std::string newprefdir)
Definition: filesystem.cpp:612
static bool file_exists(const bfs::path &fpath)
Definition: filesystem.cpp:267
child_itors child_range(config_key_type key)
Definition: config.cpp:362
bool userdata_path
True if –userdata-path was given on the command line. Prints path to user data directory and exits...
static void gzip_decode(const std::string &input_file, const std::string &output_file)
Definition: wesnoth.cpp:203
static void progress(loading_stage stage=loading_stage::none)
filesystem::scoped_istream istream_file(const std::string &fname, bool treat_failure_as_error)
std::string user_message
The message for the user explaining what went wrong.
This class implements the title screen.
void fresh_stats()
Definition: statistics.cpp:780
Type that can be thrown as an exception to quit to desktop.
Definition: video.hpp:245
void early_log_file_setup()
Sets up the initial temporary log file.
void preprocess_resource(const std::string &res_name, preproc_map *defines_map, bool write_cfg, bool write_plain_cfg, const std::string &parent_directory)
Don&#39;t reload if the previous defines equal the new defines.
static void safe_exit(int res)
Definition: wesnoth.cpp:143
std::string normalize_path(const std::string &fpath, bool normalize_separators, bool resolve_dot_entries)
Returns the absolute path of a file.
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
std::string str
Definition: statement.cpp:110
bool show(const unsigned auto_close_time=0)
Shows the window.
-file util.hpp
Definitions for the interface to Wesnoth Markup Language (WML).
static void decode(const std::string &input_file, const std::string &output_file)
Definition: wesnoth.cpp:179
std::string diff_left
Files for diffing or patching.
const std::string name_
Definition: validator.hpp:96
utils::optional< std::string > preprocess_target
Target (output) path that was given to the –preprocess option.
bool preprocess
True if –preprocess was given on the command line. Starts Wesnoth in preprocessor-only mode...
utils::optional< std::string > preprocess_output_macros
Non-empty if –preprocess-output-macros was given on the command line. Outputs all preprocessed macro...
bool broke_strict()
Definition: log.cpp:172
config get_diff(const config &c) const
A function to get the differences between this object, and &#39;c&#39;, as another config object...
Definition: config.cpp:947
bool play_multiplayer(mp_selection res)
std::vector< std::string > read_argv(int argc, char **argv)
Reads argv into a vector of STL strings.
std::string get_cwd()
Definition: filesystem.cpp:882
One of the realizations of serialization/validator.hpp abstract validator.
unsigned in
If equal to search_counter, the node is off the list.
Used in parsing config file.
Definition: validator.hpp:35
static void warn_early_init_failure()
Print an alert and instructions to stderr about early initialization errors.
Definition: wesnoth.cpp:603
bool report
True if –report was given on the command line. Prints a bug report-style info dump and exits...
static void check_fpu()
Definition: wesnoth.cpp:679
utils::optional< std::string > preprocess_input_macros
Non-empty if –preprocess-input-macros was given on the command line. Specifies a file that contains ...
Class for writing a config out to a file in pieces.
std::string get_user_data_dir()
Definition: filesystem.cpp:795
std::string get_intl_dir()
static lg::log_domain log_config("config")
utils::optional< std::string > gzip
Non-empty if –gzip was given on the command line. Compresses a file to .gz and exits.
bool strict_validation_enabled
Definition: validator.cpp:19
utils::optional< std::string > bzip2
Non-empty if –bzip2 was given on the command line. Compresses a file to .bz2 and exits...
void init()
Initializes the GUI subsystems.
Definition: gui.cpp:35
#define LOG_GENERAL
Definition: wesnoth.cpp:135
void enable_native_console_output()
Switches to using a native console instead of log file redirection.
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
std::unique_ptr< std::istream > scoped_istream
Definition: filesystem.hpp:39
std::string path
Definition: game_config.cpp:39
utils::optional< std::string > preprocess_path
Path to parse that was given to the –preprocess option.
void set_default_textdomain(const char *domain)
Definition: gettext.cpp:440
void refresh_addon_version_info_cache()
Refreshes the per-session cache of add-on&#39;s version information structs.
Definition: manager.cpp:337
std::string sanitize_path(const std::string &path)
Sanitizes a path to remove references to the user&#39;s name.
void apply_diff(const config &diff, bool track=false)
A function to apply a diff config onto this config object.
Definition: config.cpp:1068
const char * what() const noexcept
Definition: exceptions.hpp:37
utils::optional< std::string > logdomains
Non-empty if –logdomains was given on the command line. Prints possible logdomains filtered by given...
utils::optional< std::string > validate_with
Non-empty if –use-schema was given on the command line. Specifies the schema for use with –validate...
bool userconfig_path
True if –userconfig-path was given on the command line. Prints path to user config directory and exi...
static void handle_preprocess_command(const commandline_options &cmdline_opts)
Definition: wesnoth.cpp:218
utils::optional< unsigned int > rng_seed
RNG seed specified by –rng-seed option. Initializes RNG with given seed.
lu_byte right
Definition: lparser.cpp:1027
int main(int argc, char **argv)
Definition: wesnoth.cpp:981
utils::optional< std::vector< std::string > > preprocess_defines
Defines that were given to the –preprocess option.
bool load_font_config()
#define PACKAGE
Definition: wesconfig.h:23
Helper class, don&#39;t construct this directly.
static int do_gameloop(const std::vector< std::string > &args)
Setups the game environment and enters the titlescreen or game loops.
Definition: wesnoth.cpp:708
std::string dev_message
The message for developers telling which problem was triggered, this shouldn&#39;t be translated...
static void gzip_encode(const std::string &input_file, const std::string &output_file)
Definition: wesnoth.cpp:198
std::unique_ptr< std::ostream > scoped_ostream
Definition: filesystem.hpp:40
bool is_gzip_file(const std::string &filename)
Returns true if the file ends with &#39;.gz&#39;.
Some defines: VERSION, PACKAGE, MIN_SAVEGAME_VERSION.
value read(bind.buffer(), bind.length())
static void handle_lua_script_args(game_launcher *game, commandline_options &)
Handles the lua script command line arguments if present.
Definition: wesnoth.cpp:616
std::string get_exe_dir()
Definition: filesystem.cpp:910
static void init_locale()
I would prefer to setup locale first so that early error messages can get localized, but we need the game_launcher initialized to have filesystem::get_intl_dir() to work.
Definition: wesnoth.cpp:579
Log file control routines for Windows.
std::size_t i
Definition: function.cpp:933
void set_user_config_dir(const std::string &newconfigdir)
Definition: filesystem.cpp:752
bool debug_lua
True if –debug-lua was given in the commandline. Enables some Lua debugging mechanisms.
std::string get_wml_location(const std::string &filename, const std::string &current_dir)
Returns a complete path to the actual WML file or directory or an empty string if the file isn&#39;t pres...
Default, unset return value.
Definition: retval.hpp:31
const std::string revision
void set_strict_severity(int severity)
Definition: log.cpp:162
utils::optional< std::string > userconfig_dir
Non-empty if –userconfig-dir was given on the command line. Sets the user config dir to the specifie...
static int process_command_args(const commandline_options &cmdline_opts)
Process commandline-arguments.
Definition: wesnoth.cpp:362
An exception object used when an IO error occurs.
Definition: filesystem.hpp:48
structure which will hide all current floating labels, and cause floating labels instantiated after i...
std::string name
Definition: sdl_ttf.cpp:70
std::string title_music
Declarations for File-IO.
static int writer(lua_State *L, const void *b, size_t size, void *B)
Definition: lstrlib.cpp:182
Contains a basic exception class for SDL operations.
const version_info wesnoth_version(VERSION)
static map_location::DIRECTION sw
utils::optional< std::string > validate_wml
Non-empty if –validate was given on the command line. Makes Wesnoth validate a WML file against a sc...
bool set_log_domain_severity(const std::string &name, int severity)
Definition: log.cpp:119
bool data_path
True if –data-path was given on the command line. Prints path to data directory and exits...
std::string get_user_config_dir()
Definition: filesystem.cpp:766
bool screenshot
True if –screenshot was given on the command line. Starts Wesnoth in screenshot mode.
bool is_bzip2_file(const std::string &filename)
Returns true if the file ends with &#39;.bz2&#39;.
static void display(std::function< void()> f)
std::vector< aReg > areg_vec
Definition: context.hpp:40
#define LOG_PREPROC
Definition: wesnoth.cpp:138
Contains the SDL_Rect helper code.
double t
Definition: astarsearch.cpp:64
utils::optional< std::string > output_file
Output filename for WML diff or preprocessing.
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:29
void play_music_config(const config &music_node, bool allow_interrupt_current_track, int i)
Definition: sound.cpp:704
lu_byte left
Definition: lparser.cpp:1026
std::string list_logdomains(const std::string &filter)
Definition: log.cpp:152
bool version
True if –version was given on the command line. Prints version and exits.
#define LOG_CONFIG
Definition: wesnoth.cpp:133
Standard logging facilities (interface).
std::string str() const
Serializes the version number into string form.
std::string message
Definition: exceptions.hpp:31
bool strict_validation
True if –strict-validation was given on the command line. Makes Wesnoth trust validation errors as f...
std::map< std::string, struct preproc_define > preproc_map
#define e
static void encode(const std::string &input_file, const std::string &output_file)
Definition: wesnoth.cpp:151
Realization of serialization/validator.hpp abstract validator.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map *defines)
Function to use the WML preprocessor on a file.
static preproc_map::value_type read_pair(const config &)
utils::optional< std::string > userdata_dir
Non-empty if –userdata-dir was given on the command line. Sets the user data dir to the specified on...
int wesnoth_main(int argc, char **argv)
utils::optional< std::string > render_image
Image path to render. First parameter after –render-image.
utils::optional< std::string > data_dir
Non-empty if –data-dir was given on the command line. Sets the config dir to the specified one...
bool help
True if –help was given on the command line. Prints help and exits.
bool init_lua_script()
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
std::string full_build_report()
Produce a bug report-style info dump.
Definition: build_info.cpp:622
std::string wesnoth_program_dir
Definition: game_config.cpp:48
void precise_timestamps(bool pt)
Definition: log.cpp:77
void set_debug(bool new_debug)
void play_slice()
Definition: context.cpp:96
utils::optional< std::string > bunzip2
Non-empty if –bunzip2 was given on the command line. Uncompresses a .bz2 file and exits...
filesystem::scoped_ostream ostream_file(const std::string &fname, bool create_directory)
utils::optional< std::string > gunzip
Non-empty if –gunzip was given on the command line. Uncompresses a .gz file and exits.