From 63df9a116342717efabcd3d5e159f994af75c68d Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Sat, 31 Aug 2002 12:14:01 +0000 Subject: [PATCH] movie improvements --- TODO | 3 +- main/inferno.c | 4 +- main/movie.c | 56 +++++++++----- main/mveplay.c | 205 ++++++++----------------------------------------- 4 files changed, 72 insertions(+), 196 deletions(-) diff --git a/TODO b/TODO index 167164ba..7a55e96f 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ * Rearrange build system (one big makefile in a src/ directory) -* Use gr functions for mveplay * Glitches with mission briefings -* Robot movies * D1 mission briefings (render spinning robots, etc.) * Make networking compatible with official version +* bigendian networking diff --git a/main/inferno.c b/main/inferno.c index 843e37ac..bacf77e7 100644 --- a/main/inferno.c +++ b/main/inferno.c @@ -1,4 +1,4 @@ -/* $Id: inferno.c,v 1.42 2002-08-30 00:57:32 btb Exp $ */ +/* $Id: inferno.c,v 1.43 2002-08-31 12:14:01 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -693,13 +693,11 @@ int main(int argc,char **argv) con_printf( CON_DEBUG, "Initializing movie libraries...\n" ); init_movies(); //init movie libraries -#if 0 con_printf(CON_VERBOSE, "Going into graphics mode...\n"); #if defined(POLY_ACC) gr_set_mode(SM_640x480x15xPA); #else gr_set_mode(MovieHires?SM(640,480):SM(320,200)); -#endif #endif #ifndef RELEASE diff --git a/main/movie.c b/main/movie.c index 2cc13ea1..1d134006 100644 --- a/main/movie.c +++ b/main/movie.c @@ -1,4 +1,4 @@ -/* $Id: movie.c,v 1.10 2002-08-27 04:14:18 btb Exp $ */ +/* $Id: movie.c,v 1.11 2002-08-31 12:14:01 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.10 2002-08-27 04:14:18 btb Exp $"; +static char rcsid[] = "$Id: movie.c,v 1.11 2002-08-31 12:14:01 btb Exp $"; #endif #define DEBUG_LEVEL CON_NORMAL @@ -105,7 +105,9 @@ int robot_movies = 0; //0 means none, 1 means lowres, 2 means hires int MovieHires = 0; //default for now is lores int RoboFile = 0; +char Robo_filename[FILENAME_LEN]; MVESTREAM *Robo_mve; +grs_bitmap *Robo_bitmap; // Function Prototypes @@ -129,8 +131,7 @@ int PlayMovie(const char *filename, int must_have) #endif #ifndef RELEASE - //if (FindArg("-nomovies")) - if (!FindArg("-movies")) + if (FindArg("-nomovies")) return MOVIE_NOT_PLAYED; #endif @@ -176,7 +177,7 @@ int PlayMovie(const char *filename, int must_have) return ret; } -void initializeMovie(MVESTREAM *mve); +void initializeMovie(MVESTREAM *mve, grs_bitmap *mve_bitmap); void shutdownMovie(MVESTREAM *mve); //returns status. see movie.h @@ -186,6 +187,7 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy) int result=1,aborted=0; int frame_num; MVESTREAM *mve; + grs_bitmap *mve_bitmap; result=1; con_printf(DEBUG_LEVEL, "movie: RunMovie: %s %d %d %d %d\n", filename, hires_flag, must_have, dx, dy); @@ -202,16 +204,14 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy) return MOVIE_NOT_PLAYED; } -#if 0 if (hires_flag) gr_set_mode(SM(640,480)); else gr_set_mode(SM(320,200)); -#endif frame_num = 0; - FontHires = hires_flag; + FontHires = FontHiresAvailable && hires_flag; mve = mve_open(filehndl); if (mve == NULL) @@ -220,14 +220,19 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy) return 1; } -#if 1 - initializeMovie(mve); + mve_bitmap = gr_create_bitmap(hires_flag?592:320, hires_flag?312:200); + + initializeMovie(mve, mve_bitmap); while((result = mve_play_next_chunk(mve))) { int key; + gr_bitmap(hires_flag?24:12, hires_flag?84:42, mve_bitmap); + draw_subtitles(frame_num); + gr_update(); + key = key_inkey(); // If ESCAPE pressed, then quit movie. @@ -251,7 +256,8 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy) Assert(aborted || !result); ///movie should be over shutdownMovie(mve); -#endif + + gr_free_bitmap(mve_bitmap); mve_close(mve); @@ -267,12 +273,11 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy) int InitMovieBriefing() { -#if 0 if (MenuHires) gr_set_mode(SM(640,480)); else gr_set_mode(SM(320,200)); -#endif + return 1; } @@ -280,9 +285,17 @@ int InitMovieBriefing() //returns 1 if frame updated ok int RotateRobot() { - con_printf(DEBUG_LEVEL, "movie: RotateRobot\n"); + int ret; + + ret = mve_play_next_chunk(Robo_mve); + gr_bitmap(MenuHires?280:200, MenuHires?140:80, Robo_bitmap); + + if (!ret) { + DeInitRobotMovie(); + InitRobotMovie(Robo_filename); + } - return mve_play_next_chunk(Robo_mve); + return 1; } @@ -292,6 +305,8 @@ void DeInitRobotMovie(void) shutdownMovie(Robo_mve); + gr_free_bitmap(Robo_bitmap); + close(RoboFile); } @@ -300,13 +315,15 @@ int InitRobotMovie(char *filename) { con_printf(DEBUG_LEVEL, "movie: InitRobotMovie: %s\n", filename); - RoboFile = open_movie_file(filename,1); + RoboFile = open_movie_file(filename, 1); if (RoboFile == -1) { Warning("movie: InitRobotMovie: Cannot open movie file <%s>",filename); return MOVIE_NOT_PLAYED; } + strcpy(Robo_filename, filename); + Robo_mve = mve_open(RoboFile); if (Robo_mve == NULL) { @@ -314,7 +331,9 @@ int InitRobotMovie(char *filename) return 0; } - initializeMovie(Robo_mve); + Robo_bitmap = gr_create_bitmap(MenuHires?320:160, MenuHires?200:100); + + initializeMovie(Robo_mve, Robo_bitmap); return 1; } @@ -643,8 +662,7 @@ void init_movie(char *filename,int libnum,int is_robots,int required) int try = 0; #ifndef RELEASE - //if (FindArg("-nomovies")) { - if (!FindArg("-movies")) { + if (FindArg("-nomovies")) { movie_libs[libnum] = NULL; return; } diff --git a/main/mveplay.c b/main/mveplay.c index dc52ba64..76d6d562 100644 --- a/main/mveplay.c +++ b/main/mveplay.c @@ -2,9 +2,6 @@ #include #endif -#include "mvelib.h" /* next buffer */ -#include "mve_audio.h" - #include #include #include @@ -12,87 +9,26 @@ #include #include #include +#include #include #include -#if 1 +#include "error.h" #include "u_mem.h" -#else -#define d_malloc(a) malloc(a) -#define d_free(a) free(a) -#endif +#include "mvelib.h" +#include "mve_audio.h" +#include "gr.h" +#include "palette.h" #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif -#ifdef STANDALONE -static int doPlay(const char *filename); - -static void usage(void) -{ - fprintf(stderr, "usage: mveplay filename\n"); - exit(1); -} -#endif - static int g_spdFactorNum=0; static int g_spdFactorDenom=10; -#ifdef STANDALONE -int main(int c, char **v) -{ - if (c != 2 && c != 3) - usage(); - - if (c == 3) - g_spdFactorNum = atoi(v[2]); - - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) - { - fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); - exit(1); - } - atexit(SDL_Quit); - - return doPlay(v[1]); -} -#endif - -#ifdef STANDALONE -static void initializeMovie(MVESTREAM *mve); -static void playMovie(MVESTREAM *mve); -static void shutdownMovie(MVESTREAM *mve); -#else -void initializeMovie(MVESTREAM *mve); +void initializeMovie(MVESTREAM *mve, grs_bitmap *mve_bitmap); void shutdownMovie(MVESTREAM *mve); -#endif - -#ifdef STANDALONE -static int doPlay(const char *filename) -{ - MVESTREAM *mve; - int filehandle; - - filehandle = open(filename, O_RDONLY); - - if (filehandle == -1) - { - fprintf(stderr, "can't open MVE file '%s'\n", filename); - return 1; - } - - mve = mve_open(filehandle); - - initializeMovie(mve); - playMovie(mve); - shutdownMovie(mve); - - mve_close(mve); - - return 0; -} -#endif static short get_short(unsigned char *data) { @@ -119,7 +55,7 @@ static int default_seg_handler(unsigned char major, unsigned char minor, unsigne *************************/ static int end_movie_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) { - return 0; + return 0; } /************************* @@ -130,10 +66,6 @@ static int end_movie_handler(unsigned char major, unsigned char minor, unsigned * timer variables */ static int micro_frame_delay=0; -#ifdef STANDALONE -static int timer_started=0; -static Uint32 timer_expire = 0; -#endif static int create_timer_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) { @@ -150,36 +82,11 @@ static int create_timer_handler(unsigned char major, unsigned char minor, unsign return 1; } -#ifdef STANDALONE -static void timer_start(void) -{ - timer_expire = SDL_GetTicks(); - timer_expire += micro_frame_delay / 1000; - timer_started=1; -} - -static void do_timer_wait(void) -{ - Uint32 ts, tv; - if (! timer_started) - return; - - tv = SDL_GetTicks(); - if (tv > timer_expire) - goto end; - - ts = timer_expire - tv; - SDL_Delay(ts); - -end: - timer_expire += micro_frame_delay / 1000; -} -#endif /************************* * audio handlers *************************/ -static void mve_audio_callback(void *userdata, Uint8 *stream, int len); +static void mve_audio_callback(void *userdata, Uint8 *stream, int len); static short *mve_audio_buffers[64]; static int mve_audio_buflens[64]; static int mve_audio_curbuf_curpos=0; @@ -269,15 +176,15 @@ fprintf(stderr, "creating audio buffers\n"); fprintf(stderr, "stereo=%d 16bit=%d compressed=%d sample_rate=%d desired_buffer=%d\n", flags & 1, (flags >> 1) & 1, (flags >> 2) & 1, sample_rate, desired_buffer); - mve_audio_compressed = (flags >> 2) & 1; + mve_audio_compressed = flags & MVE_AUDIO_FLAGS_COMPRESSED; mve_audio_spec = (SDL_AudioSpec *)d_malloc(sizeof(SDL_AudioSpec)); mve_audio_spec->freq = sample_rate; #ifdef WORDS_BIGENDIAN - mve_audio_spec->format = ((flags >> 1) & 1)?AUDIO_S16MSB:AUDIO_U8; + mve_audio_spec->format = (flags & MVE_AUDIO_FLAGS_16BIT)?AUDIO_S16MSB:AUDIO_U8; #else - mve_audio_spec->format = ((flags >> 1) & 1)?AUDIO_S16LSB:AUDIO_U8; + mve_audio_spec->format = (flags & MVE_AUDIO_FLAGS_16BIT)?AUDIO_S16LSB:AUDIO_U8; #endif - mve_audio_spec->channels = (flags &1 )?2:1; + mve_audio_spec->channels = (flags & MVE_AUDIO_FLAGS_STEREO)?2:1; mve_audio_spec->samples = 32768; mve_audio_spec->callback = mve_audio_callback; mve_audio_spec->userdata = NULL; @@ -325,7 +232,7 @@ static int audio_data_handler(unsigned char major, unsigned char minor, unsigned { SDL_mutexP(mve_audio_mutex); mve_audio_buflens[mve_audio_buftail] = nsamp; - mve_audio_buffers[mve_audio_buftail] = (short *)d_malloc(nsamp); + mve_audio_buffers[mve_audio_buftail] = (short *)d_malloc(nsamp+4); if (major == 8) if (mve_audio_compressed) mveaudio_uncompress(mve_audio_buffers[mve_audio_buftail], data, -1); /* XXX */ @@ -352,7 +259,7 @@ static int audio_data_handler(unsigned char major, unsigned char minor, unsigned /************************* * video handlers *************************/ -static SDL_Surface *g_screen; +static grs_bitmap *g_screen; static int g_screenWidth, g_screenHeight; static int g_width, g_height; static unsigned char g_palette[768]; @@ -367,6 +274,8 @@ static int create_videobuf_handler(unsigned char major, unsigned char minor, uns h = get_short(data+2); g_width = w << 3; g_height = h << 3; + printf("mve width, height: %d, %d\n", g_width, g_height); + Assert((g_width == g_screen->bm_w) && (g_height == g_screen->bm_h)); g_vBackBuf1 = d_malloc(g_width * g_height); g_vBackBuf2 = d_malloc(g_width * g_height); memset(g_vBackBuf1, 0, g_width * g_height); @@ -374,51 +283,12 @@ static int create_videobuf_handler(unsigned char major, unsigned char minor, uns return 1; } -//static int stupefaction=0; static int display_video_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) { - int i; - unsigned char *pal = g_palette; - unsigned char *pDest; - unsigned char *pixels = g_vBackBuf1; - SDL_Surface *screenSprite; - SDL_Rect renderArea; - int x, y; - - SDL_Surface *initSprite = SDL_CreateRGBSurface(SDL_SWSURFACE, g_width, g_height, 8, 0, 0, 0, 0); - for(i = 0; i < 256; i++) - { - initSprite->format->palette->colors[i].r = (*pal++) << 2; - initSprite->format->palette->colors[i].g = (*pal++) << 2; - initSprite->format->palette->colors[i].b = (*pal++) << 2; - initSprite->format->palette->colors[i].unused = 0; - } + gr_palette_load(g_palette); - pDest = initSprite->pixels; - for (i=0; ipitch; - } + memcpy(g_screen->bm_data, g_vBackBuf1, g_width * g_height); - screenSprite = SDL_DisplayFormat(initSprite); - SDL_FreeSurface(initSprite); - - if (g_screenWidth > screenSprite->w) x = (g_screenWidth - screenSprite->w) >> 1; - else x=0; - if (g_screenHeight > screenSprite->h) y = (g_screenHeight - screenSprite->h) >> 1; - else y=0; - renderArea.x = x; - renderArea.y = y; - renderArea.w = MIN(g_screenWidth - x, screenSprite->w); - renderArea.h = MIN(g_screenHeight - y, screenSprite->h); - SDL_BlitSurface(screenSprite, NULL, g_screen, &renderArea); - if ( (g_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) - SDL_Flip(g_screen); - else - SDL_UpdateRects(g_screen, 1, &renderArea); - SDL_FreeSurface(screenSprite); return 1; } @@ -427,7 +297,6 @@ static int init_video_handler(unsigned char major, unsigned char minor, unsigned short width, height; width = get_short(data); height = get_short(data+2); - g_screen = SDL_SetVideoMode(width, height, 16, SDL_ANYFORMAT); g_screenWidth = width; g_screenHeight = height; memset(g_palette, 0, 768); @@ -487,8 +356,10 @@ static int end_chunk_handler(unsigned char major, unsigned char minor, unsigned return 1; } -void initializeMovie(MVESTREAM *mve) +void initializeMovie(MVESTREAM *mve, grs_bitmap *mve_bitmap) { + g_screen = mve_bitmap; + mve_set_handler(mve, 0x00, end_movie_handler); mve_set_handler(mve, 0x01, end_chunk_handler); mve_set_handler(mve, 0x02, create_timer_handler); @@ -513,30 +384,20 @@ void initializeMovie(MVESTREAM *mve) //mve_set_handler(mve, 0x15, default_seg_handler); } -#ifdef STANDALONE -static void playMovie(MVESTREAM *mve) +void shutdownMovie(MVESTREAM *mve) { - int init_timer=0; - int cont=1; - while (cont) - { - cont = mve_play_next_chunk(mve); - if (micro_frame_delay && !init_timer) - { - timer_start(); - init_timer = 1; - } + int i; - do_timer_wait(); - } -} -#endif + SDL_CloseAudio(); + for (i = 0; i < 64; i++) + if (mve_audio_buffers[i] != NULL) { + d_free(mve_audio_buffers[i]); + mve_audio_buffers[i] = NULL; + } -#ifdef STANDALONE -static -#endif -void shutdownMovie(MVESTREAM *mve) -{ + d_free(mve_audio_spec); + d_free(g_vBackBuf1); + d_free(g_vBackBuf2); } static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsigned char **pData, int *pDataRemain, int *curXb, int *curYb); -- 2.39.2