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
|
/* 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 "lure/animseq.h"
#include "lure/palette.h"
#include "lure/decode.h"
#include "lure/events.h"
namespace Lure {
// delay
// Delays for a given number of milliseconds. If it returns true, it indicates that
// Escape has been pressed, and the introduction should be aborted.
AnimAbortType AnimationSequence::delay(uint32 milliseconds) {
uint32 delayCtr = _system.getMillis() + milliseconds;
Events &events = Events::getReference();
while (_system.getMillis() < delayCtr) {
while (events.pollEvent()) {
if (events.type() == OSystem::EVENT_KEYDOWN) {
if (events.event().kbd.keycode == 27) return ABORT_END_INTRO;
else return ABORT_NEXT_SCENE;
} else if (events.type() == OSystem::EVENT_LBUTTONDOWN)
return ABORT_NEXT_SCENE;
else if (events.type() == OSystem::EVENT_QUIT)
return ABORT_END_INTRO;
}
uint32 delayAmount = delayCtr - _system.getMillis();
if (delayAmount > 10) delayAmount = 10;
_system.delayMillis(delayAmount);
}
return ABORT_NONE;
}
// decodeFrame
// Decodes a single frame of the animation sequence
void AnimationSequence::decodeFrame(byte *&pPixels, byte *&pLines) {
byte *screen = _screen.screen_raw();
uint16 screenPos = 0;
uint16 len;
while (screenPos < SCREEN_SIZE) {
// Get line length
len = (uint16) *pLines++;
if (len == 0) {
len = READ_LE_UINT16(pLines);
pLines += 2;
}
// Move the splice over
memcpy(screen, pPixels, len);
screen += len;
screenPos += len;
pPixels += len;
// Get the offset inc amount
len = (uint16) *pLines++;
if (len == 0) {
len = READ_LE_UINT16(pLines);
pLines += 2;
}
screen += len;
screenPos += len;
}
// Make the decoded frame visible
_screen.update();
}
AnimationSequence::AnimationSequence(Screen &screen, OSystem &system, uint16 screenId, Palette &palette,
bool fadeIn): _screen(screen), _system(system), _screenId(screenId), _palette(palette) {
PictureDecoder decoder;
Disk &d = Disk::getReference();
MemoryBlock *data = d.getEntry(_screenId);
_decodedData = decoder.decode(data, MAX_ANIM_DECODER_BUFFER_SIZE);
delete data;
_lineRefs = d.getEntry(_screenId + 1);
// Show the screen that preceeds the start of the animation data
_screen.setPaletteEmpty();
_screen.screen().data().copyFrom(_decodedData, 0, 0, FULL_SCREEN_HEIGHT * FULL_SCREEN_WIDTH);
_screen.update();
// Set the palette
if (fadeIn) _screen.paletteFadeIn(&_palette);
else _screen.setPalette(&_palette);
// Set up frame poitners
_pPixels = _decodedData->data() + SCREEN_SIZE;
_pLines = _lineRefs->data();
_pPixelsEnd = _decodedData->data() + _decodedData->size() - 1;
_pLinesEnd = _lineRefs->data() + _lineRefs->size() - 1;
}
AnimationSequence::~AnimationSequence() {
delete _lineRefs;
delete _decodedData;
}
// show
// Main method for displaying the animation
AnimAbortType AnimationSequence::show() {
AnimAbortType result;
// Loop through displaying the animations
while ((_pPixels < _pPixelsEnd) && (_pLines < _pLinesEnd)) {
decodeFrame(_pPixels, _pLines);
result = delay(130);
if (result != ABORT_NONE) return result;
}
return ABORT_NONE;
}
bool AnimationSequence::step() {
if ((_pPixels >= _pPixelsEnd) || (_pLines >= _pLinesEnd)) return false;
decodeFrame(_pPixels, _pLines);
_screen.setPalette(&_palette);
return true;
}
} // end of namespace Lure
|