Permalink
Browse files

SUPERNOVA: Removes GameManager dependency for Screen

All calls from Screen member functions to the GameManager instance
are relocated to the wrapper functions in SupernovaEngine.
  • Loading branch information...
Joefish committed Apr 22, 2018
1 parent 437b1c0 commit bd298f3b3d9159c4d1be7d007994a69324c3c745
Showing with 34 additions and 36 deletions.
  1. +17 −30 engines/supernova/screen.cpp
  2. +4 −4 engines/supernova/screen.h
  3. +13 −2 engines/supernova/supernova.cpp
@@ -168,9 +168,8 @@ void Marquee::renderCharacter() {
}
}

Screen::Screen(SupernovaEngine *vm, GameManager *gm, ResourceManager *resMan)
Screen::Screen(SupernovaEngine *vm, ResourceManager *resMan)
: _vm(vm)
, _gm(gm)
, _resMan(resMan)
, _currentImage(nullptr)
, _viewportBrightness(255)
@@ -208,6 +207,10 @@ const MSNImage *Screen::getCurrentImage() const {
return _currentImage;
}

const Screen::ImageInfo *Screen::getImageInfo(ImageId id) const {
return &imageInfo[(int)id];
}

bool Screen::isMessageShown() const {
return _messageShown;
}
@@ -327,21 +330,16 @@ void Screen::renderText(StringId stringId, int x, int y, byte color) {
renderText(_vm->getGameString(stringId), x, y, color);
}

