aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/mads/events.cpp2
-rw-r--r--engines/mads/events.h4
-rw-r--r--engines/mads/game.cpp8
-rw-r--r--engines/mads/game.h2
-rw-r--r--engines/mads/msurface.cpp15
-rw-r--r--engines/mads/nebular/dialogs_nebular.cpp40
-rw-r--r--engines/mads/nebular/nebular_scenes1.cpp2
-rw-r--r--engines/mads/palette.cpp22
-rw-r--r--engines/mads/palette.h11
-rw-r--r--engines/mads/scene.cpp10
-rw-r--r--engines/mads/screen.cpp53
-rw-r--r--engines/mads/screen.h4
-rw-r--r--engines/zvision/text/truetype_font.cpp6
13 files changed, 112 insertions, 67 deletions
diff --git a/engines/mads/events.cpp b/engines/mads/events.cpp
index e7ec8b0821..586ef7cbf3 100644
--- a/engines/mads/events.cpp
+++ b/engines/mads/events.cpp
@@ -157,7 +157,7 @@ void EventsManager::pollEvents() {
_vm->_debugger->attach();
_vm->_debugger->onFrame();
} else {
- _pendingKeys.push(event);
+ _pendingKeys.push(event.kbd);
}
return;
case Common::EVENT_KEYUP:
diff --git a/engines/mads/events.h b/engines/mads/events.h
index 870d6e03b8..21ef37407b 100644
--- a/engines/mads/events.h
+++ b/engines/mads/events.h
@@ -70,7 +70,7 @@ public:
int _vD2;
int _mouseStatusCopy;
bool _mouseMoved;
- Common::Stack<Common::Event> _pendingKeys;
+ Common::Stack<Common::KeyState> _pendingKeys;
public:
/**
* Constructor
@@ -168,6 +168,8 @@ public:
* Returns true if there's any pending keys to be processed
*/
bool isKeyPressed() const { return !_pendingKeys.empty(); }
+
+ Common::KeyState getKey() { return _pendingKeys.pop(); }
};
} // End of namespace MADS
diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp
index 0ce24daf7a..27691d3380 100644
--- a/engines/mads/game.cpp
+++ b/engines/mads/game.cpp
@@ -403,12 +403,12 @@ Common::StringArray Game::getMessage(uint32 id) {
static const char *const DEBUG_STRING = "WIDEPIPE";
-void Game::handleKeypress(const Common::Event &event) {
- if (event.kbd.flags & Common::KBD_CTRL) {
+void Game::handleKeypress(const Common::KeyState &kbd) {
+ if (kbd.flags & Common::KBD_CTRL) {
if (_widepipeCtr == 8) {
// Implement original game cheating keys here someday
} else {
- if (event.kbd.keycode == (Common::KEYCODE_a +
+ if (kbd.keycode == (Common::KEYCODE_a +
(DEBUG_STRING[_widepipeCtr] - 'a'))) {
if (++_widepipeCtr == 8) {
MessageDialog *dlg = new MessageDialog(_vm, 2,
@@ -420,7 +420,7 @@ void Game::handleKeypress(const Common::Event &event) {
}
}
- switch (event.kbd.keycode) {
+ switch (kbd.keycode) {
case Common::KEYCODE_F1:
_vm->_dialogs->_pendingDialog = DIALOG_GAME_MENU;
break;
diff --git a/engines/mads/game.h b/engines/mads/game.h
index 1a61fc8ac8..66f2580249 100644
--- a/engines/mads/game.h
+++ b/engines/mads/game.h
@@ -204,7 +204,7 @@ public:
/**
* Handle a keyboard event
*/
- void handleKeypress(const Common::Event &event);
+ void handleKeypress(const Common::KeyState &kbd);
/**
* Starts a savegame loading.
diff --git a/engines/mads/msurface.cpp b/engines/mads/msurface.cpp
index d8d01f307c..702b9e5f08 100644
--- a/engines/mads/msurface.cpp
+++ b/engines/mads/msurface.cpp
@@ -308,6 +308,9 @@ void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
if (!copyRect.isValidRect())
return;
+ if (flipped)
+ copyRect.moveTo(0, copyRect.top);
+
byte *data = src->getData();
byte *srcPtr = data + (src->getWidth() * copyRect.top + copyRect.left);
byte *destPtr = (byte *)pixels + (destY * pitch) + destX;
@@ -397,14 +400,16 @@ void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
const byte *srcP = srcPixelsP;
byte *destP = destPixelsP;
- for (int xp = 0, sprX = 0; xp < frameWidth; ++xp, ++srcP) {
- if (xp < spriteLeft)
- // Not yet reached start of display area
- continue;
- if (!lineDist[sprX++])
+ for (int xp = 0, sprX = -1; xp < frameWidth; ++xp, ++srcP) {
+ if (!lineDist[xp])
// Not a display pixel
continue;
+ ++sprX;
+ if (sprX < spriteLeft || sprX >= spriteRight)
+ // Skip pixel if it's not in horizontal display portion
+ continue;
+
// Get depth of current output pixel in depth surface
Common::Point pt((destP - (byte *)this->pixels) % this->pitch,
(destP - (byte *)this->pixels) / this->pitch);
diff --git a/engines/mads/nebular/dialogs_nebular.cpp b/engines/mads/nebular/dialogs_nebular.cpp
index 05c2e4ba96..6985455d2a 100644
--- a/engines/mads/nebular/dialogs_nebular.cpp
+++ b/engines/mads/nebular/dialogs_nebular.cpp
@@ -612,9 +612,12 @@ GameDialog::GameDialog(MADSEngine *vm) : FullScreenDialog(vm) {
}
void GameDialog::display() {
+ Palette &palette = *_vm->_palette;
+ palette.initPalette();
+ palette.resetGamePalette(18, 10);
+
FullScreenDialog::display();
- Palette &palette = *_vm->_palette;
palette.setEntry(10, 0, 63, 0);
palette.setEntry(11, 0, 45, 0);
palette.setEntry(12, 63, 63, 0);
@@ -804,7 +807,7 @@ void GameDialog::show() {
Scene &scene = _vm->_game->_scene;
- while (_selectedLine < 1 && !_vm->shouldQuit()) {
+ while (_selectedLine == -1 && !_vm->shouldQuit()) {
handleEvents();
if (_redrawFlag) {
if (!_tempLine)
@@ -831,7 +834,17 @@ void GameDialog::handleEvents() {
_lines[i]._state = DLGSTATE_UNSELECTED;
// Process pending events
- _vm->_events->pollEvents();
+ events.pollEvents();
+
+ if (events.isKeyPressed()) {
+ switch (events.getKey().keycode) {
+ case Common::KEYCODE_ESCAPE:
+ _selectedLine = 0;
+ break;
+ default:
+ break;
+ }
+ }
// Scan for objects in the dialog
Common::Point mousePos = events.currentPos() - Common::Point(0, DIALOG_TOP);
@@ -1010,12 +1023,13 @@ void GameMenuDialog::show() {
_vm->_dialogs->_pendingDialog = DIALOG_OPTIONS;
_vm->_dialogs->showDialog();
break;
+ case 5:
+ _vm->quitGame();
+ break;
case 4:
+ default:
// Resume game
break;
- case 5:
- default:
- _vm->quitGame();
}
}
@@ -1083,7 +1097,7 @@ void OptionsDialog::show() {
StoryMode prevStoryMode = game._storyMode;
do {
- _selectedLine = 0;
+ _selectedLine = -1;
GameDialog::show();
switch (_selectedLine) {
@@ -1122,22 +1136,16 @@ void OptionsDialog::show() {
clearLines();
setLines();
setClickableLines();
- } while (_selectedLine <= 7);
+ } while (!_vm->shouldQuit() && _selectedLine != 0 && _selectedLine <= 7);
- switch (_selectedLine) {
- case 8: // Done
- // New options will be applied
- break;
- case 9: // Cancel
+ // If Done button not pressed, reset settings
+ if (_selectedLine != 8) {
// Revert all options from the saved ones
_vm->_easyMouse = prevEasyMouse;
_vm->_invObjectsAnimated = prevInvObjectsAnimated;
_vm->_textWindowStill = prevTextWindowStill;
_vm->_screenFade = prevScreenFade;
game._storyMode = prevStoryMode;
- break;
- default:
- break;
}
}
diff --git a/engines/mads/nebular/nebular_scenes1.cpp b/engines/mads/nebular/nebular_scenes1.cpp
index ab072c1d3c..7c85fd44db 100644
--- a/engines/mads/nebular/nebular_scenes1.cpp
+++ b/engines/mads/nebular/nebular_scenes1.cpp
@@ -1453,7 +1453,7 @@ void Scene103::actions() {
_scene->_hotspots.activate(371, false);
_vm->_game->_player._visible = true;
_vm->_game->_player._stepEnabled = true;
- _vm->_dialogs->showItem(OBJ_REBREATHER, 805);
+ _vm->_dialogs->showItem(OBJ_TIMER_MODULE, 805);
break;
default:
diff --git a/engines/mads/palette.cpp b/engines/mads/palette.cpp
index b41eaedfcc..b5ea136abd 100644
--- a/engines/mads/palette.cpp
+++ b/engines/mads/palette.cpp
@@ -428,6 +428,14 @@ void Fader::grabPalette(byte *colors, uint start, uint num) {
g_system->getPaletteManager()->grabPalette(colors, start, num);
}
+void Fader::getFullPalette(byte palette[PALETTE_SIZE]) {
+ grabPalette(&palette[0], 0, PALETTE_COUNT);
+}
+
+void Fader::setFullPalette(byte palette[PALETTE_SIZE]) {
+ setPalette(&palette[0], 0, PALETTE_COUNT);
+}
+
void Fader::fadeOut(byte palette[PALETTE_SIZE], byte *paletteMap,
int baseColor, int numColors, int baseGrey, int numGreys,
int tickDelay, int steps) {
@@ -886,25 +894,25 @@ void Palette::refreshSceneColors() {
}
int Palette::closestColor(const byte *matchColor, const byte *refPalette,
- int listWrap, int count) {
+ int paletteInc, int count) {
int bestColor = 0;
int bestDistance = 0x7fff;
for (int idx = 0; idx < count; ++idx) {
- // Figure out hash for color
+ // Figure out figure for 'distance' between two colors
int distance = 0;
- for (int rgbIdx = 0; rgbIdx < 3; ++rgbIdx, ++refPalette) {
- byte diff = *refPalette - matchColor[rgbIdx];
- distance += (int)diff * (int)diff;
+ for (int rgbIdx = 0; rgbIdx < RGB_SIZE; ++rgbIdx) {
+ int diff = refPalette[rgbIdx] - matchColor[rgbIdx];
+ distance += diff * diff;
}
// If the given color is a closer match to our color, store the index
- if (distance < bestDistance) {
+ if (distance <= bestDistance) {
bestDistance = distance;
bestColor = idx;
}
- refPalette += listWrap - 3;
+ refPalette += paletteInc;
}
return bestColor;
diff --git a/engines/mads/palette.h b/engines/mads/palette.h
index 1c387b4368..5d3bc3a82e 100644
--- a/engines/mads/palette.h
+++ b/engines/mads/palette.h
@@ -36,6 +36,7 @@ class MADSEngine;
#define PALETTE_RESERVED_HIGH_COUNT 10
#define PALETTE_COUNT 256
+#define RGB_SIZE 3
#define PALETTE_SIZE (256 * 3)
/**
@@ -212,16 +213,12 @@ public:
/**
* Gets the entire palette at once
*/
- void getFullPalette(byte palette[PALETTE_SIZE]) {
- grabPalette(&palette[0], 0, PALETTE_COUNT);
- }
+ void getFullPalette(byte palette[PALETTE_SIZE]);
/**
* Sets the entire palette at once
*/
- void setFullPalette(byte palette[PALETTE_SIZE]) {
- setPalette(&palette[0], 0, PALETTE_COUNT);
- }
+ void setFullPalette(byte palette[PALETTE_SIZE]);
/**
* Calculates a merge/hash for a given palette entry
@@ -320,7 +317,7 @@ public:
void refreshSceneColors();
static int closestColor(const byte *matchColor, const byte *refPalette,
- int listWrap, int count);
+ int paletteInc, int count);
};
} // End of namespace MADS
diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp
index ea3fe2c148..a72648f0c9 100644
--- a/engines/mads/scene.cpp
+++ b/engines/mads/scene.cpp
@@ -592,12 +592,14 @@ void Scene::doSceneStep() {
}
void Scene::checkKeyboard() {
- if (_vm->_events->isKeyPressed()) {
- Common::Event evt = _vm->_events->_pendingKeys.pop();
+ EventsManager &events = *_vm->_events;
+
+ if (events.isKeyPressed()) {
+ Common::KeyState evt = events.getKey();
_vm->_game->handleKeypress(evt);
}
- if ((_vm->_events->_mouseStatus & 3) == 3 && _vm->_game->_player._stepEnabled) {
+ if ((events._mouseStatus & 3) == 3 && _vm->_game->_player._stepEnabled) {
_reloadSceneFlag = true;
_vm->_dialogs->_pendingDialog = DIALOG_GAME_MENU;
_action.clear();
@@ -673,7 +675,7 @@ void Scene::freeCurrentScene() {
}
void Scene::removeSprites() {
- for (int idx = _sprites.size() - 1; idx >= _spritesCount; --idx)
+ for (int idx = _sprites._assetCount - 1; idx >= _spritesCount; --idx)
_sprites.remove(idx);
}
diff --git a/engines/mads/screen.cpp b/engines/mads/screen.cpp
index f7179877d5..60f3d8aeaf 100644
--- a/engines/mads/screen.cpp
+++ b/engines/mads/screen.cpp
@@ -610,7 +610,7 @@ void ScreenSurface::transition(ScreenTransition transitionType, bool surfaceFlag
Scene &scene = _vm->_game->_scene;
byte palData[PALETTE_SIZE];
- switch (transitionType) {
+ switch (transitionType) {
case kTransitionFadeIn:
case kTransitionFadeOutIn:
Common::fill(&pal._colorValues[0], &pal._colorValues[3], 0);
@@ -738,7 +738,8 @@ void ScreenSurface::panTransition(MSurface &newScreen, byte *palData, int entryS
copyRectToScreen(Common::Rect(xAt, destPos.y, xAt + 1, destPos.y + size.y));
// Slight delay
- events.delay(1);
+ events.pollEvents();
+ g_system->delayMillis(1);
}
if ((setPalette && !loop) || throughBlack == THROUGH_BLACK2)
@@ -752,28 +753,49 @@ void ScreenSurface::panTransition(MSurface &newScreen, byte *palData, int entryS
}
}
-void ScreenSurface::swapForeground(byte palData[PALETTE_SIZE], byte *paletteMap) {
+/**
+ * Translates the current screen from the old palette to the new palette
+ */
+void ScreenSurface::swapForeground(byte newPalette[PALETTE_SIZE], byte *paletteMap) {
Palette &palette = *_vm->_palette;
byte oldPalette[PALETTE_SIZE];
- byte oldMap[256];
- byte newMap[256];
+ byte oldMap[PALETTE_COUNT];
palette.getFullPalette(oldPalette);
swapPalette(oldPalette, oldMap, true);
- swapPalette(palData, newMap, false);
-
- Common::copy(&palData[3], &palData[PALETTE_SIZE], &oldPalette[3]);
+ swapPalette(newPalette, paletteMap, false);
+
+ // Transfer translated foreground colors. Since foregrounds are interleaved
+ // with background, we only copy over each alternate RGB tuplet
+ const byte *srcP = &newPalette[RGB_SIZE];
+ byte *destP = &oldPalette[RGB_SIZE];
+ while (destP < &oldPalette[PALETTE_SIZE]) {
+ Common::copy(srcP, srcP + RGB_SIZE, destP);
+ srcP += 2 * RGB_SIZE;
+ destP += 2 * RGB_SIZE;
+ }
+ Common::Rect oldClip = _clipBounds;
+ resetClipBounds();
+
copyRectTranslate(*this, oldMap, Common::Point(0, 0),
Common::Rect(0, 0, MADS_SCREEN_WIDTH, MADS_SCREEN_HEIGHT));
palette.setFullPalette(oldPalette);
+
+ setClipBounds(oldClip);
}
-void ScreenSurface::swapPalette(byte *palData, byte swapTable[PALETTE_COUNT],
- int start) {
- byte *dynamicList = &palData[start * 3];
+/**
+ * Translates a given palette into a mapping table.
+ * Palettes consist of 128 RGB entries for the foreground and background
+ * respectively, with the two interleaved together. So the start
+ */
+void ScreenSurface::swapPalette(const byte *palData, byte swapTable[PALETTE_COUNT],
+ bool foreground) {
+ int start = foreground ? 1 : 0;
+ const byte *dynamicList = &palData[start * RGB_SIZE];
int staticStart = 1 - start;
- byte *staticList = &palData[staticStart * 3];
+ const byte *staticList = &palData[staticStart * RGB_SIZE];
const int PALETTE_START = 1;
const int PALETTE_END = 252;
@@ -781,13 +803,14 @@ void ScreenSurface::swapPalette(byte *palData, byte swapTable[PALETTE_COUNT],
for (int idx = 0; idx < PALETTE_COUNT; ++idx)
swapTable[idx] = idx;
- for (int idx = 0; idx < 128; ++idx) {
+ // Handle the 128 palette entries for the foreground or background
+ for (int idx = 0; idx < (PALETTE_COUNT / 2); ++idx) {
if (start >= PALETTE_START && start <= PALETTE_END) {
swapTable[start] = Palette::closestColor(dynamicList, staticList,
- 6, 128) * 2 + staticStart;
+ 2 * RGB_SIZE, PALETTE_COUNT / 2) * 2 + staticStart;
}
- dynamicList += 6;
+ dynamicList += 2 * RGB_SIZE;
start += 2;
}
}
diff --git a/engines/mads/screen.h b/engines/mads/screen.h
index 35042e88d2..e2462aff18 100644
--- a/engines/mads/screen.h
+++ b/engines/mads/screen.h
@@ -217,9 +217,9 @@ private:
const Common::Point &srcPos, const Common::Point &destPos,
ThroughBlack throughBlack, bool setPalette, int numTicks);
- void swapForeground(byte *palData, byte *paletteMap);
+ void swapForeground(byte newPalette[PALETTE_SIZE], byte *paletteMap);
- void swapPalette(byte palData[PALETTE_SIZE], byte swapTable[PALETTE_COUNT], int start);
+ void swapPalette(const byte palData[PALETTE_SIZE], byte swapTable[PALETTE_COUNT], bool foreground);
public:
int _shakeCountdown;
public:
diff --git a/engines/zvision/text/truetype_font.cpp b/engines/zvision/text/truetype_font.cpp
index 8e402efc08..7ad8d6db61 100644
--- a/engines/zvision/text/truetype_font.cpp
+++ b/engines/zvision/text/truetype_font.cpp
@@ -65,14 +65,14 @@ StyledTTFont::~StyledTTFont() {
}
bool StyledTTFont::loadFont(const Common::String &fontName, int32 point, uint style) {
- _style = style;
-
// Don't re-load the font if we've already loaded it
// We have to check for empty so we can default to Arial
- if (!fontName.empty() && _fontName.equalsIgnoreCase(fontName)) {
+ if (!fontName.empty() && _fontName.equalsIgnoreCase(fontName) && _lineHeight == point && _style == style) {
return true;
}
+ _style = style;
+
Common::String newFontName;
Common::String freeFontName;
Common::String liberationFontName;