File: playfli.c

package info (click to toggle)
allegro4.4 2:4.4.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 20,744 kB
  • sloc: ansic: 164,458; asm: 17,620; cpp: 3,848; objc: 1,687; sh: 1,107; python: 676; pascal: 179; makefile: 55; perl: 29; lisp: 1
file content (111 lines) | stat: -rw-r--r-- 2,312 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*         ______   ___    ___
 *        /\  _  \ /\_ \  /\_ \ 
 *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___ 
 *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
 *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
 *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
 *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
 *                                           /\____/
 *                                           \_/__/
 *
 *      FLI player test program for the Allegro library.
 *
 *      By Shawn Hargreaves.
 *
 *      See readme.txt for copyright information.
 */


#include <string.h>

#include "allegro.h"



void usage(void)
{
   allegro_message("\nFLI player test program for Allegro " ALLEGRO_VERSION_STR ", " ALLEGRO_PLATFORM_STR "\n"
		   "By Shawn Hargreaves, " ALLEGRO_DATE_STR "\n\n"
		   "Usage: playfli [options] filename.(fli|flc)\n\n"
		   "Options:\n"
		   "\t'-loop' cycles the animation until a key is pressed\n"
		   "\t'-step' selects single-step mode\n"
		   "\t'-mode screen_w screen_h' sets the screen mode\n");
}



int loop = FALSE;
int step = FALSE;



int key_checker(void)
{
   if (step) {
      if ((readkey() & 0xFF) == 27)
	 return 1;
      else
	 return 0;
   }
   else {
      if (keypressed())
	 return 1;
      else
	 return 0;
   }
}



int main(int argc, char *argv[])
{
   int w = 320;
   int h = 200;
   int c, ret;

   if (allegro_init() != 0)
      return 1;

   if (argc < 2) {
      usage();
      return 1;
   }

   for (c=1; c<argc-1; c++) {
      if (stricmp(argv[c], "-loop") == 0)
	 loop = TRUE;
      else if (stricmp(argv[c], "-step") == 0)
	 step = TRUE;
      else if ((stricmp(argv[c], "-mode") == 0) && (c<argc-3)) {
	 w = atoi(argv[c+1]);
	 h = atoi(argv[c+2]);
	 c += 2;
      }
      else {
	 usage();
	 return 1;
      }
   }

   install_keyboard();
   install_timer();

   if (set_gfx_mode(GFX_AUTODETECT, w, h, 0, 0) != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error setting graphics mode\n%s\n", allegro_error);
      return 1;
   }

   ret = play_fli(argv[c], screen, loop, key_checker);

   if (ret < 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error playing FLI file\n");
      return 1;
   }

   return 0;
}

END_OF_MAIN()