World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
EngineConfigFactory.cpp
См. документацию.
2 
3 #include <algorithm>
4 #include <cctype>
5 
6 #include "Platform/Api.h"
7 
10 
11 
12 std::shared_ptr<EngineConfig> EngineConfigFactory::CreateDefaultConfiguration() {
13  auto cfg = std::make_shared<EngineConfig>();
14 
15  if (!cfg->no_walk_sound) {
16  cfg->no_walk_sound = OS_GetAppInt("WalkSound", 1) == 0;
17  }
18  if (!cfg->always_run) {
19  cfg->always_run = OS_GetAppInt("valAlwaysRun", 0) != 0;
20  }
21  cfg->flip_on_exit = OS_GetAppInt("FlipOnExit", 0) != 0;
22 
23  cfg->show_damage = OS_GetAppInt("ShowDamage", 1) != 0;
24  int turn_type = OS_GetAppInt("TurnDelta", 3);
25 
26  switch (turn_type) {
27  case 1: // 16x
28  log->Warning(L"x16 Turn Speed"); // really shouldn't use this mode
29  cfg->turn_speed = 128;
30  break;
31 
32  case 2: // 32x
33  log->Warning(L"x32 Turn Speed"); // really shouldn't use this mode
34  cfg->turn_speed = 64;
35  break;
36 
37  case 3: // smooth
38  default:
39  cfg->turn_speed = 0;
40  break;
41  }
42 
43  cfg->sound_level = std::min(4, OS_GetAppInt("soundflag", 9));
44  cfg->music_level = std::min(3, OS_GetAppInt("musicflag", 9));
45  cfg->voice_level = std::min(4, OS_GetAppInt("CharVoices", 9));
46 
47  cfg->gamma = std::min(4, OS_GetAppInt("GammaPos", 4));
48 
49  if (OS_GetAppInt("Bloodsplats", 1))
50  cfg->flags2 |= GAME_FLAGS_2_DRAW_BLOODSPLATS;
51  else
52  cfg->flags2 &= ~GAME_FLAGS_2_DRAW_BLOODSPLATS;
53  cfg->no_bloodsplats = !(cfg->flags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS);
54 
55  return cfg;
56 }
57 
58 
59 static bool FindCaseInsensitive(const std::string &haystack, const std::string &needle) {
60  auto i = std::search(
61  haystack.begin(), haystack.end(),
62  needle.begin(), needle.end(),
63  [](char c1, char c2) {return std::toupper(c1) == std::toupper(c2); });
64 
65  return i != haystack.end();
66 }
67 
68 
69 std::shared_ptr<EngineConfig> EngineConfigFactory::Clone(std::shared_ptr<const EngineConfig> other) {
70  return std::make_shared<EngineConfig>(*other.get());
71 }
72 
73 std::shared_ptr<EngineConfig> EngineConfigFactory::Mutate(
74  std::shared_ptr<const EngineConfig> config,
75  std::function<void(std::shared_ptr<EngineConfig> &)> mutator
76 ) {
77  auto new_config = std::make_shared<EngineConfig>(*config.get());
78  mutator(new_config);
79 
80  return new_config;
81 }
82 
83 std::shared_ptr<EngineConfig> EngineConfigFactory::Create() {
85 }
86 
87 std::shared_ptr<EngineConfig> EngineConfigFactory::CreateFromCommandLine(const std::string &cmd) {
89 
90  // config->renderer_name = "OpenGL";
91 
92  if (FindCaseInsensitive(cmd, "-window")) {
93  config->dword_6BE368_debug_settings_2 |= DEBUG_SETTINGS_RUN_IN_WIDOW;
94  }
95  if (FindCaseInsensitive(cmd, "-nointro")) {
96  config->no_intro = true;
97  }
98  if (FindCaseInsensitive(cmd, "-nologo")) {
99  config->no_logo = true;
100  }
101  if (FindCaseInsensitive(cmd, "-nosound")) {
102  config->no_sound = true;
103  }
104  if (FindCaseInsensitive(cmd, "-novideo")) {
105  config->no_video = true;
106  }
107  if (FindCaseInsensitive(cmd, "-nowalksound")) {
108  config->no_walk_sound = true;
109  }
110  if (FindCaseInsensitive(cmd, "-nomarg")) {
111  config->no_margareth = true;
112  }
113  if (FindCaseInsensitive(cmd, "-render=")) {
114  if (FindCaseInsensitive(cmd, "-render=DirectDraw")) {
115  config->renderer_name = "DirectDraw";
116  }
117  if (FindCaseInsensitive(cmd, "-render=OpenGL")) {
118  config->renderer_name = "OpenGL";
119  }
120  }
121 
122  return config;
123 }
Engine_::EngineConfig
Definition: EngineConfig.h:35
Engine_::EngineConfigFactory::CreateFromCommandLine
std::shared_ptr< EngineConfig > CreateFromCommandLine(const std::string &cmd)
Definition: EngineConfigFactory.cpp:87
EngineConfigFactory.h
Engine_::EngineConfigFactory::log
Log * log
Definition: EngineConfigFactory.h:31
FindCaseInsensitive
static bool FindCaseInsensitive(const std::string &haystack, const std::string &needle)
Definition: EngineConfigFactory.cpp:59
Engine_::EngineConfigFactory
Definition: EngineConfigFactory.h:15
Engine_::EngineConfigFactory::Clone
std::shared_ptr< EngineConfig > Clone(std::shared_ptr< const EngineConfig > other)
Definition: EngineConfigFactory.cpp:69
Log::Warning
void Warning(const wchar_t *pFormat,...)
Definition: Log.cpp:28
Engine_::EngineConfigFactory::Create
std::shared_ptr< EngineConfig > Create()
Definition: EngineConfigFactory.cpp:83
Engine_::EngineConfigFactory::CreateDefaultConfiguration
std::shared_ptr< EngineConfig > CreateDefaultConfiguration()
Definition: EngineConfigFactory.cpp:12
string
GLsizei const GLchar *const * string
Definition: SDL_opengl_glext.h:691
config
EGLConfig config
Definition: SDL_egl.h:1149
Engine_::EngineConfigFactory::Mutate
std::shared_ptr< EngineConfig > Mutate(std::shared_ptr< const EngineConfig > config, std::function< void(std::shared_ptr< EngineConfig > &)> mutator)
Definition: EngineConfigFactory.cpp:73
Api.h
OS_GetAppInt
int OS_GetAppInt(const char *pKey, int uDefValue)
Definition: Lin.cpp:89