Mercurial > fife-parpg
comparison engine/core/video/devicecaps.cpp @ 646:07b1cf8e92b5
* Major improvements to fife_math.h and added corresponding Python bindings. Users now have access to FIFE's internal math functions. These functions are recommended to be used by all clients if required. Note: this may cause some problems with certain compilers. I hope this wont have to be reverted. TODO: remove the static constant globals somehow.
* Adopted the new math functions for all subsystems
* Improvements to DeviceCaps. It now detects all possible screen modes.
* User can now select 0 for their bpp and it will attempt to initialize SDL with the current screen bpp.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 13 Oct 2010 20:24:48 +0000 |
parents | edf6dcfe8cd4 |
children | b9c132cb6ea4 |
comparison
equal
deleted
inserted
replaced
645:291ba2946c73 | 646:07b1cf8e92b5 |
---|---|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
20 ***************************************************************************/ | 20 ***************************************************************************/ |
21 | 21 |
22 // Standard C++ library includes | 22 // Standard C++ library includes |
23 #include <iostream> | 23 #include <iostream> |
24 #include <algorithm> | |
24 | 25 |
25 // 3rd party library includes | 26 // 3rd party library includes |
26 #include <SDL.h> | 27 #include <SDL.h> |
27 #include <SDL_video.h> | 28 #include <SDL_video.h> |
28 | 29 |
47 ScreenMode::ScreenMode(const ScreenMode& rhs){ | 48 ScreenMode::ScreenMode(const ScreenMode& rhs){ |
48 m_width = rhs.getWidth(); | 49 m_width = rhs.getWidth(); |
49 m_height = rhs.getHeight(); | 50 m_height = rhs.getHeight(); |
50 m_bpp = rhs.getBPP(); | 51 m_bpp = rhs.getBPP(); |
51 m_SDLFlags = rhs.getSDLFlags(); | 52 m_SDLFlags = rhs.getSDLFlags(); |
53 } | |
54 | |
55 bool ScreenMode::operator <(const ScreenMode& rhs) const { | |
56 if (m_bpp < rhs.getBPP() ) { | |
57 return true; | |
58 } | |
59 else if (m_bpp == rhs.getBPP()) { | |
60 if (m_width < rhs.getWidth() || m_height < rhs.getHeight()) { | |
61 return true; | |
62 } | |
63 } | |
64 return false; | |
52 } | 65 } |
53 | 66 |
54 DeviceCaps::DeviceCaps() : | 67 DeviceCaps::DeviceCaps() : |
55 m_driverName("Invalid"), | 68 m_driverName("Invalid"), |
56 m_hwAvailable(false), | 69 m_hwAvailable(false), |
113 | 126 |
114 void DeviceCaps::fillDeviceCaps() { | 127 void DeviceCaps::fillDeviceCaps() { |
115 int bufferSize = 256; | 128 int bufferSize = 256; |
116 char buffer[bufferSize]; | 129 char buffer[bufferSize]; |
117 | 130 |
118 int numBPP = 1; | 131 int numBPP = 3; |
119 int bpps[numBPP]; | 132 int bpps[numBPP]; |
120 | 133 |
121 //clear in case this is called twice | 134 //clear in case this is called twice |
122 reset(); | 135 reset(); |
123 | 136 |
143 //SDL, fullscreen | 156 //SDL, fullscreen |
144 flags[1] = ScreenMode::FULLSCREEN_SDL; | 157 flags[1] = ScreenMode::FULLSCREEN_SDL; |
145 #endif | 158 #endif |
146 //BITS PER PIXEL | 159 //BITS PER PIXEL |
147 | 160 |
148 bpps[0] = 32; | 161 bpps[0] = 16; |
149 | 162 bpps[1] = 24; |
163 bpps[2] = 32; | |
164 | |
150 //COMMON FS RESOLUTIONS | 165 //COMMON FS RESOLUTIONS |
151 int resolutions[15][2] = { | 166 int resolutions[15][2] = { |
152 {640, 480}, | 167 {640, 480}, |
153 {800, 600}, | 168 {800, 600}, |
154 {1024, 768}, | 169 {1024, 768}, |
172 for (int j = 0; j < numFlags; ++j) { | 187 for (int j = 0; j < numFlags; ++j) { |
173 for ( int k = 0; k < numRes; ++k) { | 188 for ( int k = 0; k < numRes; ++k) { |
174 int bpp; | 189 int bpp; |
175 if (flags[j] & SDL_FULLSCREEN) { | 190 if (flags[j] & SDL_FULLSCREEN) { |
176 bpp = SDL_VideoModeOK(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]); | 191 bpp = SDL_VideoModeOK(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]); |
177 | 192 |
178 if (bpp > 0) { | 193 if (bpp > 0) { |
179 ScreenMode mode = ScreenMode(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]); | 194 m_screenModes.push_back(ScreenMode(resolutions[k][0],resolutions[k][1], bpps[i], flags[j])); |
180 m_screenModes.push_back(mode); | |
181 } | 195 } |
182 } | 196 } |
183 else { //windowed mode | 197 else { //windowed mode |
184 //check an arbitrary value as we know all resolutions are supported in windowed mode. | 198 //check an arbitrary value as we know all resolutions are supported in windowed mode. |
185 //we are checking to make sure the bpp is supported here. | 199 //we are checking to make sure the bpp is supported here. |
186 bpp = SDL_VideoModeOK(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]); | 200 bpp = SDL_VideoModeOK(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]); |
187 if (bpp > 0) { | 201 if (bpp > 0) { |
188 ScreenMode mode = ScreenMode(0,0, bpps[i], flags[j]); | 202 m_screenModes.push_back(ScreenMode(0,0, bpps[i], flags[j])); |
189 m_screenModes.push_back(mode); | |
190 break; //insert windowed mode once as all resolutions are supported. | 203 break; //insert windowed mode once as all resolutions are supported. |
191 } | 204 } |
192 } | 205 } |
193 | 206 |
194 } | 207 } |
195 } | 208 } |
196 } | 209 } |
210 | |
211 //sort the list to keep the most preferred modes at the top of the selection process | |
212 //in getNearestScreenMode() | |
213 std::sort(m_screenModes.begin(), m_screenModes.end()); | |
214 std::reverse(m_screenModes.begin(), m_screenModes.end()); | |
197 | 215 |
198 if(SDL_VideoDriverName(buffer, bufferSize) != NULL) { | 216 if(SDL_VideoDriverName(buffer, bufferSize) != NULL) { |
199 m_driverName = std::string(buffer); | 217 m_driverName = std::string(buffer); |
200 } | 218 } |
201 else { | 219 else { |
258 mode = ScreenMode(width, height, bpp, m_screenModes[i].getSDLFlags()); | 276 mode = ScreenMode(width, height, bpp, m_screenModes[i].getSDLFlags()); |
259 foundMode = true; | 277 foundMode = true; |
260 break; | 278 break; |
261 } | 279 } |
262 | 280 |
281 //current screen bpp selected | |
282 if (widthCheck && heightCheck && bpp == 0 && fsCheck && rendCheck) { | |
283 mode = ScreenMode(width, height, bpp, m_screenModes[i].getSDLFlags()); | |
284 foundMode = true; | |
285 break; | |
286 } | |
287 | |
288 if (m_screenModes[i].getWidth() == 0 && m_screenModes[i].getHeight() == 0 && bpp == 0 && fsCheck && rendCheck) { | |
289 mode = ScreenMode(width, height, bpp, m_screenModes[i].getSDLFlags()); | |
290 foundMode = true; | |
291 break; | |
292 } | |
293 | |
294 | |
263 widthCheck = false; | 295 widthCheck = false; |
264 heightCheck = false; | 296 heightCheck = false; |
265 bppCheck = false; | 297 bppCheck = false; |
266 rendCheck = false; | 298 rendCheck = false; |
267 fsCheck = false; | 299 fsCheck = false; |