KYRA: (Amiga) - minor code reduction

(eliminate some duplicate code for dirty rect handling)
This commit is contained in:
athrxx
2019-12-18 20:50:47 +01:00
parent e2d4f1e6f1
commit 04e85a0f3d
12 changed files with 65 additions and 133 deletions
+1 -1
View File
@@ -1682,7 +1682,7 @@ void EoBCoreEngine::drawSequenceBitmap(const char *file, int destRect, int x1, i
_screen->drawClippedLine(0, 121, 319, 121, guiSettings()->colors.fill);
_screen->setPagePixel(0, 319, 121, 9);
_screen->setCurPage(cp);
_screen->setupDualPalettesSplitScreen(_screen->getPalette(amigaPalIndex), _screen->getPalette(7));
_screen->setDualPalettes(_screen->getPalette(amigaPalIndex), _screen->getPalette(7));
_dialogueFieldAmiga = true;
}
+22 -83
View File
@@ -202,7 +202,7 @@ bool Screen::init() {
const int numColorsInternal = _useAmigaExtraColors ? 64 : numColors;
_use256ColorMode = (_bytesPerPixel != 2 && !_isAmiga && !_use16ColorMode && _renderMode != Common::kRenderCGA && _renderMode != Common::kRenderEGA);
_interfacePaletteEnabled = false;
_dualPaletteModeSplitY = 0;
_screenPalette = new Palette(numColorsInternal);
assert(_screenPalette);
@@ -351,7 +351,7 @@ void Screen::updateScreen() {
if (_useOverlays)
updateDirtyRectsOvl();
else if (_isAmiga && _interfacePaletteEnabled)
else if (_isAmiga && _dualPaletteModeSplitY)
updateDirtyRectsAmiga();
else
updateDirtyRects();
@@ -385,68 +385,26 @@ void Screen::updateDirtyRects() {
void Screen::updateDirtyRectsAmiga() {
if (_forceFullUpdate) {
_system->copyRectToScreen(getCPagePtr(0), SCREEN_W, 0, 0, SCREEN_W, 136);
// Page 8 is not used by Kyra 1 AMIGA, thus we can use it to adjust the colors
copyRegion(0, 136, 0, 0, 320, 64, 0, 8, CR_NO_P_CHECK);
uint8 *dst = getPagePtr(8);
for (int y = 0; y < 64; ++y)
for (int x = 0; x < 320; ++x)
*dst++ += 32;
_system->copyRectToScreen(getCPagePtr(8), SCREEN_W, 0, 136, SCREEN_W, 64);
uint32 *pos = (uint32*)(_pagePtrs[0] + _dualPaletteModeSplitY * SCREEN_W);
uint16 h = (SCREEN_H - _dualPaletteModeSplitY) * (SCREEN_W >> 2);
while (h--)
*pos++ |= 0x20202020;
_system->copyRectToScreen(getCPagePtr(0), SCREEN_W, 0, 0, SCREEN_W, SCREEN_H);
} else {
const byte *page0 = getCPagePtr(0);
Common::List<Common::Rect>::iterator it;
for (it = _dirtyRects.begin(); it != _dirtyRects.end(); ++it) {
if (it->bottom <= 136) {
_system->copyRectToScreen(page0 + it->top * SCREEN_W + it->left, SCREEN_W, it->left, it->top, it->width(), it->height());
} else {
// Check whether the rectangle is part of both the screen and the interface
if (it->top < 136) {
// The rectangle covers both screen part and interface part
const int screenHeight = 136 - it->top;
const int interfaceHeight = it->bottom - 136;
const int width = it->width();
const int lineAdd = SCREEN_W - width;
// Copy the screen part verbatim
_system->copyRectToScreen(page0 + it->top * SCREEN_W + it->left, SCREEN_W, it->left, it->top, width, screenHeight);
// Adjust the interface part
copyRegion(it->left, 136, 0, 0, width, interfaceHeight, 0, 8, Screen::CR_NO_P_CHECK);
uint8 *dst = getPagePtr(8);
for (int y = 0; y < interfaceHeight; ++y) {
for (int x = 0; x < width; ++x)
*dst++ += 32;
dst += lineAdd;
}
_system->copyRectToScreen(getCPagePtr(8), SCREEN_W, it->left, 136, width, interfaceHeight);
} else {
// The rectangle only covers the interface part
const int width = it->width();
const int height = it->height();
const int lineAdd = SCREEN_W - width;
copyRegion(it->left, it->top, 0, 0, width, height, 0, 8, Screen::CR_NO_P_CHECK);
uint8 *dst = getPagePtr(8);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x)
*dst++ += 32;
dst += lineAdd;
}
_system->copyRectToScreen(getCPagePtr(8), SCREEN_W, it->left, it->top, width, height);
if (it->bottom >= _dualPaletteModeSplitY) {
int16 startY = MAX<int16>(_dualPaletteModeSplitY, it->top);
int16 h = it->bottom - startY + 1;
int16 w = it->width();
uint8 *pos = _pagePtrs[0] + startY * SCREEN_W + it->left;
while (h--) {
for (int x = 0; x < w; ++x)
*pos++ |= 0x20;
pos += (SCREEN_W - w);
}
}
_system->copyRectToScreen(_pagePtrs[0] + it->top * SCREEN_W + it->left, SCREEN_W, it->left, it->top, it->width(), it->height());
}
}
@@ -969,8 +927,8 @@ void Screen::setScreenPalette(const Palette &pal) {
_system->getPaletteManager()->setPalette(screenPal, 0, pal.getNumColors());
}
void Screen::enableInterfacePalette(bool e) {
_interfacePaletteEnabled = e;
void Screen::enableDualPaletteMode(int splitY) {
_dualPaletteModeSplitY = splitY;
_forceFullUpdate = true;
_dirtyRects.clear();
@@ -980,28 +938,9 @@ void Screen::enableInterfacePalette(bool e) {
updateScreen();
}
void Screen::setInterfacePalette(const Palette &pal, uint8 r, uint8 g, uint8 b) {
if (!_isAmiga)
return;
uint8 screenPal[32 * 3];
assert(32 <= pal.getNumColors());
for (int i = 0; i < pal.getNumColors(); ++i) {
if (i != 0x10) {
screenPal[3 * i + 0] = (pal[i * 3 + 0] * 0xFF) / 0x3F;
screenPal[3 * i + 1] = (pal[i * 3 + 1] * 0xFF) / 0x3F;
screenPal[3 * i + 2] = (pal[i * 3 + 2] * 0xFF) / 0x3F;
} else {
screenPal[3 * i + 0] = (r * 0xFF) / 0x3F;
screenPal[3 * i + 1] = (g * 0xFF) / 0x3F;
screenPal[3 * i + 2] = (b * 0xFF) / 0x3F;
}
}
_paletteChanged = true;
_system->getPaletteManager()->setPalette(screenPal, 32, pal.getNumColors());
void Screen::disableDualPaletteMode() {
_dualPaletteModeSplitY = 0;
_forceFullUpdate = true;
}
void Screen::copyToPage0(int y, int h, uint8 page, uint8 *seqBuf) {
+4 -4
View File
@@ -453,9 +453,9 @@ public:
virtual void setScreenPalette(const Palette &pal);
// AMIGA version only
bool isInterfacePaletteEnabled() const { return _interfacePaletteEnabled; }
void enableInterfacePalette(bool e);
void setInterfacePalette(const Palette &pal, uint8 r, uint8 g, uint8 b);
bool isInterfacePaletteEnabled() const { return _dualPaletteModeSplitY; }
void enableDualPaletteMode(int splitY);
void disableDualPaletteMode();
virtual void getRealPalette(int num, uint8 *dst);
Palette &getPalette(int num);
@@ -716,7 +716,7 @@ protected:
int _drawShapeVar5;
// AMIGA version
bool _interfacePaletteEnabled;
int _dualPaletteModeSplitY;
// debug
bool _debugEnabled;
+6 -36
View File
@@ -62,7 +62,7 @@ Screen_EoB::Screen_EoB(EoBCoreEngine *vm, OSystem *system) : Screen(vm, system,
_egaDitheringTempPage = 0;
_cgaMappingDefault = 0;
_cgaDitheringTables[0] = _cgaDitheringTables[1] = 0;
_useHiResEGADithering = _dualPaletteMode = false;
_useHiResEGADithering = false;
_cyclePalette = 0;
_cpsFilePattern = "%s.";
_activePalCycle = 0;
@@ -189,7 +189,7 @@ void Screen_EoB::setMouseCursor(int x, int y, const byte *shape, const uint8 *ov
copyRegionToBuffer(6, 0, 0, mouseW, mouseH, cursor);
// Mouse cursor post processing for EOB II Amiga
if (_dualPaletteMode) {
if (_dualPaletteModeSplitY) {
int len = mouseW * mouseH;
while (--len > -1)
cursor[len] |= 0x20;
@@ -1828,54 +1828,24 @@ void Screen_EoB::loadSpecialAmigaCPS(const char *fileName, int destPage, bool is
convertAmigaGfx(_pagePtrs[destPage], 320, 200);
}
void Screen_EoB::setupDualPalettesSplitScreen(Palette &top, Palette &bottom) {
void Screen_EoB::setDualPalettes(Palette &top, Palette &bottom) {
// The original supports simultaneous fading of both palettes, but doesn't make any use of that
// feature. The fade rate is always set to 0. So I see no need to implement that.
_palettes[0]->copy(top, 0, 32, 0);
_palettes[0]->copy(bottom, 0, 32, 32);
setScreenPalette(*_palettes[0]);
_dualPaletteMode = _forceFullUpdate = true;
}
void Screen_EoB::disableDualPalettesSplitScreen() {
_dualPaletteMode = false;
_forceFullUpdate = true;
enableDualPaletteMode(120);
}
void Screen_EoB::updateDirtyRects() {
if (!_useHiResEGADithering && !_dualPaletteMode) {
if (!_useHiResEGADithering) {
Screen::updateDirtyRects();
return;
}
if (_dualPaletteMode && _forceFullUpdate) {
uint32 *pos = (uint32*)(_pagePtrs[0] + 120 * SCREEN_W);
uint16 h = 80 * (SCREEN_W >> 2);
while (h--)
*pos++ |= 0x20202020;
_system->copyRectToScreen(getCPagePtr(0), SCREEN_W, 0, 0, SCREEN_W, SCREEN_H);
} else if (_dualPaletteMode) {
Common::List<Common::Rect>::iterator it;
for (it = _dirtyRects.begin(); it != _dirtyRects.end(); ++it) {
if (it->bottom > 119) {
int16 startY = MAX<int16>(120, it->top);
int16 h = it->bottom - startY + 1;
int16 w = it->width();
uint8 *pos = _pagePtrs[0] + startY * SCREEN_W + it->left;
while (h--) {
for (int x = 0; x < w; ++x)
*pos++ |= 0x20;
pos += (SCREEN_W - w);
}
}
_system->copyRectToScreen(_pagePtrs[0] + it->top * SCREEN_W + it->left, SCREEN_W, it->left, it->top, it->width(), it->height());
}
} else if (_forceFullUpdate) {
if (_forceFullUpdate) {
ditherRect(getCPagePtr(0), _egaDitheringTempPage, SCREEN_W * 2, SCREEN_W, SCREEN_H);
_system->copyRectToScreen(_egaDitheringTempPage, SCREEN_W * 2, 0, 0, SCREEN_W * 2, SCREEN_H * 2);
} else {
const uint8 *page0 = getCPagePtr(0);
Common::List<Common::Rect>::iterator it;
+1 -3
View File
@@ -111,8 +111,7 @@ public:
// This is a simple way of emulating the Amiga copper list palette magic for more than 32 colors.
// I use colors 32 to 63 for these extra colors (which the Amiga copper sends to the color
// registers on the fly at vertical beam position 120).
void setupDualPalettesSplitScreen(Palette &top, Palette &bottom);
void disableDualPalettesSplitScreen();
void setDualPalettes(Palette &top, Palette &bottom);
private:
void updateDirtyRects();
@@ -143,7 +142,6 @@ private:
uint8 *_dsTempPage;
uint8 *_shpBuffer;
uint8 *_convertHiColorBuffer;
bool _dualPaletteMode;
uint16 *_cgaDitheringTables[2];
const uint8 *_cgaMappingDefault;
+25 -1
View File
@@ -245,8 +245,32 @@ int Screen_LoK::getRectSize(int x, int y) {
return ((x * y) << 3);
}
void Screen_LoK::setInterfacePalette(const Palette &pal, uint8 r, uint8 g, uint8 b) {
if (!_isAmiga)
return;
uint8 screenPal[32 * 3];
assert(32 <= pal.getNumColors());
for (int i = 0; i < pal.getNumColors(); ++i) {
if (i != 0x10) {
screenPal[3 * i + 0] = (pal[i * 3 + 0] * 0xFF) / 0x3F;
screenPal[3 * i + 1] = (pal[i * 3 + 1] * 0xFF) / 0x3F;
screenPal[3 * i + 2] = (pal[i * 3 + 2] * 0xFF) / 0x3F;
} else {
screenPal[3 * i + 0] = (r * 0xFF) / 0x3F;
screenPal[3 * i + 1] = (g * 0xFF) / 0x3F;
screenPal[3 * i + 2] = (b * 0xFF) / 0x3F;
}
}
_paletteChanged = true;
_system->getPaletteManager()->setPalette(screenPal, 32, pal.getNumColors());
}
void Screen_LoK::postProcessCursor(uint8 *data, int width, int height, int pitch) {
if (_vm->gameFlags().platform == Common::kPlatformAmiga && _interfacePaletteEnabled) {
if (_vm->gameFlags().platform == Common::kPlatformAmiga && _dualPaletteModeSplitY) {
pitch -= width;
for (int y = 0; y < height; ++y) {
+1
View File
@@ -56,6 +56,7 @@ public:
void bitBlitRects();
// AMIGA specific
void setInterfacePalette(const Palette &pal, uint8 r, uint8 g, uint8 b);
virtual void postProcessCursor(uint8 *data, int width, int height, int pitch);
protected:
+1 -1
View File
@@ -66,7 +66,7 @@ void EoBCoreEngine::gui_drawPlayField(bool refresh) {
if (_flags.gameID == GI_EOB1) {
_screen->getPalette(0).copy(_screen->getPalette(1), 1, 5, 1);
} else {
_screen->setupDualPalettesSplitScreen(_screen->getPalette(6), _screen->getPalette(1));
_screen->setDualPalettes(_screen->getPalette(6), _screen->getPalette(1));
_screen->getPalette(7).copy(_screen->getPalette(1), 0, 32);
}
}
+1 -1
View File
@@ -970,7 +970,7 @@ void KyraEngine_LoK::loadMainScreen(int page) {
_screen->setInterfacePalette(_screen->getPalette(1), 0x3F, 0x3F, 0x3F);
// TODO: Move this to a better place
_screen->enableInterfacePalette(true);
_screen->enableDualPaletteMode(136);
}
}
+1 -1
View File
@@ -1540,7 +1540,7 @@ int EoBInfProcessor::oeob_delay(int8 *data) {
int EoBInfProcessor::oeob_drawScene(int8 *data) {
if (_vm->game() == GI_EOB2 && _vm->gameFlags().platform == Common::kPlatformAmiga)
_screen->setupDualPalettesSplitScreen(_screen->getPalette(6), _screen->getPalette(7));
_screen->setDualPalettes(_screen->getPalette(6), _screen->getPalette(7));
_vm->drawScene(1);
return 0;
}
+1 -1
View File
@@ -1560,7 +1560,7 @@ void DarkmoonSequenceHelper::init(DarkmoonSequenceHelper::Mode mode) {
}
_screen->enableHiColorMode(false);
_screen->disableDualPalettesSplitScreen();
_screen->disableDualPaletteMode();
int numColors = 256;
if (_vm->_flags.platform == Common::kPlatformAmiga) {
+1 -1
View File
@@ -1217,7 +1217,7 @@ void KyraEngine_LoK::seq_playCredits() {
typedef Common::List<CreditsLine> CreditsLineList;
CreditsLineList lines;
_screen->enableInterfacePalette(false);
_screen->disableDualPaletteMode();
_screen->hideMouse();
if (!_flags.isTalkie) {