remove unused graphics_default, and default to the highest resolution available in fullscreen mode
authorTero Marttila <terom@fixme.fi>
Tue, 13 Jan 2009 21:36:43 +0200
changeset 392 6c4dc68360eb
parent 391 59c2499fe7bb
child 393 5dd4d782cf3a
remove unused graphics_default, and default to the highest resolution available in fullscreen mode
src/Application.cc
src/Graphics.cc
src/Graphics.hh
--- a/src/Application.cc	Tue Jan 13 21:14:12 2009 +0200
+++ b/src/Application.cc	Tue Jan 13 21:36:43 2009 +0200
@@ -56,7 +56,7 @@
     arg_resolution = PixelCoordinate(GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT);
 
     // extra state
-    bool graphics_default = true;
+    bool resolution_default = true;
     
     try {
         // parse args
@@ -90,10 +90,20 @@
 
             case ARG_FULLSCREEN:
                 arg_fullscreen = true;
+                
+                // choose best resolution unless explicitly set
+                if (resolution_default) {
+                    const CL_DisplayMode best_mode = Graphics::getBestMode();
+                    const CL_Size best_resolution = best_mode.get_resolution();
+
+                    arg_resolution = PixelCoordinate(best_resolution.width, best_resolution.height);
+                }
+
                 break;
 
             case ARG_RESOLUTION:
                 parse_arg_resolution(args.get_argument());
+                resolution_default = false;
                 break;
 
             case ARG_LIST_MODES:
@@ -114,7 +124,7 @@
         throw ArgumentError("cannot be both server and client");
 
     // enable graphics by default unless server
-    if (!arg_server && graphics_default)
+    if (!arg_server)
         arg_graphics = true;
     
     // continue
--- a/src/Graphics.cc	Tue Jan 13 21:14:12 2009 +0200
+++ b/src/Graphics.cc	Tue Jan 13 21:36:43 2009 +0200
@@ -25,6 +25,24 @@
     return CL_DisplayMode::get_display_modes();
 }
 
+const CL_DisplayMode Graphics::getBestMode (void) {
+    const std::vector<CL_DisplayMode> &modes = Graphics::getDisplayModes();
+
+    const CL_DisplayMode *best_mode = NULL;
+    
+    for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++)
+        if (best_mode == NULL || (
+                it->get_resolution().width * it->get_resolution().height > 
+                best_mode->get_resolution().width * best_mode->get_resolution().height    
+        ))
+            best_mode = &*it;
+    
+    if (best_mode == NULL)
+        throw Error("No available video modes!");
+    
+    return *best_mode;
+}
+
 void Graphics::check_input (void) {
     LocalPlayer *player;
     PlayerInput input_mask;
--- a/src/Graphics.hh	Tue Jan 13 21:14:12 2009 +0200
+++ b/src/Graphics.hh	Tue Jan 13 21:36:43 2009 +0200
@@ -38,10 +38,23 @@
 
 public:
     Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen);
-
+    
+    /**
+     * Returns a CL_Font that can be used for drawing text
+     */
     CL_Font& getSimpleFont (void) { return simple_font; }
+    
+    /**
+     * Returns a vector of CL_DisplayModes that lists possible display modes to use for fullscreen mode.
+     */
+    static const std::vector<CL_DisplayMode> & getDisplayModes (void);
 
-    static const std::vector<CL_DisplayMode> & getDisplayModes (void);
+    /**
+     * Returns the "best" CL_DisplayMode to use for fullscreen mode.
+     *
+     * Currently, this just means the largest resolution.
+     */
+    static const CL_DisplayMode getBestMode (void);
     
 private:
     /**