[Scummvm-cvs-logs] SF.net SVN: scummvm:[44957] scummvm/trunk/engines/draci
spalek at users.sourceforge.net
spalek at users.sourceforge.net
Mon Oct 12 01:01:59 CEST 2009
Revision: 44957
http://scummvm.svn.sourceforge.net/scummvm/?rev=44957&view=rev
Author: spalek
Date: 2009-10-11 23:01:59 +0000 (Sun, 11 Oct 2009)
Log Message:
-----------
Loading and caching sound samples in memory.
The sounds are not played yet, but the infrastructure is getting ready.
Modified Paths:
--------------
scummvm/trunk/engines/draci/animation.cpp
scummvm/trunk/engines/draci/animation.h
scummvm/trunk/engines/draci/barchive.cpp
scummvm/trunk/engines/draci/draci.cpp
scummvm/trunk/engines/draci/game.cpp
scummvm/trunk/engines/draci/script.cpp
scummvm/trunk/engines/draci/sound.cpp
scummvm/trunk/engines/draci/sound.h
Modified: scummvm/trunk/engines/draci/animation.cpp
===================================================================
--- scummvm/trunk/engines/draci/animation.cpp 2009-10-11 22:39:06 UTC (rev 44956)
+++ scummvm/trunk/engines/draci/animation.cpp 2009-10-11 23:01:59 UTC (rev 44957)
@@ -191,8 +191,9 @@
return _displacement.extraScaleY;
}
-void Animation::addFrame(Drawable *frame) {
+void Animation::addFrame(Drawable *frame, const SoundSample *sample) {
_frames.push_back(frame);
+ _samples.push_back(sample);
}
int Animation::getIndex() const {
@@ -246,6 +247,7 @@
delete _frames[i];
_frames.pop_back();
}
+ _samples.clear();
}
void Animation::stopAnimation() {
@@ -382,7 +384,7 @@
anim->setID(kOverlayImage);
anim->setZ(z);
anim->setPlaying(true);
- anim->addFrame(overlay);
+ anim->addFrame(overlay, NULL);
insertAnimation(anim);
}
Modified: scummvm/trunk/engines/draci/animation.h
===================================================================
--- scummvm/trunk/engines/draci/animation.h 2009-10-11 22:39:06 UTC (rev 44956)
+++ scummvm/trunk/engines/draci/animation.h 2009-10-11 23:01:59 UTC (rev 44957)
@@ -27,6 +27,7 @@
#define DRACI_ANIMATION_H
#include "draci/sprite.h"
+#include "draci/sound.h"
namespace Draci {
@@ -76,7 +77,7 @@
void nextFrame(bool force = false);
void drawFrame(Surface *surface);
- void addFrame(Drawable *frame);
+ void addFrame(Drawable *frame, const SoundSample *sample);
Drawable *getFrame(int frameNum = kCurrentFrame);
void setCurrentFrame(uint frame);
uint currentFrameNum() const;
@@ -140,6 +141,11 @@
/** Array of frames of the animation. The animation object owns these pointers.
*/
Common::Array<Drawable *> _frames;
+ /** Array of samples played during the animation. The animation
+ * object doesn't own these pointers, but they are stored in the
+ * cache.
+ */
+ Common::List<const SoundSample *> _samples;
AnimationCallback _callback;
Modified: scummvm/trunk/engines/draci/barchive.cpp
===================================================================
--- scummvm/trunk/engines/draci/barchive.cpp 2009-10-11 22:39:06 UTC (rev 44956)
+++ scummvm/trunk/engines/draci/barchive.cpp 2009-10-11 23:01:59 UTC (rev 44957)
@@ -268,6 +268,7 @@
* @return Pointer to a BAFile coresponding to the opened file or NULL (on failure)
*
* Loads individual BAR files from an archive to memory on demand.
+ * Should not be called directly.
*/
BAFile *BArchive::loadFileBAR(uint i) {
Common::File f;
@@ -305,8 +306,7 @@
* @return Pointer to a BAFile coresponding to the opened file or NULL (on failure)
*
* Loads individual DFW files from an archive to memory on demand.
- * Should not be called directly. Instead, one should access files
- * through the operator[] interface.
+ * Should not be called directly.
*/
BAFile *BArchive::loadFileDFW(uint i) {
Common::File f;
Modified: scummvm/trunk/engines/draci/draci.cpp
===================================================================
--- scummvm/trunk/engines/draci/draci.cpp 2009-10-11 22:39:06 UTC (rev 44956)
+++ scummvm/trunk/engines/draci/draci.cpp 2009-10-11 23:01:59 UTC (rev 44957)
@@ -162,6 +162,16 @@
return Common::kUnknownError;
}
+ if (!_soundsArchive->isOpen()) {
+ debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening sounds archive failed");
+ return Common::kUnknownError;
+ }
+
+ if (!_dubbingArchive->isOpen()) {
+ debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening dubbing archive failed");
+ return Common::kUnknownError;
+ }
+
_showWalkingMap = false;
// Basic archive test
Modified: scummvm/trunk/engines/draci/game.cpp
===================================================================
--- scummvm/trunk/engines/draci/game.cpp 2009-10-11 22:39:06 UTC (rev 44956)
+++ scummvm/trunk/engines/draci/game.cpp 2009-10-11 23:01:59 UTC (rev 44957)
@@ -177,25 +177,25 @@
// Initialize animation for object / room titles
Animation *titleAnim = _vm->_anims->addText(kTitleText, true);
Text *title = new Text("", _vm->_smallFont, kTitleColour, 0, 0);
- titleAnim->addFrame(title);
+ titleAnim->addFrame(title, NULL);
// Initialize animation for speech text
Animation *speechAnim = _vm->_anims->addText(kSpeechText, true);
Text *speech = new Text("", _vm->_bigFont, kFontColour1, 0, 0);
- speechAnim->addFrame(speech);
+ speechAnim->addFrame(speech, NULL);
// Initialize inventory animation
const BAFile *f = _vm->_iconsArchive->getFile(13);
Animation *inventoryAnim = _vm->_anims->addAnimation(kInventorySprite, 255, false);
Sprite *inventorySprite = new Sprite(f->_data, f->_length, 0, 0, true);
- inventoryAnim->addFrame(inventorySprite);
+ inventoryAnim->addFrame(inventorySprite, NULL);
inventoryAnim->setRelative((kScreenWidth - inventorySprite->getWidth()) / 2,
(kScreenHeight - inventorySprite->getHeight()) / 2);
for (uint i = 0; i < kDialogueLines; ++i) {
_dialogueAnims[i] = _vm->_anims->addText(kDialogueLinesID - i, true);
Text *dialogueLine = new Text("", _vm->_smallFont, kLineInactiveColour, 0, 0);
- _dialogueAnims[i]->addFrame(dialogueLine);
+ _dialogueAnims[i]->addFrame(dialogueLine, NULL);
_dialogueAnims[i]->setZ(254);
_dialogueAnims[i]->setRelative(1,
@@ -644,7 +644,7 @@
anim = _vm->_anims->addItem(anim_id);
const BAFile *img = _vm->_itemImagesArchive->getFile(2 * itemID);
Sprite *sp = new Sprite(img->_data, img->_length, 0, 0, true);
- anim->addFrame(sp);
+ anim->addFrame(sp, NULL);
}
Drawable *frame = anim->getFrame();
@@ -1117,7 +1117,7 @@
delete[] wlk;
Animation *map = _vm->_anims->addAnimation(kWalkingMapOverlay, 255, false);
- map->addFrame(ov);
+ map->addFrame(ov, NULL);
}
int Game::loadAnimation(uint animNum, uint z) {
@@ -1145,8 +1145,8 @@
uint scaledWidth = animationReader.readUint16LE();
uint scaledHeight = animationReader.readUint16LE();
byte mirror = animationReader.readByte();
- /* uint sample = */ animationReader.readUint16LE();
- /* uint freq = */ animationReader.readUint16LE();
+ uint sample = animationReader.readUint16LE();
+ uint freq = animationReader.readUint16LE();
uint delay = animationReader.readUint16LE();
const BAFile *spriteFile = _vm->_spritesArchive->getFile(spriteNum);
@@ -1171,7 +1171,9 @@
sp->setDelay(delay * 10);
- anim->addFrame(sp);
+ const SoundSample *sam = _vm->_soundsArchive->getSample(sample, freq);
+
+ anim->addFrame(sp, sam);
}
return animNum;
@@ -1282,6 +1284,8 @@
_vm->_paletteArchive->clearCache();
_vm->_animationsArchive->clearCache();
_vm->_walkingMapsArchive->clearCache();
+ _vm->_soundsArchive->clearCache();
+ _vm->_dubbingArchive->clearCache();
_vm->_screen->clearScreen();
Modified: scummvm/trunk/engines/draci/script.cpp
===================================================================
--- scummvm/trunk/engines/draci/script.cpp 2009-10-11 22:39:06 UTC (rev 44956)
+++ scummvm/trunk/engines/draci/script.cpp 2009-10-11 23:01:59 UTC (rev 44957)
@@ -569,7 +569,7 @@
Animation *itemAnim = _vm->_anims->addItem(kInventoryItemsID - itemID);
const BAFile *f = _vm->_itemImagesArchive->getFile(2 * itemID);
Sprite *sp = new Sprite(f->_data, f->_length, 0, 0, true);
- itemAnim->addFrame(sp);
+ itemAnim->addFrame(sp, NULL);
}
_vm->_game->setCurrentItem(itemID);
Modified: scummvm/trunk/engines/draci/sound.cpp
===================================================================
--- scummvm/trunk/engines/draci/sound.cpp 2009-10-11 22:39:06 UTC (rev 44956)
+++ scummvm/trunk/engines/draci/sound.cpp 2009-10-11 23:01:59 UTC (rev 44957)
@@ -74,6 +74,7 @@
for (uint i = 0; i < _sampleCount; ++i) {
_samples[i]._offset = sampleStarts[i];
_samples[i]._length = sampleStarts[i+1] - sampleStarts[i];
+ _samples[i]._frequency = 0; // set in getSample()
_samples[i]._data = NULL;
}
if (_samples[_sampleCount-1]._offset + _samples[_sampleCount-1]._length != totalLength &&
@@ -128,7 +129,7 @@
*
* Loads individual samples from an archive to memory on demand.
*/
-const SoundSample *SoundArchive::getSample(uint i) {
+const SoundSample *SoundArchive::getSample(uint i, uint freq) {
// Check whether requested file exists
if (i >= _sampleCount) {
return NULL;
@@ -140,17 +141,17 @@
// Check if file has already been opened and return that
if (_samples[i]._data) {
debugC(2, kDraciArchiverDebugLevel, "Success");
- return _samples + i;
+ } else {
+ // Read in the file (without the file header)
+ _f->seek(_samples[i]._offset);
+ _samples[i]._data = new byte[_samples[i]._length];
+ _f->read(_samples[i]._data, _samples[i]._length);
+
+ debugC(3, kDraciArchiverDebugLevel, "Cached sample %d from archive %s",
+ i, _path.c_str());
}
+ _samples[i]._frequency = freq;
- // Read in the file (without the file header)
- _f->seek(_samples[i]._offset);
- _samples[i]._data = new byte[_samples[i]._length];
- _f->read(_samples[i]._data, _samples[i]._length);
-
- debugC(3, kDraciArchiverDebugLevel, "Cached sample %d from archive %s",
- i, _path.c_str());
-
return _samples + i;
}
Modified: scummvm/trunk/engines/draci/sound.h
===================================================================
--- scummvm/trunk/engines/draci/sound.h 2009-10-11 22:39:06 UTC (rev 44956)
+++ scummvm/trunk/engines/draci/sound.h 2009-10-11 23:01:59 UTC (rev 44957)
@@ -37,6 +37,7 @@
struct SoundSample {
uint _offset;
uint _length;
+ uint _frequency;
byte* _data;
void close(void) {
@@ -68,7 +69,7 @@
void clearCache();
- const SoundSample *getSample(uint i);
+ const SoundSample *getSample(uint i, uint freq);
private:
Common::String _path; ///< Path to file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list