1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "titanic/support/movie.h"
#include "titanic/support/avi_surface.h"
#include "titanic/sound/sound_manager.h"
#include "titanic/messages/messages.h"
#include "titanic/titanic.h"
namespace Titanic {
#define CLIP_WIDTH 600
#define CLIP_WIDTH_REDUCED (CLIP_WIDTH / 2)
#define CLIP_HEIGHT 340
#define CLIP_HEIGHT_REDUCED (CLIP_HEIGHT / 2)
CMovieList *CMovie::_playingMovies;
CVideoSurface *CMovie::_movieSurface;
CMovie::CMovie() : ListItem(), _handled(false), _hasVideoFrame(false),
_hasAudioTiming(false) {
}
CMovie::~CMovie() {
removeFromPlayingMovies();
}
void CMovie::init() {
_playingMovies = new CMovieList();
_movieSurface = nullptr;
}
void CMovie::deinit() {
// At this point, there shouldn't be any playing movies left,
// since their owning objects should have freed them
assert(_playingMovies->empty());
delete _playingMovies;
delete _movieSurface;
}
void CMovie::addToPlayingMovies() {
if (!isActive())
_playingMovies->push_back(this);
}
void CMovie::removeFromPlayingMovies() {
_playingMovies->remove(this);
}
bool CMovie::isActive() const {
return _playingMovies->contains(this);
}
bool CMovie::hasVideoFrame() {
if (_hasVideoFrame) {
_hasVideoFrame = 0;
return true;
} else {
return false;
}
}
/*------------------------------------------------------------------------*/
OSMovie::OSMovie(const CResourceKey &name, CVideoSurface *surface) :
_aviSurface(name), _videoSurface(surface) {
_field18 = 0;
_field24 = 0;
_field28 = 0;
_field2C = 0;
surface->resize(_aviSurface.getWidth(), _aviSurface.getHeight());
_aviSurface.setVideoSurface(surface);
}
OSMovie::~OSMovie() {
}
void OSMovie::play(uint flags, CGameObject *obj) {
_aviSurface.play(flags, obj);
if (_aviSurface.isPlaying())
movieStarted();
}
void OSMovie::play(uint startFrame, uint endFrame, uint flags, CGameObject *obj) {
_aviSurface.play(startFrame, endFrame, flags, obj);
if (_aviSurface.isPlaying())
movieStarted();
}
void OSMovie::play(uint startFrame, uint endFrame, uint initialFrame, uint flags, CGameObject *obj) {
_aviSurface.play(startFrame, endFrame, initialFrame, flags, obj);
if (_aviSurface.isPlaying())
movieStarted();
}
bool OSMovie::playCutscene(const Rect &drawRect, uint startFrame, uint endFrame) {
if (!_movieSurface)
_movieSurface = CScreenManager::_screenManagerPtr->createSurface(600, 340, 32);
// Set a new event target whilst the clip plays, so standard scene drawing isn't called
CEventTarget eventTarget;
g_vm->_events->addTarget(&eventTarget);
bool result = _aviSurface.playCutscene(drawRect, startFrame, endFrame);
g_vm->_events->removeTarget();
return result;
}
void OSMovie::pause() {
_aviSurface.pause();
}
void OSMovie::stop() {
_aviSurface.stop();
removeFromPlayingMovies();
}
void OSMovie::addEvent(int frameNumber, CGameObject *obj) {
if (_aviSurface.addEvent(&frameNumber, obj)) {
CMovieFrameMsg frameMsg(frameNumber, 0);
frameMsg.execute(obj);
}
}
void OSMovie::setFrame(uint frameNumber) {
_aviSurface.setFrame(frameNumber);
_videoSurface->setTransparencySurface(_aviSurface.getSecondarySurface());
}
bool OSMovie::handleEvents(CMovieEventList &events) {
// WORKAROUND: If a movie is paused as part of initial
// scene loading, now's the time to un-pause it
_aviSurface.resume();
if (!_aviSurface.isPlaying())
return false;
// Handle updating the frame
while (_aviSurface.isPlaying() && _aviSurface.isNextFrame()) {
_aviSurface.handleEvents(events);
_videoSurface->setTransparencySurface(_aviSurface.getSecondarySurface());
// Flag there's a video frame
_hasVideoFrame = true;
}
return _aviSurface.isPlaying();
}
const CMovieRangeInfoList *OSMovie::getMovieRangeInfo() const {
return _aviSurface.getMovieRangeInfo();
}
void OSMovie::setSoundManager(CSoundManager *soundManager) {
_aviSurface._soundManager = soundManager;
}
int OSMovie::getFrame() const {
return _aviSurface.getFrame();
}
void OSMovie::movieStarted() {
//if (_aviSurface._hasAudio)
// _aviSurface._soundManager->movieStarted();
// Register the movie in the playing list
addToPlayingMovies();
_hasVideoFrame = true;
}
void OSMovie::setFrameRate(double rate) {
_aviSurface.setFrameRate(rate);
}
Graphics::ManagedSurface *OSMovie::duplicateTransparency() const {
return _aviSurface.duplicateTransparency();
}
} // End of namespace Titanic
|