Changeset 130

Show
Ignore:
Timestamp:
08/26/10 15:38:59 (18 months ago)
Author:
Carsten
Message:

Revised custom video mode handling and initialization.

Location:
cafu/branches/cafu_to_wx/Ca3DE
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • cafu/branches/cafu_to_wx/Ca3DE/AppCafu.cpp

    r126 r130  
    8686AppCafu::AppCafu() 
    8787    : wxApp(), 
    88       m_IsFullScreen(false), 
     88      m_IsCustomVideoMode(false), 
    8989      m_MainFrame(NULL) 
    9090{ 
     
    143143    SoundShaderManager->RegisterSoundShaderScriptsInDir("Games/"+GameName+"/SoundShader", "Games/"+GameName+"/"); 
    144144 
    145     // Change display mode. 
    146     wxDisplay Display; 
    147  
    148     m_DesktopMode=Display.GetCurrentMode(); 
    149  
    150     if (m_DesktopMode.w==0) m_DesktopMode.w=wxGetDisplaySize().x; 
    151     if (m_DesktopMode.h==0) m_DesktopMode.h=wxGetDisplaySize().y; 
    152  
    153     m_CurrentMode=m_DesktopMode; 
    154  
    155     extern ConVarT Options_ClientWindowSizeX; 
    156     extern ConVarT Options_ClientWindowSizeY; 
    157     extern ConVarT Options_ClientDisplayBPP; 
    158     extern ConVarT Options_ClientDisplayRefresh; 
     145 
     146    // Change the video mode. Although the two actions 
     147    // 
     148    //     (a) change the screen resolution (video mode) and 
     149    //     (b) show the Cafu window full-screen 
     150    // 
     151    // are theoretically independent of each other, case "(a) but not (b)" does not make sense at all; 
     152    // case "not (a) but (b)" makes more sense but is atypical as well, and is easily switched from case 
     153    // "neither (a) nor (b)" by pressing F11. Thus, we are effectively only concerned by two cases: 
     154    // 
     155    //     (1) windowed mode:    "neither (a) nor (b)" 
     156    //     (2) full-screen mode: "both (a) and (b)" 
     157    // 
     158    // For case (1), we simply open a normal application window with dimensions Options_ClientWindowSize[X/Y]. 
     159    // For case (2), we change the video mode as specified by Options_Client* and show the application 
     160    // window full-screen. 
     161    wxDisplay      Display; 
    159162    extern ConVarT Options_ClientFullScreen; 
    160163 
    161164    if (Options_ClientFullScreen.GetValueBool()) 
    162165    { 
    163         const wxVideoMode VideoMode(Options_ClientWindowSizeX.GetValueInt(), 
    164                                     Options_ClientWindowSizeY.GetValueInt(), 
    165                                     Options_ClientDisplayBPP.GetValueInt(), 
    166                                     Options_ClientDisplayRefresh.GetValueInt()); 
    167  
    168         if (Display.ChangeMode(VideoMode)) 
     166        extern ConVarT Options_ClientWindowSizeX; 
     167        extern ConVarT Options_ClientWindowSizeY; 
     168        extern ConVarT Options_ClientDisplayBPP; 
     169        extern ConVarT Options_ClientDisplayRefresh; 
     170 
     171        const wxVideoMode VideoMode1(Options_ClientWindowSizeX.GetValueInt(), 
     172                                     Options_ClientWindowSizeY.GetValueInt(), 
     173                                     Options_ClientDisplayBPP.GetValueInt(), 
     174                                     Options_ClientDisplayRefresh.GetValueInt()); 
     175 
     176        const wxVideoMode VideoMode2(Options_ClientWindowSizeX.GetValueInt(), 
     177                                     Options_ClientWindowSizeY.GetValueInt(), 
     178                                     Options_ClientDisplayBPP.GetValueInt(), 0); 
     179 
     180        const wxVideoMode VideoMode3(Options_ClientWindowSizeX.GetValueInt(), 
     181                                     Options_ClientWindowSizeY.GetValueInt(), 0, 0); 
     182 
     183        if (Display.ChangeMode(VideoMode1)) 
    169184        { 
    170             m_CurrentMode=Display.GetCurrentMode(); 
    171             m_IsFullScreen=true; 
     185            m_IsCustomVideoMode=true; 
     186        } 
     187        else if (Display.ChangeMode(VideoMode2)) 
     188        { 
     189            Options_ClientDisplayRefresh.SetValue(Display.GetCurrentMode().refresh); 
     190            m_IsCustomVideoMode=true; 
     191        } 
     192        else if (Display.ChangeMode(VideoMode3)) 
     193        { 
     194            Options_ClientDisplayBPP.SetValue(Display.GetCurrentMode().bpp); 
     195            Options_ClientDisplayRefresh.SetValue(Display.GetCurrentMode().refresh); 
     196            m_IsCustomVideoMode=true; 
    172197        } 
    173198        else 
    174199        { 
    175200            wxMessageBox("Cafu tried to change the video mode to\n"+ 
    176                 wxString::Format("        %i x %i, %i BPP at %i Hz,\n", VideoMode.w, VideoMode.h, VideoMode.bpp, VideoMode.refresh)+ 
     201                wxString::Format("        %i x %i, %i bpp at %i Hz,\n", VideoMode1.w, VideoMode1.h, VideoMode1.bpp, VideoMode1.refresh)+ 
     202                wxString::Format("        %i x %i, %i bpp at any refresh rate,\n", VideoMode2.w, VideoMode2.h, VideoMode2.bpp)+ 
     203                wxString::Format("        %i x %i at any color depth and refresh rate,\n", VideoMode3.w, VideoMode3.h)+ 
    177204                "but it didn't work out (zero values mean system defaults).\n"+ 
    178205                "We will use the currently active video mode instead and continue.\n\n"+ 
     
    180207                "or tweak the video mode details via the console variables.\n", 
    181208                "Could not change the video mode", wxOK | wxICON_EXCLAMATION); 
     209 
     210            Options_ClientFullScreen.SetValue(false); 
    182211        } 
    183212    } 
     213 
     214    m_CurrentMode=Display.GetCurrentMode(); 
     215 
     216    if (m_CurrentMode.w==0) { m_CurrentMode.w=wxGetDisplaySize().x; wxLogDebug("Set m_CurrentMode.w from 0 to %i", m_CurrentMode.w); } 
     217    if (m_CurrentMode.h==0) { m_CurrentMode.h=wxGetDisplaySize().y; wxLogDebug("Set m_CurrentMode.h from 0 to %i", m_CurrentMode.h); } 
     218 
     219    if (m_CurrentMode.w<200) { m_CurrentMode.w=1024; wxLogDebug("Set m_CurrentMode.w from <200 to %i", m_CurrentMode.w); } 
     220    if (m_CurrentMode.h<150) { m_CurrentMode.h= 768; wxLogDebug("Set m_CurrentMode.h from <150 to %i", m_CurrentMode.h); } 
     221 
    184222 
    185223    // Create the main frame. 
     
    193231int AppCafu::OnExit() 
    194232{ 
    195     if (m_CurrentMode!=m_DesktopMode) 
     233    if (m_IsCustomVideoMode) 
    196234    { 
    197235        wxDisplay Display; 
    198236 
    199         Display.ChangeMode(m_DesktopMode); 
     237        // Reset the display to default (desktop) video mode. 
     238        Display.ChangeMode(); 
    200239    } 
    201240 
  • cafu/branches/cafu_to_wx/Ca3DE/AppCafu.hpp

    r126 r130  
    4949    AppCafu(); 
    5050 
    51     /// This method returns the desktops video mode (that was active before the Cafu application was started). 
    52     const wxVideoMode& GetDesktopMode() const { return m_DesktopMode; } 
     51    /// Returns whether we successfully set a custom video mode (screen resolution) during initialization. 
     52    bool IsCustomVideoMode() const { return m_IsCustomVideoMode; } 
    5353 
    5454    /// This method returns the current video mode, which may be identical to the desktops video mode 
    5555    /// (in which case the mode as not switched at all at app init), or any custom mode. 
    5656    const wxVideoMode& GetCurrentMode() const { return m_CurrentMode; } 
    57  
    58     /// Returns whether we're running in full-screen mode (with video mode changed, no frame border, etc.) 
    59     /// or in a regular window (on the desktop, with frame border, etc.). 
    60     bool IsFullScreen() const { return m_IsFullScreen; } 
    6157 
    6258    /// Returns the main frame of the Cafu application. 
     
    7268    bool OnCmdLineParsed(wxCmdLineParser& Parser); 
    7369 
    74     wxVideoMode m_DesktopMode;      ///< The desktops video mode. 
    75     wxVideoMode m_CurrentMode;      ///< The video mode we're currently using. 
    76     bool        m_IsFullScreen;     ///< Whether we are running in full-screen mode (with video mode changed, no frame border, etc.) or in a regular window (on the desktop, with frame border, etc.). 
    77     MainFrameT* m_MainFrame; 
     70    bool        m_IsCustomVideoMode;  ///< Whether we successfully set a custom video mode (screen resolution) during initialization. 
     71    wxVideoMode m_CurrentMode;        ///< The video mode that we're currently using. 
     72    MainFrameT* m_MainFrame;          ///< The Cafu application main frame. 
    7873}; 
    7974 
  • cafu/branches/cafu_to_wx/Ca3DE/ConDefs.cpp

    r126 r130  
    7777 
    7878 
     79static bool CompareModes(const wxVideoMode& Mode1, const wxVideoMode& Mode2) 
     80{ 
     81    // Compare the widths. 
     82    if (Mode1.w < Mode2.w) return true; 
     83    if (Mode1.w > Mode2.w) return false; 
     84 
     85    // The widths are equal, now compare the heights. 
     86    if (Mode1.h < Mode2.h) return true; 
     87    if (Mode1.h > Mode2.h) return false; 
     88 
     89    // The widths and heights are equal, now compare the BPP. 
     90    if (Mode1.bpp < Mode2.bpp) return true; 
     91    if (Mode1.bpp > Mode2.bpp) return false; 
     92 
     93    // The widths, heights and BPPs are equal, now compare the refresh rate. 
     94    if (Mode1.refresh < Mode2.refresh) return true; 
     95    if (Mode1.refresh > Mode2.refresh) return false; 
     96 
     97    // The modes are equal. 
     98    return false; 
     99} 
     100 
     101static std::string GetVideoModes() 
     102{ 
     103    ArrayT<wxVideoMode> Modes; 
     104 
     105    { 
     106        wxDisplay         Display; 
     107        wxArrayVideoModes wxModes=Display.GetModes(); 
     108 
     109        for (size_t ModeNr=0; ModeNr<wxModes.GetCount(); ModeNr++) 
     110            Modes.PushBack(wxModes[ModeNr]); 
     111    } 
     112 
     113    // Remove modes according to certain filter criteria, cutting excessively long mode lists. 
     114    for (unsigned long ModeNr=0; ModeNr<Modes.Size(); ModeNr++) 
     115    { 
     116        const wxVideoMode& Mode=Modes[ModeNr]; 
     117 
     118        if (Mode.w==0 || Mode.h==0 || Mode.bpp<15) 
     119        { 
     120            Modes.RemoveAt(ModeNr); 
     121            ModeNr--; 
     122            continue; 
     123        } 
     124 
     125        for (unsigned long OtherNr=0; OtherNr<Modes.Size(); OtherNr++) 
     126        { 
     127            if (OtherNr==ModeNr) continue; 
     128 
     129            const wxVideoMode& Other=Modes[OtherNr]; 
     130 
     131            if (Mode==Other || (Mode.w==Other.w && Mode.h==Other.h && Mode.bpp<32 && Mode.bpp<Other.bpp)) 
     132            { 
     133                Modes.RemoveAt(ModeNr); 
     134                ModeNr--; 
     135                break; 
     136            } 
     137        } 
     138 
     139        // Note that the above loop is written in a way that allows no additional statements here. 
     140    } 
     141 
     142    // Sort the modes by increasing width, height, BPP and refresh rate. 
     143    Modes.QuickSort(CompareModes); 
     144 
     145    // Build the result string. 
     146    wxString List; 
     147 
     148    for (unsigned long ModeNr=0; ModeNr<Modes.Size(); ModeNr++) 
     149    { 
     150        const wxVideoMode& Mode=Modes[ModeNr]; 
     151 
     152        List+=wxString::Format("%i x %i, %i bpp, %i Hz\n", Mode.w, Mode.h, Mode.bpp, Mode.refresh); 
     153    } 
     154 
     155    return List.ToStdString(); 
     156} 
     157 
     158// Note that the format of the VideoModes string is fixed - it is parsed by the Main Menu GUI in order to populate the choice box. 
     159static ConVarT VideoModes("VideoModes", GetVideoModes(), ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_READ_ONLY, "The list of video modes that are available on your system."); 
     160 
     161 
    79162static int ConFunc_CleanupPersistentConfig_Callback(lua_State* LuaState) 
    80163{ 
  • cafu/branches/cafu_to_wx/Ca3DE/MainCanvas.cpp

    r126 r130  
    2323 
    2424#include "MainCanvas.hpp" 
     25#include "AppCafu.hpp" 
    2526#include "MainFrame.hpp" 
    2627#include "Client/Client.hpp" 
     
    902903        case WXK_F11: 
    903904        { 
    904             m_Parent->ShowFullScreen(!m_Parent->IsFullScreen()); 
     905            if (!wxGetApp().IsCustomVideoMode()) 
     906            { 
     907                // Switching full-screen mode with F11 only makes sense if we didn't set a custom video mode (screen resolution). 
     908                // See AppCafuT::OnInit() for more details. 
     909                m_Parent->ShowFullScreen(!m_Parent->IsFullScreen()); 
     910            } 
    905911            return; 
    906912        } 
  • cafu/branches/cafu_to_wx/Ca3DE/MainFrame.cpp

    r126 r130  
    3232 
    3333 
    34 static long int GetStyle() 
    35 { 
    36     // This seems to be a limitation of Windows: 
    37     // Creating a frame with a border that is shown full-screen in a video mode 
    38     // other than the default (desktop) mode does not properly fill the screen... 
    39     return wxGetApp().IsFullScreen() ? 0 : wxDEFAULT_FRAME_STYLE; 
    40 } 
    41  
    42  
    4334MainFrameT::MainFrameT() 
    44     : wxFrame(NULL /*parent*/, wxID_ANY, wxString("Cafu Engine - ") + __DATE__, wxDefaultPosition, wxDefaultSize, GetStyle()), 
     35    : wxFrame(NULL /*parent*/, wxID_ANY, wxString("Cafu Engine - ") + __DATE__), 
    4536      m_MainCanvas(NULL) 
    4637{ 
     
    5950 
    6051    // Show the frame - it is not shown by default... 
    61     if (wxGetApp().IsFullScreen()) ShowFullScreen(true); else Show(); 
     52    if (wxGetApp().IsCustomVideoMode()) ShowFullScreen(true); else Show(); 
    6253} 
    6354