summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2003-07-15 09:51:40 +0000
committererdgeist <>2003-07-15 09:51:40 +0000
commit19ca69692093a43e2d21e71b1f2dfd7615ebc829 (patch)
tree7066268cdeedc6b961e7227568f6273502f2d54d
parent866f0ad8030ea2ceea22a4d61e6ff0006546c3fa (diff)
movie handlingHEADmaster
-rwxr-xr-xMovie.c81
-rwxr-xr-xMovie.h14
-rwxr-xr-xX11.c3
3 files changed, 81 insertions, 17 deletions
diff --git a/Movie.c b/Movie.c
index b9e9bab..44a15e9 100755
--- a/Movie.c
+++ b/Movie.c
@@ -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
3struct Frame; 10struct Frame;
4struct Movie;
5 11
6typedef struct Frame Frame; 12typedef struct Frame Frame;
7typedef struct Movie Movie;
8 13
9struct Frame { 14struct Frame {
10 unsigned long *framedata; 15 unsigned long *framedata;
@@ -13,23 +18,25 @@ struct Frame {
13 18
14struct Movie { 19struct 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
21static Movie *movie_list; 27static Movie movie_list = { NULL, NULL, NULL, 0, 0};
22static Movie *current; 28static Movie *current;
29static int MoviePoints;
23 30
24void Movie_init( int points ) { 31void Movie_init( int points ) {
25 movie_list = (Movie*)0; 32 MoviePoints = points;
26 current = (Movie*)0; 33 current = NULL;
27} 34}
28 35
29void Movie_destroy( void ) { 36void 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
40Movie *Movie_loadmovie( char *filename ) { 47Movie *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
44void Movie_unloadmovie( Movie *movie ) { 92void 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
diff --git a/Movie.h b/Movie.h
index 3b2feba..576f618 100755
--- a/Movie.h
+++ b/Movie.h
@@ -1,7 +1,8 @@
1/* Opaque reference to Movie in 1/* Opaque reference to Movie in
2 Movie library 2 Movie library
3*/ 3*/
4typedef void* Movie; 4struct Movie;
5typedef 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
22File 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*/
20Movie *Movie_loadmovie( char *filename ); 30Movie *Movie_loadmovie( char *filename );
21 31
diff --git a/X11.c b/X11.c
index de552fe..887eef9 100755
--- a/X11.c
+++ b/X11.c
@@ -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 ) {