SCI: adding upscaled hires mode 640x480 for kq6 and gk1, fixing valgrind error in GfxPortrait class, not using priority anymore when drawing hires cels (shouldnt be needed for kq6)

svn-id: r49040
This commit is contained in:
Martin Kiewitz 2010-05-15 14:17:50 +00:00
parent 59a255226f
commit eb2b3f352e
10 changed files with 97 additions and 54 deletions

View file

@ -44,7 +44,7 @@ GfxCursor::GfxCursor(ResourceManager *resMan, GfxPalette *palette, GfxScreen *sc
_upscaledHires = _screen->getUpscaledHires(); _upscaledHires = _screen->getUpscaledHires();
// center mouse cursor // center mouse cursor
setPosition(Common::Point(_screen->getDisplayWidth() / 2, _screen->getDisplayHeight() / 2)); setPosition(Common::Point(_screen->getWidth() / 2, _screen->getHeight() / 2));
kernelSetMoveZone(Common::Rect(0, 0, _screen->getDisplayWidth(), _screen->getDisplayHeight())); kernelSetMoveZone(Common::Rect(0, 0, _screen->getDisplayWidth(), _screen->getDisplayHeight()));
_isVisible = true; _isVisible = true;
@ -209,16 +209,24 @@ void GfxCursor::setPosition(Common::Point pos) {
if (!_upscaledHires) { if (!_upscaledHires) {
g_system->warpMouse(pos.x, pos.y); g_system->warpMouse(pos.x, pos.y);
} else { } else {
g_system->warpMouse(pos.x * 2, pos.y * 2); _screen->adjustToUpscaledCoordinates(pos.y, pos.x);
g_system->warpMouse(pos.x, pos.y);
} }
} }
Common::Point GfxCursor::getPosition() { Common::Point GfxCursor::getPosition() {
Common::Point mousePos = g_system->getEventManager()->getMousePos(); Common::Point mousePos = g_system->getEventManager()->getMousePos();
if (_upscaledHires) { switch (_upscaledHires) {
case GFX_SCREEN_UPSCALED_640x400:
mousePos.x /= 2; mousePos.x /= 2;
mousePos.y /= 2; mousePos.y /= 2;
break;
case GFX_SCREEN_UPSCALED_640x480:
mousePos.x /= 2;
mousePos.y = (mousePos.y * 5) / 12;
default:
break;
} }
return mousePos; return mousePos;

View file

@ -75,7 +75,7 @@ private:
GfxCoordAdjuster *_coordAdjuster; GfxCoordAdjuster *_coordAdjuster;
SciEvent *_event; SciEvent *_event;
bool _upscaledHires; int _upscaledHires;
Common::Rect _moveZone; // Rectangle in which the pointer can move Common::Rect _moveZone; // Rectangle in which the pointer can move

View file

@ -128,7 +128,7 @@ void SciGui::portraitShow(Common::String resourceName, Common::Point position, u
// adjust given coordinates to curPort (but dont adjust coordinates on upscaledHires_Save_Box and give us hires coordinates // adjust given coordinates to curPort (but dont adjust coordinates on upscaledHires_Save_Box and give us hires coordinates
// on kDrawCel, yeah this whole stuff makes sense) // on kDrawCel, yeah this whole stuff makes sense)
position.x += _ports->getPort()->left; position.y += _ports->getPort()->top; position.x += _ports->getPort()->left; position.y += _ports->getPort()->top;
position.x *= 2; position.y *= 2; _screen->adjustToUpscaledCoordinates(position.y, position.x);
myPortrait->doit(position, resourceId, noun, verb, cond, seq); myPortrait->doit(position, resourceId, noun, verb, cond, seq);
delete myPortrait; delete myPortrait;
} }

View file

@ -152,15 +152,18 @@ void GfxPaint16::drawHiresCelAndShow(GuiResourceId viewId, int16 loopNo, int16 c
// adjust curPort to upscaled hires // adjust curPort to upscaled hires
clipRect = celRect; clipRect = celRect;
curPortRect = _ports->_curPort->rect; curPortRect = _ports->_curPort->rect;
curPortRect.top *= 2; curPortRect.bottom *= 2; curPortRect.bottom++; _screen->adjustToUpscaledCoordinates(curPortRect.top, curPortRect.left);
curPortRect.left *= 2; curPortRect.right *= 2; curPortRect.right++; _screen->adjustToUpscaledCoordinates(curPortRect.bottom, curPortRect.right);
curPortRect.bottom++;
curPortRect.right++;
clipRect.clip(curPortRect); clipRect.clip(curPortRect);
if (clipRect.isEmpty()) // nothing to draw if (clipRect.isEmpty()) // nothing to draw
return; return;
clipRectTranslated = clipRect; clipRectTranslated = clipRect;
if (!upscaledHiresHack) { if (!upscaledHiresHack) {
curPortPos.x = _ports->_curPort->left * 2; curPortPos.y = _ports->_curPort->top * 2; curPortPos.x = _ports->_curPort->left; curPortPos.y = _ports->_curPort->top;
_screen->adjustToUpscaledCoordinates(curPortPos.y, curPortPos.x);
clipRectTranslated.top += curPortPos.y; clipRectTranslated.bottom += curPortPos.y; clipRectTranslated.top += curPortPos.y; clipRectTranslated.bottom += curPortPos.y;
clipRectTranslated.left += curPortPos.x; clipRectTranslated.right += curPortPos.x; clipRectTranslated.left += curPortPos.x; clipRectTranslated.right += curPortPos.x;
} }
@ -308,8 +311,10 @@ reg_t GfxPaint16::bitsSave(const Common::Rect &rect, byte screenMask) {
if (screenMask == GFX_SCREEN_MASK_DISPLAY) { if (screenMask == GFX_SCREEN_MASK_DISPLAY) {
// Adjust rect to upscaled hires, but dont adjust according to port // Adjust rect to upscaled hires, but dont adjust according to port
workerRect.top *= 2; workerRect.bottom *= 2; workerRect.bottom++; _screen->adjustToUpscaledCoordinates(workerRect.top, workerRect.left);
workerRect.left *= 2; workerRect.right *= 2; workerRect.right++; _screen->adjustToUpscaledCoordinates(workerRect.bottom, workerRect.right);
workerRect.bottom++;
workerRect.right++;
} else { } else {
_ports->offsetRect(workerRect); _ports->offsetRect(workerRect);
} }

View file

@ -45,7 +45,7 @@ Portrait::Portrait(ResourceManager *resMan, SciEvent *event, SciGui *gui, GfxScr
Portrait::~Portrait() { Portrait::~Portrait() {
delete[] _bitmaps; delete[] _bitmaps;
delete _fileData; delete[] _fileData;
} }
void Portrait::init() { void Portrait::init() {

View file

@ -35,23 +35,29 @@
namespace Sci { namespace Sci {
GfxScreen::GfxScreen(ResourceManager *resMan, int16 width, int16 height, bool upscaledHires) : GfxScreen::GfxScreen(ResourceManager *resMan, int16 width, int16 height, int upscaledHires) :
_resMan(resMan), _width(width), _height(height), _upscaledHires(upscaledHires) { _resMan(resMan), _width(width), _height(height), _upscaledHires(upscaledHires) {
_pixels = _width * _height; _pixels = _width * _height;
switch (_upscaledHires) {
case GFX_SCREEN_UPSCALED_640x400:
_displayWidth = 640;
_displayHeight = 400;
for (int i = 0; i <= _height; i++)
_upscaledMapping[i] = i * 2;
break;
case GFX_SCREEN_UPSCALED_640x480:
_displayWidth = 640;
_displayHeight = 480;
for (int i = 0; i <= _height; i++)
_upscaledMapping[i] = (i * 12) / 5;
break;
default:
_displayWidth = _width; _displayWidth = _width;
_displayHeight = _height; _displayHeight = _height;
memset(&_upscaledMapping, 0, sizeof(_upscaledMapping) );
if (_upscaledHires) { break;
_displayWidth *= 2;
_displayHeight *= 2;
#ifdef ENABLE_SCI32
// SCI32 also corrects the aspect ratio when upscaling the resolution.
// This is especially needed in GK1, as the credits video is 640x480.
if (getSciVersion() >= SCI_VERSION_2)
_displayHeight = _displayHeight * 6 / 5;
#endif
} }
_displayPixels = _displayWidth * _displayHeight; _displayPixels = _displayWidth * _displayHeight;
@ -98,7 +104,7 @@ void GfxScreen::copyToScreen() {
void GfxScreen::copyFromScreen(byte *buffer) { void GfxScreen::copyFromScreen(byte *buffer) {
Graphics::Surface *screen; Graphics::Surface *screen;
screen = g_system->lockScreen(); screen = g_system->lockScreen();
memcpy(buffer, screen->pixels, _displayWidth * _displayHeight); memcpy(buffer, screen->pixels, _displayPixels);
g_system->unlockScreen(); g_system->unlockScreen();
} }
@ -113,7 +119,8 @@ void GfxScreen::copyRectToScreen(const Common::Rect &rect) {
if (!_upscaledHires) { if (!_upscaledHires) {
g_system->copyRectToScreen(_activeScreen + rect.top * _displayWidth + rect.left, _displayWidth, rect.left, rect.top, rect.width(), rect.height()); g_system->copyRectToScreen(_activeScreen + rect.top * _displayWidth + rect.left, _displayWidth, rect.left, rect.top, rect.width(), rect.height());
} else { } else {
g_system->copyRectToScreen(_activeScreen + rect.top * 2 * _displayWidth + rect.left * 2, _displayWidth, rect.left * 2, rect.top * 2, rect.width() * 2, rect.height() * 2); int rectHeight = _upscaledMapping[rect.bottom] - _upscaledMapping[rect.top];
g_system->copyRectToScreen(_activeScreen + _upscaledMapping[rect.top] * _displayWidth + rect.left * 2, _displayWidth, rect.left * 2, _upscaledMapping[rect.top], rect.width() * 2, rectHeight);
} }
} }
@ -128,7 +135,8 @@ void GfxScreen::copyRectToScreen(const Common::Rect &rect, int16 x, int16 y) {
if (!_upscaledHires) { if (!_upscaledHires) {
g_system->copyRectToScreen(_activeScreen + rect.top * _displayWidth + rect.left, _displayWidth, x, y, rect.width(), rect.height()); g_system->copyRectToScreen(_activeScreen + rect.top * _displayWidth + rect.left, _displayWidth, x, y, rect.width(), rect.height());
} else { } else {
g_system->copyRectToScreen(_activeScreen + rect.top * 2 * _displayWidth + rect.left * 2, _displayWidth, x * 2, y * 2, rect.width() * 2, rect.height() * 2); int rectHeight = _upscaledMapping[rect.bottom] - _upscaledMapping[rect.top];
g_system->copyRectToScreen(_activeScreen + _upscaledMapping[rect.top] * _displayWidth + rect.left * 2, _displayWidth, x * 2, _upscaledMapping[y], rect.width() * 2, rectHeight);
} }
} }
@ -151,11 +159,14 @@ void GfxScreen::putPixel(int x, int y, byte drawMask, byte color, byte priority,
if (!_upscaledHires) { if (!_upscaledHires) {
_displayScreen[offset] = color; _displayScreen[offset] = color;
} else { } else {
int displayOffset = y * 2 * _displayWidth + x * 2; int displayOffset = _upscaledMapping[y] * _displayWidth + x * 2;
_displayScreen[displayOffset] = color; int heightOffsetBreak = (_upscaledMapping[y + 1] - _upscaledMapping[y]) * _displayWidth;
_displayScreen[displayOffset + 1] = color; int heightOffset = 0;
_displayScreen[displayOffset + _displayWidth] = color; do {
_displayScreen[displayOffset + _displayWidth + 1] = color; _displayScreen[displayOffset + heightOffset] = color;
_displayScreen[displayOffset + heightOffset + 1] = color;
heightOffset += _displayWidth;
} while (heightOffset != heightOffsetBreak);
} }
} }
if (drawMask & GFX_SCREEN_MASK_PRIORITY) if (drawMask & GFX_SCREEN_MASK_PRIORITY)
@ -275,7 +286,8 @@ int GfxScreen::bitsGetDataSize(Common::Rect rect, byte mask) {
if (!_upscaledHires) { if (!_upscaledHires) {
byteCount += pixels; // _displayScreen byteCount += pixels; // _displayScreen
} else { } else {
byteCount += pixels * 4; // _displayScreen (upscaled hires) int rectHeight = _upscaledMapping[rect.bottom] - _upscaledMapping[rect.top];
byteCount += rectHeight * rect.width() * 2; // _displayScreen (upscaled hires)
} }
} }
if (mask & GFX_SCREEN_MASK_PRIORITY) { if (mask & GFX_SCREEN_MASK_PRIORITY) {
@ -334,9 +346,10 @@ void GfxScreen::bitsSaveDisplayScreen(Common::Rect rect, byte *&memoryPtr) {
if (!_upscaledHires) { if (!_upscaledHires) {
screen += (rect.top * _displayWidth) + rect.left; screen += (rect.top * _displayWidth) + rect.left;
} else { } else {
screen += (rect.top * 2 * _displayWidth) + rect.left * 2; screen += (_upscaledMapping[rect.top] * _displayWidth) + rect.left * 2;
width *= 2; width *= 2;
rect.top *= 2; rect.bottom *= 2; rect.top = _upscaledMapping[rect.top];
rect.bottom = _upscaledMapping[rect.bottom];
} }
for (y = rect.top; y < rect.bottom; y++) { for (y = rect.top; y < rect.bottom; y++) {
@ -393,9 +406,10 @@ void GfxScreen::bitsRestoreDisplayScreen(Common::Rect rect, byte *&memoryPtr) {
if (!_upscaledHires) { if (!_upscaledHires) {
screen += (rect.top * _displayWidth) + rect.left; screen += (rect.top * _displayWidth) + rect.left;
} else { } else {
screen += (rect.top * 2 * _displayWidth) + rect.left * 2; screen += (_upscaledMapping[rect.top] * _displayWidth) + rect.left * 2;
width *= 2; width *= 2;
rect.top *= 2; rect.bottom *= 2; rect.top = _upscaledMapping[rect.top];
rect.bottom = _upscaledMapping[rect.bottom];
} }
for (y = rect.top; y < rect.bottom; y++) { for (y = rect.top; y < rect.bottom; y++) {
@ -542,6 +556,11 @@ void GfxScreen::scale2x(byte *src, byte *dst, int16 srcWidth, int16 srcHeight) {
} }
} }
void GfxScreen::adjustToUpscaledCoordinates(int16 &y, int16 &x) {
x *= 2;
y = _upscaledMapping[y];
}
int16 GfxScreen::kernelPicNotValid(int16 newPicNotValid) { int16 GfxScreen::kernelPicNotValid(int16 newPicNotValid) {
int16 oldPicNotValid; int16 oldPicNotValid;

View file

@ -33,7 +33,7 @@
namespace Sci { namespace Sci {
#define SCI_SCREEN_MAXHEIGHT 400 #define SCI_SCREEN_UPSCALEDMAXHEIGHT 200
enum GfxScreenUpscaledMode { enum GfxScreenUpscaledMode {
GFX_SCREEN_UPSCALED_DISABLED = 0, GFX_SCREEN_UPSCALED_DISABLED = 0,
@ -58,7 +58,7 @@ enum GfxScreenMasks {
*/ */
class GfxScreen { class GfxScreen {
public: public:
GfxScreen(ResourceManager *resMan, int16 width = 320, int16 height = 200, bool upscaledHires = false); GfxScreen(ResourceManager *resMan, int16 width = 320, int16 height = 200, int upscaledHires = GFX_SCREEN_UPSCALED_DISABLED);
~GfxScreen(); ~GfxScreen();
uint16 getWidth() { return _width; } uint16 getWidth() { return _width; }
@ -82,7 +82,7 @@ public:
void drawLine(int16 left, int16 top, int16 right, int16 bottom, byte color, byte prio, byte control) { void drawLine(int16 left, int16 top, int16 right, int16 bottom, byte color, byte prio, byte control) {
drawLine(Common::Point(left, top), Common::Point(right, bottom), color, prio, control); drawLine(Common::Point(left, top), Common::Point(right, bottom), color, prio, control);
} }
bool getUpscaledHires() { int getUpscaledHires() {
return _upscaledHires; return _upscaledHires;
} }
void putKanjiChar(Graphics::FontSJIS *commonFont, int16 x, int16 y, uint16 chr, byte color); void putKanjiChar(Graphics::FontSJIS *commonFont, int16 x, int16 y, uint16 chr, byte color);
@ -102,6 +102,8 @@ public:
void scale2x(byte *src, byte *dst, int16 srcWidth, int16 srcHeight); void scale2x(byte *src, byte *dst, int16 srcWidth, int16 srcHeight);
void adjustToUpscaledCoordinates(int16 &y, int16 &x);
void dither(bool addToFlag); void dither(bool addToFlag);
void debugUnditherSetState(bool flag); void debugUnditherSetState(bool flag);
int16 *unditherGetMemorial(); int16 *unditherGetMemorial();
@ -138,7 +140,7 @@ private:
byte *_priorityScreen; byte *_priorityScreen;
byte *_controlScreen; byte *_controlScreen;
// this screen is the one that is actually displayed to the user. It may be 640x480 for japanese SCI1 games // this screen is the one that is actually displayed to the user. It may be 640x400 for japanese SCI1 games
// SCI0 games may be undithered in here. Only read from this buffer for Save/ShowBits usage. // SCI0 games may be undithered in here. Only read from this buffer for Save/ShowBits usage.
byte *_displayScreen; byte *_displayScreen;
@ -148,7 +150,12 @@ private:
// this is a pointer to the currently active screen (changing it only required for debug purposes) // this is a pointer to the currently active screen (changing it only required for debug purposes)
byte *_activeScreen; byte *_activeScreen;
bool _upscaledHires;
// this variable defines, if upscaled hires is active and what upscaled mode is used
int _upscaledHires;
// this here holds a translation for vertical coordinates between native (visual) and actual (display) screen
int _upscaledMapping[SCI_SCREEN_UPSCALEDMAXHEIGHT + 1];
}; };
} // End of namespace Sci } // End of namespace Sci

View file

@ -269,8 +269,8 @@ void GfxTransitions::copyRectToScreen(const Common::Rect rect, bool blackoutFlag
surface->fillRect(rect, 0); surface->fillRect(rect, 0);
} else { } else {
Common::Rect upscaledRect = rect; Common::Rect upscaledRect = rect;
upscaledRect.top *= 2; upscaledRect.bottom *= 2; _screen->adjustToUpscaledCoordinates(upscaledRect.top, upscaledRect.left);
upscaledRect.left *= 2; upscaledRect.right *= 2; _screen->adjustToUpscaledCoordinates(upscaledRect.bottom, upscaledRect.right);
surface->fillRect(upscaledRect, 0); surface->fillRect(upscaledRect, 0);
} }
g_system->unlockScreen(); g_system->unlockScreen();

View file

@ -524,15 +524,19 @@ void GfxView::draw(Common::Rect rect, Common::Rect clipRect, Common::Rect clipRe
for (y = 0; y < height; y++, bitmap += celWidth) { for (y = 0; y < height; y++, bitmap += celWidth) {
for (x = 0; x < width; x++) { for (x = 0; x < width; x++) {
color = bitmap[x]; color = bitmap[x];
if (color != clearKey && priority >= _screen->getPriority(clipRectTranslated.left + x, clipRectTranslated.top + y)) { if (color != clearKey) {
// UpscaledHires means view is hires and is supposed to get drawn onto lowres screen if (!upscaledHires) {
if (!upscaledHires) if (priority >= _screen->getPriority(clipRectTranslated.left + x, clipRectTranslated.top + y))
_screen->putPixel(clipRectTranslated.left + x, clipRectTranslated.top + y, drawMask, palette->mapping[color], priority, 0); _screen->putPixel(clipRectTranslated.left + x, clipRectTranslated.top + y, drawMask, palette->mapping[color], priority, 0);
else } else {
// UpscaledHires means view is hires and is supposed to get drawn onto lowres screen
// FIXME(?): we can't read priority directly with the hires coordinates. may not be needed at all
// in kq6
_screen->putPixelOnDisplay(clipRectTranslated.left + x, clipRectTranslated.top + y, palette->mapping[color]); _screen->putPixelOnDisplay(clipRectTranslated.left + x, clipRectTranslated.top + y, palette->mapping[color]);
} }
} }
} }
}
} else { } else {
byte *EGAmapping = _EGAmapping + (EGAmappingNr * SCI_VIEW_EGAMAPPING_SIZE); byte *EGAmapping = _EGAmapping + (EGAmappingNr * SCI_VIEW_EGAMAPPING_SIZE);
for (y = 0; y < height; y++, bitmap += celWidth) { for (y = 0; y < height; y++, bitmap += celWidth) {

View file

@ -141,30 +141,30 @@ Common::Error SciEngine::run() {
} }
// Scale the screen, if needed // Scale the screen, if needed
bool upscaledHires = false; int upscaledHires = GFX_SCREEN_UPSCALED_DISABLED;
// King's Quest 6 and Gabriel Knight 1 have hires content, gk1/cd was able to provide that under DOS as well, but as // King's Quest 6 and Gabriel Knight 1 have hires content, gk1/cd was able to provide that under DOS as well, but as
// gk1/floppy does support upscaled hires scriptswise, but doesn't actually have the hires content we need to limit // gk1/floppy does support upscaled hires scriptswise, but doesn't actually have the hires content we need to limit
// it to platform windows. // it to platform windows.
if (getPlatform() == Common::kPlatformWindows) { if (getPlatform() == Common::kPlatformWindows) {
if (!strcmp(getGameID(), "kq6")) if (!strcmp(getGameID(), "kq6"))
upscaledHires = true; upscaledHires = GFX_SCREEN_UPSCALED_640x480;
#ifdef ENABLE_SCI32 #ifdef ENABLE_SCI32
if (!strcmp(getGameID(), "gk1")) if (!strcmp(getGameID(), "gk1"))
upscaledHires = true; upscaledHires = GFX_SCREEN_UPSCALED_640x480;
#endif #endif
} }
// Japanese versions of games use hi-res font on upscaled version of the game // Japanese versions of games use hi-res font on upscaled version of the game
if ((getLanguage() == Common::JA_JPN) && (getSciVersion() <= SCI_VERSION_1_1)) if ((getLanguage() == Common::JA_JPN) && (getSciVersion() <= SCI_VERSION_1_1))
upscaledHires = true; upscaledHires = GFX_SCREEN_UPSCALED_640x400;
// Initialize graphics-related parts // Initialize graphics-related parts
GfxScreen *screen = 0; GfxScreen *screen = 0;
// invokes initGraphics() // invokes initGraphics()
if (_resMan->detectHires()) if (_resMan->detectHires())
screen = new GfxScreen(_resMan, 640, 480, false); screen = new GfxScreen(_resMan, 640, 480);
else else
screen = new GfxScreen(_resMan, 320, 200, upscaledHires); screen = new GfxScreen(_resMan, 320, 200, upscaledHires);