2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: movie.c,v 1.1.1.1 2001-01-19 03:30:14 bradleyb Exp $";
17 #pragma on (unreferenced)
30 #include "pa_enabl.h" //$$POLY_ACC
61 extern char *Args[100]; // Arguments from args.c for
62 char *FirstVid,*SecondVid;
64 char RobBufCount=0,PlayingBuf=0,RobBufLimit=0;
66 unsigned RobSX=75,RobSY=50,RobDX=100,RobDY=100;
67 int RoboFile=0,RoboFilePos=0,MVEPaletteCalls=0;
69 // Function Prototypes
70 int RunMovie(char *filename, int highres_flag, int allow_abort,int dx,int dy);
71 extern void do_briefing_screens (char *,int);
75 short first_frame,last_frame;
80 // #define BUFFER_MOVIE
82 #define MAX_SUBTITLES 500
83 subtitle Subtitles[MAX_SUBTITLES];
86 // ----------------------------------------------------------------------
87 void* __cdecl MPlayAlloc(unsigned size)
92 void __cdecl MPlayFree(void *p)
97 extern WORD hSOSDigiDriver;
101 //-----------------------------------------------------------------------
103 unsigned __cdecl FileRead(int handle, void *buf, unsigned count)
106 numread = read(handle, buf, count);
107 return (numread == count);
115 extern int Digi_initialized;
116 extern int digi_timer_rate;
118 int MovieHires = 0; //default for now is lores
120 #define MOVIE_VOLUME_SCALE (32767) //32767 is MAX
122 //filename will actually get modified to be either low-res or high-res
123 //returns status. see values in movie.h
124 int PlayMovie(const char *filename, int must_have)
126 char name[FILENAME_LEN],*p;
128 int save_sample_rate;
130 #if defined(POLY_ACC)
131 PA_DFX (pa_set_write_mode (1));
132 PA_DFX (pa_set_frontbuffer_current());
135 if (!Digi_initialized)
136 return MOVIE_NOT_PLAYED;
139 if (FindArg("-nomovies"))
140 return MOVIE_NOT_PLAYED;
143 strcpy(name,filename);
145 if ((p=strchr(name,'.')) == NULL) //add extension, if missing
148 //check for escape already pressed & abort if so
149 while ((c=key_inkey()) != 0)
151 return MOVIE_ABORTED;
153 // Stop all digital sounds currently playing.
159 save_sample_rate = digi_sample_rate;
160 digi_sample_rate = SAMPLE_RATE_22K; //always 22K for movies
161 digi_reset(); digi_reset();
164 if (hSOSDigiDriver < 0xffff) {
165 MVE_SOS_sndInit(hSOSDigiDriver);
166 MVE_sndVolume((Config_digi_volume*MOVIE_VOLUME_SCALE)/8);
171 MVE_rmFastMode (MVE_RM_NORMAL);
173 ret = RunMovie(name,MovieHires,must_have,-1,-1);
175 //@@ if (ret == MOVIE_NOT_PLAYED) { //couldn't find movie. try other version
176 //@@ name[strlen(name)-5] = MovieHires?'l':'h'; //change name
177 //@@ ret = RunMovie(name,!MovieHires,allow_abort,-1,-1); //try again
180 gr_palette_clear(); //clear out palette in case movie aborted
182 digi_sample_rate = save_sample_rate; //restore rate for game
183 digi_reset(); digi_reset();
185 Screen_mode = -1; //force screen reset
187 #if defined(POLY_ACC)
188 PA_DFX(pa_set_write_mode (0));
195 void __cdecl MovieShowFrame (ubyte *buf,uint bufw,uint bufh,uint sx,uint sy,uint w,uint h,uint dstx,uint dsty)
197 grs_bitmap source_bm;
199 //mprintf((0,"MovieShowFrame %d,%d %d,%d %d,%d %d,%d\n",bufw,bufh,sx,sy,w,h,dstx,dsty));
201 Assert(bufw == w && bufh == h);
203 source_bm.bm_x = source_bm.bm_y = 0;
204 source_bm.bm_w = source_bm.bm_rowsize = bufw;
205 source_bm.bm_h = bufh;
206 source_bm.bm_type = BM_LINEAR;
207 source_bm.bm_flags = 0;
208 source_bm.bm_data = buf;
210 gr_bm_ubitblt(bufw,bufh,dstx,dsty,sx,sy,&source_bm,&grd_curcanv->cv_bitmap);
213 //our routine to set the pallete, called from the movie code
214 void __cdecl MovieSetPalette(unsigned char *p, unsigned start, unsigned count)
219 //mprintf((0,"SetPalette p=%x, start=%d, count=%d\n",p,start,count));
221 //Color 0 should be black, and we get color 255
222 Assert(start>=1 && start+count-1<=254);
224 //Set color 0 to be black
225 gr_palette[0] = gr_palette[1] = gr_palette[2] = 0;
227 //Set color 255 to be our subtitle color
228 gr_palette[765] = gr_palette[766] = gr_palette[767] = 50;
230 //movie libs palette into our array
231 memcpy(gr_palette+start*3,p+start*3,count*3);
233 //finally set the palette in the hardware
234 gr_palette_load(gr_palette);
236 //MVE_SetPalette(p, start, count);
240 short x, y, w, h; // The location of the menu.
241 grs_bitmap * bmp; // The background under the menu.
244 bkg movie_bg = {0,0,0,0,NULL};
246 #define BOX_BORDER (MenuHires?40:20)
248 void show_pause_message(char *msg)
253 gr_set_current_canvas(NULL);
254 gr_set_curfont( SMALL_FONT );
256 gr_get_string_size(msg,&w,&h,&aw);
258 x = (grd_curscreen->sc_w-w)/2;
259 y = (grd_curscreen->sc_h-h)/2;
262 gr_free_bitmap(movie_bg.bmp);
266 // Save the background of the display
267 movie_bg.x=x; movie_bg.y=y; movie_bg.w=w; movie_bg.h=h;
269 movie_bg.bmp = gr_create_bitmap( w+BOX_BORDER, h+BOX_BORDER );
271 gr_bm_ubitblt(w+BOX_BORDER, h+BOX_BORDER, 0, 0, x-BOX_BORDER/2, y-BOX_BORDER/2, &(grd_curcanv->cv_bitmap), movie_bg.bmp );
274 gr_rect(x-BOX_BORDER/2,y-BOX_BORDER/2,x+w+BOX_BORDER/2-1,y+h+BOX_BORDER/2-1);
276 gr_set_fontcolor( 255, -1 );
278 gr_ustring( 0x8000, y, msg );
281 void clear_pause_message()
286 gr_bitmap(movie_bg.x-BOX_BORDER/2, movie_bg.y-BOX_BORDER/2, movie_bg.bmp);
288 gr_free_bitmap(movie_bg.bmp);
293 int open_movie_file(char *filename,int must_have);
295 //returns status. see movie.h
296 int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy)
299 int result,aborted=0;
303 // Open Movie file. If it doesn't exist, no movie, just return.
305 filehndl = open_movie_file(filename,must_have);
307 if (filehndl == -1) {
312 Error("Cannot open movie file <%s>",filename);
315 return MOVIE_NOT_PLAYED;
317 return MOVIE_NOT_PLAYED;
321 MVE_memCallbacks(MPlayAlloc, MPlayFree);
322 MVE_ioCallbacks(FileRead);
324 #if defined(POLY_ACC)
328 #ifdef PA_3DFX_VOODOO
330 MVE_sfSVGA( 640, 480, 2048, 0, pa_get_buffer_address(0), 0, 0, NULL, 1);
333 MVE_sfSVGA( 640, 480, 1280, 0, pa_get_buffer_address(0), 0, 0, NULL, 1);
336 pa_clear_buffer(0, 0);
339 vga_set_mode(SM_640x480V);
340 if (!MVE_gfxMode(MVE_GFX_VESA_CURRENT)) {
342 close(filehndl); // Close Movie File
343 return MOVIE_NOT_PLAYED;
347 vga_set_mode(SM_320x200C);
348 if (!MVE_gfxMode(MVE_GFX_VGA_CURRENT)) {
350 close(filehndl); // Close Movie File
351 return MOVIE_NOT_PLAYED;
356 Vid_State = VID_PLAY; // Set to PLAY
358 if (MVE_rmPrepMovie(filehndl, dx, dy, track)) {
360 return MOVIE_NOT_PLAYED;
363 #if !defined(POLY_ACC)
364 MVE_sfCallbacks ((mve_cb_ShowFrame *) MovieShowFrame);
365 MVE_palCallbacks ((mve_cb_SetPalette *) MovieSetPalette);
370 FontHires = hires_flag;
372 while((result = MVE_rmStepMovie()) == 0) {
375 draw_subtitles(frame_num);
379 // If ESCAPE pressed, then quit movie.
380 if (key == KEY_ESC) {
381 result = aborted = 1;
385 // If PAUSE pressed, then pause movie
386 if (key == KEY_PAUSE) {
388 show_pause_message(TXT_PAUSE);
389 while (!key_inkey()) ;
390 clear_pause_message();
396 Assert(aborted || result == MVE_ERR_EOF); ///movie should be over
401 close(filehndl); // Close Movie File
405 // Restore old graphic state
407 Screen_mode=-1; //force reset of screen mode
410 //@@ vga_set_mode(SM_640x480V);
412 //@@ vga_set_mode(SM_320x200C);
414 return (aborted?MOVIE_ABORTED:MOVIE_PLAYED_FULL);
418 int InitMovieBriefing ()
420 #if defined(POLY_ACC)
424 #ifdef PA_3DFX_VOODOO
426 MVE_sfSVGA( 640, 480, 2048, 0, pa_get_buffer_address(0), 0, 0, NULL, 1);
429 MVE_sfSVGA( 640, 480, 1280, 0, pa_get_buffer_address(0), 0, 0, NULL, 1);
432 pa_clear_buffer(0, 0);
437 vga_set_mode(SM_640x480V);
438 if (!MVE_gfxMode(MVE_GFX_VESA_CURRENT)) {
440 return MOVIE_NOT_PLAYED;
444 vga_set_mode(SM_320x200C);
445 if (!MVE_gfxMode(MVE_GFX_VGA_CURRENT)) {
447 return MOVIE_NOT_PLAYED;
455 int MyShowFrame (void)
457 grs_bitmap source_bm;
462 { rw=320; rh=200; rdx=280; rdy=200;}
464 { rw=160; rh=100; rdx=140; rdy=80;}
466 source_bm.bm_x = source_bm.bm_y = 0;
467 source_bm.bm_w = source_bm.bm_rowsize = rw;
469 source_bm.bm_type = BM_LINEAR;
470 source_bm.bm_flags = 0;
474 memcpy (RoboBuffer[RobBufCount++],SecondVid,rw*rh);
476 source_bm.bm_data = SecondVid;
480 source_bm.bm_data = FirstVid;
482 memcpy (RoboBuffer[RobBufCount++],FirstVid,rw*rh);
486 gr_bm_ubitblt(rw,rh,rdx,rdy,0,0,&source_bm,&grd_curcanv->cv_bitmap);
494 static fix RobBufTime=0;
497 void ShowRobotBuffer ()
499 // shows a frame from the robot buffer
502 Int3(); // Get Jason...how'd we get here?
505 grs_bitmap source_bm;
508 if (timer_get_approx_seconds()<(RobBufTime+fixdiv (F1_0,i2f(15))))
511 RobBufTime=timer_get_approx_seconds();
514 { rw=320; rh=200; rdx=280; rdy=200;}
516 { rw=160; rh=100; rdx=140; rdy=80;}
518 source_bm.bm_x = source_bm.bm_y = 0;
519 source_bm.bm_w = source_bm.bm_rowsize = rw;
521 source_bm.bm_type = BM_LINEAR;
522 source_bm.bm_flags = 0;
524 source_bm.bm_data = RoboBuffer[RobBufCount];
526 gr_bm_ubitblt(rw,rh,rdx,rdy,0,0,&source_bm,&grd_curcanv->cv_bitmap);
529 RobBufCount%=RobBufLimit;
533 //returns 1 if frame updated ok
538 if (!Digi_initialized) //we should fix this for full version
548 #if defined(POLY_ACC)
549 PA_DFX (pa_set_write_mode (1));
552 err = MVE_rmStepMovie();
554 #if defined(POLY_ACC)
555 PA_DFX (pa_set_write_mode (0));
559 if (err == MVE_ERR_EOF) //end of movie, so reset
563 RobBufLimit=RobBufCount;
565 //RobBufTime=timer_get_approx_seconds();
568 reset_movie_file(RoboFile);
569 #if defined(POLY_ACC)
570 if (MVE_rmPrepMovie(RoboFile, 280, 200, 0)) {
572 if (MVE_rmPrepMovie(RoboFile, -1, -1, 0)) {
587 void FreeRoboBuffer (int n)
589 // frees the 64k frame buffers, starting with n and then working down
598 free (RoboBuffer[i]);
604 void DeInitRobotMovie()
606 RobBufCount=0; PlayingBuf=0;
608 #if !defined(POLY_ACC)
609 memset (FirstVid,0,64000);
610 memset (SecondVid,0,64000);
621 MVE_palCallbacks (MVE_SetPalette);
622 close(RoboFile); // Close Movie File
625 void __cdecl PaletteChecker (unsigned char *p,unsigned start,unsigned count)
633 if (i>=255 && (MVEPaletteCalls++)>0)
636 MVE_SetPalette (p,start,count);
640 int InitRobotMovie (char *filename)
648 RobBufCount=0; PlayingBuf=0; RobBufLimit=0;
650 if (FindArg("-nomovies"))
656 //@@ filename[4]='h';
658 //@@ filename[4]='l';
660 mprintf ((0,"RoboFile=%s\n",filename));
667 RoboBuffer[i]=malloc(65000L);
669 RoboBuffer[i]=malloc(17000L);
671 if (RoboBuffer[i]==NULL)
673 mprintf ((0,"ROBOERROR: Could't allocate frame %d!\n",i));
675 FreeRoboBuffer (i-1);
681 if ((FirstVid=calloc (65000L,1))==NULL)
686 if ((SecondVid=calloc (65000L,1))==NULL)
693 MVE_SOS_sndInit(-1); //tell movies to play no sound for robots
695 MVE_memCallbacks(MPlayAlloc, MPlayFree);
696 MVE_ioCallbacks(FileRead);
697 MVE_memVID (FirstVid,SecondVid,65000);
699 RoboFile = open_movie_file(filename,1);
701 if (RoboFile == -1) {
706 Error("Cannot open movie file <%s>",filename);
708 return MOVIE_NOT_PLAYED;
712 Vid_State = VID_PLAY;
714 #if !defined(POLY_ACC)
715 MVE_sfCallbacks ((mve_cb_ShowFrame *)MyShowFrame);
718 #if defined(POLY_ACC)
719 if (MVE_rmPrepMovie(RoboFile, 280, 200, 0)) {
721 if (MVE_rmPrepMovie(RoboFile, -1, -1, 0)) {
730 #if !defined(POLY_ACC)
731 MVE_palCallbacks (PaletteChecker);
734 RoboFilePos=lseek (RoboFile,0L,SEEK_CUR);
736 mprintf ((0,"RoboFilePos=%d!\n",RoboFilePos));
741 * Subtitle system code
744 ubyte *subtitle_raw_data;
746 //search for next field following whitespace
747 ubyte *next_field(ubyte *p)
749 while (*p && !isspace(*p))
755 while (*p && isspace(*p))
764 void change_filename_ext( char *dest, char *src, char *ext );
765 void decode_text_line(char *p);
767 int init_subtitles(char *filename)
776 if (! FindArg("-subtitles"))
779 ifile = cfopen(filename,"rb"); //try text version
781 if (!ifile) { //no text version, try binary version
782 char filename2[FILENAME_LEN];
783 change_filename_ext(filename2,filename,".TXB");
784 ifile = cfopen(filename2,"rb");
790 size = cfilelength(ifile);
792 MALLOC (subtitle_raw_data, ubyte, size+1);
794 read_count = cfread(subtitle_raw_data, 1, size, ifile);
798 subtitle_raw_data[size] = 0;
800 if (read_count != size) {
801 free(subtitle_raw_data);
805 p = subtitle_raw_data;
807 while (p && p < subtitle_raw_data+size) {
810 endp = strchr(p,'\n');
812 if (endp[-1] == '\r')
813 endp[-1] = 0; //handle 0d0a pair
814 *endp = 0; //string termintor
821 Subtitles[Num_subtitles].first_frame = atoi(p);
822 p = next_field(p); if (!p) continue;
823 Subtitles[Num_subtitles].last_frame = atoi(p);
824 p = next_field(p); if (!p) continue;
825 Subtitles[Num_subtitles].msg = p;
827 Assert(Num_subtitles==0 || Subtitles[Num_subtitles].first_frame >= Subtitles[Num_subtitles-1].first_frame);
828 Assert(Subtitles[Num_subtitles].last_frame >= Subtitles[Num_subtitles].first_frame);
841 void close_subtitles()
843 if (subtitle_raw_data)
844 free(subtitle_raw_data);
845 subtitle_raw_data = NULL;
849 #define MAX_ACTIVE_SUBTITLES 3
851 //draw the subtitles for this frame
852 void draw_subtitles(int frame_num)
854 static int active_subtitles[MAX_ACTIVE_SUBTITLES];
855 static int num_active_subtitles,next_subtitle,line_spacing;
859 if (frame_num == 0) {
860 num_active_subtitles = 0;
862 gr_set_curfont( GAME_FONT );
863 line_spacing = grd_curcanv->cv_font->ft_h + (grd_curcanv->cv_font->ft_h >> 2);
864 gr_set_fontcolor(255,-1);
867 //get rid of any subtitles that have expired
868 for (t=0;t<num_active_subtitles;)
869 if (frame_num > Subtitles[active_subtitles[t]].last_frame) {
871 for (t2=t;t2<num_active_subtitles-1;t2++)
872 active_subtitles[t2] = active_subtitles[t2+1];
873 num_active_subtitles--;
879 //get any subtitles new for this frame
880 while (next_subtitle < Num_subtitles && frame_num >= Subtitles[next_subtitle].first_frame) {
881 if (num_active_subtitles >= MAX_ACTIVE_SUBTITLES)
882 Error("Too many active subtitles!");
883 active_subtitles[num_active_subtitles++] = next_subtitle;
887 //find y coordinate for first line of subtitles
888 y = grd_curcanv->cv_bitmap.bm_h-((line_spacing+1)*MAX_ACTIVE_SUBTITLES+2);
890 //erase old subtitles if necessary
893 gr_rect(0,y,grd_curcanv->cv_bitmap.bm_w-1,grd_curcanv->cv_bitmap.bm_h-1);
896 //now draw the current subtitles
897 for (t=0;t<num_active_subtitles;t++)
898 if (active_subtitles[t] != -1) {
899 gr_string(0x8000,y,Subtitles[active_subtitles[t]].msg);
905 char name[FILENAME_LEN];
912 char name[100]; //[FILENAME_LEN];
918 #define MAX_MOVIES_PER_LIB 50 //determines size of malloc
920 movielib *init_new_movie_lib(char *filename,FILE *fp)
926 //read movie file header
928 fread(&nfiles,4,1,fp); //get number of files
930 table = malloc(sizeof(*table) + sizeof(ml_entry)*nfiles);
932 strcpy(table->name,filename);
933 table->n_movies = nfiles;
935 offset = 4+4+nfiles*(13+4); //id + nfiles + nfiles * (filename + size)
937 for (i=0;i<nfiles;i++) {
940 n = fread( table->movies[i].name, 13, 1, fp );
942 break; //end of file (probably)
944 n = fread( &len, 4, 1, fp );
946 Error("error reading movie library <%s>",filename);
948 table->movies[i].len = INTEL_INT(len);
949 table->movies[i].offset = offset;
951 offset += table->movies[i].len;
963 movielib *init_old_movie_lib(char *filename,FILE *fp)
967 movielib *table,*table2;
972 table = malloc(sizeof(*table) + sizeof(ml_entry)*MAX_MOVIES_PER_LIB);
977 i = fread( table->movies[nfiles].name, 13, 1, fp );
979 break; //end of file (probably)
981 i = fread( &len, 4, 1, fp );
983 Error("error reading movie library <%s>",filename);
985 table->movies[nfiles].len = INTEL_INT(len);
986 table->movies[nfiles].offset = ftell( fp );
988 fseek( fp, INTEL_INT(len), SEEK_CUR ); //skip data
993 //allocate correct-sized table
994 size = sizeof(*table) + sizeof(ml_entry)*nfiles;
995 table2 = malloc(size);
996 memcpy(table2,table,size);
1000 strcpy(table->name,filename);
1002 table->n_movies = nfiles;
1012 //find the specified movie library, and read in list of movies in it
1013 movielib *init_movie_lib(char *filename)
1015 //note: this based on cfile_init_hogfile()
1020 fp = fopen( filename, "rb" );
1024 fread( id, 4, 1, fp );
1025 if ( !strncmp( id, "DMVL", 4 ) )
1026 return init_new_movie_lib(filename,fp);
1027 else if ( !strncmp( id, "DHF", 3 ) ) {
1028 fseek(fp,-1,SEEK_CUR); //old file had 3 char id
1029 return init_old_movie_lib(filename,fp);
1038 char *movielib_files[] = {"intro-l.mvl","other-l.mvl","robots-l.mvl","oem-l.mvl"};
1040 char *movielib_files[] = {"intro-l.mvl","other-l.mvl","robots-l.mvl"};
1043 #define N_BUILTIN_MOVIE_LIBS (sizeof(movielib_files)/sizeof(*movielib_files))
1044 #define N_MOVIE_LIBS (N_BUILTIN_MOVIE_LIBS+1)
1045 #define EXTRA_ROBOT_LIB N_BUILTIN_MOVIE_LIBS
1046 movielib *movie_libs[N_MOVIE_LIBS];
1051 free(movie_libs[i]);
1058 for (i=0;i<N_MOVIE_LIBS;i++)
1062 #include "gamepal.h"
1064 extern char CDROM_dir[];
1065 extern int MenuHiresAvailable;
1067 extern ubyte last_palette_for_color_fonts[];
1069 extern int force_rb_register;
1071 //ask user to put the D2 CD in.
1072 //returns -1 if ESC pressed, 0 if OK chosen
1073 //CD may not have been inserted
1076 ubyte save_pal[256*3];
1077 grs_canvas *save_canv,*tcanv;
1078 int ret,was_faded=gr_palette_faded_out;
1082 save_canv = grd_curcanv;
1083 tcanv = gr_create_canvas(grd_curcanv->cv_w,grd_curcanv->cv_h);
1085 gr_set_current_canvas(tcanv);
1086 gr_ubitmap(0,0,&save_canv->cv_bitmap);
1087 gr_set_current_canvas(save_canv);
1089 gr_clear_canvas(BM_XRGB(0,0,0));
1091 memcpy(save_pal,gr_palette,sizeof(save_pal));
1093 memcpy(gr_palette,last_palette_for_color_fonts,sizeof(gr_palette));
1097 ret = nm_messagebox( "CD ERROR", 1, "Ok", "Please insert your Descent II CD");
1102 ret2 = nm_messagebox( "CD ERROR", 2, "Try Again", "Leave Game", "You must insert your\nDescent II CD to Continue");
1104 if (ret2 == -1 || ret2 == 0)
1108 force_rb_register = 1; //disc has changed; force register new CD
1112 memcpy(gr_palette,save_pal,sizeof(save_pal));
1114 gr_ubitmap(0,0,&tcanv->cv_bitmap);
1117 gr_palette_load(gr_palette);
1119 gr_free_canvas(tcanv);
1124 //do we have the robot movies available
1125 int robot_movies=0; //0 means none, 1 means lowres, 2 means hires
1127 init_movie(char *filename,int libnum,int is_robots,int required)
1132 if (FindArg("-nomovies")) {
1133 movie_libs[libnum] = NULL;
1138 //for robots, load highres versions if highres menus set
1140 high_res = MenuHiresAvailable;
1142 high_res = MovieHires;
1145 strchr(filename,'.')[-1] = 'h';
1149 if ((movie_libs[libnum] = init_movie_lib(filename)) == NULL) {
1152 strcpy(name2,CDROM_dir);
1153 strcat(name2,filename);
1154 movie_libs[libnum] = init_movie_lib(name2);
1156 if (movie_libs[libnum] != NULL)
1157 movie_libs[libnum]->flags |= MLF_ON_CD;
1160 #if defined(RELEASE) && !defined(D2_OEM) //allow no movies if not release
1162 Error("Cannot open movie file <%s>",filename);
1165 #if defined(D2_OEM) //if couldn't get higres, try low
1166 if (is_robots == 1) { //first try, try again with lowres
1167 strchr(filename,'.')[-1] = 'l';
1172 else if (is_robots == 2) { //failed twice. bail with error
1174 Error("Cannot open movie file <%s>",filename);
1180 if (is_robots && movie_libs[libnum]!=NULL)
1181 robot_movies = high_res?2:1;
1184 //find and initialize the movie libraries
1190 for (i=0;i<N_BUILTIN_MOVIE_LIBS;i++) {
1192 if (!strnicmp(movielib_files[i],"robot",5))
1197 init_movie(movielib_files[i],i,is_robots,1);
1200 movie_libs[EXTRA_ROBOT_LIB] = NULL;
1202 atexit(close_movies);
1206 init_extra_robot_movie(char *filename)
1208 close_movie(EXTRA_ROBOT_LIB);
1209 init_movie(filename,EXTRA_ROBOT_LIB,1,0);
1213 int movie_handle,movie_start;
1215 //looks through a movie library for a movie file
1216 //returns filehandle, with fileposition at movie, or -1 if can't find
1217 search_movie_lib(movielib *lib,char *filename,int must_have)
1225 for (i=0;i<lib->n_movies;i++)
1226 if (!stricmp(filename,lib->movies[i].name)) { //found the movie in a library
1229 from_cd = (lib->flags & MLF_ON_CD);
1232 songs_stop_redbook(); //ready to read from CD
1234 do { //keep trying until we get the file handle
1236 movie_handle = filehandle = open(lib->name, O_RDONLY + O_BINARY);
1238 if (must_have && from_cd && filehandle == -1) { //didn't get file!
1240 if (request_cd() == -1) //ESC from requester
1241 break; //bail from here. will get error later
1244 } while (must_have && from_cd && filehandle == -1);
1246 if (filehandle != -1)
1247 lseek(filehandle,(movie_start=lib->movies[i].offset),SEEK_SET);
1255 //returns file handle
1256 int open_movie_file(char *filename,int must_have)
1260 for (i=0;i<N_MOVIE_LIBS;i++) {
1262 if ((filehandle = search_movie_lib(movie_libs[i],filename,must_have)) != -1)
1266 return -1; //couldn't find it
1269 //sets the file position to the start of this already-open file
1270 int reset_movie_file(int handle)
1272 Assert(handle == movie_handle);
1274 lseek(handle,movie_start,SEEK_SET);
1276 return 0; //everything is cool