Fixed reality to match docs: (ManyMouse_Init() == 0) still means initialized.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 08 Aug 2012 20:00:48 -0400
changeset 120 e3b5fc6ade02
parent 119 45c353d13c50
child 121 cb7c8d9a9d02
Fixed reality to match docs: (ManyMouse_Init() == 0) still means initialized.
README.txt
example/detect_mice.c
example/manymousepong.c
example/mmpong.c
example/test_manymouse_sdl.c
example/test_manymouse_stdio.c
manymouse.c
--- a/README.txt	Wed Aug 08 18:30:01 2012 -0400
+++ b/README.txt	Wed Aug 08 20:00:48 2012 -0400
@@ -49,7 +49,8 @@
    you poll for other system GUI events...once per iteration of your
    program's main loop.
  - When you are done processing mice, call ManyMouse_Quit() once, usually at
-   program termination.
+   program termination. You should call this even if ManyMouse_Init() returned
+   zero.
 
 There are examples of complete usage in the "example" directory. The simplest
  is test_manymouse_stdio.c ...
--- a/example/detect_mice.c	Wed Aug 08 18:30:01 2012 -0400
+++ b/example/detect_mice.c	Wed Aug 08 20:00:48 2012 -0400
@@ -14,12 +14,12 @@
 
 int main(int argc, char **argv)
 {
-    int available_mice = ManyMouse_Init();
-    if (available_mice <= 0)
-    {
+    const int available_mice = ManyMouse_Init();
+
+    if (available_mice < 0)
+        printf("ManyMouse failed to initialize!\n");
+    else if (available_mice == 0)
         printf("No mice detected!\n");
-        return 1;
-    }
     else
     {
         int i;
@@ -27,6 +27,7 @@
         for (i = 0; i < available_mice; i++)
             printf("#%d: %s\n", i, ManyMouse_DeviceName(i));
     }
+
     ManyMouse_Quit();
     return 0;
 } /* main */
--- a/example/manymousepong.c	Wed Aug 08 18:30:01 2012 -0400
+++ b/example/manymousepong.c	Wed Aug 08 20:00:48 2012 -0400
@@ -169,26 +169,42 @@
 
 static int initMice(void)
 {
+    int i;
+
     available_mice = ManyMouse_Init();
-    if (available_mice > MAX_PADDLES)
-        available_mice = MAX_PADDLES;
+
+    if (available_mice < 0)
+    {
+        printf("Error initializing ManyMouse!\n");
+        return 0;
+    }
+
+    printf("ManyMouse driver: %s\n", ManyMouse_DriverName());
 
     if (available_mice == 0)
         printf("No mice detected!\n");
     else
     {
-        int i;
-        printf("ManyMouse driver: %s\n", ManyMouse_DriverName());
+        for (i = 0; i < available_mice; i++)
+        {
+            const char *name = ManyMouse_DeviceName(i);
+            printf("#%d: %s\n", i, name);
+        }
+
+        if (available_mice > MAX_PADDLES)
+        {
+            printf("Clamping to first %d mice.\n");
+            available_mice = MAX_PADDLES;
+        }
+
         for (i = 0; i < available_mice; i++)
         {
             const char *name = ManyMouse_DeviceName(i);
             paddles[i].exists = 1;
-            printf("#%d: %s\n", i, name);
-        } /* for */
-    } /* else */
+        }
+    }
 
     setSidesExists();
-
     return 1;
 } /* initMice */
 
--- a/example/mmpong.c	Wed Aug 08 18:30:01 2012 -0400
+++ b/example/mmpong.c	Wed Aug 08 20:00:48 2012 -0400
@@ -103,30 +103,48 @@
 }
 
 
+
 static void init_mice(void)
 {
+    int i;
+
     available_mice = ManyMouse_Init();
+
+    if (available_mice < 0)
+    {
+        printf("Error initializing ManyMouse!\n");
+        return;
+    }
+
+    printf("ManyMouse driver: %s\n", ManyMouse_DriverName());
+
+    if (available_mice == 0)
+    {
+        printf("No mice detected!\n");
+        return;
+    }
+
+    for (i = 0; i < available_mice; i++)
+    {
+        const char *name = ManyMouse_DeviceName(i);
+        printf("#%d: %s\n", i, name);
+    }
+
     if (available_mice > MAX_MICE)
+    {
+        printf("Clamping to first %d mice.\n");
         available_mice = MAX_MICE;
-	
-    if (available_mice == 0)
-        printf("No mice detected!\n");
-    else
+    }
+
+    for (i = 0; i < available_mice; i++)
     {
-        int i;
-        printf("ManyMouse driver: %s\n", ManyMouse_DriverName());
-        for (i = 0; i < available_mice; i++)
-        {
-            const char *name = ManyMouse_DeviceName(i);
-            strncpy(mice[i].name, name, sizeof (mice[i].name));
-            mice[i].name[sizeof (mice[i].name) - 1] = '\0';
-            mice[i].connected = 1;
-            printf("#%d: %s\n", i, mice[i].name);
-        }
+        const char *name = ManyMouse_DeviceName(i);
+        strncpy(mice[i].name, name, sizeof (mice[i].name));
+        mice[i].name[sizeof (mice[i].name) - 1] = '\0';
+        mice[i].connected = 1;
     }
 }
 
