EngineConfig.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Core/Context.h"
  23. #include "../IO/Log.h"
  24. #include "../IO/File.h"
  25. #include "../IO/FileSystem.h"
  26. #include "../Resource/JSONFile.h"
  27. #include "../Graphics/GraphicsDefs.h"
  28. #include "EngineConfig.h"
  29. namespace Atomic
  30. {
  31. EngineConfig EngineConfig::engineConfig_;
  32. bool EngineConfig::LoadEngineConfig(const JSONValue& jengine)
  33. {
  34. if (!jengine.IsObject())
  35. return false;
  36. for (JSONObject::ConstIterator i = jengine.Begin(); i != jengine.End(); ++i)
  37. {
  38. String key = i->first_.ToLower();
  39. const JSONValue& jvalue = i->second_;
  40. if (key == "workerthreads")
  41. valueMap_["WorkerThreads"] = GetBoolValue(jvalue, true);
  42. else if (key == "logquiet")
  43. valueMap_["LogQuiet"] = GetBoolValue(jvalue, false);
  44. else if (key == "loglevel")
  45. valueMap_["LogLevel"] = GetIntValue(jvalue, 1);
  46. }
  47. return true;
  48. }
  49. bool EngineConfig::LoadGraphicsConfig(const JSONValue& jgraphics)
  50. {
  51. if (!jgraphics.IsObject())
  52. return false;
  53. for (JSONObject::ConstIterator i = jgraphics.Begin(); i != jgraphics.End(); ++i)
  54. {
  55. String key = i->first_.ToLower();
  56. const JSONValue& jvalue = i->second_;
  57. if (key == "headless")
  58. valueMap_["Headless"] = GetBoolValue(jvalue, false);
  59. else if (key == "framelimiter")
  60. valueMap_["FrameLimiter"] = GetBoolValue(jvalue, true);
  61. else if (key == "maxfps")
  62. valueMap_["MaxFps"] = GetIntValue(jvalue, 0);
  63. else if (key == "minfps")
  64. valueMap_["MinFps"] = GetIntValue(jvalue, 0);
  65. else if (key == "flushgpu")
  66. valueMap_["FlushGPU"] = GetBoolValue(jvalue, false);
  67. else if (key == "forcegl2")
  68. valueMap_["ForceGL2"] = GetBoolValue(jvalue, false);
  69. else if (key == "orientations")
  70. valueMap_["Orientations"] = GetStringValue(jvalue, "LandscapeLeft LandscapeRight");
  71. else if (key == "vsync")
  72. valueMap_["VSync"] = GetBoolValue(jvalue, false);
  73. else if (key == "triplebuffer")
  74. valueMap_["TripleBuffer"] = GetBoolValue(jvalue, false);
  75. else if (key == "multisample")
  76. valueMap_["Multisample"] = GetIntValue(jvalue, 1);
  77. else if (key == "renderpath")
  78. {
  79. String renderPath = GetStringValue(jvalue, "forward").ToLower();
  80. if (renderPath == "forward")
  81. valueMap_["RenderPath"] = "RenderPaths/Forward.xml";
  82. else if (renderPath == "prepass")
  83. valueMap_["RenderPath"] = "RenderPaths/Prepass.xml";
  84. else if (renderPath == "deferred")
  85. valueMap_["RenderPath"] = "RenderPaths/Deferred.xml";
  86. }
  87. else if (key == "shadows")
  88. valueMap_["Shadows"] = GetBoolValue(jvalue, true);
  89. else if (key == "lowqualityshadows")
  90. valueMap_["LowQualityShadows"] = GetBoolValue(jvalue, false);
  91. else if (key == "materialquality")
  92. {
  93. String quality = GetStringValue(jvalue, "high").ToLower();
  94. if (quality == "high")
  95. valueMap_["MaterialQuality"] = QUALITY_HIGH;
  96. else if (quality == "medium")
  97. valueMap_["MaterialQuality"] = QUALITY_MEDIUM;
  98. else if (quality == "low")
  99. valueMap_["MaterialQuality"] = QUALITY_LOW;
  100. }
  101. else if (key == "texturequality")
  102. {
  103. String quality = GetStringValue(jvalue, "high").ToLower();
  104. if (quality == "high")
  105. valueMap_["TextureQuality"] = QUALITY_HIGH;
  106. else if (quality == "medium")
  107. valueMap_["TextureQuality"] = QUALITY_MEDIUM;
  108. else if (quality == "low")
  109. valueMap_["TextureQuality"] = QUALITY_LOW;
  110. }
  111. else if (key == "texturefiltermode")
  112. {
  113. String mode = GetStringValue(jvalue, "trilinear").ToLower();
  114. if (mode == "trilinear")
  115. valueMap_["TextureFilterMode"] = FILTER_TRILINEAR;
  116. else if (mode == "bilinear")
  117. valueMap_["TextureFilterMode"] = FILTER_BILINEAR;
  118. else if (mode == "nearest")
  119. valueMap_["TextureFilterMode"] = FILTER_NEAREST;
  120. else if (mode == "anisotropic")
  121. valueMap_["TextureFilterMode"] = FILTER_ANISOTROPIC;
  122. }
  123. else if (key == "textureanisotropy")
  124. {
  125. valueMap_["TextureAnisotropy"] = GetIntValue(jvalue, 4);
  126. }
  127. }
  128. return true;
  129. }
  130. bool EngineConfig::LoadWindowConfig(const JSONValue& jwindow)
  131. {
  132. if (!jwindow.IsObject())
  133. return false;
  134. for (JSONObject::ConstIterator i = jwindow.Begin(); i != jwindow.End(); ++i)
  135. {
  136. String key = i->first_.ToLower();
  137. const JSONValue& jvalue = i->second_;
  138. if (key == "title")
  139. valueMap_["WindowTitle"] = GetStringValue(jvalue, "Atomic");
  140. else if (key == "fullscreen")
  141. valueMap_["FullScreen"] = GetBoolValue(jvalue, false);
  142. else if (key == "borderless")
  143. valueMap_["Borderless"] = GetBoolValue(jvalue, false);
  144. else if (key == "resizable")
  145. valueMap_["WindowResizable"] = GetBoolValue(jvalue, false);
  146. else if (key == "width")
  147. valueMap_["WindowWidth"] = GetIntValue(jvalue, false);
  148. else if (key == "height")
  149. valueMap_["WindowHeight"] = GetIntValue(jvalue, false);
  150. else if (key == "positionx")
  151. valueMap_["WindowPositionX"] = GetIntValue(jvalue, false);
  152. else if (key == "positiony")
  153. valueMap_["WindowPositionY"] = GetIntValue(jvalue, false);
  154. }
  155. return true;
  156. }
  157. bool EngineConfig::LoadSoundConfig(const JSONValue& jsound)
  158. {
  159. if (!jsound.IsObject())
  160. return false;
  161. for (JSONObject::ConstIterator i = jsound.Begin(); i != jsound.End(); ++i)
  162. {
  163. String key = i->first_.ToLower();
  164. const JSONValue& jvalue = i->second_;
  165. if (key == "enabled")
  166. valueMap_["Sound"] = GetBoolValue(jvalue, true);
  167. else if (key == "interpolation")
  168. valueMap_["SoundInterpolation"] = GetBoolValue(jvalue, true);
  169. else if (key == "stereo")
  170. valueMap_["SoundStereo"] = GetBoolValue(jvalue, true);
  171. else if (key == "bufferms")
  172. valueMap_["SoundBuffer"] = GetIntValue(jvalue, 100);
  173. else if (key == "mixrate")
  174. valueMap_["SoundMixRate"] = GetIntValue(jvalue, 44100);
  175. }
  176. return true;
  177. }
  178. bool EngineConfig::LoadInputConfig(const JSONValue& jinput)
  179. {
  180. if (!jinput.IsObject())
  181. return false;
  182. for (JSONObject::ConstIterator i = jinput.Begin(); i != jinput.End(); ++i)
  183. {
  184. String key = i->first_.ToLower();
  185. const JSONValue& jvalue = i->second_;
  186. if (key == "touchemulation")
  187. valueMap_["TouchEmulation"] = GetBoolValue(jvalue, false);
  188. }
  189. return true;
  190. }
  191. bool EngineConfig::LoadWebViewConfig(const JSONValue& jwebview)
  192. {
  193. if (!jwebview.IsObject())
  194. return false;
  195. for (JSONObject::ConstIterator i = jwebview.Begin(); i != jwebview.End(); ++i)
  196. {
  197. String key = i->first_.ToLower();
  198. const JSONValue& jvalue = i->second_;
  199. if (key == "useragent")
  200. valueMap_["WebViewUserAgent"] = GetStringValue(jvalue, String::EMPTY);
  201. else if (key == "productversion")
  202. valueMap_["WebViewProductVersion"] = GetStringValue(jvalue, String::EMPTY);
  203. else if (key == "debugPort")
  204. valueMap_["WebViewDebugPort"] = GetIntValue(jvalue, 8080);
  205. }
  206. return true;
  207. }
  208. bool EngineConfig::LoadDesktopConfig(JSONValue root)
  209. {
  210. const JSONValue& jdesktop = root["desktop"];
  211. if (!jdesktop.IsObject())
  212. return false;
  213. const JSONValue& jengine = jdesktop["engine"];
  214. if (jengine.IsObject())
  215. LoadEngineConfig(jengine);
  216. const JSONValue& jgraphics = jdesktop["graphics"];
  217. if (jgraphics.IsObject())
  218. LoadGraphicsConfig(jgraphics);
  219. const JSONValue& jwindow = jdesktop["window"];
  220. if (jwindow.IsObject())
  221. LoadWindowConfig(jwindow);
  222. const JSONValue& jsound = jdesktop["sound"];
  223. if (jsound.IsObject())
  224. LoadSoundConfig(jsound);
  225. const JSONValue& jinput = jdesktop["input"];
  226. if (jinput.IsObject())
  227. LoadInputConfig(jinput);
  228. const JSONValue& jwebview = jdesktop["webview"];
  229. if (jwebview.IsObject())
  230. LoadWebViewConfig(jwebview);
  231. return true;
  232. }
  233. }