Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

AutoSelect.c

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  AutoSelect.c                                                                        */
00003 /*                                                                                      */
00004 /*  Author: Mike Sandige                                                                */
00005 /*  Description:    Attempts to automatically choose a good video mode                  */
00006 /*                                                                                      */
00007 /*  Copyright (c) 1997, 1999, Eclipse Entertainment; All rights reserved.               */
00008 /*                                                                                      */
00009 /*  See the accompanying file LICENSE.TXT for terms on the use of this library.         */
00010 /*  This library is distributed in the hope that it will be useful but WITHOUT          */
00011 /*  ANY WARRANTY OF ANY KIND and without any implied warranty of MERCHANTABILITY        */
00012 /*  or FITNESS FOR ANY PURPOSE.  Refer to LICENSE.TXT for more details.                 */
00013 /*                                                                                      */
00014 /****************************************************************************************/
00015 
00016 #include    <stdlib.h>  // qsort 
00017 #include        <assert.h>
00018 #include    <Windows.h>
00019 
00020 
00021 #include        "AutoSelect.h"
00022 
00023 #include    "ErrorLog.h"
00024 #include    "Ram.h"
00025 
00026 
00027 
00028 static int AutoSelect_Compare( const void *arg1, const void *arg2 )
00029 {
00030         /* used for quicksort comparison.  
00031                 returns <0 if arg1 is 'smaller than' arg2
00032                 returns >0 if arg1 is 'greater than' arg2
00033                 returns =0 if arg1 is 'the same as'  arg2
00034                    since the list is sorted by most desirable mode/resolution first, the better mode is 'smaller than'
00035         */
00036         #define A1_BETTER  (-1)
00037         #define A2_BETTER  ( 1)
00038         #define TIE        ( 0)
00039 
00040         int Compare = 0;
00041         ModeList *A1,*A2;
00042         assert(arg1);
00043         assert(arg2);
00044         A1 = (ModeList *)arg1;
00045         A2 = (ModeList *)arg2;
00046 
00047         // sort by DriverType            (smaller enum value first)
00048         // then by windowed
00049         // then by Width             (larger width first)
00050         // then by Height            (larger height first) 
00051         
00052         if      ( A1->DriverType < A2->DriverType )
00053                 return A1_BETTER;
00054         else if ( A2->DriverType < A1->DriverType )
00055                 return A2_BETTER;
00056 
00057         if              ( !A1->InAWindow && A2->InAWindow )
00058                 return A1_BETTER;
00059         if              ( A1->InAWindow && !A2->InAWindow )
00060                 return A2_BETTER;
00061 
00062         if      ( A1->Width > A2->Width )
00063                 return A1_BETTER;
00064         else if ( A2->Width > A1->Width )
00065                 return A2_BETTER;
00066 
00067         if      ( A1->Height > A2->Height )
00068                 return A1_BETTER;
00069         else if ( A2->Height > A1->Height )
00070                 return A2_BETTER;
00071 
00072         return TIE;
00073 }
00074 
00075 void AutoSelect_SortDriverList(ModeList *DriverList, int ListLength)
00076 {
00077         qsort( DriverList, ListLength, sizeof( DriverList[0] ), AutoSelect_Compare );
00078 }
00079         
00080 extern  void GameMgr_ResetMainWindow(HWND hWnd, int32 Width, int32 Height);
00081 
00082 // assumes list is sorted!      
00083 geBoolean AutoSelect_PickDriver(HWND hWnd, geEngine *Engine,ModeList *DriverList, int ListLength, int *Selection)
00084 {
00085         int i;
00086 
00087         assert( Engine      != NULL );
00088         assert( DriverList  != NULL );
00089         assert( Selection   != NULL );
00090 
00091         for (i=0; i<ListLength; i++)
00092                 {
00093                         if (DriverList[i].Evaluation == MODELIST_EVALUATED_OK)
00094                                 {
00095                                         if (DriverList[i].InAWindow)
00096                                                 {
00097                                                         GameMgr_ResetMainWindow(hWnd, DriverList[i].Width, DriverList[i].Height);
00098                                                 }
00099 
00100                                         if (!geEngine_SetDriverAndMode(Engine, DriverList[i].Driver, DriverList[i].Mode))
00101                                                 {
00102                                                         geErrorLog_AddString(-1, "AutoSelect_ModeAndDriver:  driver mode set failed.  continuing.  Driver:", DriverList[i].DriverNamePtr);
00103                                                         geErrorLog_AddString(-1, "AutoSelect_ModeAndDriver:  driver mode set failed.  continuing.    Mode:", DriverList[i].ModeNamePtr);
00104                                                 }
00105                                         else 
00106                                                 {
00107                                                         *Selection = i;
00108                                                         return GE_TRUE;
00109                                                 }
00110                                 }
00111                 }
00112 
00113         return GE_FALSE;
00114 }

Generated on Tue Sep 30 12:35:15 2003 for GTestAndEngine by doxygen 1.3.2