Skip to content

Commit

Permalink
Fixed reality to match docs: (ManyMouse_Init() == 0) still means init…
Browse files Browse the repository at this point in the history
…ialized.
  • Loading branch information
icculus committed Aug 9, 2012
1 parent 924b24d commit f164606
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 52 deletions.
3 changes: 2 additions & 1 deletion README.txt
Expand Up @@ -49,7 +49,8 @@ Basic usage:
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 ...
Expand Down
11 changes: 6 additions & 5 deletions example/detect_mice.c
Expand Up @@ -14,19 +14,20 @@

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;
printf("ManyMouse driver: %s\n", ManyMouse_DriverName());
for (i = 0; i < available_mice; i++)
printf("#%d: %s\n", i, ManyMouse_DeviceName(i));
}

ManyMouse_Quit();
return 0;
} /* main */
Expand Down
32 changes: 24 additions & 8 deletions example/manymousepong.c
Expand Up @@ -169,26 +169,42 @@ static void setSidesExists(void)

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);
paddles[i].exists = 1;
printf("#%d: %s\n", i, name);
} /* for */
} /* else */
}

setSidesExists();
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;
}
}

setSidesExists();
return 1;
} /* initMice */

Expand Down
48 changes: 33 additions & 15 deletions example/mmpong.c
Expand Up @@ -103,29 +103,47 @@ static void initial_setup(int screen_w, int screen_h)
}



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;
}
}

static void update_mice(int screen_w, int screen_h)
{
Expand Down
44 changes: 31 additions & 13 deletions example/test_manymouse_sdl.c
Expand Up @@ -187,24 +187,42 @@ static void initial_setup(int screen_w, int screen_h)

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;
}
}

Expand Down
21 changes: 12 additions & 9 deletions example/test_manymouse_stdio.c
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion manymouse.c
Expand Up @@ -63,7 +63,7 @@ int ManyMouse_Init(void)
if (mice > retval)
retval = mice; /* may move from "error" to "no mice found". */

if (mice > 0)
if (mice >= 0)
driver = this_driver;
} /* if */
} /* for */
Expand Down

0 comments on commit f164606

Please sign in to comment.