From 4f3f231afd98d63a2ebdbec94671549d0d68f46f Mon Sep 17 00:00:00 2001 From: Joseph-Eugene Winzer Date: Sun, 18 Jun 2017 17:05:21 +0200 Subject: SUPERNOVA: Adds Container for temporarily storing screen sections --- engines/supernova/supernova.cpp | 37 +++++++++++++++++++++++++++++++++++++ engines/supernova/supernova.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'engines/supernova') diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp index 6bd50f9572..bcc2347c30 100644 --- a/engines/supernova/supernova.cpp +++ b/engines/supernova/supernova.cpp @@ -431,4 +431,41 @@ Object *Inventory::get(size_t index) { return NULL; } +ScreenBufferStack::ScreenBufferStack() + : _last(_buffer) { +} + +void ScreenBufferStack::push(int x, int y, int width, int height, int pitch) { + if (_last == ARRAYEND(_buffer)) + return; + + byte *pixels = new byte[width * height]; + const byte *screen = static_cast(g_system->lockScreen()->getBasePtr(x, y)); + for (int i = 0; i < height; ++i) { + Common::copy(screen, screen + width, pixels); + screen += pitch * i; + } + g_system->unlockScreen(); + + _last->_x = x; + _last->_y = y; + _last->_width = width; + _last->_height = height; + _last->_pitch = pitch; + _last->_pixels = pixels; + + ++_last; +} + +void ScreenBufferStack::restore() { + if (_last == _buffer) + return; + + g_system->lockScreen()->copyRectToSurface( + _last->_pixels, _last->_width, _last->_x, _last->_y, + _last->_width, _last->_height); + g_system->unlockScreen(); + --_last; +} + } diff --git a/engines/supernova/supernova.h b/engines/supernova/supernova.h index 2844c2aa6f..f97cd401e9 100644 --- a/engines/supernova/supernova.h +++ b/engines/supernova/supernova.h @@ -37,6 +37,35 @@ namespace Supernova { +struct ScreenBuffer { + ScreenBuffer() + : _x(0) + , _y(0) + , _width(0) + , _height(0) + , _pitch(0) + , _pixels(0) + {} + + byte *_pixels; + int _x; + int _y; + int _width; + int _height; + int _pitch; +}; +class ScreenBufferStack { +public: + ScreenBufferStack(); + + void push(int x, int y, int width, int height, int pitch = 320); + void restore(); + +private: + ScreenBuffer _buffer[8]; + ScreenBuffer *_last; +}; + class SupernovaEngine : public Engine { public: SupernovaEngine(OSystem *syst); -- cgit v1.2.3