FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
enginesettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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 {
42  static Logger _log(LM_CONTROLLER);
43 
44  const float MAXIMUM_VOLUME = 10.0;
45 
47  m_bitsperpixel(0),
48  m_fullscreen(false),
49  m_initialvolume(MAXIMUM_VOLUME / 2),
50  m_renderbackend("SDL"),
51  m_sdlremovefakealpha(false),
52  m_oglcompressimages(false),
53  m_ogluseframebuffer(true),
54  m_oglusenpot(true),
55  m_oglMipmapping(false),
56  m_oglMonochrome(false),
57  m_oglTextureFilter(TEXTURE_FILTER_NONE),
58  m_oglDepthBuffer(false),
59  m_alphaTestValue(0.3),
60  m_screenwidth(800),
61  m_screenheight(600),
62  m_windowtitle("FIFE"),
63  m_windowicon(""),
64  m_defaultfontpath("fonts/FreeSans.ttf"),
65  m_defaultfontsize(8),
66  m_defaultfontglyphs("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&amp;`'*#=[]\\\""),
67  m_iscolorkeyenabled(false),
68  m_lighting(0),
69  m_isframelimit(false),
70  m_framelimit(60),
71  m_mousesensitivity(0.0),
72  m_mouseacceleration(false) {
73  m_colorkey.r = 255;
74  m_colorkey.g = 0;
75  m_colorkey.b = 255;
76 
77 #if defined( __unix__ )
78  m_videodriver = "x11";
79 #elif defined( WIN32 )
80  m_videodriver = "windib";
81 #elif defined( __APPLE_CC__ )
82  m_videodriver = "x11";
83 #else
84  m_videodriver = "";
85 #endif
86 
87  }
88 
90  }
91 
93  std::vector<uint8_t> pv = getPossibleBitsPerPixel();
94  std::vector<uint8_t>::iterator i = std::find(pv.begin(), pv.end(), bitsperpixel);
95  if (i != pv.end()) {
96  m_bitsperpixel = bitsperpixel;
97  return;
98  }
99 
100  FL_WARN(_log, LMsg("EngineSettings::setBitsPerPixel() - ")
101  << " Tried to set screen bpp to an unsupporded value of " << bitsperpixel <<
102  ". Setting bpp to use the default value of 0 (the current screen bpp)");
103 
104  m_bitsperpixel = 0; //default value
105  }
106 
107  std::vector<uint8_t> EngineSettings::getPossibleBitsPerPixel() const {
108  std::vector<uint8_t> tmp;
109  tmp.push_back(0);
110  tmp.push_back(16);
111  tmp.push_back(24);
112  tmp.push_back(32);
113  return tmp;
114  }
115 
116  void EngineSettings::setInitialVolume(float volume) {
117  if (volume > getMaxVolume() || volume < 0) {
118  FL_WARN(_log, LMsg("EngineSettings::setInitialVolume() - ")
119  << " Tried to set initial volume to an unsupporded value of " << volume <<
120  ". Setting volume to the default value of 5 (minumum is 0, maximum is 10)");
121 
122  m_initialvolume = 5.0;
123  return;
124  }
125 
126  m_initialvolume = volume;
127  }
128 
130  return MAXIMUM_VOLUME;
131  }
132 
133  void EngineSettings::setRenderBackend(const std::string& renderbackend) {
134  std::vector<std::string> pv = getPossibleRenderBackends();
135  std::vector<std::string>::iterator i = std::find(pv.begin(), pv.end(), renderbackend);
136  if (i != pv.end()) {
137  m_renderbackend = renderbackend;
138  return;
139  }
140  FL_WARN(_log, LMsg("EngineSettings::setRenderBackend() - ")
141  << renderbackend << " is not a valid render backend " <<
142  ". Setting the render backend to the default value of \"SDL\".");
143 
144  m_renderbackend = "SDL";
145  }
146 
147  std::vector<std::string> EngineSettings::getPossibleRenderBackends() {
148  std::vector<std::string> tmp;
149  tmp.push_back("SDL");
150  tmp.push_back("OpenGL");
151  return tmp;
152  }
153 
154  void EngineSettings::setSDLRemoveFakeAlpha(bool sdlremovefakealpha) {
155  m_sdlremovefakealpha = sdlremovefakealpha;
156  }
157 
158  void EngineSettings::setGLCompressImages(bool oglcompressimages) {
159  m_oglcompressimages = oglcompressimages;
160  }
161 
162  void EngineSettings::setGLUseFramebuffer(bool ogluseframebuffer) {
163  m_ogluseframebuffer = ogluseframebuffer;
164  }
165 
166  void EngineSettings::setGLUseNPOT(bool oglusenpot) {
167  m_oglusenpot = oglusenpot;
168  }
169 
171  m_oglTextureFilter = filter;
172  }
173 
175  return m_oglTextureFilter;
176  }
177 
178  void EngineSettings::setGLUseMipmapping(bool mipmapping) {
179  m_oglMipmapping = mipmapping;
180  }
181 
183  return m_oglMipmapping;
184  }
185 
186  void EngineSettings::setGLUseMonochrome(bool monochrome) {
187  m_oglMonochrome = monochrome;
188  }
189 
191  return m_oglMonochrome;
192  }
193 
195  m_oglDepthBuffer = buffer;
196  }
197 
199  return m_oglDepthBuffer;
200  }
201 
203  m_alphaTestValue = alpha;
204  }
205 
207  return m_alphaTestValue;
208  }
209 
211  m_screenwidth = screenwidth;
212  }
213 
215  m_screenheight = screenheight;
216  }
217 
218  void EngineSettings::setDefaultFontPath(const std::string& defaultfontpath) {
219  m_defaultfontpath = defaultfontpath;
220  }
221 
223  m_defaultfontsize = defaultfontsize;
224  }
225 
226  void EngineSettings::setDefaultFontGlyphs(const std::string& defaultfontglyphs) {
227  m_defaultfontglyphs = defaultfontglyphs;
228  }
229 
230  void EngineSettings::setWindowTitle(const std::string& title) {
231  m_windowtitle = title;
232  }
233 
234  void EngineSettings::setWindowIcon(const std::string& icon) {
235  m_windowicon = icon;
236  }
237 
238  void EngineSettings::setColorKeyEnabled(bool colorkeyenable) {
239  m_iscolorkeyenabled = colorkeyenable;
240  }
241 
243  return m_iscolorkeyenabled;
244  }
245 
247  m_colorkey.r = r;
248  m_colorkey.g = g;
249  m_colorkey.b = b;
250  }
251 
252  const SDL_Color& EngineSettings::getColorKey() const {
253  return m_colorkey;
254  }
255 
256  void EngineSettings::setVideoDriver(const std::string& driver) {
257  //TODO: validate the video driver
258  m_videodriver = driver;
259  }
260 
261  const std::string& EngineSettings::getVideoDriver() const {
262  return m_videodriver;
263  }
265  if (lighting <= 2) {
266  m_lighting = lighting;
267  return;
268  }
269 
270  FL_WARN(_log, LMsg("EngineSettings::setLightingModel() - ")
271  << lighting << " is not a valid lighting model." <<
272  ". Setting the lighting model to the default value of 0 (off)");
273 
274  m_lighting = 0;
275  }
276 
278  m_isframelimit = limited;
279  }
280 
282  return m_isframelimit;
283  }
284 
286  m_framelimit = framelimit;
287  }
288 
290  return m_framelimit;
291  }
292 
294  m_mousesensitivity = sens;
295  }
296 
298  return m_mousesensitivity;
299  }
300 
302  m_mouseacceleration = acceleration;
303  }
304 
306  return m_mouseacceleration;
307  }
308 }
309 
#define FL_WARN(logger, msg)
Definition: logger.h:72
bool isGLUseMonochrome() const
Tells if OpenGL renderbackend should render only monochrome.
void setDefaultFontSize(uint16_t defaultfontsize)
Sets size for default font.
float getMaxVolume() const
Gets maximum volume that can be set.
bool isColorKeyEnabled() const
Gets whether the colorkey feature is in use.
const float MAXIMUM_VOLUME
~EngineSettings()
Destructor.
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
Definition: logger.h:82
void setGLUseFramebuffer(bool ogluseframebuffer)
Sets if OpenGL renderbackend should use FramebufferObject (when available)
void setFrameLimitEnabled(bool limited)
Sets whether to use the frame limiter.
void setInitialVolume(float volume)
Sets initial engine sound volume.
void setSDLRemoveFakeAlpha(bool sdlremovefakealpha)
Sets if fake alpha is removed in SDL renderbackend.
void setDefaultFontGlyphs(const std::string &defaultfontglyphs)
Sets glyphs for default font.
TextureFiltering m_oglTextureFilter
EngineSettings()
Constructor.
void setMouseSensitivity(float sens)
Sets mouse sensitivity.
static Logger _log(LM_AUDIO)
bool isFrameLimitEnabled() const
Gets whether the frame limiter is in use.
void setGLUseMonochrome(bool monochrome)
Sets if OpenGL renderbackend should render only monochrome.
void setGLTextureFiltering(TextureFiltering filter)
Sets texture filtering method for OpenGL renderbackend.
std::string m_defaultfontglyphs
void setColorKeyEnabled(bool colorkeyenable)
Sets whether to use the colorkey feature.
const SDL_Color & getColorKey() const
Gets the global colorkey setting.
const std::string & getVideoDriver() const
void setGLCompressImages(bool oglcompressimages)
Sets if images are compress by video driver in OpenGL renderbackend.
void setWindowTitle(const std::string &title)
Sets the title of the window.
unsigned char uint8_t
Definition: core.h:38
float getMouseSensitivity() const
Gets mouse sensitivity.
bool isGLUseMipmapping() const
Tells if OpenGL renderbackend should use mipmapping.
void setDefaultFontPath(const std::string &defaultfontpath)
Sets path for default font.
void setGLUseDepthBuffer(bool buffer)
Sets if OpenGL renderbackend should use depth buffer.
void setGLUseMipmapping(bool mipmapping)
Sets if OpenGL renderbackend should use mipmapping.
TextureFiltering getGLTextureFiltering() const
Gets current texture filter which uses OpenGL.
std::string m_defaultfontpath
void setScreenHeight(uint16_t screenheight)
Sets screen height (pixels)
void setFrameLimit(uint16_t framelimit)
Sets the frame limit.
void setGLAlphaTestValue(float alpha)
Sets alpha test value for OpenGL renderbackend.
void setRenderBackend(const std::string &renderbackend)
Sets name for renderbackend.
unsigned short uint16_t
Definition: core.h:39
void setScreenWidth(uint16_t screenwidth)
Sets screen width (pixels)
void setColorKey(uint8_t r, uint8_t g, uint8_t b)
Sets the global colorkey to use for images.
std::vector< uint8_t > getPossibleBitsPerPixel() const
Gets all possible bits per pixel values.
bool isMouseAccelerationEnabled() const
Returns if mouse acceleration is enabled or not.
std::string m_windowtitle
uint16_t getFrameLimit() const
Gets the frame limit.
float getGLAlphaTestValue() const
Gets current alpha test value which uses OpenGL.
std::string m_windowicon
void setGLUseNPOT(bool oglusenpot)
Sets if OpenGL renderbackend should use NPOT Textures (when available)
void setBitsPerPixel(uint8_t bitsperpixel)
Sets bits per pixel.
TextureFiltering
Definition: renderbackend.h:99
void setMouseAccelerationEnabled(bool acceleration)
Sets mouse acceleration if mouse acceleration is enabled, then the mouse sensitivity is used as speed...
void setLightingModel(uint32_t lighting)
Sets the light model.
void setWindowIcon(const std::string &icon)
Sets the icon that appears in the window title bar.
void setVideoDriver(const std::string &driver)
std::string m_videodriver
unsigned int uint32_t
Definition: core.h:40
bool isGLUseDepthBuffer() const
Tells if OpenGL renderbackend should use depth buffer.
std::string m_renderbackend
std::vector< std::string > getPossibleRenderBackends()
Gets all possible renderbackend names.