comparison engine/core/controller/enginesettings.cpp @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, 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
28 // FIFE includes
29 // These includes are split up in two parts, separated by one empty line
30 // First block: files included from the FIFE root src directory
31 // Second block: files included from the same folder
32 #include "util/base/exception.h"
33
34 #include "enginesettings.h"
35
36 namespace FIFE {
37 const float MAXIMUM_VOLUME = 10.0;
38
39 EngineSettings::EngineSettings():
40 m_bitsperpixel(0),
41 m_fullscreen(false),
42 m_initialvolume(MAXIMUM_VOLUME / 2),
43 m_renderbackend("SDL"),
44 m_sldremovefakealpha(false),
45 m_screenwidth(800),
46 m_screenheight(600),
47 m_defaultfontpath(""),
48 m_defaultfontsize(8),
49 m_defaultfontglyphs(""),
50 m_image_chunking_size(256) {
51 }
52
53 EngineSettings::~EngineSettings() {
54 }
55
56 void EngineSettings::validate() const {
57 if (m_defaultfontpath == "") {
58 throw NotSet("Path for default font is not set");
59 }
60 std::string::size_type loc = m_defaultfontpath.find(".ttf", 0);
61 if ((loc == std::string::npos) && (m_defaultfontglyphs == "")) {
62 throw NotSet("Glyphs for default font are not set");
63 }
64 }
65
66 void EngineSettings::setBitsPerPixel(unsigned int bitsperpixel) {
67 std::vector<unsigned int> pv = getPossibleBitsPerPixel();
68 std::vector<unsigned int>::iterator i = std::find(pv.begin(), pv.end(), bitsperpixel);
69 if (i != pv.end()) {
70 m_bitsperpixel = bitsperpixel;
71 return;
72 }
73 throw NotSupported("Given bits per pixel value is not supported");
74 }
75
76 std::vector<unsigned int> EngineSettings::getPossibleBitsPerPixel() const {
77 std::vector<unsigned int> tmp;
78 tmp.push_back(0);
79 tmp.push_back(16);
80 tmp.push_back(24);
81 tmp.push_back(32);
82 return tmp;
83 }
84
85 void EngineSettings::setInitialVolume(float volume) {
86 if (volume > getMaxVolume()) {
87 throw NotSupported("Given volume exceeds maximum volume");
88 }
89 if (volume < 0) {
90 throw NotSupported("Given volume is below 0");
91 }
92 m_initialvolume = volume;
93 }
94
95 float EngineSettings::getMaxVolume() const {
96 return MAXIMUM_VOLUME;
97 }
98
99 void EngineSettings::setRenderBackend(const std::string& renderbackend) {
100 std::vector<std::string> pv = getPossibleRenderBackends();
101 std::vector<std::string>::iterator i = std::find(pv.begin(), pv.end(), renderbackend);
102 if (i != pv.end()) {
103 m_renderbackend = renderbackend;
104 return;
105 }
106 throw NotSupported("Given render backend is not supported");
107 }
108
109 std::vector<std::string> EngineSettings::getPossibleRenderBackends() {
110 std::vector<std::string> tmp;
111 tmp.push_back("SDL");
112 tmp.push_back("OpenGL");
113 return tmp;
114 }
115
116 void EngineSettings::setSDLRemoveFakeAlpha(bool sldremovefakealpha) {
117 m_sldremovefakealpha = sldremovefakealpha;
118 }
119
120 void EngineSettings::setScreenWidth(unsigned int screenwidth) {
121 m_screenwidth = screenwidth;
122 }
123
124 void EngineSettings::setScreenHeight(unsigned int screenheight) {
125 m_screenheight = screenheight;
126 }
127
128 void EngineSettings::setDefaultFontPath(const std::string& defaultfontpath) {
129 m_defaultfontpath = defaultfontpath;
130 }
131
132 void EngineSettings::setDefaultFontSize(const unsigned int defaultfontsize) {
133 m_defaultfontsize = defaultfontsize;
134 }
135
136 void EngineSettings::setDefaultFontGlyphs(const std::string& defaultfontglyphs) {
137 m_defaultfontglyphs = defaultfontglyphs;
138 }
139 }
140