enginesettings.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2010 by the FIFE team                              *
00003  *   http://www.fifengine.net                                              *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 // Standard C++ library includes
00023 #include <algorithm>
00024 #include <string>
00025 
00026 // 3rd party library includes
00027 #include <SDL.h>
00028 
00029 // FIFE includes
00030 // These includes are split up in two parts, separated by one empty line
00031 // First block: files included from the FIFE root src directory
00032 // Second block: files included from the same folder
00033 #include "util/base/exception.h"
00034 #include "util/log/logger.h"
00035 
00036 #include "enginesettings.h"
00037 
00038 namespace FIFE {
00039     static Logger _log(LM_CONTROLLER);
00040 
00041     const float MAXIMUM_VOLUME = 10.0;
00042 
00043     EngineSettings::EngineSettings():
00044         m_bitsperpixel(0),
00045         m_fullscreen(false),
00046         m_initialvolume(MAXIMUM_VOLUME / 2),
00047         m_renderbackend("SDL"),
00048         m_sdlremovefakealpha(false),
00049         m_oglcompressimages(false),
00050         m_ogluseframebuffer(true),
00051         m_oglusenpot(true),
00052         m_screenwidth(800),
00053         m_screenheight(600),
00054         m_windowtitle("FIFE"),
00055         m_windowicon(""),
00056         m_defaultfontpath("fonts/FreeSans.ttf"),
00057         m_defaultfontsize(8),
00058         m_defaultfontglyphs("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&amp;`'*#=[]\\\""),
00059         m_iscolorkeyenabled(false),
00060         m_lighting(0),
00061         m_isframelimit(false),
00062         m_framelimit(60),
00063         m_mousesensitivity(0.0),
00064         m_mouseacceleration(false) {
00065             m_colorkey.r = 255;
00066             m_colorkey.g = 0;
00067             m_colorkey.b = 255;
00068 
00069 #if defined( __unix__ )
00070             m_videodriver = "x11";
00071 #elif defined( WIN32 )
00072             m_videodriver = "windib";
00073 #elif defined( __APPLE_CC__ )
00074             m_videodriver = "x11";
00075 #else
00076             m_videodriver = "";
00077 #endif
00078 
00079     }
00080 
00081     EngineSettings::~EngineSettings() {
00082     }
00083 
00084     void EngineSettings::setBitsPerPixel(uint8_t bitsperpixel) {
00085         std::vector<uint8_t> pv = getPossibleBitsPerPixel();
00086         std::vector<uint8_t>::iterator i = std::find(pv.begin(), pv.end(), bitsperpixel);
00087         if (i != pv.end()) {
00088             m_bitsperpixel = bitsperpixel;
00089             return;
00090         }
00091 
00092         FL_WARN(_log, LMsg("EngineSettings::setBitsPerPixel() - ")
00093             << " Tried to set screen bpp to an unsupporded value of " << bitsperpixel <<
00094             ".  Setting bpp to use the default value of 0 (the current screen bpp)");
00095 
00096         m_bitsperpixel = 0;  //default value
00097     }
00098 
00099     std::vector<uint8_t> EngineSettings::getPossibleBitsPerPixel() const {
00100         std::vector<uint8_t> tmp;
00101         tmp.push_back(0);
00102         tmp.push_back(16);
00103         tmp.push_back(24);
00104         tmp.push_back(32);
00105         return tmp;
00106     }
00107 
00108     void EngineSettings::setInitialVolume(float volume) {
00109         if (volume > getMaxVolume() || volume < 0) {
00110             FL_WARN(_log, LMsg("EngineSettings::setInitialVolume() - ")
00111                 << " Tried to set initial volume to an unsupporded value of " << volume <<
00112                 ".  Setting volume to the default value of 5 (minumum is 0, maximum is 10)");
00113 
00114             m_initialvolume = 5.0;
00115             return;
00116         }
00117 
00118         m_initialvolume = volume;
00119     }
00120 
00121     float EngineSettings::getMaxVolume() const {
00122         return MAXIMUM_VOLUME;
00123     }
00124 
00125     void EngineSettings::setRenderBackend(const std::string& renderbackend) {
00126         std::vector<std::string> pv = getPossibleRenderBackends();
00127         std::vector<std::string>::iterator i = std::find(pv.begin(), pv.end(), renderbackend);
00128         if (i != pv.end()) {
00129             m_renderbackend = renderbackend;
00130             return;
00131         }
00132         FL_WARN(_log, LMsg("EngineSettings::setRenderBackend() - ")
00133             << renderbackend << " is not a valid render backend " <<
00134             ".  Setting the render backend to the default value of \"SDL\".");
00135 
00136         m_renderbackend = "SDL";
00137     }
00138 
00139     std::vector<std::string> EngineSettings::getPossibleRenderBackends() {
00140         std::vector<std::string> tmp;
00141         tmp.push_back("SDL");
00142         tmp.push_back("OpenGL");
00143         tmp.push_back("OpenGLe");
00144         return tmp;
00145     }
00146 
00147     void EngineSettings::setSDLRemoveFakeAlpha(bool sdlremovefakealpha) {
00148         m_sdlremovefakealpha = sdlremovefakealpha;
00149     }
00150 
00151     void EngineSettings::setGLCompressImages(bool oglcompressimages) {
00152         m_oglcompressimages = oglcompressimages;
00153     }
00154 
00155     void EngineSettings::setGLUseFramebuffer(bool ogluseframebuffer) {
00156         m_ogluseframebuffer = ogluseframebuffer;
00157     }
00158 
00159     void EngineSettings::setGLUseNPOT(bool oglusenpot) {
00160         m_oglusenpot = oglusenpot;
00161     }
00162 
00163     void EngineSettings::setScreenWidth(uint16_t screenwidth) {
00164         m_screenwidth = screenwidth;
00165     }
00166 
00167     void EngineSettings::setScreenHeight(uint16_t screenheight) {
00168         m_screenheight = screenheight;
00169     }
00170 
00171     void EngineSettings::setDefaultFontPath(const std::string& defaultfontpath) {
00172         m_defaultfontpath = defaultfontpath;
00173     }
00174 
00175     void EngineSettings::setDefaultFontSize(uint16_t defaultfontsize) {
00176         m_defaultfontsize = defaultfontsize;
00177     }
00178 
00179     void EngineSettings::setDefaultFontGlyphs(const std::string& defaultfontglyphs) {
00180         m_defaultfontglyphs = defaultfontglyphs;
00181     }
00182 
00183     void EngineSettings::setWindowTitle(const std::string& title) {
00184         m_windowtitle = title;
00185     }
00186 
00187     void EngineSettings::setWindowIcon(const std::string& icon) {
00188         m_windowicon = icon;
00189     }
00190 
00191     void EngineSettings::setColorKeyEnabled(bool colorkeyenable) {
00192         m_iscolorkeyenabled = colorkeyenable;
00193     }
00194 
00195     bool EngineSettings::isColorKeyEnabled() const {
00196         return m_iscolorkeyenabled;
00197     }
00198 
00199     void EngineSettings::setColorKey(uint8_t r, uint8_t g, uint8_t b) {
00200         m_colorkey.r = r;
00201         m_colorkey.g = g;
00202         m_colorkey.b = b;
00203     }
00204 
00205     const SDL_Color& EngineSettings::getColorKey() const {
00206         return m_colorkey;
00207     }
00208 
00209     void EngineSettings::setVideoDriver(const std::string& driver) {
00210         //TODO: validate the video driver
00211         m_videodriver = driver;
00212     }
00213 
00214     const std::string& EngineSettings::getVideoDriver() const {
00215         return m_videodriver;
00216     }
00217     void EngineSettings::setLightingModel(uint32_t lighting) {
00218         if (lighting <= 2 && lighting >=0) {
00219             m_lighting = lighting;
00220             return;
00221         }
00222 
00223         FL_WARN(_log, LMsg("EngineSettings::setLightingModel() - ")
00224             << lighting << " is not a valid lighting model." <<
00225             ".  Setting the lighting model to the default value of 0 (off)");
00226 
00227         m_lighting = 0;
00228     }
00229 
00230     void EngineSettings::setFrameLimitEnabled(bool limited) {
00231         m_isframelimit = limited;
00232     }
00233 
00234     bool EngineSettings::isFrameLimitEnabled() const {
00235         return m_isframelimit;
00236     }
00237 
00238     void EngineSettings::setFrameLimit(uint16_t framelimit) {
00239         m_framelimit = framelimit;
00240     }
00241 
00242     uint16_t EngineSettings::getFrameLimit() const {
00243         return m_framelimit;
00244     }
00245 
00246     void EngineSettings::setMouseSensitivity(float sens) {
00247         m_mousesensitivity = sens;
00248     }
00249 
00250     float EngineSettings::getMouseSensitivity() const {
00251         return m_mousesensitivity;
00252     }
00253 
00254     void EngineSettings::setMouseAcceleration(bool acceleration) {
00255         m_mouseacceleration = acceleration;
00256     }
00257 
00258     bool EngineSettings::getMouseAcceleration() const {
00259         return m_mouseacceleration;
00260     }
00261 }
00262