#include #include #include #include "Movie.h" #ifndef NULL #define NULL ((void*)0) #endif struct Frame; typedef struct Frame Frame; struct Frame { unsigned long *framedata; Frame *next; }; struct Movie { Frame *Movie; Frame *current; Movie *next; int rate; time_t starttime; }; static Movie movie_list = { NULL, NULL, NULL, 0, 0}; static Movie *current; static int MoviePoints; void Movie_init( int points ) { MoviePoints = points; current = NULL; } void Movie_destroy( void ) { Movie *tmp = movie_list.next; current = NULL; while( tmp ) { Movie *next = tmp->next; Movie_unloadmovie( tmp ); tmp = next; } } Movie *Movie_loadmovie( char *filename ) { FILE *infile = fopen( filename, "r" ); Movie *movie = NULL; Frame **loaded = NULL; int points, frames, i; if( infile == NULL ) return NULL; if( ( fscanf( infile, "%d\n", &points ) != 1 ) || ( MoviePoints != points ) || ( fscanf( infile, "%d\n", &frames ) != 1 ) || ( ( movie = malloc( sizeof( Movie ) ) ) == NULL ) || ( fscanf( infile, "%d\n", &movie->rate ) != 1 ) ) goto error; loaded = &movie->Movie; while( frames-- > 0 ) { if( ( ( *loaded = malloc( sizeof( Frame ) ) ) == NULL ) || ( ( (*loaded)->framedata = malloc( points * points * points * sizeof( unsigned long ) ) ) == NULL ) ) goto error; for( i = 0; i < points * points * points; ++i ) { if( fscanf( infile, "%d%d%d", ((char *)((*loaded)->framedata)), ((char *)((*loaded)->framedata))+1, ((char *)((*loaded)->framedata))+2 ) != 3 ) goto error; } loaded = &((*loaded)->next); } error: if( loaded ) (*loaded)->next = NULL; if( movie ) Movie_unloadmovie( movie ); movie = NULL; success: fclose( infile ); return movie; } void Movie_unloadmovie( Movie *movie ) { Movie *tmp = &movie_list; if( current == movie ) current = NULL; while( tmp && ( tmp->next != movie )) tmp = tmp->next; if( tmp->next) { Frame *frame = tmp->next->Movie; while( frame != NULL ) { Frame *next = frame->next; free( frame ); frame = next; } tmp->next = tmp->next->next; free( tmp->next ); } } void Movie_playmovie( Movie *movie, int rate ) { } void Movie_stamptime( void ) { } int Movie_checkframe( ) { return 1; } unsigned long Movie_getpixelcolor( int x, int y, int z) { }