Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5131 | clevermous | 1 | /* |
2 | playflic - play a FLIC file on the screen |
||
3 | Placed in the public domain by Andre de Leiradella on 24-fev-2003. |
||
4 | |||
5 | You'll need SDL and SDLmain to compile this program. |
||
6 | */ |
||
7 | |||
8 | #include |
||
9 | #include |
||
10 | #include |
||
11 | #include |
||
12 | #include "SDL_flic.h" |
||
13 | |||
14 | int main(int argc, char *argv[]) { |
||
15 | SDL_RWops *rwops; |
||
16 | FLI_Animation *flic; |
||
17 | int error; |
||
18 | SDL_Surface *screen; |
||
19 | SDL_Rect pos; |
||
20 | SDL_Event event; |
||
21 | Uint32 ticks, ticks2; |
||
22 | |||
23 | if (argc != 2) { |
||
24 | fprintf(stderr, "Usage: playflic |
||
25 | return 0; |
||
26 | } |
||
27 | /* Open the flic. */ |
||
28 | rwops = SDL_RWFromFile(argv[1], "rb"); |
||
29 | if (rwops == NULL) { |
||
30 | fprintf(stderr, "FLIC file not found\n"); |
||
31 | return 0; |
||
32 | } |
||
33 | flic = FLI_Open(rwops, &error); |
||
34 | if (error != FLI_OK) |
||
35 | goto out; |
||
36 | /* Init SDL. */ |
||
37 | if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { |
||
38 | fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
||
39 | goto out; |
||
40 | } |
||
41 | atexit(SDL_Quit); |
||
42 | /* Set the video with the size of the flic. */ |
||
43 | screen = SDL_SetVideoMode(flic->width, flic->height, 0, SDL_SWSURFACE); |
||
44 | if (screen == NULL) { |
||
45 | fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", flic->width, flic->height, SDL_GetError()); |
||
46 | goto out; |
||
47 | } |
||
48 | /* Play the flic. */ |
||
49 | pos.x = pos.y = 0; |
||
50 | ticks = SDL_GetTicks(); |
||
51 | for (;;) { |
||
52 | /* Render the next frame. */ |
||
53 | error = FLI_NextFrame(flic); |
||
54 | if (error != FLI_OK) |
||
55 | goto out; |
||
56 | /* Blit it. */ |
||
57 | SDL_BlitSurface(flic->surface, NULL, screen, &pos); |
||
58 | SDL_UpdateRect(screen, 0, 0, 0, 0); |
||
59 | /* Exit program in case of any event. */ |
||
60 | while (SDL_PollEvent(&event) == 1) { |
||
61 | switch (event.type) { |
||
62 | case SDL_MOUSEBUTTONDOWN: |
||
63 | case SDL_KEYDOWN: |
||
64 | case SDL_QUIT: |
||
65 | goto out; |
||
66 | } |
||
67 | } |
||
68 | /* Delay between frames. */ |
||
69 | ticks = SDL_GetTicks() - ticks; |
||
70 | if (ticks < flic->delay) |
||
71 | SDL_Delay(flic->delay - ticks); |
||
72 | ticks = SDL_GetTicks(); |
||
73 | } |
||
74 | out: |
||
75 | /* Describe the error. */ |
||
76 | switch (error) { |
||
77 | case FLI_READERROR: |
||
78 | fprintf(stderr, "Error while reading FLIC\n"); |
||
79 | break; |
||
80 | case FLI_CORRUPTEDFILE: |
||
81 | fprintf(stderr, "FLIC file corrupted\n"); |
||
82 | break; |
||
83 | case FLI_SDLERROR: |
||
84 | fprintf(stderr, "SDL error: %s\n", SDL_GetError()); |
||
85 | break; |
||
86 | case FLI_OUTOFMEMORY: |
||
87 | fprintf(stderr, "Out of memory\n"); |
||
88 | break; |
||
89 | } |
||
90 | FLI_Close(flic); |
||
91 | return 0; |
||
92 | }>> |