FIFE 2008.0
|
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 00035 #include "enginesettings.h" 00036 00037 namespace FIFE { 00038 const float MAXIMUM_VOLUME = 10.0; 00039 00040 EngineSettings::EngineSettings(): 00041 m_bitsperpixel(0), 00042 m_fullscreen(false), 00043 m_initialvolume(MAXIMUM_VOLUME / 2), 00044 m_renderbackend("SDL"), 00045 m_sdlremovefakealpha(false), 00046 m_screenwidth(800), 00047 m_screenheight(600), 00048 m_windowtitle("FIFE"), 00049 m_windowicon(""), 00050 m_defaultfontpath(""), 00051 m_defaultfontsize(8), 00052 m_defaultfontglyphs(""), 00053 m_iscolorkeyenabled(false), 00054 m_lighting(0) { 00055 m_colorkey.r = 255; 00056 m_colorkey.g = 0; 00057 m_colorkey.b = 255; 00058 00059 #if defined( __unix__ ) 00060 m_videodriver = "x11"; 00061 #elif defined( WIN32 ) 00062 m_videodriver = "windib"; 00063 #elif defined( __APPLE_CC__ ) 00064 m_videodriver = "x11"; 00065 #else 00066 m_videodriver = ""; 00067 #endif 00068 00069 } 00070 00071 EngineSettings::~EngineSettings() { 00072 } 00073 00074 void EngineSettings::validate() const { 00075 if (m_defaultfontpath == "") { 00076 throw NotSet("Path for default font is not set"); 00077 } 00078 std::string::size_type loc = m_defaultfontpath.find(".ttf", 0); 00079 if ((loc == std::string::npos) && (m_defaultfontglyphs == "")) { 00080 throw NotSet("Glyphs for default font are not set"); 00081 } 00082 } 00083 00084 std::vector<std::pair<uint16_t, uint16_t> > EngineSettings::getPossibleResolutions() const { 00085 SDL_Rect **modes = SDL_ListModes(NULL, ((getRenderBackend() != "SDL") ? (SDL_OPENGL | SDL_HWPALETTE | SDL_HWACCEL) : 0) | (isFullScreen() ? SDL_FULLSCREEN : 0)); 00086 if(modes == (SDL_Rect **)0) 00087 throw NotFound("No VideoMode Found"); 00088 00089 std::vector<std::pair<uint16_t, uint16_t> > result; 00090 if(modes != (SDL_Rect **)-1) 00091 for(unsigned int i = 0; modes[i]; ++i) 00092 result.push_back(std::pair<uint16_t, uint16_t>(modes[i]->w, modes[i]->h)); 00093 return result; 00094 } 00095 00096 void EngineSettings::setBitsPerPixel(uint16_t bitsperpixel) { 00097 std::vector<uint16_t> pv = getPossibleBitsPerPixel(); 00098 std::vector<uint16_t>::iterator i = std::find(pv.begin(), pv.end(), bitsperpixel); 00099 if (i != pv.end()) { 00100 m_bitsperpixel = bitsperpixel; 00101 return; 00102 } 00103 throw NotSupported("Given bits per pixel value is not supported"); 00104 } 00105 00106 std::vector<uint16_t> EngineSettings::getPossibleBitsPerPixel() const { 00107 std::vector<uint16_t> tmp; 00108 tmp.push_back(0); 00109 tmp.push_back(16); 00110 tmp.push_back(24); 00111 tmp.push_back(32); 00112 return tmp; 00113 } 00114 00115 void EngineSettings::setInitialVolume(float volume) { 00116 if (volume > getMaxVolume()) { 00117 throw NotSupported("Given volume exceeds maximum volume"); 00118 } 00119 if (volume < 0) { 00120 throw NotSupported("Given volume is below 0"); 00121 } 00122 m_initialvolume = volume; 00123 } 00124 00125 float EngineSettings::getMaxVolume() const { 00126 return MAXIMUM_VOLUME; 00127 } 00128 00129 void EngineSettings::setRenderBackend(const std::string& renderbackend) { 00130 std::vector<std::string> pv = getPossibleRenderBackends(); 00131 std::vector<std::string>::iterator i = std::find(pv.begin(), pv.end(), renderbackend); 00132 if (i != pv.end()) { 00133 m_renderbackend = renderbackend; 00134 return; 00135 } 00136 throw NotSupported("Given render backend is not supported"); 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 return tmp; 00144 } 00145 00146 void EngineSettings::setSDLRemoveFakeAlpha(bool sdlremovefakealpha) { 00147 m_sdlremovefakealpha = sdlremovefakealpha; 00148 } 00149 00150 void EngineSettings::setScreenWidth(uint16_t screenwidth) { 00151 m_screenwidth = screenwidth; 00152 } 00153 00154 void EngineSettings::setScreenHeight(uint16_t screenheight) { 00155 m_screenheight = screenheight; 00156 } 00157 00158 void EngineSettings::setDefaultFontPath(const std::string& defaultfontpath) { 00159 m_defaultfontpath = defaultfontpath; 00160 } 00161 00162 void EngineSettings::setDefaultFontSize(uint16_t defaultfontsize) { 00163 m_defaultfontsize = defaultfontsize; 00164 } 00165 00166 void EngineSettings::setDefaultFontGlyphs(const std::string& defaultfontglyphs) { 00167 m_defaultfontglyphs = defaultfontglyphs; 00168 } 00169 00170 void EngineSettings::setWindowTitle(const std::string& title) { 00171 m_windowtitle = title; 00172 } 00173 00174 void EngineSettings::setWindowIcon(const std::string& icon) { 00175 m_windowicon = icon; 00176 } 00177 00178 void EngineSettings::setColorKeyEnabled(bool colorkeyenable) { 00179 m_iscolorkeyenabled = colorkeyenable; 00180 } 00181 00182 bool EngineSettings::isColorKeyEnabled() const { 00183 return m_iscolorkeyenabled; 00184 } 00185 00186 void EngineSettings::setColorKey(uint8_t r, uint8_t g, uint8_t b) { 00187 m_colorkey.r = r; 00188 m_colorkey.g = g; 00189 m_colorkey.b = b; 00190 } 00191 00192 const SDL_Color& EngineSettings::getColorKey() const { 00193 return m_colorkey; 00194 } 00195 00196 void EngineSettings::setVideoDriver(const std::string& driver) { 00197 m_videodriver = driver; 00198 } 00199 00200 const std::string& EngineSettings::getVideoDriver() const { 00201 return m_videodriver; 00202 } 00203 void EngineSettings::setLightingModel(unsigned int lighting) { 00204 if (lighting <= 2) { 00205 m_lighting = lighting; 00206 return; 00207 } 00208 throw NotSupported("Given light model is not supported"); 00209 } 00210 00211 } 00212