diff options
-rwxr-xr-x | Movie.c | 81 | ||||
-rwxr-xr-x | Movie.h | 14 | ||||
-rwxr-xr-x | X11.c | 3 |
3 files changed, 81 insertions, 17 deletions
@@ -1,10 +1,15 @@ | |||
1 | #include <time.h> | 1 | #include <time.h> |
2 | #include <stdlib.h> | ||
3 | #include <stdio.h> | ||
4 | #include "Movie.h" | ||
5 | |||
6 | #ifndef NULL | ||
7 | #define NULL ((void*)0) | ||
8 | #endif | ||
2 | 9 | ||
3 | struct Frame; | 10 | struct Frame; |
4 | struct Movie; | ||
5 | 11 | ||
6 | typedef struct Frame Frame; | 12 | typedef struct Frame Frame; |
7 | typedef struct Movie Movie; | ||
8 | 13 | ||
9 | struct Frame { | 14 | struct Frame { |
10 | unsigned long *framedata; | 15 | unsigned long *framedata; |
@@ -13,23 +18,25 @@ struct Frame { | |||
13 | 18 | ||
14 | struct Movie { | 19 | struct Movie { |
15 | Frame *Movie; | 20 | Frame *Movie; |
21 | Frame *current; | ||
16 | Movie *next; | 22 | Movie *next; |
17 | int rate; | 23 | int rate; |
18 | time_t starttime; | 24 | time_t starttime; |
19 | }; | 25 | }; |
20 | 26 | ||
21 | static Movie *movie_list; | 27 | static Movie movie_list = { NULL, NULL, NULL, 0, 0}; |
22 | static Movie *current; | 28 | static Movie *current; |
29 | static int MoviePoints; | ||
23 | 30 | ||
24 | void Movie_init( int points ) { | 31 | void Movie_init( int points ) { |
25 | movie_list = (Movie*)0; | 32 | MoviePoints = points; |
26 | current = (Movie*)0; | 33 | current = NULL; |
27 | } | 34 | } |
28 | 35 | ||
29 | void Movie_destroy( void ) { | 36 | void Movie_destroy( void ) { |
30 | Movie *tmp = movie_list; | 37 | Movie *tmp = movie_list.next; |
31 | 38 | ||
32 | current = (Movie*)0; | 39 | current = NULL; |
33 | while( tmp ) { | 40 | while( tmp ) { |
34 | Movie *next = tmp->next; | 41 | Movie *next = tmp->next; |
35 | Movie_unloadmovie( tmp ); | 42 | Movie_unloadmovie( tmp ); |
@@ -38,20 +45,68 @@ void Movie_destroy( void ) { | |||
38 | } | 45 | } |
39 | 46 | ||
40 | Movie *Movie_loadmovie( char *filename ) { | 47 | Movie *Movie_loadmovie( char *filename ) { |
48 | FILE *infile = fopen( filename, "r" ); | ||
49 | Movie *movie = NULL; | ||
50 | Frame **loaded = NULL; | ||
51 | int points, frames, i; | ||
52 | |||
53 | if( infile == NULL ) return NULL; | ||
54 | |||
55 | if( ( fscanf( infile, "%d\n", &points ) != 1 ) || | ||
56 | ( MoviePoints != points ) || | ||
57 | ( fscanf( infile, "%d\n", &frames ) != 1 ) || | ||
58 | ( ( movie = malloc( sizeof( Movie ) ) ) == NULL ) || | ||
59 | ( fscanf( infile, "%d\n", &movie->rate ) != 1 ) ) | ||
60 | goto error; | ||
61 | |||
62 | loaded = &movie->Movie; | ||
63 | |||
64 | while( frames-- > 0 ) { | ||
65 | if( | ||
66 | ( ( *loaded = malloc( sizeof( Frame ) ) ) == NULL ) || | ||
67 | ( ( (*loaded)->framedata = malloc( points * points * points * sizeof( unsigned long ) ) ) == NULL ) | ||
68 | ) | ||
69 | goto error; | ||
70 | |||
71 | for( i = 0; i < points * points * points; ++i ) { | ||
72 | if( fscanf( infile, "%d%d%d", ((char *)((*loaded)->framedata)), | ||
73 | ((char *)((*loaded)->framedata))+1, | ||
74 | ((char *)((*loaded)->framedata))+2 ) | ||
75 | != 3 ) | ||
76 | goto error; | ||
77 | } | ||
78 | loaded = &((*loaded)->next); | ||
79 | } | ||
41 | 80 | ||
81 | error: | ||
82 | if( loaded ) | ||
83 | (*loaded)->next = NULL; | ||
84 | if( movie ) | ||
85 | Movie_unloadmovie( movie ); | ||
86 | movie = NULL; | ||
87 | success: | ||
88 | fclose( infile ); | ||
89 | return movie; | ||
42 | } | 90 | } |
43 | 91 | ||
44 | void Movie_unloadmovie( Movie *movie ) { | 92 | void Movie_unloadmovie( Movie *movie ) { |
45 | Movie *tmp = movie_list; | 93 | Movie *tmp = &movie_list; |
46 | if( current == movie ) | 94 | if( current == movie ) |
47 | current = (Movie*)0; | 95 | current = NULL; |
48 | 96 | ||
49 | while( tmp && ( tmp != movie )) | 97 | while( tmp && ( tmp->next != movie )) |
50 | tmp = tmp->next; | 98 | tmp = tmp->next; |
51 | 99 | ||
52 | if( tmp) { | 100 | if( tmp->next) { |
53 | 101 | Frame *frame = tmp->next->Movie; | |
54 | free( tmp ); | 102 | while( frame != NULL ) { |
103 | Frame *next = frame->next; | ||
104 | free( frame ); | ||
105 | frame = next; | ||
106 | } | ||
107 | |||
108 | tmp->next = tmp->next->next; | ||
109 | free( tmp->next ); | ||
55 | } | 110 | } |
56 | } | 111 | } |
57 | 112 | ||
@@ -1,7 +1,8 @@ | |||
1 | /* Opaque reference to Movie in | 1 | /* Opaque reference to Movie in |
2 | Movie library | 2 | Movie library |
3 | */ | 3 | */ |
4 | typedef void* Movie; | 4 | struct Movie; |
5 | typedef struct Movie Movie; | ||
5 | 6 | ||
6 | /* Initialise Movie handler | 7 | /* Initialise Movie handler |
7 | - points is number of balls | 8 | - points is number of balls |
@@ -15,7 +16,16 @@ void Movie_destroy( void ); | |||
15 | /* Load one movie from File | 16 | /* Load one movie from File |
16 | - filename pointer to file containing | 17 | - filename pointer to file containing |
17 | Movie | 18 | Movie |
18 | - returns handle to the Movie | 19 | - returns handle to the Movie or NULL |
20 | on error | ||
21 | |||
22 | File format is: | ||
23 | %d\n number of points for Cube | ||
24 | %d\n number of frames | ||
25 | %d\n frame rate | ||
26 | foreach frame | ||
27 | foreach point * point * point | ||
28 | %d%d%d RGB of pixel | ||
19 | */ | 29 | */ |
20 | Movie *Movie_loadmovie( char *filename ); | 30 | Movie *Movie_loadmovie( char *filename ); |
21 | 31 | ||
@@ -96,7 +96,7 @@ int main(int argc, char **argv) { | |||
96 | signal( SIGINT, handle_signal ); | 96 | signal( SIGINT, handle_signal ); |
97 | signal( SIGALRM, handle_signal ); | 97 | signal( SIGALRM, handle_signal ); |
98 | 98 | ||
99 | Vector_init( 8, 300); | 99 | Vector_init( 5, 300); |
100 | 100 | ||
101 | #ifdef ENABLE_X11_SHARED_MEMORY_PIXMAPS | 101 | #ifdef ENABLE_X11_SHARED_MEMORY_PIXMAPS |
102 | shminfo = malloc( sizeof( shminfo )); | 102 | shminfo = malloc( sizeof( shminfo )); |
@@ -244,7 +244,6 @@ int main(int argc, char **argv) { | |||
244 | } | 244 | } |
245 | 245 | ||
246 | default: | 246 | default: |
247 | printf( "Uncatched event!" ); | ||
248 | break; | 247 | break; |
249 | } | 248 | } |
250 | if( shallredraw == 1 ) { | 249 | if( shallredraw == 1 ) { |