Re: [AD] Runtime Gfx Mode Info - Submission for A4.3.11+

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2009-02-16, Edgar <edgarreynaldo@xxxxxxxxxx> wrote:
> Peter Wang said :
> "The is_a_* functions definitely sound wrong. Maybe change them to  
> gfx_mode_is_*?
> I don't think so many functions are required. You should be able to call  
> one function to tell you both whether a mode is windowed or fullscreen,  
> and whether that's definite. I'm not sure there's any need for  
> is_a_magic_mode()."
>
> How about a single function called get_gfx_mode_type instead then? It  
> would return a bitfield containing it's type, with one bit each for  
> windowed, fullscreen, definitely windowed or fullscreen, and the magic  
> driver type. Unknown types would return GFX_TYPE_UNKNOWN which is  
> defined to 0. I renamed current_gfx_mode to get_gfx_mode and rewrote the  
> function. Example source code attached here, as well as an updated  
> example on the a.cc forum thread.

It looks pretty good to me.  Let's see what others have to say.

>
> Peter said "Stick to Allegro formatting conventions."
>
> Which ones did I break? I used a 3 space indentation level, 3 lines  
> between functions, lower cased underscored function names, and added a  
> short description comment section before the function definitions. What  
> else should I have done?

The attached diff shows the changes I would make.

In C "void f();" declares a function which takes any number of
arguments, not none.

> Also, please tell me how to quote properly for  
> the mailing list.

Like this (">" for level of quoting).  Your email client should do it
automatically.

Peter
diff -u -r GfxModeQueryTest2_Source_orig/window_mode2.c GfxModeQueryTest2_Source/window_mode2.c
--- GfxModeQueryTest2_Source_orig/window_mode2.c	2009-02-16 04:20:14.000000000 +1100
+++ GfxModeQueryTest2_Source/window_mode2.c	2009-02-16 23:30:18.914467671 +1100
@@ -7,70 +7,76 @@
 /// Reworked functions according to suggestions by Peter Wang
 /// To be added to src\graphics.c at line 1753
 
-/* get_gfx_mode_type :
- * Evaluates the type of the graphics driver card
- * and tells you whether it is a windowed, fullscreen,
- * definitely windowed or fullscreen, and/or a magic driver.
+/* get_gfx_mode_type:
+ *  Evaluates the type of the graphics driver card
+ *  and tells you whether it is a windowed, fullscreen,
+ *  definitely windowed or fullscreen, and/or a magic driver.
  */
-int get_gfx_mode_type(const int graphics_card) {
-   int gfx_type = GFX_TYPE_UNKNOWN;// 0
-   
-   _DRIVER_INFO* gfx_driver_info  = NULL;
-   GFX_DRIVER*   gfx_driver_entry = NULL;
-   
+int get_gfx_mode_type(int graphics_card)
+{
+   int gfx_type = GFX_TYPE_UNKNOWN;
+   _DRIVER_INFO *gfx_driver_info;
+   GFX_DRIVER *gfx_driver_entry;
+
    ASSERT(system_driver);
-   
-   /* ask the system driver for a list of graphics hardware drivers */
+
+   /* Ask the system driver for a list of graphics hardware drivers. */
    if (system_driver->gfx_drivers) {
       gfx_driver_info = system_driver->gfx_drivers();
-   } else {
+   }
+   else {
       gfx_driver_info = _gfx_driver_list;
    }
-   
+
    ASSERT(gfx_driver_info);
-   
-   while(gfx_driver_info->driver) {
+
+   while (gfx_driver_info->driver) {
       if (gfx_driver_info->id == graphics_card) {
          gfx_driver_entry = (GFX_DRIVER*)gfx_driver_info->driver;
          if (gfx_driver_entry->windowed) {
             gfx_type |= (GFX_TYPE_WINDOWED   | GFX_TYPE_DEFINITE);
-         } else {
+         }
+         else {
             gfx_type |= (GFX_TYPE_FULLSCREEN | GFX_TYPE_DEFINITE);
          }
          break;
       }
-      ++gfx_driver_info;
+      gfx_driver_info++;
    }
-   
+
    switch (graphics_card) {
-      case GFX_AUTODETECT :
+      case GFX_AUTODETECT:
          gfx_type |= GFX_TYPE_MAGIC;
          break;
-      case GFX_AUTODETECT_FULLSCREEN :
+      case GFX_AUTODETECT_FULLSCREEN:
          gfx_type |= (GFX_TYPE_MAGIC | GFX_TYPE_FULLSCREEN | GFX_TYPE_DEFINITE);
          break;
-      case GFX_AUTODETECT_WINDOWED :
+      case GFX_AUTODETECT_WINDOWED:
          gfx_type |= (GFX_TYPE_MAGIC | GFX_TYPE_WINDOWED   | GFX_TYPE_DEFINITE);
          break;
-      case GFX_SAFE :
+      case GFX_SAFE:
          gfx_type |= GFX_TYPE_MAGIC;
          break;
-      case GFX_TEXT :
+      case GFX_TEXT:
          gfx_type |= GFX_TYPE_MAGIC;
          break;
    }
+
    return gfx_type;
 }
 
 
 
-/* get_gfx_mode :
- * Tells you which graphics mode is currently set.
- * Useful for determining the actual driver that
- * GFX_AUTODETECT* or GFX_SAFE set successfully.
+/* get_gfx_mode:
+ *  Tells you which graphics mode is currently set.
+ *  Useful for determining the actual driver that
+ *  GFX_AUTODETECT* or GFX_SAFE set successfully.
  */
-int get_gfx_mode() {
-   if (!gfx_driver) {return GFX_NONE;}
+int get_gfx_mode(void)
+{
+   if (!gfx_driver)
+      return GFX_NONE;
+
    return gfx_driver->id;
 }
 
diff -u -r GfxModeQueryTest2_Source_orig/window_mode2.h GfxModeQueryTest2_Source/window_mode2.h
--- GfxModeQueryTest2_Source_orig/window_mode2.h	2009-02-16 03:52:48.000000000 +1100
+++ GfxModeQueryTest2_Source/window_mode2.h	2009-02-16 23:30:21.918574779 +1100
@@ -1,31 +1,31 @@
 
 
 
-#ifndef window_mode_h
-#define window_mode_h
+#ifndef WINDOW_MODE_H
+#define WINDOW_MODE_H
 
 #ifdef __cplusplus
-	extern "C" {
+   extern "C" {
 #endif
 
 
 /// To be added to allegro\gfx.h at line 430 or so
 
-/// Bitfield for relaying graphics driver type information
+/* Bitfield for relaying graphics driver type information */
 #define GFX_TYPE_UNKNOWN     0
 #define GFX_TYPE_WINDOWED    1
 #define GFX_TYPE_FULLSCREEN  2
 #define GFX_TYPE_DEFINITE    4
 #define GFX_TYPE_MAGIC       8
 
-AL_FUNC(int , get_gfx_mode_type , (const int graphics_card));
-AL_FUNC(int , get_gfx_mode      , ());
+AL_FUNC(int, get_gfx_mode_type, (int graphics_card));
+AL_FUNC(int, get_gfx_mode, (void));
 
 
 #ifdef __cplusplus
-	}
+   }
 #endif
 
 
-#endif // window_mode_h
+#endif /* WINDOW_MODE_H */
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/