1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef TITANIC_MOVIE_H
24 #define TITANIC_MOVIE_H
25 
26 #include "common/list.h"
27 #include "video/video_decoder.h"
28 #include "titanic/core/list.h"
29 #include "titanic/core/resource_key.h"
30 #include "titanic/support/avi_surface.h"
31 #include "titanic/support/movie_range_info.h"
32 
33 namespace Titanic {
34 
35 class CGameObject;
36 class CMovie;
37 class CSoundManager;
38 class CVideoSurface;
39 
40 class CMovieList : public List<CMovie> {
41 public:
42 };
43 
44 class CMovie : public ListItem {
45 protected:
46 	/**
47 	 * Adds the movie to the list of currently playing movies
48 	 */
49 	void addToPlayingMovies();
50 public:
51 	bool _handled;
52 	bool _hasVideoFrame;
53 public:
54 	static CMovieList *_playingMovies;
55 	static CVideoSurface *_movieSurface;
56 
57 	/**
58 	 * Initializes statics
59 	 */
60 	static void init();
61 
62 	/**
63 	 * Deinitializes statics
64 	 */
65 	static void deinit();
66 public:
67 	CMovie();
68 	~CMovie() override;
69 
70 	/**
71 	 * Starts playing the movie
72 	 */
73 	virtual void play(uint flags, CGameObject *obj) = 0;
74 
75 	/**
76 	 * Starts playing the movie
77 	 */
78 	virtual void play(uint startFrame, uint endFrame, uint flags, CGameObject *obj) = 0;
79 
80 	/**
81 	 * Starts playing the movie
82 	 */
83 	virtual void play(uint startFrame, uint endFrame, uint initialFrame, uint flags, CGameObject *obj) = 0;
84 
85 	/**
86 	 * Plays a sub-section of a movie, and doesn't return until either
87 	 * the playback ends or a key has been pressed
88 	 * @returns		True if the cutscene was not interrupted
89 	 */
90 	virtual bool playCutscene(const Rect &drawRect, uint startFrame, uint endFrame) = 0;
91 
92 	/**
93 	 * Pauses a movie
94 	 * @remarks	Acts a workaround for our video decoder, since some movies started
95 	 * as part of a scene load need to be paused until the scene is interactive,
96 	 * or else they get played back too quickly
97 	 */
98 	virtual void pause() = 0;
99 
100 	/**
101 	 * Stops the movie
102 	 */
103 	virtual void stop() = 0;
104 
105 	/**
106 	 * Add a playback event
107 	 */
108 	virtual void addEvent(int frameNumber, CGameObject *obj) = 0;
109 
110 	/**
111 	 * Set the current frame number
112 	 */
113 	virtual void setFrame(uint frameNumber) = 0;
114 
115 	/**
116 	 * Handle any pending movie events
117 	 */
118 	virtual bool handleEvents(CMovieEventList &events) = 0;
119 
120 	/**
121 	 * Return any movie range info associated with the movie
122 	 */
123 	virtual const CMovieRangeInfoList *getMovieRangeInfo() const = 0;
124 
125 	/**
126 	 * Set the sound manager reference
127 	 */
128 	virtual void setSoundManager(CSoundManager *soundManager) = 0;
129 
130 	/**
131 	 * Get the current movie frame
132 	 */
133 	virtual int getFrame() const = 0;
134 
135 	/**
136 	 * Set the frame rate for the movie
137 	 */
138 	virtual void setFrameRate(double rate) = 0;
139 
140 	/**
141 	 * Sets whether the video is playing (versus paused)
142 	 */
143 	virtual void setPlaying(bool playingFlag) = 0;
144 
145 	/**
146 	 * Creates a duplicate of the transparency surface
147 	 */
148 	virtual Graphics::ManagedSurface *duplicateTransparency() const = 0;
149 
150 	/**
151 	 * Removes the movie from the list of currently playing movies
152 	 */
153 	void removeFromPlayingMovies();
154 
155 	/**
156 	 * Returns true if the movie is currently active
157 	 */
158 	bool isActive() const;
159 
160 	/**
161 	 * Returns true if there's a video frame
162 	 */
163 	bool hasVideoFrame();
164 };
165 
166 class OSMovie : public CMovie {
167 private:
168 	AVISurface _aviSurface;
169 	CVideoSurface *_videoSurface;
170 	int _field18;
171 	int _field24;
172 	int _field28;
173 	int _field2C;
174 private:
175 	/**
176 	 * Called when a movie is started playing
177 	 */
178 	void movieStarted();
179 public:
180 	OSMovie(const CResourceKey &name, CVideoSurface *surface);
181 	~OSMovie() override;
182 
183 	/**
184 	 * Starts playing the movie
185 	 */
186 	void play(uint flags, CGameObject *obj) override;
187 
188 	/**
189 	 * Starts playing the movie
190 	 */
191 	void play(uint startFrame, uint endFrame, uint flags, CGameObject *obj) override;
192 
193 	/**
194 	 * Starts playing the movie
195 	 */
196 	void play(uint startFrame, uint endFrame, uint initialFrame, uint flags, CGameObject *obj) override;
197 
198 	/**
199 	 * Plays a sub-section of a movie, and doesn't return until either
200 	 * the playback ends or a key has been pressed
201 	 * @returns		True if the cutscene was not interrupted
202 	 */
203 	bool playCutscene(const Rect &drawRect, uint startFrame, uint endFrame) override;
204 
205 	/**
206 	 * Pauses a movie
207 	 * @remarks		Acts a workaround for our video decoder, since some movies started
208 	 * as part of a scene load need to be paused until the scene is interactive,
209 	 * or else they get played back too quickly
210 	 */
211 	void pause() override;
212 
213 	/**
214 	 * Stops the movie
215 	 */
216 	void stop() override;
217 
218 	/**
219 	 * Add a playback event
220 	 */
221 	void addEvent(int eventId, CGameObject *obj) override;
222 
223 	/**
224 	 * Set the current frame number
225 	 */
226 	void setFrame(uint frameNumber) override;
227 
228 	/**
229 	 * Handle any pending movie events
230 	 */
231 	bool handleEvents(CMovieEventList &events) override;
232 
233 	/**
234 	 * Get the current frame number
235 	 */
236 	int getFrame() const override;
237 
238 	/**
239 	 * Return any movie range info associated with the movie
240 	 */
241 	const CMovieRangeInfoList *getMovieRangeInfo() const override;
242 
243 	/**
244 	 * Set the sound manager reference
245 	 */
246 	void setSoundManager(CSoundManager *soundManager) override;
247 
248 	/**
249 	 * Set the frame rate for the movie
250 	 */
251 	void setFrameRate(double rate) override;
252 
253 	/**
254 	 * Sets whether the video is playing (versus paused)
255 	 */
256 	void setPlaying(bool playingFlag) override;
257 
258 	/**
259 	 * Creates a duplicate of the transparency surface
260 	 */
261 	Graphics::ManagedSurface *duplicateTransparency() const override;
262 };
263 
264 } // End of namespace Titanic
265 
266 #endif /* TITANIC_MOVIE_H */
267