aboutsummaryrefslogtreecommitdiff
path: root/engines/supernova/supernova.cpp
diff options
context:
space:
mode:
authorThierry Crozat2017-11-16 02:34:51 +0000
committerThierry Crozat2018-01-23 02:15:40 +0000
commitb11772d9044196666117cb0e8141664e7385b746 (patch)
tree05b61c67d3920e47bee4388404aacc5ad56858c3 /engines/supernova/supernova.cpp
parentee905b762a6356a6313aa9c150338991fc0dc6ed (diff)
downloadscummvm-rg350-b11772d9044196666117cb0e8141664e7385b746.tar.gz
scummvm-rg350-b11772d9044196666117cb0e8141664e7385b746.tar.bz2
scummvm-rg350-b11772d9044196666117cb0e8141664e7385b746.zip
SUPERNOVA: Fix logic in rendering code
There were several issues fixed by this commit. The main ones are: - It was in many places only drawing the first section even for images that have multiple sections. - It was in some places using the wrong image. The first issue has been fixed by removing the GameManager::drawImage function, and moving its logic to SupernovaEngine::renderImage which was initially only drawing one section, but was nevertheless called directly from many place. The second image required more changes to the rendering code to allow setting the current image file when it is different from the room file. This fixes some memory issues and random crashes in places where it was for example trying to use the image -1. This also fixes the rendering of the flying cutscene.
Diffstat (limited to 'engines/supernova/supernova.cpp')
-rw-r--r--engines/supernova/supernova.cpp64
1 files changed, 42 insertions, 22 deletions
diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp
index 66fde2806f..f56db88bb7 100644
--- a/engines/supernova/supernova.cpp
+++ b/engines/supernova/supernova.cpp
@@ -103,7 +103,6 @@ SupernovaEngine::SupernovaEngine(OSystem *syst)
, _currentImage(_images)
, _brightness(255)
, _menuBrightness(255)
- , _imageIndex(0)
, _delay(33)
, _textSpeed(kTextSpeed[2])
, _screenWidth(320)
@@ -413,7 +412,7 @@ void SupernovaEngine::playSoundMod(int filenumber)
-1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
}
-void SupernovaEngine::renderImage(MSNImageDecoder &image, int section) {
+void SupernovaEngine::renderImageSection(int section) {
// Note: inverting means we are removing the section. So we should get the rect for that
// section but draw the background (section 0) instead.
bool invert = false;
@@ -421,19 +420,14 @@ void SupernovaEngine::renderImage(MSNImageDecoder &image, int section) {
section -= 128;
invert = true;
}
- if (section > image._numSections - 1)
+ if (!_currentImage || section > _currentImage->_numSections - 1)
return;
- _currentImage = ℑ
- _imageIndex = image._filenumber;
- _system->getPaletteManager()->setPalette(image.getPalette(), 16, 239);
- paletteBrightness();
-
- Common::Rect sectionRect(image._section[section].x1,
- image._section[section].y1,
- image._section[section].x2 + 1,
- image._section[section].y2 + 1) ;
- if (image._filenumber == 1 || image._filenumber == 2) {
+ Common::Rect sectionRect(_currentImage->_section[section].x1,
+ _currentImage->_section[section].y1,
+ _currentImage->_section[section].x2 + 1,
+ _currentImage->_section[section].y2 + 1) ;
+ if (_currentImage->_filenumber == 1 || _currentImage->_filenumber == 2) {
sectionRect.setWidth(640);
sectionRect.setHeight(480);
if (_screenWidth != 640) {
@@ -452,22 +446,49 @@ void SupernovaEngine::renderImage(MSNImageDecoder &image, int section) {
uint offset = 0;
int pitch = sectionRect.width();
if (invert) {
- pitch = image._pitch;
- offset = image._section[section].y1 * pitch + image._section[section].x1;
+ pitch = _currentImage->_pitch;
+ offset = _currentImage->_section[section].y1 * pitch + _currentImage->_section[section].x1;
section = 0;
}
- _system->copyRectToScreen(static_cast<const byte *>(image._sectionSurfaces[section]->getPixels()) + offset,
+ _system->copyRectToScreen(static_cast<const byte *>(_currentImage->_sectionSurfaces[section]->getPixels()) + offset,
pitch,
sectionRect.left, sectionRect.top,
sectionRect.width(), sectionRect.height());
}
void SupernovaEngine::renderImage(int filenumber, int section) {
- if (filenumber > ARRAYSIZE(_images) - 1)
- return;
+ if (setCurrentImage(filenumber))
+ renderImage(section);
+}
+
+void SupernovaEngine::renderImage(int section) {
+ bool sectionVisible = true;
+
+ if (section > 128) {
+ sectionVisible = false;
+ section -= 128;
+ }
- renderImage(_images[filenumber], section);
+ _gm->_currentRoom->setSectionVisible(section, sectionVisible);
+
+ do {
+ if (sectionVisible)
+ renderImageSection(section);
+ else
+ renderImageSection(section + 128);
+ section = _currentImage->_section[section].next;
+ } while (section != 0);
+}
+
+bool SupernovaEngine::setCurrentImage(int filenumber) {
+ if (filenumber == -1 || filenumber > ARRAYSIZE(_images) - 1)
+ return false;
+
+ _currentImage = &(_images[filenumber]);
+ _system->getPaletteManager()->setPalette(_currentImage->getPalette(), 16, 239);
+ paletteBrightness();
+ return true;
}
void SupernovaEngine::saveScreen(int x, int y, int width, int height) {
@@ -479,13 +500,12 @@ void SupernovaEngine::restoreScreen() {
}
void SupernovaEngine::renderRoom(Room &room) {
- if (room.getFileNumber() != -1) {
- _currentImage = &(_images[room.getFileNumber()]);
+ if (setCurrentImage(room.getFileNumber())) {
for (int i = 0; i < _currentImage->_numSections; ++i) {
int section = i;
if (room.isSectionVisible(section)) {
do {
- renderImage(*_currentImage, section);
+ renderImageSection(section);
section = _currentImage->_section[section].next;
} while (section != 0);
}