Changeset 126

Show
Ignore:
Timestamp:
08/23/10 22:34:43 (18 months ago)
Author:
Carsten
Message:

Added:

  • support for changing the video mode,
  • switching to full-screen display, and
  • parsing the command-line options.

Minor cosmetic enhancements:

  • blanked system mouse cursor in our 3D canvas, and
  • "Initializing Cafu..." message during initialization.

This completes the transfer of features from (old) file Cafu.cpp to the new wx-based code! :-)

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

Legend:

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

    r116 r126  
    4040#include "../Games/Game.hpp" 
    4141 
     42#include "wx/cmdline.h" 
    4243#include "wx/filename.h" 
    4344#include "wx/msgdlg.h" 
     
    8586AppCafu::AppCafu() 
    8687    : wxApp(), 
     88      m_IsFullScreen(false), 
    8789      m_MainFrame(NULL) 
    8890{ 
     
    117119 
    118120    ConsoleInterpreter->RunCommand("dofile('config.lua');"); 
     121 
     122    // Parse the command line. 
     123    if (!wxApp::OnInit()) return false; 
    119124 
    120125    // Insert legacy dialog here... 
     
    138143    SoundShaderManager->RegisterSoundShaderScriptsInDir("Games/"+GameName+"/SoundShader", "Games/"+GameName+"/"); 
    139144 
     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; 
     159    extern ConVarT Options_ClientFullScreen; 
     160 
     161    if (Options_ClientFullScreen.GetValueBool()) 
     162    { 
     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)) 
     169        { 
     170            m_CurrentMode=Display.GetCurrentMode(); 
     171            m_IsFullScreen=true; 
     172        } 
     173        else 
     174        { 
     175            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)+ 
     177                "but it didn't work out (zero values mean system defaults).\n"+ 
     178                "We will use the currently active video mode instead and continue.\n\n"+ 
     179                "Alternatively, you can set a different video mode at the Options menu,\n"+ 
     180                "or tweak the video mode details via the console variables.\n", 
     181                "Could not change the video mode", wxOK | wxICON_EXCLAMATION); 
     182        } 
     183    } 
     184 
    140185    // Create the main frame. 
    141186    m_MainFrame=new MainFrameT(); 
    142187    SetTopWindow(m_MainFrame); 
    143188 
    144     return wxApp::OnInit(); 
     189    return true; 
    145190} 
    146191 
     
    148193int AppCafu::OnExit() 
    149194{ 
     195    if (m_CurrentMode!=m_DesktopMode) 
     196    { 
     197        wxDisplay Display; 
     198 
     199        Display.ChangeMode(m_DesktopMode); 
     200    } 
     201 
    150202    delete g_WinSock; 
    151203    g_WinSock=NULL; 
     
    157209    return wxApp::OnExit(); 
    158210} 
     211 
     212 
     213extern ConVarT Options_ServerGameName; 
     214extern ConVarT Options_ServerWorldName; 
     215extern ConVarT Options_ServerPortNr; 
     216extern ConVarT Options_ClientPortNr; 
     217extern ConVarT Options_ClientRemoteName; 
     218extern ConVarT Options_ClientRemotePortNr; 
     219 
     220extern ConVarT Options_ClientWindowSizeX; 
     221extern ConVarT Options_ClientWindowSizeY; 
     222extern ConVarT Options_ClientDisplayBPP;        // TODO 
     223extern ConVarT Options_ClientDisplayRefresh;    // TODO 
     224extern ConVarT Options_ClientFullScreen; 
     225 
     226extern ConVarT Options_ClientDesiredRenderer; 
     227extern ConVarT Options_ClientDesiredSoundSystem; 
     228extern ConVarT Options_ClientTextureDetail; 
     229extern ConVarT Options_DeathMatchPlayerName; 
     230extern ConVarT Options_DeathMatchModelName; 
     231 
     232 
     233void AppCafu::OnInitCmdLine(wxCmdLineParser& Parser) 
     234{ 
     235    Parser.AddOption("con",            "", "Runs the given commands in the console. -con \"x=3;\" is equivalent to appending x=3; to the end of the config.lua file.", wxCMD_LINE_VAL_STRING); 
     236    Parser.AddOption("svGame",         "", "Name of the MOD / game the server should run ["+Options_ServerGameName.GetValueString()+"]. Case sensitive!", wxCMD_LINE_VAL_STRING); 
     237    Parser.AddOption("svWorld",        "", "Name of the world the server should run ["+Options_ServerWorldName.GetValueString()+"]. Case sensitive!", wxCMD_LINE_VAL_STRING); 
     238    Parser.AddOption("svPort",         "", wxString::Format("Server port number [%i].", Options_ServerPortNr.GetValueInt()), wxCMD_LINE_VAL_NUMBER); 
     239    Parser.AddSwitch("noFS", "clNoFullscreen", "Don't run full-screen, but rather in a window."); 
     240    Parser.AddOption("clPort",         "", wxString::Format("Client port number [%i].", Options_ClientPortNr.GetValueInt()), wxCMD_LINE_VAL_NUMBER); 
     241    Parser.AddOption("clRemoteName",   "", "Name or IP of the server we connect to ["+Options_ClientRemoteName.GetValueString()+"].", wxCMD_LINE_VAL_STRING); 
     242    Parser.AddOption("clRemotePort",   "", wxString::Format("Port number of the remote server [%i].", Options_ClientRemotePortNr.GetValueInt()), wxCMD_LINE_VAL_NUMBER); 
     243    Parser.AddOption("clTexDetail",    "", wxString::Format("0 high detail, 1 medium detail, 2 low detail [%i].", Options_ClientTextureDetail.GetValueInt()), wxCMD_LINE_VAL_NUMBER); 
     244    Parser.AddOption("clWinSizeX",     "", wxString::Format("If not full-screen, this is the width  of the window [%i].", Options_ClientWindowSizeX.GetValueInt()), wxCMD_LINE_VAL_NUMBER); 
     245    Parser.AddOption("clWinSizeY",     "", wxString::Format("If not full-screen, this is the height of the window [%i].", Options_ClientWindowSizeY.GetValueInt()), wxCMD_LINE_VAL_NUMBER); 
     246    Parser.AddOption("clRenderer",     "", "Override the auto-selection of the best available renderer [auto].", wxCMD_LINE_VAL_STRING); 
     247    Parser.AddOption("clSoundSystem",  "", "Override the auto-selection of the best available sound system [auto].", wxCMD_LINE_VAL_STRING); 
     248    Parser.AddOption("clPlayerName",   "", "Player name ["+Options_DeathMatchPlayerName.GetValueString()+"].", wxCMD_LINE_VAL_STRING); 
     249    Parser.AddOption("clModelName",    "", "Name of the players model ["+Options_DeathMatchModelName.GetValueString()+"].", wxCMD_LINE_VAL_STRING); 
     250 
     251    wxApp::OnInitCmdLine(Parser); 
     252    Parser.AddUsageText("\nDefault values are enclosed in [brackets]."); 
     253    Parser.AddUsageText("It is also ok to omit the \"-svWorld\" option for specifying a world name: \"Cafu MyWorld\" is the same as \"Cafu -svWorld MyWorld\".\n"); 
     254    Parser.SetSwitchChars("-"); 
     255} 
     256 
     257 
     258bool AppCafu::OnCmdLineParsed(wxCmdLineParser& Parser) 
     259{ 
     260    long int i=0; 
     261    wxString s=""; 
     262 
     263    if (Parser.Found("con",           &s)) ConsoleInterpreter->RunCommand(s.ToStdString()); 
     264    if (Parser.Found("svGame",        &s)) Options_ServerGameName=s; 
     265    if (Parser.Found("svWorld",       &s)) Options_ServerWorldName=s; 
     266    if (Parser.Found("svPort",        &i)) Options_ServerPortNr=i; 
     267    if (Parser.Found("noFS")             ) Options_ClientFullScreen=false; 
     268    if (Parser.Found("clPort",        &i)) Options_ClientPortNr=i; 
     269    if (Parser.Found("clRemoteName",  &s)) Options_ClientRemoteName=s; 
     270    if (Parser.Found("clRemotePort",  &i)) Options_ClientRemotePortNr=i; 
     271    if (Parser.Found("clTexDetail",   &i)) Options_ClientTextureDetail=i % 3; 
     272    if (Parser.Found("clWinSizeX",    &i)) Options_ClientWindowSizeX=i; 
     273    if (Parser.Found("clWinSizeY",    &i)) Options_ClientWindowSizeY=i; 
     274    if (Parser.Found("clRenderer",    &s)) Options_ClientDesiredRenderer=s; 
     275    if (Parser.Found("clSoundSystem", &s)) Options_ClientDesiredSoundSystem=s; 
     276    if (Parser.Found("clPlayerName",  &s)) Options_DeathMatchPlayerName=s; 
     277    if (Parser.Found("clModelName",   &s)) Options_DeathMatchModelName=s; 
     278 
     279    if (!Parser.Found("svWorld") && Parser.GetParamCount()==1) 
     280        Options_ServerWorldName=Parser.GetParam(0); 
     281 
     282    return wxApp::OnCmdLineParsed(Parser); 
     283} 
  • cafu/branches/cafu_to_wx/Ca3DE/AppCafu.hpp

    r116 r126  
    3636 
    3737#include "wx/app.h" 
     38#include "wx/display.h" 
    3839 
    3940 
     
    4849    AppCafu(); 
    4950 
     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; } 
     53 
     54    /// This method returns the current video mode, which may be identical to the desktops video mode 
     55    /// (in which case the mode as not switched at all at app init), or any custom mode. 
     56    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; } 
     61 
     62    /// Returns the main frame of the Cafu application. 
    5063    MainFrameT* GetMainFrame() const { return m_MainFrame; } 
    5164 
     
    5669    private: 
    5770 
     71    void OnInitCmdLine(wxCmdLineParser& Parser); 
     72    bool OnCmdLineParsed(wxCmdLineParser& Parser); 
     73 
     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.). 
    5877    MainFrameT* m_MainFrame; 
    5978}; 
  • cafu/branches/cafu_to_wx/Ca3DE/ConDefs.cpp

    r116 r126  
    5454/*static*/ ConVarT Options_DeathMatchPlayerName    ("dlg_dmPlayerName",      "Player", ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_PERSISTENT, "Player name for the DeathMatch game."); 
    5555/*static*/ ConVarT Options_DeathMatchModelName     ("dlg_dmModelName",        "James", ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_PERSISTENT, "Name of the model to use for the DeathMatch game."); 
    56 /*static*/ ConVarT Options_ClientFullScreen        ("dlg_clFullScreen",          true, ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_PERSISTENT, "If the clients runs in full-screen or windowed mode."); 
     56/*static*/ ConVarT Options_ClientFullScreen        ("dlg_clFullScreen",          true, ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_PERSISTENT, "When true, the video mode is changed on startup and fullscreen display is used. Otherwise, Cafu runs in an application window on the desktop."); 
    5757/*static*/ ConVarT Options_ClientWindowSizeX       ("dlg_clWindowSizeX",         1024, ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_PERSISTENT, "The size of the client window in X direction."); 
    5858/*static*/ ConVarT Options_ClientWindowSizeY       ("dlg_clWindowSizeY",          768, ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_PERSISTENT, "The size of the client window in Y direction."); 
     
    6262/*static*/ ConVarT Options_ClientRemoteName        ("dlg_clRemoteName", "192.168.1.1", ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_PERSISTENT, "Name or IP of the server the client connects to."); 
    6363/*static*/ ConVarT Options_ClientRemotePortNr      ("dlg_clRemotePort",         30000, ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_PERSISTENT, "Port number of the remote server.", 0, 0xFFFF); 
    64 /*static*/ ConVarT Options_ClientDisplayBPP        ("dlg_clDisplayBPP",             1, ConVarT::FLAG_MAIN_EXE,                            "Use 0 for 16 BPP, 1 for 32 BPP.", 0, 1); 
     64/*static*/ ConVarT Options_ClientDisplayBPP        ("dlg_clDisplayBPP",            32, ConVarT::FLAG_MAIN_EXE,                            "The display depth in bits-per-pixel. Normally use 32, or 0 for system default.", 0, 64); 
     65/*static*/ ConVarT Options_ClientDisplayRefresh    ("dlg_clDisplayRefresh",         0, ConVarT::FLAG_MAIN_EXE,                            "The display refresh rate. Use 0 for system default, check with your monitor specs for any other value."); 
    6566/*static*/ ConVarT Options_ClientTextureDetail     ("dlg_clTextureDetail",          0, ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_PERSISTENT, "0 high detail, 1 medium detail, 2 low detail", 0, 2); 
    6667/*static*/ ConVarT Options_ServerGameName          ("dlg_svGameName",    "DeathMatch", ConVarT::FLAG_MAIN_EXE,                            "Name of the game (MOD) to load."); 
  • cafu/branches/cafu_to_wx/Ca3DE/MainCanvas.cpp

    r125 r126  
    125125    m_GLContext=new wxGLContext(this); 
    126126 
     127    SetCursor(wxCURSOR_BLANK); 
    127128    SetBackgroundStyle(wxBG_STYLE_PAINT); 
    128129} 
     
    504505    if (m_InitState==INIT_REQUIRED) 
    505506    { 
     507        dc.SetBackground(*wxBLACK_BRUSH); 
     508        dc.Clear(); 
     509        dc.SetBackgroundMode(wxTRANSPARENT); 
     510        dc.SetTextForeground(wxColour(255, 200, 0)); 
     511        dc.DrawText("Initializing Cafu...", 10, 40); 
     512 
    506513        // This code is in this place due to a few peculiarities of OpenGL under GTK that do not exist under MSW: 
    507514        //   - An OpenGL context can only be made current with a canvas that is shown on the screen. 
     
    892899            return; 
    893900        } 
     901 
     902        case WXK_F11: 
     903        { 
     904            m_Parent->ShowFullScreen(!m_Parent->IsFullScreen()); 
     905            return; 
     906        } 
    894907    } 
    895908 
  • cafu/branches/cafu_to_wx/Ca3DE/MainFrame.cpp

    r116 r126  
    2323 
    2424#include "MainFrame.hpp" 
     25#include "AppCafu.hpp" 
    2526#include "MainCanvas.hpp" 
    2627 
     
    3132 
    3233 
     34static 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 
    3343MainFrameT::MainFrameT() 
    34     : wxFrame(NULL /*parent*/, wxID_ANY, wxString("Cafu Engine - ") + __DATE__), 
     44    : wxFrame(NULL /*parent*/, wxID_ANY, wxString("Cafu Engine - ") + __DATE__, wxDefaultPosition, wxDefaultSize, GetStyle()), 
    3545      m_MainCanvas(NULL) 
    3646{ 
     
    4959 
    5060    // Show the frame - it is not shown by default... 
    51     Show(); 
     61    if (wxGetApp().IsFullScreen()) ShowFullScreen(true); else Show(); 
    5262} 
    5363