clientlauncher.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef __CLIENT_LAUNCHER_H__
  17. #define __CLIENT_LAUNCHER_H__
  18. #include "irrlichttypes_extrabloated.h"
  19. #include "client/inputhandler.h"
  20. #include "gameparams.h"
  21. // A small helper class
  22. class TimeGetter
  23. {
  24. public:
  25. virtual u32 getTime(TimePrecision prec) = 0;
  26. };
  27. // A precise irrlicht one
  28. class IrrlichtTimeGetter: public TimeGetter
  29. {
  30. public:
  31. IrrlichtTimeGetter(IrrlichtDevice *device):
  32. m_device(device)
  33. {}
  34. u32 getTime(TimePrecision prec)
  35. {
  36. if (prec == PRECISION_MILLI) {
  37. if (m_device == NULL)
  38. return 0;
  39. return m_device->getTimer()->getRealTime();
  40. } else {
  41. return porting::getTime(prec);
  42. }
  43. }
  44. private:
  45. IrrlichtDevice *m_device;
  46. };
  47. // Not so precise one which works without irrlicht
  48. class SimpleTimeGetter: public TimeGetter
  49. {
  50. public:
  51. u32 getTime(TimePrecision prec)
  52. {
  53. return porting::getTime(prec);
  54. }
  55. };
  56. class ClientLauncher
  57. {
  58. public:
  59. ClientLauncher() :
  60. list_video_modes(false),
  61. skip_main_menu(false),
  62. use_freetype(false),
  63. random_input(false),
  64. address(""),
  65. playername(""),
  66. password(""),
  67. device(NULL),
  68. input(NULL),
  69. receiver(NULL),
  70. skin(NULL),
  71. font(NULL),
  72. simple_singleplayer_mode(false),
  73. current_playername("inv£lid"),
  74. current_password(""),
  75. current_address("does-not-exist"),
  76. current_port(0)
  77. {}
  78. ~ClientLauncher();
  79. bool run(GameParams &game_params, const Settings &cmd_args);
  80. protected:
  81. void init_args(GameParams &game_params, const Settings &cmd_args);
  82. bool init_engine();
  83. bool launch_game(std::string &error_message, bool reconnect_requested,
  84. GameParams &game_params, const Settings &cmd_args);
  85. void main_menu(MainMenuData *menudata);
  86. bool create_engine_device();
  87. void speed_tests();
  88. bool print_video_modes();
  89. bool list_video_modes;
  90. bool skip_main_menu;
  91. bool use_freetype;
  92. bool random_input;
  93. std::string address;
  94. std::string playername;
  95. std::string password;
  96. IrrlichtDevice *device;
  97. InputHandler *input;
  98. MyEventReceiver *receiver;
  99. gui::IGUISkin *skin;
  100. gui::IGUIFont *font;
  101. scene::ISceneManager *smgr;
  102. SubgameSpec gamespec;
  103. WorldSpec worldspec;
  104. bool simple_singleplayer_mode;
  105. // These are set up based on the menu and other things
  106. // TODO: Are these required since there's already playername, password, etc
  107. std::string current_playername;
  108. std::string current_password;
  109. std::string current_address;
  110. int current_port;
  111. };
  112. #endif