aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Montoir2008-11-28 23:51:59 +0000
committerGregory Montoir2008-11-28 23:51:59 +0000
commit443c57146d74d7a92d1c9ec48c0f7eb8a497749b (patch)
tree5a6375854df2938a02bc5147abb66abd106f0c25
parentb25257d4eb377b2c2e63af0783c2b6d5c1b364ab (diff)
downloadscummvm-rg350-443c57146d74d7a92d1c9ec48c0f7eb8a497749b.tar.gz
scummvm-rg350-443c57146d74d7a92d1c9ec48c0f7eb8a497749b.tar.bz2
scummvm-rg350-443c57146d74d7a92d1c9ec48c0f7eb8a497749b.zip
added load/closeFile to Graphics::FlicPlayer (matching DXAPlayer class)
svn-id: r35170
-rw-r--r--engines/tucker/sequences.cpp65
-rw-r--r--engines/tucker/tucker.h2
-rw-r--r--graphics/flic_player.cpp23
-rw-r--r--graphics/flic_player.h5
4 files changed, 55 insertions, 40 deletions
diff --git a/engines/tucker/sequences.cpp b/engines/tucker/sequences.cpp
index f0c15b48d5..57e037cf97 100644
--- a/engines/tucker/sequences.cpp
+++ b/engines/tucker/sequences.cpp
@@ -482,7 +482,6 @@ AnimationSequencePlayer::AnimationSequencePlayer(OSystem *system, Audio::Mixer *
_newSeq = false;
memset(_animationPalette, 0, sizeof(_animationPalette));
memset(_paletteBuffer, 0, sizeof(_paletteBuffer));
- memset(_flicPlayer, 0, sizeof(_flicPlayer));
_soundsListSeqData = 0;
_soundsList1 = 0;
_soundsList1Count = 0;
@@ -836,10 +835,6 @@ void AnimationSequencePlayer::fadeOutPalette() {
void AnimationSequencePlayer::unloadAnimation() {
_mixer->stopAll();
- for (int i = 0; i < ARRAYSIZE(_flicPlayer); ++i) {
- delete _flicPlayer[i];
- _flicPlayer[i] = 0;
- }
free(_picBufPtr);
_picBufPtr = 0;
free(_pic2BufPtr);
@@ -860,20 +855,24 @@ uint8 *AnimationSequencePlayer::loadPicture(const char *fileName) {
}
void AnimationSequencePlayer::openAnimation(int index, const char *fileName) {
- _flicPlayer[index] = new ::Graphics::FlicPlayer(fileName);
- _flicPlayer[index]->decodeFrame();
+ if (!_flicPlayer[index].loadFile(fileName)) {
+ warning("Unable to open flc animation file '%s'", fileName);
+ _seqNum = 1;
+ return;
+ }
+ _flicPlayer[index].decodeFrame();
if (index == 0) {
- memcpy(_animationPalette, _flicPlayer[index]->getPalette(), 1024);
- memcpy(_offscreenBuffer, _flicPlayer[index]->getOffscreen(), kScreenWidth * kScreenHeight);
+ memcpy(_animationPalette, _flicPlayer[index].getPalette(), 1024);
+ memcpy(_offscreenBuffer, _flicPlayer[index].getOffscreen(), kScreenWidth * kScreenHeight);
}
}
void AnimationSequencePlayer::decodeNextAnimationFrame(int index) {
- _flicPlayer[index]->decodeFrame();
- memcpy(_offscreenBuffer, _flicPlayer[index]->getOffscreen(), kScreenWidth * kScreenHeight);
+ _flicPlayer[index].decodeFrame();
+ memcpy(_offscreenBuffer, _flicPlayer[index].getOffscreen(), kScreenWidth * kScreenHeight);
if (index == 0) {
- if (_flicPlayer[index]->isPaletteDirty()) {
- memcpy(_animationPalette, _flicPlayer[index]->getPalette(), 1024);
+ if (_flicPlayer[index].isPaletteDirty()) {
+ memcpy(_animationPalette, _flicPlayer[index].getPalette(), 1024);
}
}
if (_seqNum != 19) {
@@ -889,7 +888,7 @@ void AnimationSequencePlayer::introSeq17_18() {
_newSeq = false;
}
decodeNextAnimationFrame(0);
- if (_flicPlayer[0]->getCurFrame() == _flicPlayer[0]->getFrameCount()) {
+ if (_flicPlayer[0].isLastFrame()) {
_seqNum = 19;
}
updateSounds();
@@ -904,20 +903,20 @@ void AnimationSequencePlayer::introSeq19_20() {
_frameTime = 1;
_newSeq = false;
}
- if (_flicPlayer[0]->getCurFrame() >= 116) {
- _flicPlayer[1]->decodeFrame();
- if (_flicPlayer[1]->getCurFrame() == _flicPlayer[1]->getFrameCount()) {
- _flicPlayer[1]->reset();
+ if (_flicPlayer[0].getCurFrame() >= 116) {
+ _flicPlayer[1].decodeFrame();
+ if (_flicPlayer[1].isLastFrame()) {
+ _flicPlayer[1].reset();
}
}
- _flicPlayer[0]->decodeFrame();
- const uint8 *t = _flicPlayer[1]->getOffscreen();
+ _flicPlayer[0].decodeFrame();
+ const uint8 *t = _flicPlayer[1].getOffscreen();
for (int i = 0; i < 64000; ++i) {
- const uint8 color = _flicPlayer[0]->getOffscreen()[i];
+ const uint8 color = _flicPlayer[0].getOffscreen()[i];
_offscreenBuffer[i] = color ? color : t[i];
}
updateSounds();
- if (_flicPlayer[0]->getCurFrame() == _flicPlayer[0]->getFrameCount()) {
+ if (_flicPlayer[0].isLastFrame()) {
_seqNum = 3;
}
}
@@ -974,10 +973,10 @@ void AnimationSequencePlayer::introSeq3_4() {
}
if (!_updateScreenPicture) {
decodeNextAnimationFrame(0);
- if (_flicPlayer[0]->getCurFrame() == 706) {
+ if (_flicPlayer[0].getCurFrame() == 706) {
initPicPart4();
}
- if (_flicPlayer[0]->getCurFrame() == _flicPlayer[0]->getFrameCount()) {
+ if (_flicPlayer[0].isLastFrame()) {
_seqNum = 9;
}
} else {
@@ -1018,7 +1017,7 @@ void AnimationSequencePlayer::drawPic1Part10() {
memcpy(_offscreenBuffer + y * 320, _picBufPtr + 800 + y * 640 + _updateScreenWidth, 320);
}
for (int i = 0; i < 64000; ++i) {
- const uint8 color = _flicPlayer[0]->getOffscreen()[i];
+ const uint8 color = _flicPlayer[0].getOffscreen()[i];
if (color) {
_offscreenBuffer[i] = color;
}
@@ -1036,20 +1035,20 @@ void AnimationSequencePlayer::introSeq9_10() {
_newSeq = false;
}
decodeNextAnimationFrame(0);
- if (_flicPlayer[0]->getCurFrame() == 984) {
+ if (_flicPlayer[0].getCurFrame() == 984) {
drawPic2Part10();
}
- if (_flicPlayer[0]->getCurFrame() >= 264 && _flicPlayer[0]->getCurFrame() <= 295) {
+ if (_flicPlayer[0].getCurFrame() >= 264 && _flicPlayer[0].getCurFrame() <= 295) {
drawPic1Part10();
_updateScreenWidth += 6;
- } else if (_flicPlayer[0]->getCurFrame() >= 988 && _flicPlayer[0]->getCurFrame() <= 996) {
+ } else if (_flicPlayer[0].getCurFrame() >= 988 && _flicPlayer[0].getCurFrame() <= 996) {
drawPic1Part10();
_updateScreenWidth -= 25;
if (_updateScreenWidth < 0) {
_updateScreenWidth = 0;
}
}
- if (_flicPlayer[0]->getCurFrame() == _flicPlayer[0]->getFrameCount()) {
+ if (_flicPlayer[0].isLastFrame()) {
_seqNum = 21;
}
updateSounds();
@@ -1063,7 +1062,7 @@ void AnimationSequencePlayer::introSeq21_22() {
_newSeq = false;
}
decodeNextAnimationFrame(0);
- if (_flicPlayer[0]->getCurFrame() == _flicPlayer[0]->getFrameCount()) {
+ if (_flicPlayer[0].isLastFrame()) {
_seqNum = 1;
}
updateSounds();
@@ -1077,7 +1076,7 @@ void AnimationSequencePlayer::introSeq13_14() {
_newSeq = false;
}
decodeNextAnimationFrame(0);
- if (_flicPlayer[0]->getCurFrame() == _flicPlayer[0]->getFrameCount()) {
+ if (_flicPlayer[0].isLastFrame()) {
_seqNum = 15;
}
updateSounds();
@@ -1091,7 +1090,7 @@ void AnimationSequencePlayer::introSeq15_16() {
_newSeq = false;
}
decodeNextAnimationFrame(0);
- if (_flicPlayer[0]->getCurFrame() == _flicPlayer[0]->getFrameCount()) {
+ if (_flicPlayer[0].isLastFrame()) {
_seqNum = 27;
}
updateSounds();
@@ -1105,7 +1104,7 @@ void AnimationSequencePlayer::introSeq27_28() {
_newSeq = false;
}
decodeNextAnimationFrame(0);
- if (_flicPlayer[0]->getCurFrame() == _flicPlayer[0]->getFrameCount()) {
+ if (_flicPlayer[0].isLastFrame()) {
_seqNum = 1;
}
updateSounds();
diff --git a/engines/tucker/tucker.h b/engines/tucker/tucker.h
index ae175d6207..be51ce5a56 100644
--- a/engines/tucker/tucker.h
+++ b/engines/tucker/tucker.h
@@ -865,7 +865,7 @@ private:
bool _newSeq;
int _seqNum, _currentSeqNum;
- ::Graphics::FlicPlayer *_flicPlayer[2];
+ ::Graphics::FlicPlayer _flicPlayer[2];
uint8 _animationPalette[256 * 4], _paletteBuffer[256 * 4];
const int *_soundsListSeqData;
const char **_soundsList1;
diff --git a/graphics/flic_player.cpp b/graphics/flic_player.cpp
index 19766d7af5..af32209279 100644
--- a/graphics/flic_player.cpp
+++ b/graphics/flic_player.cpp
@@ -27,12 +27,21 @@
namespace Graphics {
-FlicPlayer::FlicPlayer(const char *fileName)
+FlicPlayer::FlicPlayer()
: _paletteDirty(false), _offscreen(0), _currFrame(0) {
-
memset(&_flicInfo, 0, sizeof(_flicInfo));
- _fileStream.open(fileName);
- assert(_fileStream.isOpen());
+}
+
+FlicPlayer::~FlicPlayer() {
+ closeFile();
+}
+
+bool FlicPlayer::loadFile(const char *fileName) {
+ closeFile();
+
+ if (!_fileStream.open(fileName)) {
+ return false;
+ }
_flicInfo.size = _fileStream.readUint32LE();
_flicInfo.type = _fileStream.readUint16LE();
@@ -56,10 +65,14 @@ FlicPlayer::FlicPlayer(const char *fileName)
// Seek to the first frame
_fileStream.seek(_flicInfo.offsetFrame1);
+ return true;
}
-FlicPlayer::~FlicPlayer() {
+void FlicPlayer::closeFile() {
+ memset(&_flicInfo, 0, sizeof(_flicInfo));
+ _fileStream.close();
delete[] _offscreen;
+ _offscreen = 0;
}
void FlicPlayer::redraw() {
diff --git a/graphics/flic_player.h b/graphics/flic_player.h
index 64b29969c8..7d92a652d3 100644
--- a/graphics/flic_player.h
+++ b/graphics/flic_player.h
@@ -60,15 +60,18 @@ struct FrameTypeChunkHeader {
class FlicPlayer {
public:
- FlicPlayer(const char *fileName);
+ FlicPlayer();
~FlicPlayer();
+ bool loadFile(const char *fileName);
+ void closeFile();
void decodeFrame();
int getWidth() const { return _flicInfo.width; }
int getHeight() const { return _flicInfo.height; }
bool hasFrames() const { return _flicInfo.numFrames > 0; }
int getCurFrame() const { return _currFrame; }
int getFrameCount() const { return _flicInfo.numFrames; }
+ bool isLastFrame() const { return _currFrame == _flicInfo.numFrames; }
uint32 getSpeed() const { return _flicInfo.speed; }
bool isPaletteDirty() const { return _paletteDirty; }
const uint8 *getPalette() { _paletteDirty = false; return _palette; }