From 3f0cd4771c94a83c72f09f74ba351a3905357d1c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 13 Mar 2014 22:25:16 -0400 Subject: MADS: Fixed handling of dirty rects to copy areas to the physical screen --- engines/mads/dialogs.cpp | 2 +- engines/mads/game.cpp | 2 +- engines/mads/game_data.cpp | 2 +- engines/mads/graphics.cpp | 91 -------------------------- engines/mads/graphics.h | 86 ------------------------- engines/mads/mads.cpp | 2 +- engines/mads/mads.h | 2 +- engines/mads/messages.cpp | 2 +- engines/mads/module.mk | 2 +- engines/mads/msurface.cpp | 2 +- engines/mads/nebular/dialogs_nebular.cpp | 2 +- engines/mads/nebular/game_nebular.cpp | 2 +- engines/mads/scene.cpp | 4 +- engines/mads/scene.h | 2 +- engines/mads/scene_data.cpp | 20 ++++-- engines/mads/scene_data.h | 16 ++++- engines/mads/screen.cpp | 106 +++++++++++++++++++++++++++++++ engines/mads/screen.h | 99 +++++++++++++++++++++++++++++ engines/mads/sprites.cpp | 2 +- engines/mads/user_interface.cpp | 2 +- 20 files changed, 251 insertions(+), 197 deletions(-) delete mode 100644 engines/mads/graphics.cpp delete mode 100644 engines/mads/graphics.h create mode 100644 engines/mads/screen.cpp create mode 100644 engines/mads/screen.h diff --git a/engines/mads/dialogs.cpp b/engines/mads/dialogs.cpp index d159d48ace..571cca5d29 100644 --- a/engines/mads/dialogs.cpp +++ b/engines/mads/dialogs.cpp @@ -23,7 +23,7 @@ #include "common/scummsys.h" #include "common/config-manager.h" #include "mads/mads.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/msurface.h" #include "mads/nebular/dialogs_nebular.h" diff --git a/engines/mads/game.cpp b/engines/mads/game.cpp index 6a7f6fb18d..bcebc04a00 100644 --- a/engines/mads/game.cpp +++ b/engines/mads/game.cpp @@ -25,7 +25,7 @@ #include "mads/game.h" #include "mads/game_data.h" #include "mads/events.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/msurface.h" #include "mads/resources.h" #include "mads/nebular/game_nebular.h" diff --git a/engines/mads/game_data.cpp b/engines/mads/game_data.cpp index ba24ed9ca1..cbc8f93a4b 100644 --- a/engines/mads/game_data.cpp +++ b/engines/mads/game_data.cpp @@ -24,7 +24,7 @@ #include "mads/mads.h" #include "mads/game.h" #include "mads/nebular/game_nebular.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/msurface.h" #include "mads/resources.h" diff --git a/engines/mads/graphics.cpp b/engines/mads/graphics.cpp deleted file mode 100644 index 769b4dd2d2..0000000000 --- a/engines/mads/graphics.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "common/scummsys.h" -#include "mads/mads.h" -#include "mads/game.h" -#include "mads/graphics.h" -#include "mads/palette.h" - -namespace MADS { - -void ScreenSurface::init() { - setSize(g_system->getWidth(), g_system->getHeight()); -} - -void ScreenSurface::updateScreen() { - g_system->copyRectToScreen((const byte *)pixels, pitch, 0, 0, w, h); - g_system->updateScreen(); -} - -void ScreenSurface::transition(ScreenTransition transitionType, bool surfaceFlag) { - switch (transitionType) { - case kTransitionFadeOutIn: - fadeOut(); - fadeIn(); - break; - - case kTransitionFadeIn: - fadeIn(); - break; - - case kTransitionBoxInBottomLeft: - case kTransitionBoxInBottomRight: - case kTransitionBoxInTopLeft: - case kTransitionBoxInTopRight: - error("TODO: transition"); - break; - - case kTransitionPanLeftToRight: - case kTransitionPanRightToLeft: - error("TODO: transition"); - - case kTransitionCircleIn1: - case kTransitionCircleIn2: - case kTransitionCircleIn3: - case kTransitionCircleIn4: - error("TODO circle transition"); - - case kCenterVertTransition: - error("TODO: center vert transition"); - - default: - // Quick transitions - break; - } -} - -void ScreenSurface::setPointer(MSurface *s) { - _pixels = s->getData(); - _pitch = s->w; -} - -void ScreenSurface::fadeOut() { - warning("TODO: Proper fade out"); -} - -void ScreenSurface::fadeIn() { - warning("TODO: Proper fade in"); - _vm->_palette->setFullPalette(_vm->_palette->_mainPalette); -} - -} // End of namespace MADS diff --git a/engines/mads/graphics.h b/engines/mads/graphics.h deleted file mode 100644 index d4933ae68d..0000000000 --- a/engines/mads/graphics.h +++ /dev/null @@ -1,86 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef MADS_GRAPHICS_H -#define MADS_GRAPHICS_H - -#include "common/scummsys.h" -#include "common/array.h" -#include "mads/msurface.h" - -namespace MADS { - -#define MADS_SCREEN_WIDTH 320 -#define MADS_SCREEN_HEIGHT 200 - -enum ScreenTransition { - kTransitionNone = 0, - kTransitionFadeIn, kTransitionFadeOutIn, - kTransitionBoxInBottomLeft, kTransitionBoxInBottomRight, - kTransitionBoxInTopLeft, kTransitionBoxInTopRight, - kTransitionPanLeftToRight, kTransitionPanRightToLeft, - kTransitionCircleIn1, kTransitionCircleIn2, - kTransitionCircleIn3, kTransitionCircleIn4, - kVertTransition1, kVertTransition2, kVertTransition3, - kVertTransition4, kVertTransition5, kVertTransition6, - kVertTransition7, kCenterVertTransition -}; - -class ScreenSurface : public MSurface { -private: - /** - * Handles screen fade out - */ - void fadeOut(); - - /** - * Handles screen fade in - */ - void fadeIn(); -public: - Common::Point _offset; - byte *_pixels; - int _pitch; -public: - /** - * Constructor - */ - ScreenSurface() {} - - /** - * Initialise the surface - */ - void init(); - - void setPointer(MSurface *s); - - /** - * Updates the screen with the contents of the surface - */ - void updateScreen(); - - void transition(ScreenTransition transitionType, bool surfaceFlag); -}; - -} // End of namespace MADS - -#endif /* MADS_GRAPHICS_H */ diff --git a/engines/mads/mads.cpp b/engines/mads/mads.cpp index 6dfdf7b3b8..9cab1ad8f9 100644 --- a/engines/mads/mads.cpp +++ b/engines/mads/mads.cpp @@ -26,7 +26,7 @@ #include "common/events.h" #include "engines/util.h" #include "mads/mads.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/msurface.h" #include "mads/resources.h" #include "mads/sound.h" diff --git a/engines/mads/mads.h b/engines/mads/mads.h index 2fbac32c4a..749c69a64c 100644 --- a/engines/mads/mads.h +++ b/engines/mads/mads.h @@ -35,7 +35,7 @@ #include "mads/events.h" #include "mads/font.h" #include "mads/game.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/msurface.h" #include "mads/resources.h" #include "mads/sound.h" diff --git a/engines/mads/messages.cpp b/engines/mads/messages.cpp index dcac541cf8..21463aa58a 100644 --- a/engines/mads/messages.cpp +++ b/engines/mads/messages.cpp @@ -23,7 +23,7 @@ #include "common/scummsys.h" #include "mads/mads.h" #include "mads/font.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/messages.h" #include "mads/scene_data.h" diff --git a/engines/mads/module.mk b/engines/mads/module.mk index 2f4982f9f8..a65519faea 100644 --- a/engines/mads/module.mk +++ b/engines/mads/module.mk @@ -18,7 +18,6 @@ MODULE_OBJS := \ font.o \ game.o \ game_data.o \ - graphics.o \ hotspots.o \ interface.o \ mads.o \ @@ -29,6 +28,7 @@ MODULE_OBJS := \ resources.o \ scene.o \ scene_data.o \ + screen.o \ sequence.o \ sound.o \ sprites.o \ diff --git a/engines/mads/msurface.cpp b/engines/mads/msurface.cpp index e8d391ff89..c8c66234cb 100644 --- a/engines/mads/msurface.cpp +++ b/engines/mads/msurface.cpp @@ -22,7 +22,7 @@ #include "engines/util.h" #include "mads/compression.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/mads.h" #include "mads/msurface.h" #include "mads/resources.h" diff --git a/engines/mads/nebular/dialogs_nebular.cpp b/engines/mads/nebular/dialogs_nebular.cpp index 6d2321eae2..dc74f39fe8 100644 --- a/engines/mads/nebular/dialogs_nebular.cpp +++ b/engines/mads/nebular/dialogs_nebular.cpp @@ -23,7 +23,7 @@ #include "common/scummsys.h" #include "common/config-manager.h" #include "mads/mads.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/msurface.h" #include "mads/nebular/dialogs_nebular.h" diff --git a/engines/mads/nebular/game_nebular.cpp b/engines/mads/nebular/game_nebular.cpp index 65abb40f1e..8948689622 100644 --- a/engines/mads/nebular/game_nebular.cpp +++ b/engines/mads/nebular/game_nebular.cpp @@ -24,7 +24,7 @@ #include "common/config-manager.h" #include "mads/mads.h" #include "mads/game.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/msurface.h" #include "mads/nebular/game_nebular.h" #include "mads/nebular/dialogs_nebular.h" diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp index ef5fd78f74..8bf0b6a527 100644 --- a/engines/mads/scene.cpp +++ b/engines/mads/scene.cpp @@ -438,7 +438,7 @@ void Scene::drawElements(ScreenTransition transitionType, bool surfaceFlag) { _dirtyAreas.merge(1, DIRTY_AREAS_SIZE); // Copy dirty areas to the main display surface - _dirtyAreas.copy(&_vm->_screen, &_backgroundSurface, _posAdjust); + _dirtyAreas.copy(&_backgroundSurface, &_vm->_screen, _posAdjust); // Handle dirty areas for foreground objects _spriteSlots.setDirtyAreas(); @@ -463,7 +463,7 @@ void Scene::drawElements(ScreenTransition transitionType, bool surfaceFlag) { _vm->_sound->startQueuedCommands(); } else { // Copy dirty areas to the screen - _dirtyAreas.copy(&_vm->_screen, &_backgroundSurface, _vm->_screen._offset); + _dirtyAreas.copyToScreen(_vm->_screen._offset); } warning("TODO: sub_115A2"); diff --git a/engines/mads/scene.h b/engines/mads/scene.h index 79c5910d85..0b20fb077f 100644 --- a/engines/mads/scene.h +++ b/engines/mads/scene.h @@ -27,7 +27,7 @@ #include "common/array.h" #include "common/rect.h" #include "mads/assets.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/hotspots.h" #include "mads/messages.h" #include "mads/msurface.h" diff --git a/engines/mads/scene_data.cpp b/engines/mads/scene_data.cpp index 8f981ef37d..fe768934c3 100644 --- a/engines/mads/scene_data.cpp +++ b/engines/mads/scene_data.cpp @@ -24,7 +24,7 @@ #include "mads/scene_data.h" #include "mads/mads.h" #include "mads/compression.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/resources.h" #include "mads/nebular/nebular_scenes.h" @@ -276,7 +276,20 @@ void DirtyAreas::mergeAreas(int idx1, int idx2) { da1._textActive = true; } -void DirtyAreas::copy(MSurface *dest, MSurface *src, const Common::Point &posAdjust) { +void DirtyAreas::copy(MSurface *srcSurface, MSurface *destSurface, const Common::Point &posAdjust) { + for (uint i = 0; i < size(); ++i) { + const Common::Rect &srcBounds = (*this)[i]._bounds; + + Common::Rect bounds(srcBounds.left + posAdjust.x, srcBounds.top + posAdjust.y, + srcBounds.right + posAdjust.x, srcBounds.bottom + posAdjust.y); + + if ((*this)[i]._active && bounds.isValidRect()) { + srcSurface->copyTo(destSurface, bounds, Common::Point(bounds.left, bounds.top)); + } + } +} + +void DirtyAreas::copyToScreen(const Common::Point &posAdjust) { for (uint i = 0; i < size(); ++i) { const Common::Rect &srcBounds = (*this)[i]._bounds; @@ -284,8 +297,7 @@ void DirtyAreas::copy(MSurface *dest, MSurface *src, const Common::Point &posAdj srcBounds.right + posAdjust.x, srcBounds.bottom + posAdjust.y); if ((*this)[i]._active && (*this)[i]._bounds.isValidRect()) { - src->copyTo(dest, bounds, Common::Point((*this)[i]._bounds.left, - (*this)[i]._bounds.top)); + _vm->_screen.copyRectToScreen(bounds); } } } diff --git a/engines/mads/scene_data.h b/engines/mads/scene_data.h index d0c61ae3f7..7a41bab1f8 100644 --- a/engines/mads/scene_data.h +++ b/engines/mads/scene_data.h @@ -151,7 +151,21 @@ public: bool intersects(int idx1, int idx2); void mergeAreas(int idx1, int idx2); - void copy(MSurface *dest, MSurface *src, const Common::Point &posAdjust); + + /** + * Copy the data specified by the dirty rect list between surfaces + * @param srcSurface Source surface + * @param destSurface Dest surface + * @param posAdjust Position adjustment + */ + void copy(MSurface *srcSurface, MSurface *destSurface, const Common::Point &posAdjust); + + /** + * Use the lsit of dirty areas to copy areas of the screen surface to + * the physical screen + * @param posAdjust Position adjustment */ + void copyToScreen(const Common::Point &posAdjust); + void reset(); }; diff --git a/engines/mads/screen.cpp b/engines/mads/screen.cpp new file mode 100644 index 0000000000..20ff4f6df2 --- /dev/null +++ b/engines/mads/screen.cpp @@ -0,0 +1,106 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/scummsys.h" +#include "mads/mads.h" +#include "mads/game.h" +#include "mads/screen.h" +#include "mads/palette.h" + +namespace MADS { + +ScreenSurface::ScreenSurface() { + _dataP = nullptr; +} + +void ScreenSurface::init() { + setSize(g_system->getWidth(), g_system->getHeight()); +} + +void ScreenSurface::copyRectToScreen(const Common::Point &destPos, + const Common::Rect &bounds) { + byte *buf = getBasePtr(destPos.x, destPos.y); + g_system->copyRectToScreen(buf, this->pitch, bounds.left, bounds.top, + bounds.width(), bounds.height()); +} + +void ScreenSurface::copyRectToScreen(const Common::Rect &bounds) { + copyRectToScreen(Common::Point(bounds.left, bounds.top), bounds); +} + + +void ScreenSurface::updateScreen() { + g_system->updateScreen(); +} + +void ScreenSurface::transition(ScreenTransition transitionType, bool surfaceFlag) { + switch (transitionType) { + case kTransitionFadeOutIn: + fadeOut(); + fadeIn(); + break; + + case kTransitionFadeIn: + fadeIn(); + break; + + case kTransitionBoxInBottomLeft: + case kTransitionBoxInBottomRight: + case kTransitionBoxInTopLeft: + case kTransitionBoxInTopRight: + error("TODO: transition"); + break; + + case kTransitionPanLeftToRight: + case kTransitionPanRightToLeft: + error("TODO: transition"); + + case kTransitionCircleIn1: + case kTransitionCircleIn2: + case kTransitionCircleIn3: + case kTransitionCircleIn4: + error("TODO circle transition"); + + case kCenterVertTransition: + error("TODO: center vert transition"); + + default: + // Quick transitions + break; + } +} + +void ScreenSurface::setPointer(MSurface *s) { + _dataP = s->getData(); +} + +void ScreenSurface::fadeOut() { + warning("TODO: Proper fade out"); +} + +void ScreenSurface::fadeIn() { + warning("TODO: Proper fade in"); + _vm->_palette->setFullPalette(_vm->_palette->_mainPalette); + _vm->_screen.copyRectToScreen(Common::Rect(0, 0, 320, 200)); +} + +} // End of namespace MADS diff --git a/engines/mads/screen.h b/engines/mads/screen.h new file mode 100644 index 0000000000..e101020fc8 --- /dev/null +++ b/engines/mads/screen.h @@ -0,0 +1,99 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef MADS_SCREEN_H +#define MADS_SCREEN_H + +#include "common/scummsys.h" +#include "common/array.h" +#include "mads/msurface.h" + +namespace MADS { + +#define MADS_SCREEN_WIDTH 320 +#define MADS_SCREEN_HEIGHT 200 + +enum ScreenTransition { + kTransitionNone = 0, + kTransitionFadeIn, kTransitionFadeOutIn, + kTransitionBoxInBottomLeft, kTransitionBoxInBottomRight, + kTransitionBoxInTopLeft, kTransitionBoxInTopRight, + kTransitionPanLeftToRight, kTransitionPanRightToLeft, + kTransitionCircleIn1, kTransitionCircleIn2, + kTransitionCircleIn3, kTransitionCircleIn4, + kVertTransition1, kVertTransition2, kVertTransition3, + kVertTransition4, kVertTransition5, kVertTransition6, + kVertTransition7, kCenterVertTransition +}; + +class ScreenSurface : public MSurface { +private: + /** + * Handles screen fade out + */ + void fadeOut(); + + /** + * Handles screen fade in + */ + void fadeIn(); +public: + Common::Point _offset; + byte *_dataP; +public: + /** + * Constructor + */ + ScreenSurface(); + + /** + * Initialise the surface + */ + void init(); + + void setPointer(MSurface *s); + + /** + * Copys an area of the screen surface to a given destination position on + * the ScummVM physical screen buffer + * @param destPos Destination position + * @param bounds Area of screen surface to copy + */ + void copyRectToScreen(const Common::Point &destPos, const Common::Rect &bounds); + + /** + * Copys an area of the screen surface to the ScmmVM physical screen buffer + * @param bounds Area of screen surface to copy + */ + void copyRectToScreen(const Common::Rect &bounds); + + /** + * Updates the screen with the contents of the surface + */ + void updateScreen(); + + void transition(ScreenTransition transitionType, bool surfaceFlag); +}; + +} // End of namespace MADS + +#endif /* MADS_SCREEN_H */ diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index a7a46ce29f..6f227fa341 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -24,7 +24,7 @@ #include "engines/util.h" #include "graphics/palette.h" #include "mads/mads.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/msurface.h" #include "mads/sprites.h" diff --git a/engines/mads/user_interface.cpp b/engines/mads/user_interface.cpp index 3bbf6a0b2b..ec5ca8a0b5 100644 --- a/engines/mads/user_interface.cpp +++ b/engines/mads/user_interface.cpp @@ -22,7 +22,7 @@ #include "common/scummsys.h" #include "mads/mads.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/user_interface.h" #include "mads/msurface.h" -- cgit v1.2.3