void Screen::renderImageSection(const MSNImage *image, int section) {
void Screen::renderImageSection(const MSNImage *image, int section, bool invert) {
// 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;
if (section > 128) {
section -= 128;
invert = true;
}
if (section > image->_numSections - 1)
return;

Common::Rect sectionRect(image->_section[section].x1,
image->_section[section].y1,
image->_section[section].x2 + 1,
image->_section[section].y2 + 1);
image->_section[section].y1,
image->_section[section].x2 + 1,
image->_section[section].y2 + 1);
if (image->_filenumber == 1 || image->_filenumber == 2) {
sectionRect.setWidth(640);
sectionRect.setHeight(480);
@@ -383,11 +381,7 @@ void Screen::renderImage(ImageId id, bool removeImage) {
}

do {
if (removeImage)
renderImageSection(image, info.section + 128);
else
renderImageSection(image, info.section);

renderImageSection(image, info.section, removeImage);
info.section = image->_section[info.section].next;
} while (info.section != 0);
}
@@ -396,20 +390,14 @@ void Screen::renderImage(int section) {
if (!_currentImage)
return;

bool sectionVisible = true;

bool removeImage = false;
if (section > 128) {
sectionVisible = false;
removeImage = true;
section -= 128;
}

_gm->_currentRoom->setSectionVisible(section, sectionVisible);

do {
if (sectionVisible)
renderImageSection(_currentImage, section);
else
renderImageSection(_currentImage, section + 128);
renderImageSection(_currentImage, section, removeImage);
section = _currentImage->_section[section].next;
} while (section != 0);
}
@@ -443,7 +431,7 @@ void Screen::renderRoom(Room &room) {
int section = i;
if (room.isSectionVisible(section)) {
do {
renderImageSection(_currentImage, section);
renderImageSection(_currentImage, section, false);
section = _currentImage->_section[section].next;
} while (section != 0);
}
@@ -554,7 +542,6 @@ void Screen::renderMessage(const char *text, MessagePosition position) {
}

_messageShown = true;
_gm->_messageDuration = (Common::strnlen(text, 512) + 20) * _vm->_textSpeed / 10;
}

void Screen::removeMessage() {
@@ -613,17 +600,17 @@ void Screen::paletteFadeOut() {
_vm->_system->updateScreen();
}

void Screen::paletteFadeIn() {
void Screen::paletteFadeIn(int maxViewportBrightness) {
while (_guiBrightness < 245) {
if (_viewportBrightness < _gm->_roomBrightness)
if (_viewportBrightness < maxViewportBrightness)
_viewportBrightness += 10;
_guiBrightness += 10;
paletteBrightness();
_vm->_system->updateScreen();
_vm->_system->delayMillis(_vm->_delay);
}
_guiBrightness = 255;
_viewportBrightness = _gm->_roomBrightness;
_viewportBrightness = maxViewportBrightness;
paletteBrightness();
_vm->_system->updateScreen();
}
@@ -132,15 +132,16 @@ class Screen {
static int textWidth(const Common::String &text);

public:
Screen(SupernovaEngine *vm, GameManager *gm, ResourceManager *resMan);
Screen(SupernovaEngine *vm, ResourceManager *resMan);

int getViewportBrightness() const;
void setViewportBrightness(int brightness);
int getGuiBrightness() const;
void setGuiBrightness(int brightness);
const MSNImage *getCurrentImage() const;
const ImageInfo *getImageInfo(ImageId id) const;
bool isMessageShown() const;
void paletteFadeIn();
void paletteFadeIn(int maxViewportBrightness);
void paletteFadeOut();
void paletteBrightness();
void renderImage(ImageId id, bool removeImage = false);
@@ -174,11 +175,10 @@ class Screen {
void update();

private:
void renderImageSection(const MSNImage *image, int section);
void renderImageSection(const MSNImage *image, int section, bool invert);

private:
SupernovaEngine *_vm;
GameManager *_gm;
ResourceManager *_resMan;
const MSNImage *_currentImage;
ScreenBufferStack _screenBuffer;
@@ -136,7 +136,7 @@ void SupernovaEngine::init() {
_resMan = new ResourceManager();
_sound = new Sound(_mixer, _resMan);
_gm = new GameManager(this, _sound);
_screen = new Screen(this, _gm, _resMan);
_screen = new Screen(this, _resMan);
_console = new Console(this, _gm);

setTotalPlayTime(0);
@@ -244,10 +244,16 @@ void SupernovaEngine::playSound(MusicId index) {
}

void SupernovaEngine::renderImage(int section) {
if (section > 128)
_gm->_currentRoom->setSectionVisible(section - 128, false);
else
_gm->_currentRoom->setSectionVisible(section, true);

_screen->renderImage(section);
}

void SupernovaEngine::renderImage(ImageId id, bool removeImage) {
_gm->_currentRoom->setSectionVisible(_screen->getImageInfo(id)->section, !removeImage);
_screen->renderImage(id, removeImage);
}

@@ -271,14 +277,17 @@ void SupernovaEngine::renderRoom(Room &room) {
}

void SupernovaEngine::renderMessage(const char *text, MessagePosition position) {
_gm->_messageDuration = (Common::strnlen(text, 512) + 20) * _textSpeed / 10;
_screen->renderMessage(text, position);
}

void SupernovaEngine::renderMessage(const Common::String &text, MessagePosition position) {
_gm->_messageDuration = (text.size() + 20) * _textSpeed / 10;
_screen->renderMessage(text, position);
}

void SupernovaEngine::renderMessage(StringId stringId, MessagePosition position, Common::String var1, Common::String var2) {
_gm->_messageDuration = (getGameString(stringId).size() + 20) * _textSpeed / 10;
_screen->renderMessage(stringId, position, var1, var2);
}

@@ -329,6 +338,7 @@ void SupernovaEngine::renderBox(int x, int y, int width, int height, byte color)
void SupernovaEngine::renderBox(const GuiElement &guiElement) {
_screen->renderBox(guiElement);
}

void SupernovaEngine::paletteBrightness() {
_screen->paletteBrightness();
}
@@ -338,7 +348,8 @@ void SupernovaEngine::paletteFadeOut() {
}

void SupernovaEngine::paletteFadeIn() {
_screen->paletteFadeIn();
_gm->roomBrightness();
_screen->paletteFadeIn(_gm->_roomBrightness);
}

void SupernovaEngine::setColor63(byte value) {

0 comments on commit bd298f3

Please sign in to comment.