diff 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
line wrap: on
line diff
--- a/engine/core/video/devicecaps.cpp	Tue Oct 12 18:58:47 2010 +0000
+++ b/engine/core/video/devicecaps.cpp	Wed Oct 13 20:24:48 2010 +0000
@@ -21,6 +21,7 @@
 
 // Standard C++ library includes
 #include <iostream>
+#include <algorithm>
 
 // 3rd party library includes
 #include <SDL.h>
@@ -51,6 +52,18 @@
 		m_SDLFlags = rhs.getSDLFlags();
 	}
 
+	bool ScreenMode::operator <(const ScreenMode& rhs) const {
+		if (m_bpp < rhs.getBPP() ) {
+			return true;
+		}
+		else if (m_bpp == rhs.getBPP()) {
+			if (m_width < rhs.getWidth() || m_height < rhs.getHeight()) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 	DeviceCaps::DeviceCaps() :
 	    m_driverName("Invalid"),
 		m_hwAvailable(false),
@@ -115,7 +128,7 @@
 		int bufferSize = 256;
 		char buffer[bufferSize];
 
-		int numBPP = 1;
+		int numBPP = 3;
 		int bpps[numBPP];
 
 		//clear in case this is called twice
@@ -145,8 +158,10 @@
 #endif
 		//BITS PER PIXEL
 
-		bpps[0] = 32;
-		
+		bpps[0] = 16;
+		bpps[1] = 24;
+		bpps[2] = 32;
+
 		//COMMON FS RESOLUTIONS
 		int resolutions[15][2] = {
 			{640, 480},
@@ -174,10 +189,9 @@
 					int bpp;
 					if (flags[j] & SDL_FULLSCREEN) {
 						bpp = SDL_VideoModeOK(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]);
-						
+
 						if (bpp > 0) {
-							ScreenMode mode = ScreenMode(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]);
-							m_screenModes.push_back(mode);
+							m_screenModes.push_back(ScreenMode(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]));
 						}
 					}
 					else {  //windowed mode
@@ -185,8 +199,7 @@
 						//we are checking to make sure the bpp is supported here.
 						bpp = SDL_VideoModeOK(resolutions[k][0],resolutions[k][1], bpps[i], flags[j]);
 						if (bpp > 0) {
-							ScreenMode mode = ScreenMode(0,0, bpps[i], flags[j]);
-							m_screenModes.push_back(mode);
+							m_screenModes.push_back(ScreenMode(0,0, bpps[i], flags[j]));
 							break; //insert windowed mode once as all resolutions are supported.
 						}
 					}
@@ -195,6 +208,11 @@
 			}
 		}
 
+		//sort the list to keep the most preferred modes at the top of the selection process
+		//in getNearestScreenMode()
+		std::sort(m_screenModes.begin(), m_screenModes.end());
+		std::reverse(m_screenModes.begin(), m_screenModes.end());
+
 		if(SDL_VideoDriverName(buffer, bufferSize) != NULL) {
 			m_driverName = std::string(buffer);
 		}
@@ -260,6 +278,20 @@
 				break;
 			}
 
+			//current screen bpp selected
+			if (widthCheck && heightCheck && bpp == 0 && fsCheck && rendCheck) {
+				mode = ScreenMode(width, height, bpp, m_screenModes[i].getSDLFlags());
+				foundMode = true;
+				break;
+			}
+
+			if (m_screenModes[i].getWidth() == 0 && m_screenModes[i].getHeight() == 0  && bpp == 0 && fsCheck && rendCheck) {
+				mode = ScreenMode(width, height, bpp, m_screenModes[i].getSDLFlags());
+				foundMode = true;
+				break;
+			}
+
+
 			widthCheck = false;
 			heightCheck = false;
 			bppCheck = false;