EngineConfig.cpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 == "flushgpu")
  62. valueMap_["FlushGPU"] = GetBoolValue(jvalue, false);
  63. else if (key == "forcegl2")
  64. valueMap_["ForceGL2"] = GetBoolValue(jvalue, false);
  65. else if (key == "orientations")
  66. valueMap_["Orientations"] = GetStringValue(jvalue, "LandscapeLeft LandscapeRight");
  67. else if (key == "vsync")
  68. valueMap_["VSync"] = GetBoolValue(jvalue, false);
  69. else if (key == "triplebuffer")
  70. valueMap_["TripleBuffer"] = GetBoolValue(jvalue, false);
  71. else if (key == "multisample")
  72. valueMap_["Multisample"] = GetIntValue(jvalue, 1);
  73. else if (key == "renderpath")
  74. {
  75. String renderPath = GetStringValue(jvalue, "forward").ToLower();
  76. if (renderPath == "forward")
  77. valueMap_["RenderPath"] = "RenderPaths/Forward.xml";
  78. else if (renderPath == "prepass")
  79. valueMap_["RenderPath"] = "RenderPaths/Prepass.xml";
  80. else if (renderPath == "deferred")
  81. valueMap_["RenderPath"] = "RenderPaths/Deferred.xml";
  82. }
  83. else if (key == "shadows")
  84. valueMap_["Shadows"] = GetBoolValue(jvalue, true);
  85. else if (key == "lowqualityshadows")
  86. valueMap_["LowQualityShadows"] = GetBoolValue(jvalue, false);
  87. else if (key == "materialquality")
  88. {
  89. String quality = GetStringValue(jvalue, "high").ToLower();
  90. if (quality == "high")
  91. valueMap_["MaterialQuality"] = QUALITY_HIGH;
  92. else if (quality == "medium")
  93. valueMap_["MaterialQuality"] = QUALITY_MEDIUM;
  94. else if (quality == "low")
  95. valueMap_["MaterialQuality"] = QUALITY_LOW;
  96. }
  97. else if (key == "texturequality")
  98. {
  99. String quality = GetStringValue(jvalue, "high").ToLower();
  100. if (quality == "high")
  101. valueMap_["TextureQuality"] = QUALITY_HIGH;
  102. else if (quality == "medium")
  103. valueMap_["TextureQuality"] = QUALITY_MEDIUM;
  104. else if (quality == "low")
  105. valueMap_["TextureQuality"] = QUALITY_LOW;
  106. }
  107. else if (key == "texturefiltermode")
  108. {
  109. String mode = GetStringValue(jvalue, "trilinear").ToLower();
  110. if (mode == "trilinear")
  111. valueMap_["TextureFilterMode"] = FILTER_TRILINEAR;
  112. else if (mode == "bilinear")
  113. valueMap_["TextureFilterMode"] = FILTER_BILINEAR;
  114. else if (mode == "nearest")
  115. valueMap_["TextureFilterMode"] = FILTER_NEAREST;
  116. else if (mode == "anisotropic")
  117. valueMap_["TextureFilterMode"] = FILTER_ANISOTROPIC;
  118. }
  119. else if (key == "textureanisotropy")
  120. {
  121. valueMap_["TextureAnisotropy"] = GetIntValue(jvalue, 4);
  122. }
  123. }
  124. return true;
  125. }
  126. bool EngineConfig::LoadWindowConfig(const JSONValue& jwindow)
  127. {
  128. if (!jwindow.IsObject())
  129. return false;
  130. for (JSONObject::ConstIterator i = jwindow.Begin(); i != jwindow.End(); ++i)
  131. {
  132. String key = i->first_.ToLower();
  133. const JSONValue& jvalue = i->second_;
  134. if (key == "title")
  135. valueMap_["WindowTitle"] = GetStringValue(jvalue, "Atomic");
  136. else if (key == "fullscreen")
  137. valueMap_["FullScreen"] = GetBoolValue(jvalue, false);
  138. else if (key == "borderless")
  139. valueMap_["Borderless"] = GetBoolValue(jvalue, false);
  140. else if (key == "resizable")
  141. valueMap_["WindowResizable"] = GetBoolValue(jvalue, false);
  142. else if (key == "width")
  143. valueMap_["WindowWidth"] = GetIntValue(jvalue, false);
  144. else if (key == "height")
  145. valueMap_["WindowHeight"] = GetIntValue(jvalue, false);
  146. else if (key == "positionx")
  147. valueMap_["WindowPositionX"] = GetIntValue(jvalue, false);
  148. else if (key == "positiony")
  149. valueMap_["WindowPositionY"] = GetIntValue(jvalue, false);
  150. }
  151. return true;
  152. }
  153. bool EngineConfig::LoadSoundConfig(const JSONValue& jsound)
  154. {
  155. if (!jsound.IsObject())
  156. return false;
  157. for (JSONObject::ConstIterator i = jsound.Begin(); i != jsound.End(); ++i)
  158. {
  159. String key = i->first_.ToLower();
  160. const JSONValue& jvalue = i->second_;
  161. if (key == "enabled")
  162. valueMap_["Sound"] = GetBoolValue(jvalue, true);
  163. else if (key == "interpolation")
  164. valueMap_["SoundInterpolation"] = GetBoolValue(jvalue, true);
  165. else if (key == "stereo")
  166. valueMap_["SoundStereo"] = GetBoolValue(jvalue, true);
  167. else if (key == "bufferms")
  168. valueMap_["SoundBuffer"] = GetIntValue(jvalue, 100);
  169. else if (key == "mixrate")
  170. valueMap_["SoundMixRate"] = GetIntValue(jvalue, 44100);
  171. }
  172. return true;
  173. }
  174. bool EngineConfig::LoadInputConfig(const JSONValue& jinput)
  175. {
  176. if (!jinput.IsObject())
  177. return false;
  178. for (JSONObject::ConstIterator i = jinput.Begin(); i != jinput.End(); ++i)
  179. {
  180. String key = i->first_.ToLower();
  181. const JSONValue& jvalue = i->second_;
  182. if (key == "touchemulation")
  183. valueMap_["TouchEmulation"] = GetBoolValue(jvalue, false);
  184. }
  185. return true;
  186. }
  187. bool EngineConfig::LoadWebViewConfig(const JSONValue& jwebview)
  188. {
  189. if (!jwebview.IsObject())
  190. return false;
  191. for (JSONObject::ConstIterator i = jwebview.Begin(); i != jwebview.End(); ++i)
  192. {
  193. String key = i->first_.ToLower();
  194. const JSONValue& jvalue = i->second_;
  195. if (key == "useragent")
  196. valueMap_["WebViewUserAgent"] = GetStringValue(jvalue, String::EMPTY);
  197. else if (key == "productversion")
  198. valueMap_["WebViewProductVersion"] = GetStringValue(jvalue, String::EMPTY);
  199. else if (key == "debugPort")
  200. valueMap_["WebViewDebugPort"] = GetIntValue(jvalue, 8080);
  201. }
  202. return true;
  203. }
  204. bool EngineConfig::LoadDesktopConfig(JSONValue root)
  205. {
  206. const JSONValue& jdesktop = root["desktop"];
  207. if (!jdesktop.IsObject())
  208. return false;
  209. const JSONValue& jengine = jdesktop["engine"];
  210. if (jengine.IsObject())
  211. LoadEngineConfig(jengine);
  212. const JSONValue& jgraphics = jdesktop["graphics"];
  213. if (jgraphics.IsObject())
  214. LoadGraphicsConfig(jgraphics);
  215. const JSONValue& jwindow = jdesktop["window"];
  216. if (jwindow.IsObject())
  217. LoadWindowConfig(jwindow);
  218. const JSONValue& jsound = jdesktop["sound"];
  219. if (jsound.IsObject())
  220. LoadSoundConfig(jsound);
  221. const JSONValue& jinput = jdesktop["input"];
  222. if (jinput.IsObject())
  223. LoadInputConfig(jinput);
  224. const JSONValue& jwebview = jdesktop["webview"];
  225. if (jwebview.IsObject())
  226. LoadWebViewConfig(jwebview);
  227. return true;
  228. }
  229. }