FS2_Open
Open source remastering of the Freespace 2 engine
movie.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifdef _WIN32
13 #include <windows.h>
14 #endif
15 
16 #include "cfile/cfile.h"
17 #include "cmdline/cmdline.h"
18 #include "cutscene/cutscenes.h" // cutscene_mark_viewable()
19 #include "cutscene/movie.h"
20 #include "cutscene/mvelib.h"
21 #include "cutscene/oggplayer.h"
22 #include "globalincs/systemvars.h"
23 #include "graphics/2d.h"
24 #include "osapi/osapi.h"
25 
26 extern int Game_mode;
27 
28 const char *movie_ext_list[] = { ".ogg", ".mve" };
29 const int NUM_MOVIE_EXT = sizeof(movie_ext_list) / sizeof(char*);
30 
31 
32 #define MOVIE_NONE -1
33 #define MOVIE_OGG 0
34 #define MOVIE_MVE 1
35 
36 // This module links freespace movie calls to the actual API calls the play the movie.
37 // This module handles all the different requires of OS and gfx API and finding the file to play
38 
39 
40 // filename - file to search for
41 // out_name - output, full path to file
42 // returns non-zero if file is found
43 int movie_find(char *filename, char *out_name)
44 {
45  char full_path[MAX_PATH];
46  char tmp_name[MAX_PATH];
47  int size, offset = 0;
48 
49  if (out_name == NULL)
50  return MOVIE_NONE;
51 
52 
53  memset( full_path, 0, sizeof(full_path) );
54  memset( tmp_name, 0, sizeof(tmp_name) );
55 
56  // remove extension
57  strcpy_s( tmp_name, filename );
58  char *p = strrchr(tmp_name, '.');
59  if ( p ) *p = 0;
60 
61  int rc = cf_find_file_location_ext(tmp_name, NUM_MOVIE_EXT, movie_ext_list, CF_TYPE_ANY, sizeof(full_path) - 1, full_path, &size, &offset, 0);
62 
63  if (rc == MOVIE_NONE)
64  return MOVIE_NONE;
65 
66  strcpy( out_name, full_path );
67 
68  return rc;
69 }
70 
71 // Play one movie
72 bool movie_play(char *name)
73 {
74  // mark the movie as viewable to the player when in a campaign
75  // do this before anything else so that we're sure the movie is available
76  // to the player even if it's not going to play right now
79  }
80 
81  extern int Mouse_hidden;
82  extern int Is_standalone;
83 
84  if (Cmdline_nomovies || Is_standalone)
85  return false;
86 
87 
88  char full_name[MAX_PATH];
89  int rc = 0;
90 
91  memset(full_name, 0, sizeof(full_name));
92 
93  rc = movie_find(name, full_name);
94 
95  if (rc == MOVIE_NONE) {
96  strcpy_s(full_name, name);
97  char *p = strrchr(full_name, '.');
98  if ( p ) *p = 0;
99 
100  mprintf(("Movie Error: Unable to open '%s' movie in any supported format.\n", full_name));
101  return false;
102  }
103 
104  // clear the screen and hide the mouse cursor
105  Mouse_hidden++;
106  gr_reset_clip();
107  gr_set_color(255, 255, 255);
108  gr_set_clear_color(0, 0, 0);
109  gr_zbuffer_clear(0);
110  // clear first buffer
111  gr_clear();
112  gr_flip();
113  // clear second buffer (may not be one, but that's ok)
114  gr_clear();
115  gr_flip();
116  // clear third buffer (may not be one, but that's ok)
117  gr_clear();
118 
119  if (rc == MOVIE_OGG) {
120  THEORAFILE *movie_ogg = theora_open(name);
121 
122  if (movie_ogg) {
123  // start playing ...
124  theora_play(movie_ogg);
125 
126  // ... done playing, close the movie
127  theora_close(movie_ogg);
128  } else {
129  // uh-oh, movie is invalid... Abory, Retry, Fail?
130  mprintf(("MOVIE ERROR: Found invalid movie! (%s)\n", name));
131  Mouse_hidden--; // show the mouse cursor!
132  return false;
133  }
134  } else if (rc == MOVIE_MVE) {
135  MVESTREAM *movie_mve = mve_open(name);
136 
137  if (movie_mve) {
138  // start playing ...
139  mve_init(movie_mve);
140  mve_play(movie_mve);
141 
142  // ... done playing, close the movie
143  mve_shutdown();
144  mve_close(movie_mve);
145  } else {
146  // uh-oh, movie is invalid... Abory, Retry, Fail?
147  mprintf(("MOVIE ERROR: Found invalid movie! (%s)\n", name));
148  Mouse_hidden--; // show the mouse cursor!
149  return false;
150  }
151  }
152 
153  // show the mouse cursor again
154  Mouse_hidden--;
155 
156  return true;
157 }
158 
159 void movie_play_two(char *name1, char *name2)
160 {
161  if ( movie_play(name1) )
162  movie_play(name2);
163 }
const char * movie_ext_list[]
Definition: movie.cpp:28
#define gr_clear
Definition: 2d.h:749
int Game_mode
Definition: systemvars.cpp:24
void gr_flip()
Definition: 2d.cpp:2113
#define MAX_PATH
void theora_close(THEORAFILE *movie)
Definition: oggplayer.cpp:697
#define gr_set_clear_color
Definition: 2d.h:850
#define mprintf(args)
Definition: pstypes.h:238
int Mouse_hidden
Definition: mouse.cpp:52
int cf_find_file_location_ext(const char *filename, const int ext_num, const char **ext_list, int pathtype, int max_out=0, char *pack_filename=NULL, int *size=NULL, int *offset=NULL, bool localize=false)
GLsizeiptr size
Definition: Glext.h:5496
void mve_play(MVESTREAM *mve)
Definition: mveplayer.cpp:760
void gr_set_color(int r, int g, int b)
Definition: 2d.cpp:1188
#define gr_reset_clip
Definition: 2d.h:745
GLintptr offset
Definition: Glext.h:5497
#define MOVIE_NONE
Definition: movie.cpp:32
char * filename
void mve_close(MVESTREAM *stream)
Definition: mvelib.cpp:287
void movie_play_two(char *name1, char *name2)
Definition: movie.cpp:159
int Cmdline_nomovies
Definition: cmdline.cpp:439
THEORAFILE * theora_open(char *filename)
Definition: oggplayer.cpp:738
const int NUM_MOVIE_EXT
Definition: movie.cpp:29
GLuint const GLchar * name
Definition: Glext.h:5608
void theora_play(THEORAFILE *movie)
Definition: oggplayer.cpp:924
#define MOVIE_MVE
Definition: movie.cpp:34
MVESTREAM * mve_open(char *filename)
Definition: mvelib.cpp:265
GLfloat GLfloat p
Definition: Glext.h:8373
bool movie_play(char *name)
Definition: movie.cpp:72
void mve_init(MVESTREAM *mve)
Definition: mveplayer.cpp:744
#define MOVIE_OGG
Definition: movie.cpp:33
void cutscene_mark_viewable(char *filename)
Definition: cutscenes.cpp:126
#define CF_TYPE_ANY
Definition: cfile.h:42
#define GM_CAMPAIGN_MODE
Definition: systemvars.h:29
int movie_find(char *filename, char *out_name)
Definition: movie.cpp:43
void mve_shutdown()
Definition: mveplayer.cpp:781
#define gr_zbuffer_clear
Definition: 2d.h:818
#define strcpy_s(...)
Definition: safe_strings.h:67
int Is_standalone
Definition: systemvars.cpp:59