FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
enginesettings.cpp
1 /***************************************************************************
2  * Copyright (C) 2005-2010 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  static Logger _log(LM_CONTROLLER);
40 
41  const float MAXIMUM_VOLUME = 10.0;
42 
44  m_bitsperpixel(0),
45  m_fullscreen(false),
46  m_initialvolume(MAXIMUM_VOLUME / 2),
47  m_renderbackend("SDL"),
48  m_sdlremovefakealpha(false),
49  m_oglcompressimages(false),
50  m_ogluseframebuffer(true),
51  m_oglusenpot(true),
52  m_screenwidth(800),
53  m_screenheight(600),
54  m_windowtitle("FIFE"),
55  m_windowicon(""),
56  m_defaultfontpath("fonts/FreeSans.ttf"),
57  m_defaultfontsize(8),
58  m_defaultfontglyphs("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&amp;`'*#=[]\\\""),
59  m_iscolorkeyenabled(false),
60  m_lighting(0),
61  m_isframelimit(false),
62  m_framelimit(60),
63  m_mousesensitivity(0.0),
64  m_mouseacceleration(false) {
65  m_colorkey.r = 255;
66  m_colorkey.g = 0;
67  m_colorkey.b = 255;
68 
69 #if defined( __unix__ )
70  m_videodriver = "x11";
71 #elif defined( WIN32 )
72  m_videodriver = "windib";
73 #elif defined( __APPLE_CC__ )
74  m_videodriver = "x11";
75 #else
76  m_videodriver = "";
77 #endif
78 
79  }
80 
82  }
83 
84  void EngineSettings::setBitsPerPixel(uint8_t bitsperpixel) {
85  std::vector<uint8_t> pv = getPossibleBitsPerPixel();
86  std::vector<uint8_t>::iterator i = std::find(pv.begin(), pv.end(), bitsperpixel);
87  if (i != pv.end()) {
88  m_bitsperpixel = bitsperpixel;
89  return;
90  }
91 
92  FL_WARN(_log, LMsg("EngineSettings::setBitsPerPixel() - ")
93  << " Tried to set screen bpp to an unsupporded value of " << bitsperpixel <<
94  ". Setting bpp to use the default value of 0 (the current screen bpp)");
95 
96  m_bitsperpixel = 0; //default value
97  }
98 
99  std::vector<uint8_t> EngineSettings::getPossibleBitsPerPixel() const {
100  std::vector<uint8_t> tmp;
101  tmp.push_back(0);
102  tmp.push_back(16);
103  tmp.push_back(24);
104  tmp.push_back(32);
105  return tmp;
106  }
107 
108  void EngineSettings::setInitialVolume(float volume) {
109  if (volume > getMaxVolume() || volume < 0) {
110  FL_WARN(_log, LMsg("EngineSettings::setInitialVolume() - ")
111  << " Tried to set initial volume to an unsupporded value of " << volume <<
112  ". Setting volume to the default value of 5 (minumum is 0, maximum is 10)");
113 
114  m_initialvolume = 5.0;
115  return;
116  }
117 
118  m_initialvolume = volume;
119  }
120 
122  return MAXIMUM_VOLUME;
123  }
124 
125  void EngineSettings::setRenderBackend(const std::string& renderbackend) {
126  std::vector<std::string> pv = getPossibleRenderBackends();
127  std::vector<std::string>::iterator i = std::find(pv.begin(), pv.end(), renderbackend);
128  if (i != pv.end()) {
129  m_renderbackend = renderbackend;
130  return;
131  }
132  FL_WARN(_log, LMsg("EngineSettings::setRenderBackend() - ")
133  << renderbackend << " is not a valid render backend " <<
134  ". Setting the render backend to the default value of \"SDL\".");
135 
136  m_renderbackend = "SDL";
137  }
138 
139  std::vector<std::string> EngineSettings::getPossibleRenderBackends() {
140  std::vector<std::string> tmp;
141  tmp.push_back("SDL");
142  tmp.push_back("OpenGL");
143  tmp.push_back("OpenGLe");
144  return tmp;
145  }
146 
147  void EngineSettings::setSDLRemoveFakeAlpha(bool sdlremovefakealpha) {
148  m_sdlremovefakealpha = sdlremovefakealpha;
149  }
150 
151  void EngineSettings::setGLCompressImages(bool oglcompressimages) {
152  m_oglcompressimages = oglcompressimages;
153  }
154 
155  void EngineSettings::setGLUseFramebuffer(bool ogluseframebuffer) {
156  m_ogluseframebuffer = ogluseframebuffer;
157  }
158 
159  void EngineSettings::setGLUseNPOT(bool oglusenpot) {
160  m_oglusenpot = oglusenpot;
161  }
162 
163  void EngineSettings::setScreenWidth(uint16_t screenwidth) {
164  m_screenwidth = screenwidth;
165  }
166 
167  void EngineSettings::setScreenHeight(uint16_t screenheight) {
168  m_screenheight = screenheight;
169  }
170 
171  void EngineSettings::setDefaultFontPath(const std::string& defaultfontpath) {
172  m_defaultfontpath = defaultfontpath;
173  }
174 
175  void EngineSettings::setDefaultFontSize(uint16_t defaultfontsize) {
176  m_defaultfontsize = defaultfontsize;
177  }
178 
179  void EngineSettings::setDefaultFontGlyphs(const std::string& defaultfontglyphs) {
180  m_defaultfontglyphs = defaultfontglyphs;
181  }
182 
183  void EngineSettings::setWindowTitle(const std::string& title) {
184  m_windowtitle = title;
185  }
186 
187  void EngineSettings::setWindowIcon(const std::string& icon) {
188  m_windowicon = icon;
189  }
190 
191  void EngineSettings::setColorKeyEnabled(bool colorkeyenable) {
192  m_iscolorkeyenabled = colorkeyenable;
193  }
194 
196  return m_iscolorkeyenabled;
197  }
198 
199  void EngineSettings::setColorKey(uint8_t r, uint8_t g, uint8_t b) {
200  m_colorkey.r = r;
201  m_colorkey.g = g;
202  m_colorkey.b = b;
203  }
204 
205  const SDL_Color& EngineSettings::getColorKey() const {
206  return m_colorkey;
207  }
208 
209  void EngineSettings::setVideoDriver(const std::string& driver) {
210  //TODO: validate the video driver
211  m_videodriver = driver;
212  }
213 
214  const std::string& EngineSettings::getVideoDriver() const {
215  return m_videodriver;
216  }
217  void EngineSettings::setLightingModel(uint32_t lighting) {
218  if (lighting <= 2 && lighting >=0) {
219  m_lighting = lighting;
220  return;
221  }
222 
223  FL_WARN(_log, LMsg("EngineSettings::setLightingModel() - ")
224  << lighting << " is not a valid lighting model." <<
225  ". Setting the lighting model to the default value of 0 (off)");
226 
227  m_lighting = 0;
228  }
229 
231  m_isframelimit = limited;
232  }
233 
235  return m_isframelimit;
236  }
237 
238  void EngineSettings::setFrameLimit(uint16_t framelimit) {
239  m_framelimit = framelimit;
240  }
241 
242  uint16_t EngineSettings::getFrameLimit() const {
243  return m_framelimit;
244  }
245 
247  m_mousesensitivity = sens;
248  }
249 
251  return m_mousesensitivity;
252  }
253 
254  void EngineSettings::setMouseAcceleration(bool acceleration) {
255  m_mouseacceleration = acceleration;
256  }
257 
259  return m_mouseacceleration;
260  }
261 }
262