aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra/sequences_v2.cpp
blob: e94b850e8d14cb054542b019cec2b34a7bc15e7f (plain)
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
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2005-2006 The ScummVM project
 *
 * 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.
 *
 * $URL$
 * $Id$
 *
 */

#include "kyra/kyra.h"
#include "kyra/kyra2.h"
#include "kyra/screen.h"
#include "kyra/wsamovie.h"
#include "kyra/sound.h"

#include "common/system.h"

namespace Kyra {

void KyraEngine_v2::seq_playSequences(int startSeq, int endSeq) {
	if (endSeq == -1)
		endSeq = startSeq;
	
	assert(startSeq >= 0 && endSeq < 4 && startSeq <= endSeq);

	static const Sequence sequences[] = { 
		// type, filename, callback, framedelay, duration, numframes, fadeOut, timeOut
		{2, "virgin.cps",   0,                                 100, 0,   1,  true,  true},
		{1, "westwood.wsa", &KyraEngine_v2::seq_introWestwood, 6,   160, 18, true,  true},
		{1, "title.wsa",    &KyraEngine_v2::seq_introTitle,    6,   10,  26, false,  false},
		{2, "over.cps",     &KyraEngine_v2::seq_introOverview, 16,  30,  1,  false, true}
	};

	_activeWSA = new ActiveWSA[8];
	assert(_activeWSA);	
	memset(_activeWSA, 0, sizeof(ActiveWSA) * 8);

	_screen->hideMouse();

	uint8 pal[768];
	memset(pal, 0, sizeof(pal));
	_screen->setScreenPalette(pal);
	
	for (int i = startSeq; i <= endSeq; i++) {
		uint32 seqDelay = 0;
		int seqNum = 0;

		_screen->clearPage(0);

		if (sequences[i].type == 2) {
			_screen->loadBitmap(sequences[i].filename, 0, 0, _screen->_currentPalette);
			_screen->updateScreen();
			seqDelay = sequences[i].frameDelay * _tickLength;
		} else if(sequences[i].type == 1) {
			seq_loadWSA(0, sequences[i].filename, sequences[i].frameDelay);
			seqDelay = sequences[i].duration * _tickLength;
		}

		if (sequences[i].callback)
			(*this.*sequences[i].callback)(seqNum++);

		seq_playWSAs();
		_screen->updateScreen();
		_screen->fadeFromBlack(40);

		seqDelay += _system->getMillis();
		bool mayEndLoop = sequences[i].timeOut;
		
		while(1) {
			uint32 startTime = _system->getMillis();
			
			if (sequences[i].callback) {
				int newTime = (*this.*sequences[i].callback)(seqNum++);
				if (newTime != -1) {
					seqDelay = newTime * _tickLength + _system->getMillis();
					mayEndLoop = true;
				}
			}
		
			seq_playWSAs();
			_screen->updateScreen();
			
			uint32 currTime = _system->getMillis();
			if (seqDelay <= currTime && mayEndLoop)
				break;
			else {
				uint32 loopTime = currTime - startTime;
				delay(loopTime > _tickLength ? loopTime : _tickLength);
			}
		}

		if (sequences[i].fadeOut)
			_screen->fadeToBlack(40);
		
		if (sequences[i].type == 1)
			seq_unloadWSA(0);
	}
	_screen->showMouse();
	delete[] _activeWSA;
}

int KyraEngine_v2::seq_introOverview(int seqNum) {
	switch (seqNum) {
		case 0:
			_sound->playTrack(4);
			break;
		case 40:
			seq_loadWSA(1, "over1.wsa", 10);
			break;
		case 60:
			seq_loadWSA(2, "over2.wsa", 9);
			break;
		case 282:
			seq_loadWSA(3, "forest.wsa", 6);
			break;
		case 434:
			seq_loadWSA(4, "dragon.wsa", 6);
			break;
		case 540:
			seq_unloadWSA(1);
			seq_unloadWSA(2);
			seq_unloadWSA(3);
			seq_unloadWSA(4);
			return 0;
			break;	
	}

	return -1;
}

int KyraEngine_v2::seq_introTitle(int seqNum) {
	if (seqNum == 1)
		_sound->playTrack(3);
	else if (seqNum == 25) {
		// XXX: handle menu
		return 200;
	}

	return -1;
}

int KyraEngine_v2::seq_introWestwood(int seqNum) {
	if (seqNum == 0)
		_sound->playTrack(2);

	return -1;
}

void KyraEngine_v2::seq_playWSAs() {
	uint32 currTime = _system->getMillis();

	for (int i = 0; i < 8; i++) {
		if (_activeWSA[i].movie && currTime >= _activeWSA[i].nextFrame && _activeWSA[i].currentFrame < _activeWSA[i].endFrame) {
			_activeWSA[i].movie->displayFrame(_activeWSA[i].currentFrame++);
			_activeWSA[i].nextFrame = currTime + _activeWSA[i].frameDelay * _tickLength;
		}
	}
}

void KyraEngine_v2::seq_loadWSA(int wsaNum, const char *filename, int frameDelay) {
	_activeWSA[wsaNum].movie = new WSAMovieV2(this);
	assert(_activeWSA[wsaNum].movie);
	_activeWSA[wsaNum].endFrame = _activeWSA[wsaNum].movie->open(filename, 0, _screen->_currentPalette);
	assert(_activeWSA[wsaNum].movie->opened());
	_activeWSA[wsaNum].currentFrame = 0;
	_activeWSA[wsaNum].frameDelay = frameDelay;
	_activeWSA[wsaNum].nextFrame = _system->getMillis();
	_activeWSA[wsaNum].movie->setX(0);
	_activeWSA[wsaNum].movie->setY(0);	
	_activeWSA[wsaNum].movie->setDrawPage(0);	
}

void KyraEngine_v2::seq_unloadWSA(int wsaNum) {
	assert(_activeWSA[wsaNum].movie);
	_activeWSA[wsaNum].movie->close();
	delete _activeWSA[wsaNum].movie;
}

} // end of namespace Kyra