Permalink
Browse files

STARTREK: Palette fading

  • Loading branch information...
Drenn1 authored and sev- committed May 13, 2018
1 parent 4927cd9 commit dbeb58f3926dba1bd0e5cb1556eb71040dd94afc
Showing with 75 additions and 19 deletions.
  1. +63 −15 engines/startrek/graphics.cpp
  2. +8 −0 engines/startrek/graphics.h
  3. +4 −4 engines/startrek/startrek.cpp
@@ -52,13 +52,17 @@ Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) {
_textboxVar6 = 0;
_textboxHasMultipleChoices = false;

_palData = new byte[256 * 3];
_lutData = new byte[256 * 3];

_paletteFadeLevel = 0;

setMouseCursor(loadBitmap("pushbtn"));
CursorMan.showMouse(true);
}

Graphics::~Graphics() {
delete[] _egaData;
delete[] _lutData;

delete _font;
}
@@ -68,35 +72,79 @@ void Graphics::setBackgroundImage(SharedPtr<Bitmap> bitmap) {
_backgroundImage = bitmap;
}

/**
* Note: this doesn't flush the palette to the screen (must call "setPaletteFadeLevel")
*/
void Graphics::loadPalette(const Common::String &paletteName) {
// Set the palette from a PAL file
Common::String palFile = paletteName + ".PAL";
Common::String lutFile = paletteName + ".LUT";

SharedPtr<Common::SeekableReadStream> palStream = _vm->loadFile(palFile.c_str());
byte *palette = new byte[256 * 3];
palStream->read(palette, 256 * 3);

// Expand color components
if (_vm->getPlatform() == Common::kPlatformDOS || _vm->getPlatform() == Common::kPlatformMacintosh)
for (uint16 i = 0; i < 256 * 3; i++)
palette[i] <<= 2;

_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);

delete[] palette;
palStream->read(_palData, 256 * 3);

// Load LUT file
SharedPtr<Common::SeekableReadStream> lutStream = _vm->loadFile(lutFile.c_str());

delete[] _lutData;
_lutData = new byte[256];
lutStream->read(_lutData, 256);
}

void Graphics::fadeinScreen() {
while (_paletteFadeLevel <= 100) {
TrekEvent event;
do {
_vm->popNextEvent(&event);
}
while (event.type != TREKEVENT_TICK);

setPaletteFadeLevel(_palData, _paletteFadeLevel);
_paletteFadeLevel += 10;
}

_paletteFadeLevel = 100;
}

void Graphics::fadeoutScreen() {
while (_paletteFadeLevel >= 0) {
TrekEvent event;
do {
_vm->popNextEvent(&event);
}
while (event.type != TREKEVENT_TICK);

setPaletteFadeLevel(_palData, _paletteFadeLevel);
_paletteFadeLevel -= 10;
}

_paletteFadeLevel = 0;
}

/**
* This flushes the palette to the screen. fadeLevel ranges from 0-100.
*/
void Graphics::setPaletteFadeLevel(byte *palData, int fadeLevel) {
byte palBuffer[256 * 3];

int multiplier = (fadeLevel << 8) / 100;

for (uint16 i = 0; i < 256 * 3; i++) {
palBuffer[i] = (palData[i] * multiplier) >> 8;

// Expand color components
if (_vm->getPlatform() == Common::kPlatformDOS || _vm->getPlatform() == Common::kPlatformMacintosh)
palBuffer[i] <<= 2;
}

_vm->_system->getPaletteManager()->setPalette(palBuffer, 0, 256);

// FIXME: this isn't supposed to flush changes to graphics, only palettes.
// Might not matter...
_vm->_system->updateScreen();
}

void Graphics::loadPri(const char *priFile) {
SharedPtr<Common::SeekableReadStream> priStream = _vm->loadFile(priFile);
priStream->read(_priData, SCREEN_WIDTH*SCREEN_HEIGHT / 2);
priStream->read(_priData, SCREEN_WIDTH * SCREEN_HEIGHT / 2);
}

void Graphics::clearPri() {
@@ -71,7 +71,12 @@ class Graphics {
~Graphics();

void setBackgroundImage(SharedPtr<Bitmap> bitmap);

void loadPalette(const String &paletteFile);
void fadeinScreen();
void fadeoutScreen();
void setPaletteFadeLevel(byte *palData, int fadeLevel);

void loadPri(const char *priFile);
void clearPri();
byte getPriValue(int x, int y);
@@ -99,9 +104,12 @@ class Graphics {

bool _egaMode;
byte *_egaData;
byte *_palData;
byte *_lutData;
byte _priData[SCREEN_WIDTH*SCREEN_HEIGHT / 2];

int16 _paletteFadeLevel;

Common::Rect _screenRect;
SharedPtr<Bitmap> _backgroundImage;

@@ -214,7 +214,7 @@ void StarTrekEngine::runTransportSequence(const Common::String &name) {
};

_sound->stopAllVocSounds();
// sub_1e70d();
_gfx->fadeoutScreen();
objectFunc1();
initObjects();

@@ -229,7 +229,7 @@ void StarTrekEngine::runTransportSequence(const Common::String &name) {
Common::String filename = getCrewmanAnimFilename(i, name);
int x = crewmanTransportPositions[i][0];
int y = crewmanTransportPositions[i][1];
loadAnimationForObject(i, filename, x, y, 128);
loadAnimationForObject(i, filename, x, y, 256);
_objectList[i].animationString[0] = '\0';
}

@@ -252,7 +252,7 @@ void StarTrekEngine::runTransportSequence(const Common::String &name) {
// TODO: redraw mouse and sprite_52c4e?

_gfx->drawAllSprites();
// sub_1e6ab();
_gfx->fadeinScreen();

playSoundEffectIndex(0x0a);

@@ -276,7 +276,7 @@ void StarTrekEngine::runTransportSequence(const Common::String &name) {
// TODO: redraw sprite_52c4e?

_gfx->drawAllSprites();
// sub_1e70d();
_gfx->fadeoutScreen();
objectFunc1();
initObjects();
}

0 comments on commit dbeb58f

Please sign in to comment.