1 /*************************************************************************** 2 * Copyright (C) 2005-2019 by the FIFE team * 3 * http://www.fifengine.net * 4 * This file is part of FIFE. * 5 * * 6 * FIFE is free software; you can redistribute it and/or * 7 * modify it under the terms of the GNU Lesser General Public * 8 * License as published by the Free Software Foundation; either * 9 * version 2.1 of the License, or (at your option) any later version. * 10 * * 11 * This library is distributed in the hope that it will be useful, * 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 14 * Lesser General Public License for more details. * 15 * * 16 * You should have received a copy of the GNU Lesser General Public * 17 * License along with this library; if not, write to the * 18 * Free Software Foundation, Inc., * 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 20 ***************************************************************************/ 21 22 // Standard C++ library includes 23 #include <algorithm> 24 #include <string> 25 26 // 3rd party library includes 27 #include <SDL.h> 28 29 // FIFE includes 30 // These includes are split up in two parts, separated by one empty line 31 // First block: files included from the FIFE root src directory 32 // Second block: files included from the same folder 33 #include "util/base/exception.h" 34 #include "util/log/logger.h" 35 36 #include "enginesettings.h" 37 38 namespace FIFE { 39 /** Logger to use for this source file. 40 * @relates Logger 41 */ 42 static Logger _log(LM_CONTROLLER); 43 44 const float MAXIMUM_VOLUME = 10.0; 45 EngineSettings()46 EngineSettings::EngineSettings(): 47 m_bitsperpixel(0), 48 m_fullscreen(false), 49 m_refreshRate(60), 50 m_displayIndex(0), 51 m_vSync(false), 52 m_renderDriver(""), 53 m_initialvolume(MAXIMUM_VOLUME / 2), 54 m_renderbackend("SDL"), 55 m_sdlremovefakealpha(false), 56 m_oglcompressimages(false), 57 m_ogluseframebuffer(true), 58 m_oglusenpot(true), 59 m_oglMipmapping(false), 60 m_oglMonochrome(false), 61 m_oglTextureFilter(TEXTURE_FILTER_NONE), 62 m_oglDepthBuffer(false), 63 m_alphaTestValue(0.3), 64 m_screenwidth(800), 65 m_screenheight(600), 66 m_windowtitle("FIFE"), 67 m_windowicon(""), 68 m_defaultfontpath("fonts/FreeSans.ttf"), 69 m_defaultfontsize(8), 70 m_defaultfontglyphs("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\\\""), 71 m_iscolorkeyenabled(false), 72 m_lighting(0), 73 m_isframelimit(false), 74 m_framelimit(60), 75 m_mousesensitivity(0.0), 76 m_mouseacceleration(false), 77 m_nativeimagecursor(false), 78 m_joystickSupport(false) { 79 m_colorkey.r = 255; 80 m_colorkey.g = 0; 81 m_colorkey.b = 255; 82 83 #if defined( __unix__ ) 84 m_videodriver = "x11"; 85 #elif defined( WIN32 ) 86 m_videodriver = "windib"; 87 #elif defined( __APPLE_CC__ ) 88 m_videodriver = "x11"; 89 #else 90 m_videodriver = ""; 91 #endif 92 93 } 94 ~EngineSettings()95 EngineSettings::~EngineSettings() { 96 } 97 setBitsPerPixel(uint8_t bitsperpixel)98 void EngineSettings::setBitsPerPixel(uint8_t bitsperpixel) { 99 std::vector<uint8_t> pv = getPossibleBitsPerPixel(); 100 std::vector<uint8_t>::iterator i = std::find(pv.begin(), pv.end(), bitsperpixel); 101 if (i != pv.end()) { 102 m_bitsperpixel = bitsperpixel; 103 return; 104 } 105 106 FL_WARN(_log, LMsg("EngineSettings::setBitsPerPixel() - ") 107 << " Tried to set screen bpp to an unsupporded value of " << bitsperpixel << 108 ". Setting bpp to use the default value of 0 (the current screen bpp)"); 109 110 m_bitsperpixel = 0; //default value 111 } 112 getPossibleBitsPerPixel() const113 std::vector<uint8_t> EngineSettings::getPossibleBitsPerPixel() const { 114 std::vector<uint8_t> tmp; 115 tmp.push_back(0); 116 tmp.push_back(16); 117 tmp.push_back(24); 118 tmp.push_back(32); 119 return tmp; 120 } 121 setInitialVolume(float volume)122 void EngineSettings::setInitialVolume(float volume) { 123 if (volume > getMaxVolume() || volume < 0) { 124 FL_WARN(_log, LMsg("EngineSettings::setInitialVolume() - ") 125 << " Tried to set initial volume to an unsupporded value of " << volume << 126 ". Setting volume to the default value of 5 (minumum is 0, maximum is 10)"); 127 128 m_initialvolume = 5.0; 129 return; 130 } 131 132 m_initialvolume = volume; 133 } 134 getMaxVolume() const135 float EngineSettings::getMaxVolume() const { 136 return MAXIMUM_VOLUME; 137 } 138 setRenderBackend(const std::string & renderbackend)139 void EngineSettings::setRenderBackend(const std::string& renderbackend) { 140 std::vector<std::string> pv = getPossibleRenderBackends(); 141 std::vector<std::string>::iterator i = std::find(pv.begin(), pv.end(), renderbackend); 142 if (i != pv.end()) { 143 m_renderbackend = renderbackend; 144 return; 145 } 146 FL_WARN(_log, LMsg("EngineSettings::setRenderBackend() - ") 147 << renderbackend << " is not a valid render backend " << 148 ". Setting the render backend to the default value of \"SDL\"."); 149 150 m_renderbackend = "SDL"; 151 } 152 getPossibleRenderBackends()153 std::vector<std::string> EngineSettings::getPossibleRenderBackends() { 154 std::vector<std::string> tmp; 155 tmp.push_back("SDL"); 156 tmp.push_back("OpenGL"); 157 return tmp; 158 } 159 setSDLRemoveFakeAlpha(bool sdlremovefakealpha)160 void EngineSettings::setSDLRemoveFakeAlpha(bool sdlremovefakealpha) { 161 m_sdlremovefakealpha = sdlremovefakealpha; 162 } 163 setGLCompressImages(bool oglcompressimages)164 void EngineSettings::setGLCompressImages(bool oglcompressimages) { 165 m_oglcompressimages = oglcompressimages; 166 } 167 setGLUseFramebuffer(bool ogluseframebuffer)168 void EngineSettings::setGLUseFramebuffer(bool ogluseframebuffer) { 169 m_ogluseframebuffer = ogluseframebuffer; 170 } 171 setGLUseNPOT(bool oglusenpot)172 void EngineSettings::setGLUseNPOT(bool oglusenpot) { 173 m_oglusenpot = oglusenpot; 174 } 175 setGLTextureFiltering(TextureFiltering filter)176 void EngineSettings::setGLTextureFiltering(TextureFiltering filter) { 177 m_oglTextureFilter = filter; 178 } 179 getGLTextureFiltering() const180 TextureFiltering EngineSettings::getGLTextureFiltering() const { 181 return m_oglTextureFilter; 182 } 183 setGLUseMipmapping(bool mipmapping)184 void EngineSettings::setGLUseMipmapping(bool mipmapping) { 185 m_oglMipmapping = mipmapping; 186 } 187 isGLUseMipmapping() const188 bool EngineSettings::isGLUseMipmapping() const { 189 return m_oglMipmapping; 190 } 191 setGLUseMonochrome(bool monochrome)192 void EngineSettings::setGLUseMonochrome(bool monochrome) { 193 m_oglMonochrome = monochrome; 194 } 195 isGLUseMonochrome() const196 bool EngineSettings::isGLUseMonochrome() const { 197 return m_oglMonochrome; 198 } 199 setGLUseDepthBuffer(bool buffer)200 void EngineSettings::setGLUseDepthBuffer(bool buffer) { 201 m_oglDepthBuffer = buffer; 202 } 203 isGLUseDepthBuffer() const204 bool EngineSettings::isGLUseDepthBuffer() const { 205 return m_oglDepthBuffer; 206 } 207 setGLAlphaTestValue(float alpha)208 void EngineSettings::setGLAlphaTestValue(float alpha) { 209 m_alphaTestValue = alpha; 210 } 211 getGLAlphaTestValue() const212 float EngineSettings::getGLAlphaTestValue() const { 213 return m_alphaTestValue; 214 } 215 setScreenWidth(uint16_t screenwidth)216 void EngineSettings::setScreenWidth(uint16_t screenwidth) { 217 m_screenwidth = screenwidth; 218 } 219 setScreenHeight(uint16_t screenheight)220 void EngineSettings::setScreenHeight(uint16_t screenheight) { 221 m_screenheight = screenheight; 222 } 223 setDefaultFontPath(const std::string & defaultfontpath)224 void EngineSettings::setDefaultFontPath(const std::string& defaultfontpath) { 225 m_defaultfontpath = defaultfontpath; 226 } 227 setDefaultFontSize(uint16_t defaultfontsize)228 void EngineSettings::setDefaultFontSize(uint16_t defaultfontsize) { 229 m_defaultfontsize = defaultfontsize; 230 } 231 setDefaultFontGlyphs(const std::string & defaultfontglyphs)232 void EngineSettings::setDefaultFontGlyphs(const std::string& defaultfontglyphs) { 233 m_defaultfontglyphs = defaultfontglyphs; 234 } 235 setWindowTitle(const std::string & title)236 void EngineSettings::setWindowTitle(const std::string& title) { 237 m_windowtitle = title; 238 } 239 setWindowIcon(const std::string & icon)240 void EngineSettings::setWindowIcon(const std::string& icon) { 241 m_windowicon = icon; 242 } 243 setColorKeyEnabled(bool colorkeyenable)244 void EngineSettings::setColorKeyEnabled(bool colorkeyenable) { 245 m_iscolorkeyenabled = colorkeyenable; 246 } 247 isColorKeyEnabled() const248 bool EngineSettings::isColorKeyEnabled() const { 249 return m_iscolorkeyenabled; 250 } 251 setColorKey(uint8_t r,uint8_t g,uint8_t b)252 void EngineSettings::setColorKey(uint8_t r, uint8_t g, uint8_t b) { 253 m_colorkey.r = r; 254 m_colorkey.g = g; 255 m_colorkey.b = b; 256 } 257 getColorKey() const258 const SDL_Color& EngineSettings::getColorKey() const { 259 return m_colorkey; 260 } 261 setVideoDriver(const std::string & driver)262 void EngineSettings::setVideoDriver(const std::string& driver) { 263 //TODO: validate the video driver 264 m_videodriver = driver; 265 } 266 getVideoDriver() const267 const std::string& EngineSettings::getVideoDriver() const { 268 return m_videodriver; 269 } setLightingModel(uint32_t lighting)270 void EngineSettings::setLightingModel(uint32_t lighting) { 271 if (lighting <= 2) { 272 m_lighting = lighting; 273 return; 274 } 275 276 FL_WARN(_log, LMsg("EngineSettings::setLightingModel() - ") 277 << lighting << " is not a valid lighting model." << 278 ". Setting the lighting model to the default value of 0 (off)"); 279 280 m_lighting = 0; 281 } 282 setFrameLimitEnabled(bool limited)283 void EngineSettings::setFrameLimitEnabled(bool limited) { 284 m_isframelimit = limited; 285 } 286 isFrameLimitEnabled() const287 bool EngineSettings::isFrameLimitEnabled() const { 288 return m_isframelimit; 289 } 290 setFrameLimit(uint16_t framelimit)291 void EngineSettings::setFrameLimit(uint16_t framelimit) { 292 m_framelimit = framelimit; 293 } 294 getFrameLimit() const295 uint16_t EngineSettings::getFrameLimit() const { 296 return m_framelimit; 297 } 298 setMouseSensitivity(float sens)299 void EngineSettings::setMouseSensitivity(float sens) { 300 m_mousesensitivity = sens; 301 } 302 getMouseSensitivity() const303 float EngineSettings::getMouseSensitivity() const { 304 return m_mousesensitivity; 305 } 306 setMouseAccelerationEnabled(bool acceleration)307 void EngineSettings::setMouseAccelerationEnabled(bool acceleration) { 308 m_mouseacceleration = acceleration; 309 } 310 isMouseAccelerationEnabled() const311 bool EngineSettings::isMouseAccelerationEnabled() const { 312 return m_mouseacceleration; 313 } 314 setNativeImageCursorEnabled(bool nativeimagecursor)315 void EngineSettings::setNativeImageCursorEnabled(bool nativeimagecursor) { 316 m_nativeimagecursor = nativeimagecursor; 317 } 318 isNativeImageCursorEnabled() const319 bool EngineSettings::isNativeImageCursorEnabled() const { 320 return m_nativeimagecursor; 321 } 322 setJoystickSupport(bool support)323 void EngineSettings::setJoystickSupport(bool support) { 324 m_joystickSupport = support; 325 } 326 isJoystickSupport() const327 bool EngineSettings::isJoystickSupport() const { 328 return m_joystickSupport; 329 } 330 } 331 332