Skip to content

Commit

Permalink
DIRECTOR: Load palette directly to engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Iskrich authored and sev- committed Aug 3, 2016
1 parent 57e092a commit 6b5c062
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
10 changes: 8 additions & 2 deletions engines/director/director.cpp
Expand Up @@ -64,6 +64,7 @@ DirectorEngine::DirectorEngine(OSystem *syst, const DirectorGameDescription *gam
DirectorEngine::~DirectorEngine() {
delete _mainArchive;
delete _macBinary;
delete[] _currentPalette;
}

Common::Error DirectorEngine::run() {
Expand All @@ -85,7 +86,7 @@ Common::Error DirectorEngine::run() {
_mainArchive = new RIFFArchive();
_mainArchive->openFile("bookshelf_example.mmm");

Score score(*_mainArchive, *_lingo, *_soundManager);
Score score(this);
debug(0, "Score name %s", score.getMacName().c_str());

score.loadArchive();
Expand All @@ -110,7 +111,7 @@ Common::HashMap<Common::String, Score *> DirectorEngine::loadMMMNames(Common::St
for (Common::FSList::const_iterator i = movies.begin(); i != movies.end(); ++i) {
RIFFArchive *arc = new RIFFArchive();
arc->openFile(i->getPath());
Score *sc = new Score(*arc, *_lingo, *_soundManager);
Score *sc = new Score(this);
nameMap[sc->getMacName()] = sc;
}
}
Expand Down Expand Up @@ -266,4 +267,9 @@ Common::String DirectorEngine::readPascalString(Common::SeekableReadStream &stre
return x;
}

void DirectorEngine::setPalette(byte *palette, uint16 count) {
_currentPalette = palette;
_currentPaletteLength = count;
}

} // End of namespace Director
9 changes: 7 additions & 2 deletions engines/director/director.h
Expand Up @@ -59,7 +59,12 @@ class DirectorEngine : public ::Engine {
Common::Language getLanguage() const;
Common::String getEXEName() const;
DirectorSound *getSoundManager() const { return _soundManager; }
Archive *getMainArchive() const { return _mainArchive; }
Lingo *getLingo() const { return _lingo; }
void setPalette(byte *palette, uint16 count);
bool hasFeature(EngineFeature f) const;
const byte *getPalette() const { return _currentPalette; }
uint16 getPaletteColorCount() const { return _currentPaletteLength; }

protected:
virtual Common::Error run();
Expand All @@ -74,15 +79,15 @@ class DirectorEngine : public ::Engine {
void loadEXEv5(Common::SeekableReadStream *stream);
void loadEXEv7(Common::SeekableReadStream *stream);
void loadEXERIFX(Common::SeekableReadStream *stream, uint32 offset);

void loadMac();

Common::String readPascalString(Common::SeekableReadStream &stream);

Archive *_mainArchive;
Common::MacResManager *_macBinary;
DirectorSound *_soundManager;

byte *_currentPalette;
uint16 _currentPaletteLength;
Lingo *_lingo;
};

Expand Down
35 changes: 28 additions & 7 deletions engines/director/score.cpp
Expand Up @@ -39,12 +39,13 @@

namespace Director {

Score::Score(Archive &movie, Lingo &lingo, DirectorSound &soundManager) {
Score::Score(DirectorEngine *vm) {
_vm = vm;
_surface = new Graphics::ManagedSurface;
_trailSurface = new Graphics::ManagedSurface;
_movieArchive = &movie;
_lingo = &lingo;
_soundManager = &soundManager;
_movieArchive = _vm->getMainArchive();
_lingo = _vm->getLingo();
_soundManager = _vm->getSoundManager();
_lingo->processEvent(kEventPrepareMovie, 0);
_movieScriptCount = 0;

Expand Down Expand Up @@ -95,7 +96,7 @@ void Score::loadArchive() {
}
}

DIBDecoder palette;

Common::Array<uint16> clutList = _movieArchive->getResourceIDList(MKTAG('C','L','U','T'));

if (clutList.size() > 1)
Expand All @@ -106,8 +107,8 @@ void Score::loadArchive() {

Common::SeekableReadStream *pal = _movieArchive->getResource(MKTAG('C', 'L', 'U', 'T'), clutList[0]);

palette.loadPalette(*pal);
g_system->getPaletteManager()->setPalette(palette.getPalette(), 0, palette.getPaletteColorCount());
loadPalette(*pal);
g_system->getPaletteManager()->setPalette(_vm->getPalette(), 0, _vm->getPaletteColorCount());
}

Score::~Score() {
Expand All @@ -121,6 +122,26 @@ Score::~Score() {
delete _movieArchive;
}

void Score::loadPalette(Common::SeekableReadStream &stream) {
uint16 steps = stream.size() / 6;
uint16 index = (steps * 3) - 1;
uint16 _paletteColorCount = steps;
byte *_palette = new byte[index];

for (uint8 i = 0; i < steps; i++) {
_palette[index - 2] = stream.readByte();
stream.readByte();

_palette[index - 1] = stream.readByte();
stream.readByte();

_palette[index] = stream.readByte();
stream.readByte();
index -= 3;
}
_vm->setPalette(_palette, _paletteColorCount);
}

void Score::loadFrames(Common::SeekableReadStream &stream) {
uint32 size = stream.readUint32BE();
size -= 4;
Expand Down
5 changes: 4 additions & 1 deletion engines/director/score.h
Expand Up @@ -35,6 +35,7 @@ namespace Director {
class Lingo;
class DirectorSound;
class Score;
class DirectorEngine;

#define CHANNEL_COUNT 24

Expand Down Expand Up @@ -285,7 +286,7 @@ class Frame {

class Score {
public:
Score(Archive &movie, Lingo &lingo, DirectorSound &soundManager);
Score(DirectorEngine *vm);
~Score();

static Common::Rect readRect(Common::SeekableReadStream &stream);
Expand All @@ -298,6 +299,7 @@ class Score {
void update();
void readVersion(uint32 rid);
void loadConfig(Common::SeekableReadStream &stream);
void loadPalette(Common::SeekableReadStream &stream);
void loadCastData(Common::SeekableReadStream &stream);
void loadFrames(Common::SeekableReadStream &stream);
void loadLabels(Common::SeekableReadStream &stream);
Expand Down Expand Up @@ -341,6 +343,7 @@ class Score {
uint16 _stageColor;
Lingo *_lingo;
DirectorSound *_soundManager;
DirectorEngine *_vm;
};

} //End of namespace Director
Expand Down

0 comments on commit 6b5c062

Please sign in to comment.