From e53f1b4d83710ff7b1b3ae20018393dc8d2e94d6 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Tue, 18 Feb 2003 07:05:14 +0000 Subject: [PATCH] many improvements to mve code. Fixes (at least) bugs #41, #348, #350, and #359. --- include/mvelib.h | 5 + main/movie.c | 251 ++++++++++++++++++++++++++--------------------- main/mve_main.c | 118 ++++++++++++++++++---- main/mvelib.c | 54 +++++++++- main/mveplay.c | 182 ++++++++++++++++++++++------------ main/mveplay.h | 11 +-- main/titles.c | 13 ++- 7 files changed, 430 insertions(+), 204 deletions(-) diff --git a/include/mvelib.h b/include/mvelib.h index e5188a89..8e289094 100644 --- a/include/mvelib.h +++ b/include/mvelib.h @@ -86,6 +86,11 @@ MVESTREAM *mve_open_filehandle(int filehandle); void mve_close(MVESTREAM *movie); void mve_close_filehandle(MVESTREAM *movie); +/* + * reset an MVE stream + */ +void mve_reset(MVESTREAM *movie); + /* * set segment type handler */ diff --git a/main/movie.c b/main/movie.c index 27ced971..d854d81a 100644 --- a/main/movie.c +++ b/main/movie.c @@ -1,4 +1,4 @@ -/* $Id: movie.c,v 1.16 2003-02-14 03:45:31 btb Exp $ */ +/* $Id: movie.c,v 1.17 2003-02-18 07:05:14 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -17,7 +17,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: movie.c,v 1.16 2003-02-14 03:45:31 btb Exp $"; +static char rcsid[] = "$Id: movie.c,v 1.17 2003-02-18 07:05:14 btb Exp $"; #endif #define DEBUG_LEVEL CON_NORMAL @@ -45,10 +45,9 @@ static char rcsid[] = "$Id: movie.c,v 1.16 2003-02-14 03:45:31 btb Exp $"; #include "gamefont.h" #include "cfile.h" #include "menu.h" -#include "mvelib.h" +#include "mveplay.h" #include "text.h" #include "fileutil.h" -#include "mveplay.h" extern int MenuHiresAvailable; extern char CDROM_dir[]; @@ -71,6 +70,7 @@ subtitle Subtitles[MAX_SUBTITLES]; int Num_subtitles; +// Movielib data typedef struct { char name[FILENAME_LEN]; int offset,len; @@ -79,7 +79,6 @@ typedef struct { #define MLF_ON_CD 1 #define MAX_MOVIES_PER_LIB 50 //determines size of malloc - typedef struct { char name[100]; //[FILENAME_LEN]; int n_movies; @@ -98,38 +97,34 @@ char movielib_files[][FILENAME_LEN] = {"intro-l.mvl","other-l.mvl","robots-l.mvl #define EXTRA_ROBOT_LIB N_BUILTIN_MOVIE_LIBS movielib *movie_libs[N_MOVIE_LIBS]; -int MVEPaletteCalls = 0; //do we have the robot movies available int robot_movies = 0; //0 means none, 1 means lowres, 2 means hires int MovieHires = 0; //default for now is lores -int RoboFile = 0; -off_t Robo_filepos; -MVESTREAM *Robo_mve; -grs_bitmap *Robo_bitmap; +int RoboFile = 0, RoboFilePos = 0; - -// Function Prototypes +// Function Prototypes int RunMovie(char *filename, int highres_flag, int allow_abort,int dx,int dy); int open_movie_file(char *filename,int must_have); +int reset_movie_file(int handle); void change_filename_ext( char *dest, char *src, char *ext ); void decode_text_line(char *p); void draw_subtitles(int frame_num); +//----------------------------------------------------------------------- + + //filename will actually get modified to be either low-res or high-res //returns status. see values in movie.h int PlayMovie(const char *filename, int must_have) { char name[FILENAME_LEN],*p; int c, ret; -#if 0 - int save_sample_rate; -#endif #ifndef RELEASE if (FindArg("-nomovies")) @@ -152,33 +147,19 @@ int PlayMovie(const char *filename, int must_have) // Stop all songs songs_stop_all(); -#if 0 - save_sample_rate = digi_sample_rate; - digi_sample_rate = SAMPLE_RATE_22K; //always 22K for movies - digi_reset(); digi_reset(); -#else digi_close(); -#endif ret = RunMovie(name,MovieHires,must_have,-1,-1); -#if 0 - gr_palette_clear(); //clear out palette in case movie aborted -#endif - -#if 0 - digi_sample_rate = save_sample_rate; //restore rate for game - digi_reset(); digi_reset(); -#else if (!FindArg("-nosound")) digi_init(); -#endif Screen_mode = -1; //force screen reset return ret; } + #if 0 typedef struct bkg { short x, y, w, h; // The location of the menu. @@ -190,6 +171,7 @@ bkg movie_bg = {0,0,0,0,NULL}; #define BOX_BORDER (MenuHires?40:20) + void show_pause_message(char *msg) { int w,h,aw; @@ -240,16 +222,15 @@ void clear_pause_message() #endif } + //returns status. see movie.h int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy) { int filehndl; int result=1,aborted=0; + int track = 0; int frame_num; - MVESTREAM *mve; - grs_bitmap *mve_bitmap; int key; - int x, y, w, h; result=1; @@ -258,79 +239,61 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy) filehndl = open_movie_file(filename,must_have); if (filehndl == -1) { -#ifndef EDITOR if (must_have) Warning("movie: RunMovie: Cannot open movie <%s>\n",filename); -#endif return MOVIE_NOT_PLAYED; } if (hires_flag) { gr_set_mode(SM(640,480)); - x = 24; - y = 84; - w = 592; - h = 312; } else { gr_set_mode(SM(320,200)); - x = 0; - y = 32; - w = 320; - h = 136; + } + + if (MVE_rmPrepMovie(filehndl, dx, dy, track)) { + Int3(); + return MOVIE_NOT_PLAYED; } frame_num = 0; FontHires = FontHiresAvailable && hires_flag; - mve = mve_open_filehandle(filehndl); - - mve_bitmap = gr_create_bitmap(w, h); // w, h must match the mve exactly! - - mveplay_initializeMovie(mve, mve_bitmap); - - while(result) { - - result = mveplay_stepMovie(mve); - - gr_bitmap(x, y, mve_bitmap); + while((result = MVE_rmStepMovie()) == 0) { draw_subtitles(frame_num); + gr_update(); + key = key_inkey(); - switch (key) { - case KEY_ESC: - // If ESCAPE pressed, then quit movie. - result = 0; - aborted = 1; + // If ESCAPE pressed, then quit movie. + if (key == KEY_ESC) { + result = aborted = 1; break; - case KEY_PAUSE: - // If PAUSE pressed, then pause movie + } + + // If PAUSE pressed, then pause movie + if (key == KEY_PAUSE) { + MVE_rmHoldMovie(); show_pause_message(TXT_PAUSE); while (!key_inkey()) ; - mveplay_restartTimer(mve); clear_pause_message(); - break; + } + #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE - case KEY_CTRLED+KEY_SHIFTED+KEY_PADENTER: - case KEY_ALTED+KEY_CTRLED+KEY_PADENTER: - case KEY_ALTED+KEY_SHIFTED+KEY_PADENTER: + if ((key == KEY_CTRLED+KEY_SHIFTED+KEY_PADENTER) || + (key == KEY_ALTED+KEY_CTRLED+KEY_PADENTER) || + (key == KEY_ALTED+KEY_SHIFTED+KEY_PADENTER)) gr_toggle_fullscreen(); - break; #endif - } frame_num++; } - Assert(aborted || !result); ///movie should be over - - mveplay_shutdownMovie(mve); - - gr_free_bitmap(mve_bitmap); + Assert(aborted || result == MVE_ERR_EOF); ///movie should be over - mve_close(mve); + MVE_rmEndMovie(); close(filehndl); // Close Movie File @@ -356,17 +319,21 @@ int InitMovieBriefing() //returns 1 if frame updated ok int RotateRobot() { - int ret; + int err; - ret = mveplay_stepMovie(Robo_mve); - gr_bitmap(MenuHires?280:140, MenuHires?200:80, Robo_bitmap); + err = MVE_rmStepMovie(); - if (!ret) { - mveplay_shutdownMovie(Robo_mve); - mve_close(Robo_mve); - lseek(RoboFile, Robo_filepos, SEEK_SET); - Robo_mve = mve_open_filehandle(RoboFile); - mveplay_initializeMovie(Robo_mve, Robo_bitmap); + if (err == MVE_ERR_EOF) //end of movie, so reset + { + reset_movie_file(RoboFile); + if (MVE_rmPrepMovie(RoboFile, MenuHires?280:140, MenuHires?200:80, 0)) { + Int3(); + return 0; + } + } + else if (err) { + Int3(); + return 0; } return 1; @@ -375,17 +342,18 @@ int RotateRobot() void DeInitRobotMovie(void) { - mveplay_shutdownMovie(Robo_mve); - mve_close(Robo_mve); - - gr_free_bitmap(Robo_bitmap); - - close(RoboFile); + MVE_rmEndMovie(); + close(RoboFile); // Close Movie File } int InitRobotMovie(char *filename) { + if (FindArg("-nomovies")) + return 0; + + con_printf(DEBUG_LEVEL, "RoboFile=%s\n", filename); + RoboFile = open_movie_file(filename, 1); if (RoboFile == -1) { @@ -393,13 +361,16 @@ int InitRobotMovie(char *filename) return MOVIE_NOT_PLAYED; } - Robo_filepos = lseek(RoboFile, 0, SEEK_CUR); + Vid_State = VID_PLAY; - Robo_mve = mve_open_filehandle(RoboFile); + if (MVE_rmPrepMovie(RoboFile, MenuHires?280:140, MenuHires?200:80, 0)) { + Int3(); + return 0; + } - Robo_bitmap = gr_create_bitmap(MenuHires?320:160, MenuHires?200:88); + RoboFilePos=lseek (RoboFile,0L,SEEK_CUR); - mveplay_initializeMovie(Robo_mve, Robo_bitmap); + con_printf(DEBUG_LEVEL, "RoboFilePos=%d!\n", RoboFilePos); return 1; } @@ -455,7 +426,7 @@ int init_subtitles(char *filename) } size = cfilelength(ifile); - + MALLOC (subtitle_raw_data, ubyte, size+1); read_count = cfread(subtitle_raw_data, 1, size, ifile); @@ -565,15 +536,6 @@ void draw_subtitles(int frame_num) gr_string(0x8000,y,Subtitles[active_subtitles[t]].msg); y += line_spacing+1; } - - gr_update(); -} - - -int request_cd(void) -{ - con_printf(DEBUG_LEVEL, "STUB: movie: request_cd\n"); - return 0; } @@ -724,6 +686,65 @@ void close_movies() } +//ask user to put the D2 CD in. +//returns -1 if ESC pressed, 0 if OK chosen +//CD may not have been inserted +int request_cd(void) +{ +#if 0 + ubyte save_pal[256*3]; + grs_canvas *save_canv,*tcanv; + int ret,was_faded=gr_palette_faded_out; + + gr_palette_clear(); + + save_canv = grd_curcanv; + tcanv = gr_create_canvas(grd_curcanv->cv_w,grd_curcanv->cv_h); + + gr_set_current_canvas(tcanv); + gr_ubitmap(0,0,&save_canv->cv_bitmap); + gr_set_current_canvas(save_canv); + + gr_clear_canvas(BM_XRGB(0,0,0)); + + memcpy(save_pal,gr_palette,sizeof(save_pal)); + + memcpy(gr_palette,last_palette_for_color_fonts,sizeof(gr_palette)); + + try_again:; + + ret = nm_messagebox( "CD ERROR", 1, "Ok", "Please insert your Descent II CD"); + + if (ret == -1) { + int ret2; + + ret2 = nm_messagebox( "CD ERROR", 2, "Try Again", "Leave Game", "You must insert your\nDescent II CD to Continue"); + + if (ret2 == -1 || ret2 == 0) + goto try_again; + } + + force_rb_register = 1; //disc has changed; force register new CD + + gr_palette_clear(); + + memcpy(gr_palette,save_pal,sizeof(save_pal)); + + gr_ubitmap(0,0,&tcanv->cv_bitmap); + + if (!was_faded) + gr_palette_load(gr_palette); + + gr_free_canvas(tcanv); + + return ret; +#else + con_printf(DEBUG_LEVEL, "STUB: movie: request_cd\n"); + return 0; +#endif +} + + void init_movie(char *filename,int libnum,int is_robots,int required) { int high_res; @@ -813,6 +834,8 @@ void init_extra_robot_movie(char *filename) } +int movie_handle,movie_start; + //looks through a movie library for a movie file //returns filehandle, with fileposition at movie, or -1 if can't find int search_movie_lib(movielib *lib,char *filename,int must_have) @@ -834,10 +857,10 @@ int search_movie_lib(movielib *lib,char *filename,int must_have) do { //keep trying until we get the file handle -#ifdef __WIN32 - /* movie_handle = */ filehandle = open(lib->name, O_RDONLY | O_BINARY); +#ifdef O_BINARY + movie_handle = filehandle = open(lib->name, O_RDONLY | O_BINARY); #else - /* movie_handle = */ filehandle = open(lib->name, O_RDONLY); + movie_handle = filehandle = open(lib->name, O_RDONLY); #endif if ((filehandle == -1) && (AltHogdir_initialized)) { @@ -845,10 +868,10 @@ int search_movie_lib(movielib *lib,char *filename,int must_have) strcpy(temp, AltHogDir); strcat(temp, "/"); strcat(temp, lib->name); -#ifdef __WIN32 - filehandle = open(temp, O_RDONLY | O_BINARY); +#ifdef O_BINARY + movie_handle = filehandle = open(temp, O_RDONLY | O_BINARY); #else - filehandle = open(temp, O_RDONLY); + movie_handle = filehandle = open(temp, O_RDONLY); #endif } @@ -861,7 +884,7 @@ int search_movie_lib(movielib *lib,char *filename,int must_have) } while (must_have && from_cd && filehandle == -1); if (filehandle != -1) - lseek(filehandle,(/* movie_start = */ lib->movies[i].offset),SEEK_SET); + lseek(filehandle,(movie_start=lib->movies[i].offset),SEEK_SET); return filehandle; } @@ -883,4 +906,12 @@ int open_movie_file(char *filename,int must_have) return -1; //couldn't find it } +//sets the file position to the start of this already-open file +int reset_movie_file(int handle) +{ + Assert(handle == movie_handle); + lseek(handle,movie_start,SEEK_SET); + + return 0; //everything is cool +} diff --git a/main/mve_main.c b/main/mve_main.c index 2d8b997f..3c7a7beb 100644 --- a/main/mve_main.c +++ b/main/mve_main.c @@ -1,11 +1,18 @@ #include +#include +#include +#include +#include #include #include "mvelib.h" +#define MAX_FILES 256 + extern int g_spdFactorNum; extern int g_sdlVidFlags; +extern int g_loop; void initializeMovie(MVESTREAM *mve); void playMovie(MVESTREAM *mve); @@ -13,42 +20,109 @@ void shutdownMovie(MVESTREAM *mve); static void usage(void) { - fprintf(stderr, "usage: mveplay [-f] filename\n" - "-f\tFullscreen mode\n"); + fprintf(stderr, "usage: mveplay [-f] [-l] [-s ] [] \n" + "-f\tFullscreen mode\n" + "-s\tSpeed Factor \n" + ); exit(1); } -static int doPlay(const char *filename) +static int doPlay(int filehandle) { - MVESTREAM *mve = mve_open(filename); - if (mve == NULL) - { - fprintf(stderr, "can't open MVE file '%s'\n", filename); - return 1; - } + MVESTREAM *mve = mve_open_filehandle(filehandle); + if (mve == NULL) { + fprintf(stderr, "can't open MVE file\n"); + exit(1); + } initializeMovie(mve); playMovie(mve); shutdownMovie(mve); - mve_close(mve); + mve_close_filehandle(mve); - return 0; + return 1; } -int main(int c, char *v[]) +int main(int argc, char *argv[]) { - if (c < 2) - usage(); + int i, filehandle; + char *mvlfile = NULL, *mvefile = NULL; + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-h")) + usage(); + + if (!strcmp(argv[i], "-f")) + g_sdlVidFlags |= SDL_FULLSCREEN; + + if (!strcmp(argv[i], "-l")) + g_loop = 1; - if (!strcmp(v[1], "-f")) { - g_sdlVidFlags |= SDL_FULLSCREEN; - c--; - v++; + if (!strcmp(argv[i], "-s")) { + if (argc < i + 2) + usage(); + g_spdFactorNum = atoi(argv[i + 1]); + i++; + } + + if (strchr(argv[i], '.') && !strcasecmp(strchr(argv[i], '.'), ".mvl")) + mvlfile = argv[i]; + + if (strchr(argv[i], '.') && !strcasecmp(strchr(argv[i], '.'), ".mve")) + mvefile = argv[i]; } - if (c == 3) - g_spdFactorNum = atoi(v[2]); + if (mvlfile) { + int nfiles; + char filename[MAX_FILES][13]; + int filesize[MAX_FILES]; + char sig[4]; + +#ifdef O_BINARY + filehandle = open(mvlfile, O_RDONLY | O_BINARY); +#else + filehandle = open(mvlfile, O_RDONLY); +#endif + if (filehandle == -1) { + fprintf(stderr, "Error opening %s\n", mvlfile); + exit(1); + } + if ((read(filehandle, sig, 4) < 4) || + (strncmp(sig, "DMVL", 4)) || + (read(filehandle, &nfiles, 4) < 4)) { + fprintf(stderr, "Error reading %s\n", mvlfile); + exit(1); + } + for (i = 0; i < nfiles; i++) { + if ((read(filehandle, filename[i], 13) < 13) || + (read(filehandle, &filesize[i], 4) < 4) || + (strlen(filename[i]) > 12)) { + fprintf(stderr, "Error reading %s\n", mvlfile); + exit(1); + } + } + + for (i = 0; i < nfiles; i++) { + if (mvefile) { + if (!strcasecmp(filename[i], mvefile)) + break; + else + lseek(filehandle, filesize[i], SEEK_CUR); + } else + printf("%13s\t%d\n", filename[i], filesize[i]); + } + if (!mvefile) + exit(0); + + } else if (mvefile) { +#ifdef O_BINARY + filehandle = open(mvefile, O_RDONLY | O_BINARY); +#else + filehandle = open(mvefile, O_RDONLY); +#endif + } else + usage(); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { @@ -57,5 +131,7 @@ int main(int c, char *v[]) } atexit(SDL_Quit); - return doPlay(v[1]); + doPlay(filehandle); + + return 0; } diff --git a/main/mvelib.c b/main/mvelib.c index f2976749..a2b12c6f 100644 --- a/main/mvelib.c +++ b/main/mvelib.c @@ -25,6 +25,7 @@ static void _mvefile_free(MVEFILE *movie); static void _mvefile_free_filehandle(MVEFILE *movie); static int _mvefile_open(MVEFILE *movie, const char *filename); static int _mvefile_open_filehandle(MVEFILE *movie, int filehandle); +static void _mvefile_reset(MVEFILE *movie); static int _mvefile_read_header(MVEFILE *movie); static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size); static int _mvefile_fetch_next_chunk(MVEFILE *movie); @@ -37,6 +38,7 @@ static void _mvestream_free(MVESTREAM *movie); static void _mvestream_free_filehandle(MVESTREAM *movie); static int _mvestream_open(MVESTREAM *movie, const char *filename); static int _mvestream_open_filehandle(MVESTREAM *movie, int filehandle); +static void _mvestream_reset(MVESTREAM *movie); /************************************************************ * public MVEFILE functions @@ -114,6 +116,27 @@ void mvefile_close_filehandle(MVEFILE *movie) _mvefile_free_filehandle(movie); } +/* + * reset a MVE file + */ +void mvefile_reset(MVEFILE *file) +{ + _mvefile_reset(file); + + /* initialize the file */ + _mvefile_set_buffer_size(file, 1024); + + /* verify the file's header */ + if (! _mvefile_read_header(file)) + { + _mvefile_free_filehandle(file); + //return NULL; + } + + /* now, prefetch the next chunk */ + _mvefile_fetch_next_chunk(file); +} + /* * get the size of the next segment */ @@ -263,6 +286,14 @@ void mve_close_filehandle(MVESTREAM *movie) _mvestream_free_filehandle(movie); } +/* + * reset an MVE stream + */ +void mve_reset(MVESTREAM *movie) +{ + _mvestream_reset(movie); +} + /* * set segment type handler */ @@ -383,7 +414,7 @@ static void _mvefile_free_filehandle(MVEFILE *movie) */ static int _mvefile_open(MVEFILE *file, const char *filename) { -#ifdef __WIN32 +#ifdef O_BINARY file->stream = open(filename, O_RDONLY | O_BINARY); #else file->stream = open(filename, O_RDONLY); @@ -403,6 +434,19 @@ static int _mvefile_open_filehandle(MVEFILE *file, int filehandle) return 1; } +/* + * allocate an MVEFILE + */ +static void _mvefile_reset(MVEFILE *file) +{ +#if 0 + file->cur_chunk = NULL; + file->buf_size = 0; + file->cur_fill = 0; + file->next_segment = 0; +#endif +} + /* * read and verify the header of the recently opened file */ @@ -563,3 +607,11 @@ static int _mvestream_open_filehandle(MVESTREAM *movie, int filehandle) return (movie->movie == NULL) ? 0 : 1; } + +/* + * reset an MVESTREAM + */ +static void _mvestream_reset(MVESTREAM *movie) +{ + mvefile_reset(movie->movie); +} diff --git a/main/mveplay.c b/main/mveplay.c index b583ec28..19baa716 100644 --- a/main/mveplay.c +++ b/main/mveplay.c @@ -1,4 +1,4 @@ -/* $Id: mveplay.c,v 1.15 2003-02-14 19:13:25 btb Exp $ */ +/* $Id: mveplay.c,v 1.16 2003-02-18 07:05:14 btb Exp $ */ #ifdef HAVE_CONFIG_H #include #endif @@ -32,6 +32,11 @@ #include "palette.h" #endif +#ifdef STANDALONE +#define d_malloc(size) malloc(size) +#define d_free(ptr) free(ptr) +#endif + #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif @@ -61,15 +66,16 @@ int g_spdFactorNum=0; static int g_spdFactorDenom=10; -static int playing = 1; #ifdef STANDALONE +static int playing = 1; int g_sdlVidFlags = SDL_ANYFORMAT | SDL_DOUBLEBUF; -#endif +int g_loop = 0; void initializeMovie(MVESTREAM *mve); void playMovie(MVESTREAM *mve); void shutdownMovie(MVESTREAM *mve); +#endif static short get_short(unsigned char *data) { @@ -101,6 +107,7 @@ static int default_seg_handler(unsigned char major, unsigned char minor, unsigne return 1; } + /************************* * general handlers *************************/ @@ -116,6 +123,7 @@ static int end_movie_handler(unsigned char major, unsigned char minor, unsigned /* * timer variables */ +static int timer_created = 0; static int micro_frame_delay=0; static int timer_started=0; static struct timeval timer_expire = {0, 0}; @@ -153,6 +161,12 @@ int nanosleep(struct timespec *ts, void *rem) static int create_timer_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) { __extension__ long long temp; + + if (timer_created) + return 1; + else + timer_created = 1; + micro_frame_delay = get_int(data) * (int)get_short(data+4); if (g_spdFactorNum != 0) { @@ -230,6 +244,7 @@ static void do_timer_wait(void) #ifdef AUDIO #define TOTAL_AUDIO_BUFFERS 64 +static int audiobuf_created = 0; static void mve_audio_callback(void *userdata, unsigned char *stream, int len); static short *mve_audio_buffers[TOTAL_AUDIO_BUFFERS]; static int mve_audio_buflens[TOTAL_AUDIO_BUFFERS]; @@ -255,13 +270,13 @@ static void mve_audio_callback(void *userdata, unsigned char *stream, int len) { length = mve_audio_buflens[mve_audio_bufhead]-mve_audio_curbuf_curpos; memcpy(stream, /* cur output position */ - ((unsigned char *)mve_audio_buffers[mve_audio_bufhead])+mve_audio_curbuf_curpos, /* cur input position */ - length); /* cur input length */ + ((unsigned char *)mve_audio_buffers[mve_audio_bufhead])+mve_audio_curbuf_curpos, /* cur input position */ + length); /* cur input length */ total += length; stream += length; /* advance output */ len -= length; /* decrement avail ospace */ - free(mve_audio_buffers[mve_audio_bufhead]); /* free the buffer */ + d_free(mve_audio_buffers[mve_audio_bufhead]); /* free the buffer */ mve_audio_buffers[mve_audio_bufhead]=NULL; /* free the buffer */ mve_audio_buflens[mve_audio_bufhead]=0; /* free the buffer */ @@ -273,8 +288,8 @@ static void mve_audio_callback(void *userdata, unsigned char *stream, int len) //fprintf(stderr, "= <%d (%d), %d, %d>: %d\n", mve_audio_bufhead, mve_audio_curbuf_curpos, mve_audio_buftail, len, total); /* return total; */ - if (len != 0 /* ospace remaining */ - && mve_audio_bufhead != mve_audio_buftail) /* buffers remaining */ + if (len != 0 /* ospace remaining */ + && mve_audio_bufhead != mve_audio_buftail) /* buffers remaining */ { memcpy(stream, /* dest */ ((unsigned char *)mve_audio_buffers[mve_audio_bufhead]) + mve_audio_curbuf_curpos, /* src */ @@ -286,11 +301,11 @@ static void mve_audio_callback(void *userdata, unsigned char *stream, int len) if (mve_audio_curbuf_curpos >= mve_audio_buflens[mve_audio_bufhead]) /* if this ends the current chunk */ { - free(mve_audio_buffers[mve_audio_bufhead]); /* free buffer */ + d_free(mve_audio_buffers[mve_audio_bufhead]); /* free buffer */ mve_audio_buffers[mve_audio_bufhead]=NULL; mve_audio_buflens[mve_audio_bufhead]=0; - if (++mve_audio_bufhead == TOTAL_AUDIO_BUFFERS) /* next buffer */ + if (++mve_audio_bufhead == TOTAL_AUDIO_BUFFERS) /* next buffer */ mve_audio_bufhead = 0; mve_audio_curbuf_curpos = 0; } @@ -313,6 +328,11 @@ static int create_audiobuf_handler(unsigned char major, unsigned char minor, uns int format; + if (audiobuf_created) + return 1; + else + audiobuf_created = 1; + #ifndef STANDALONE if (FindArg("-nosound")) return 1; @@ -343,7 +363,7 @@ static int create_audiobuf_handler(unsigned char major, unsigned char minor, uns fprintf(stderr, "sample rate = %d, stereo = %d, bitsize = %d, compressed = %d\n", sample_rate, stereo, bitsize ? 16 : 8, compressed); - mve_audio_spec = (SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec)); + mve_audio_spec = (SDL_AudioSpec *)d_malloc(sizeof(SDL_AudioSpec)); mve_audio_spec->freq = sample_rate; mve_audio_spec->format = format; mve_audio_spec->channels = (stereo) ? 2 : 1; @@ -363,8 +383,8 @@ static int create_audiobuf_handler(unsigned char major, unsigned char minor, uns memset(mve_audio_buffers, 0, sizeof(mve_audio_buffers)); memset(mve_audio_buflens, 0, sizeof(mve_audio_buflens)); - #endif + return 1; } @@ -401,19 +421,19 @@ static int audio_data_handler(unsigned char major, unsigned char minor, unsigned nsamp += 4; mve_audio_buflens[mve_audio_buftail] = nsamp; - mve_audio_buffers[mve_audio_buftail] = (short *)malloc(nsamp); + mve_audio_buffers[mve_audio_buftail] = (short *)d_malloc(nsamp); mveaudio_uncompress(mve_audio_buffers[mve_audio_buftail], data, -1); /* XXX */ } else { nsamp -= 8; data += 8; mve_audio_buflens[mve_audio_buftail] = nsamp; - mve_audio_buffers[mve_audio_buftail] = (short *)malloc(nsamp); + mve_audio_buffers[mve_audio_buftail] = (short *)d_malloc(nsamp); memcpy(mve_audio_buffers[mve_audio_buftail], data, nsamp); } } else { mve_audio_buflens[mve_audio_buftail] = nsamp; - mve_audio_buffers[mve_audio_buftail] = (short *)malloc(nsamp); + mve_audio_buffers[mve_audio_buftail] = (short *)d_malloc(nsamp); memset(mve_audio_buffers[mve_audio_buftail], 0, nsamp); /* XXX */ } @@ -436,26 +456,32 @@ static int audio_data_handler(unsigned char major, unsigned char minor, unsigned /************************* * video handlers *************************/ +static int videobuf_created = 0; +static int video_initialized = 0; int g_width, g_height; -void *g_vBuffers, *g_vBackBuf1, *g_vBackBuf2; +void *g_vBuffers = NULL, *g_vBackBuf1, *g_vBackBuf2; #ifdef STANDALONE static SDL_Surface *g_screen; #else -static grs_bitmap *g_screen; +static int g_destX, g_destY; #endif static int g_screenWidth, g_screenHeight; static unsigned char g_palette[768]; static unsigned char *g_pCurMap=NULL; static int g_nMapLength=0; static int g_truecolor; -static int g_palette_changed = 0; static int create_videobuf_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) { short w, h; short count, truecolor; + if (videobuf_created) + return 1; + else + videobuf_created = 1; + w = get_short(data); h = get_short(data+2); @@ -474,12 +500,8 @@ static int create_videobuf_handler(unsigned char major, unsigned char minor, uns g_width = w << 3; g_height = h << 3; -#ifndef STANDALONE - Assert((g_width <= g_screen->bm_w) && (g_height <= g_screen->bm_h)); -#endif - /* TODO: * 4 causes crashes on some files */ - g_vBackBuf1 = g_vBuffers = malloc(g_width * g_height * 8); + g_vBackBuf1 = g_vBuffers = d_malloc(g_width * g_height * 8); if (truecolor) { g_vBackBuf2 = (unsigned short *)g_vBackBuf1 + (g_width * g_height); } else { @@ -488,7 +510,9 @@ static int create_videobuf_handler(unsigned char major, unsigned char minor, uns memset(g_vBackBuf1, 0, g_width * g_height * 4); +#ifdef DEBUG fprintf(stderr, "DEBUG: w,h=%d,%d count=%d, tc=%d\n", w, h, count, truecolor); +#endif g_truecolor = truecolor; @@ -606,30 +630,20 @@ static int display_video_handler(unsigned char major, unsigned char minor, unsig do_sdl_events(); #else - if (g_palette_changed) - { - gr_palette_load(g_palette); - g_palette_changed = 0; - } + grs_bitmap *bitmap; - if (g_width == g_screen->bm_w && g_height >= g_screen->bm_h) - memcpy(g_screen->bm_data, g_vBackBuf1, g_width * g_height); - else { - int i, x = 0, y = 0; - char *pSrc, *pDest; - - if (g_screen->bm_w > g_width) - x = (g_screen->bm_w - g_width) >> 1; - if (g_screen->bm_h > g_height) - y = (g_screen->bm_h - g_height) >> 1; - pSrc = g_vBackBuf1; - pDest = g_screen->bm_data + g_screen->bm_w * y + x; - for (i = 0; i < g_height; i++) { - memcpy(pDest, pSrc, g_width * (g_truecolor?2:1)); - pSrc += g_width * (g_truecolor?2:1); - pDest += g_screen->bm_w * (g_truecolor?2:1); - } - } + bitmap = gr_create_bitmap_raw(g_width, g_height, g_vBackBuf1); + + if (g_destX == -1) // center it + g_destX = (g_screenWidth - g_width) >> 1; + if (g_destY == -1) // center it + g_destY = (g_screenHeight - g_height) >> 1; + + gr_bitmap(g_destX, g_destY, bitmap); + + gr_free_sub_bitmap(bitmap); + + gr_palette_load(g_palette); #endif return 1; @@ -638,6 +652,12 @@ static int display_video_handler(unsigned char major, unsigned char minor, unsig static int init_video_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) { short width, height; + + if (video_initialized) + return 1; + else + video_initialized = 1; + width = get_short(data); height = get_short(data+2); #ifdef STANDALONE @@ -648,6 +668,7 @@ static int init_video_handler(unsigned char major, unsigned char minor, unsigned memset(g_palette, 0, 765); // 255 needs to default to white, for subtitles, etc memset(g_palette + 765, 63, 3); + return 1; } @@ -657,7 +678,6 @@ static int video_palette_handler(unsigned char major, unsigned char minor, unsig start = get_short(data); count = get_short(data+2); memcpy(g_palette + 3*start, data+4, 3*count); - g_palette_changed = 1; return 1; } @@ -711,6 +731,8 @@ static int end_chunk_handler(unsigned char major, unsigned char minor, unsigned return 1; } + +#ifdef STANDALONE void initializeMovie(MVESTREAM *mve) { int i; @@ -753,28 +775,50 @@ void playMovie(MVESTREAM *mve) } do_timer_wait(); + + if (g_loop && !cont) { + mve_reset(mve); + cont = 1; + } } } void shutdownMovie(MVESTREAM *mve) { +#ifdef DEBUG int i; +#endif timer_stop(); +#ifdef DEBUG for (i = 0; i < 32*256; i++) { if (unhandled_chunks[i]) { fprintf(stderr, "unhandled chunks of type %02x/%02x: %d\n", i>>8, i&0xFF, unhandled_chunks[i]); } } +#endif } -#ifndef STANDALONE -void mveplay_initializeMovie(MVESTREAM *mve, grs_bitmap *mve_bitmap) +#else +static MVESTREAM *mve = NULL; + +int MVE_rmPrepMovie(int filehandle, int x, int y, int track) { int i; - g_screen = mve_bitmap; + if (mve) { + mve_reset(mve); + return 0; + } + + mve = mve_open_filehandle(filehandle); + + if (!mve) + return 1; + + g_destX = x; + g_destY = y; for (i = 0; i < 32; i++) mve_set_handler(mve, i, default_seg_handler); @@ -798,9 +842,10 @@ void mveplay_initializeMovie(MVESTREAM *mve, grs_bitmap *mve_bitmap) mve_set_handler(mve, MVE_OPCODE_VIDEODATA, video_data_handler); + return 0; } -int mveplay_stepMovie(MVESTREAM *mve) +int MVE_rmStepMovie() { static int init_timer=0; int cont=1; @@ -816,20 +861,22 @@ int mveplay_stepMovie(MVESTREAM *mve) do_timer_wait(); - return cont; -} - -void mveplay_restartTimer(MVESTREAM *mve) -{ - timer_start(); + if (cont) + return 0; + else + return MVE_ERR_EOF; } -void mveplay_shutdownMovie(MVESTREAM *mve) +void MVE_rmEndMovie() { +#ifdef AUDIO int i; +#endif timer_stop(); + timer_created = 0; +#ifdef AUDIO SDL_CloseAudio(); if (mve_audio_canplay) { // only close audio if we opened it @@ -837,7 +884,7 @@ void mveplay_shutdownMovie(MVESTREAM *mve) } for (i = 0; i < TOTAL_AUDIO_BUFFERS; i++) if (mve_audio_buffers[i] != NULL) - free(mve_audio_buffers[i]); + d_free(mve_audio_buffers[i]); memset(mve_audio_buffers, 0, sizeof(mve_audio_buffers)); memset(mve_audio_buflens, 0, sizeof(mve_audio_buflens)); mve_audio_curbuf_curpos=0; @@ -847,12 +894,25 @@ void mveplay_shutdownMovie(MVESTREAM *mve) mve_audio_canplay=0; mve_audio_compressed=0; if (mve_audio_spec) - free(mve_audio_spec); + d_free(mve_audio_spec); mve_audio_spec=NULL; + audiobuf_created = 0; +#endif - free(g_vBuffers); + d_free(g_vBuffers); g_vBuffers = NULL; g_pCurMap=NULL; g_nMapLength=0; + videobuf_created = 0; + video_initialized = 0; + + mve_close_filehandle(mve); + mve = NULL; +} + + +void MVE_rmHoldMovie() +{ + timer_started = 0; } #endif diff --git a/main/mveplay.h b/main/mveplay.h index b914e571..87a7c715 100644 --- a/main/mveplay.h +++ b/main/mveplay.h @@ -1,12 +1,11 @@ #ifndef _MVEPLAY_H #define _MVEPLAY_H -#include "gr.h" -#include "mvelib.h" +#define MVE_ERR_EOF 1 -void mveplay_initializeMovie(MVESTREAM *mve, grs_bitmap *mve_bitmap); -int mveplay_stepMovie(MVESTREAM *mve); -void mveplay_restartTimer(MVESTREAM *mve); -void mveplay_shutdownMovie(MVESTREAM *mve); +int MVE_rmPrepMovie(int filehandle, int x, int y, int track); +int MVE_rmStepMovie(); +void MVE_rmHoldMovie(); +void MVE_rmEndMovie(); #endif /* _MVEPLAY_H */ diff --git a/main/titles.c b/main/titles.c index c21ecded..484da97a 100644 --- a/main/titles.c +++ b/main/titles.c @@ -1,4 +1,4 @@ -/* $Id: titles.c,v 1.17 2003-01-11 02:57:39 btb Exp $ */ +/* $Id: titles.c,v 1.18 2003-02-18 07:05:14 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -76,8 +76,6 @@ int DefineBriefingBox (char **buf); extern unsigned RobSX,RobSY,RobDX,RobDY; // Robot movie coords -extern int MVEPaletteCalls; - ubyte New_pal[768]; int New_pal_254_bash; @@ -1259,6 +1257,13 @@ int show_briefing_message(int screen_num, char *message) if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER)) delay_count = 0; +#ifdef GR_SUPPORTS_FULLSCREEN + if ((key_check == KEY_CTRLED+KEY_SHIFTED+KEY_PADENTER) || + (key_check == KEY_ALTED+KEY_CTRLED+KEY_PADENTER) || + (key_check == KEY_ALTED+KEY_SHIFTED+KEY_PADENTER)) + gr_toggle_fullscreen(); +#endif + if (Briefing_text_x > bsp->text_ulx + bsp->text_width) { Briefing_text_x = bsp->text_ulx; Briefing_text_y += bsp->text_uly; @@ -1548,8 +1553,6 @@ void do_briefing_screens(char *filename,int level_num) int abort_briefing_screens = 0; int cur_briefing_screen = 0; - MVEPaletteCalls=0; - if (Skip_briefing_screens) { mprintf((0, "Skipping all briefing screens.\n")); return; -- 2.39.2