-
 static void update_mice(int screen_w, int screen_h)
 {
     ManyMouseEvent event;
--- a/example/test_manymouse_sdl.c	Wed Aug 08 18:30:01 2012 -0400
+++ b/example/test_manymouse_sdl.c	Wed Aug 08 20:00:48 2012 -0400
@@ -187,24 +187,42 @@
 
 static void init_mice(void)
 {
+    int i;
+
     available_mice = ManyMouse_Init();
-    if (available_mice > MAX_MICE)
-        available_mice = MAX_MICE;
+
+    if (available_mice < 0)
+    {
+        printf("Error initializing ManyMouse!\n");
+        return;
+    }
+
+    printf("ManyMouse driver: %s\n", ManyMouse_DriverName());
 
     if (available_mice == 0)
+    {
         printf("No mice detected!\n");
-    else
+        return;
+    }
+
+    for (i = 0; i < available_mice; i++)
     {
-        int i;
-        printf("ManyMouse driver: %s\n", ManyMouse_DriverName());
-        for (i = 0; i < available_mice; i++)
-        {
-            const char *name = ManyMouse_DeviceName(i);
-            strncpy(mice[i].name, name, sizeof (mice[i].name));
-            mice[i].name[sizeof (mice[i].name) - 1] = '\0';
-            mice[i].connected = 1;
-            printf("#%d: %s\n", i, mice[i].name);
-        }
+        const char *name = ManyMouse_DeviceName(i);
+        printf("#%d: %s\n", i, name);
+    }
+
+    if (available_mice > MAX_MICE)
+    {
+        printf("Clamping to first %d mice.\n");
+        available_mice = MAX_MICE;
+    }
+
+    for (i = 0; i < available_mice; i++)
+    {
+        const char *name = ManyMouse_DeviceName(i);
+        strncpy(mice[i].name, name, sizeof (mice[i].name));
+        mice[i].name[sizeof (mice[i].name) - 1] = '\0';
+        mice[i].connected = 1;
     }
 }
 
--- a/example/test_manymouse_stdio.c	Wed Aug 08 18:30:01 2012 -0400
+++ b/example/test_manymouse_stdio.c	Wed Aug 08 20:00:48 2012 -0400
@@ -15,24 +15,27 @@
 int main(int argc, char **argv)
 {
     ManyMouseEvent event;
-    int available_mice = ManyMouse_Init();
+    const int available_mice = ManyMouse_Init();
+    int i;
+
     if (available_mice < 0)
     {
         printf("Error initializing ManyMouse!\n");
+        ManyMouse_Quit();
         return 2;
     }
-    else if (available_mice == 0)
+
+    printf("ManyMouse driver: %s\n", ManyMouse_DriverName());
+
+    if (available_mice == 0)
     {
         printf("No mice detected!\n");
+        ManyMouse_Quit();
         return 1;
     }
-    else
-    {
-        int i;
-        printf("ManyMouse driver: %s\n", ManyMouse_DriverName());
-        for (i = 0; i < available_mice; i++)
-            printf("#%d: %s\n", i, ManyMouse_DeviceName(i));
-    }
+
+    for (i = 0; i < available_mice; i++)
+        printf("#%d: %s\n", i, ManyMouse_DeviceName(i));
     printf("\n");
 
     printf("Use your mice, CTRL-C to exit.\n");
--- a/manymouse.c	Wed Aug 08 18:30:01 2012 -0400
+++ b/manymouse.c	Wed Aug 08 20:00:48 2012 -0400
@@ -63,7 +63,7 @@
             if (mice > retval)
                 retval = mice; /* may move from "error" to "no mice found". */
 
-            if (mice > 0)
+            if (mice >= 0)
                 driver = this_driver;
         } /* if */
     } /* for */