aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/xeen/module.mk3
-rw-r--r--engines/xeen/resources.cpp18
-rw-r--r--engines/xeen/resources.h27
-rw-r--r--engines/xeen/screen.cpp67
-rw-r--r--engines/xeen/screen.h17
-rw-r--r--engines/xeen/xsurface.cpp75
-rw-r--r--engines/xeen/xsurface.h51
7 files changed, 243 insertions, 15 deletions
diff --git a/engines/xeen/module.mk b/engines/xeen/module.mk
index 3b4529e73f..c036376e93 100644
--- a/engines/xeen/module.mk
+++ b/engines/xeen/module.mk
@@ -9,7 +9,8 @@ MODULE_OBJS := \
events.o \
resources.o \
screen.o \
- xeen.o
+ xeen.o \
+ xsurface.o
# This module can be built as a plugin
ifeq ($(ENABLE_XEEN), DYNAMIC_PLUGIN)
diff --git a/engines/xeen/resources.cpp b/engines/xeen/resources.cpp
index f99be12c3d..e9c31e337f 100644
--- a/engines/xeen/resources.cpp
+++ b/engines/xeen/resources.cpp
@@ -206,9 +206,27 @@ void Resources::init(XeenEngine *vm) {
/*------------------------------------------------------------------------*/
+/**
+ * Opens the given file, throwing an error if it can't be opened
+ */
void File::openFile(const Common::String &filename) {
if (!Common::File::open(filename))
error("Could not open file - %s", filename.c_str());
}
+/*------------------------------------------------------------------------*/
+
+SpriteResource::SpriteResource(const Common::String &filename) {
+
+}
+
+int SpriteResource::size() const {
+ return _frames.size();
+}
+
+const XSurface &SpriteResource::getFrame(int frame) {
+ return _frames[frame];
+}
+
+
} // End of namespace Xeen
diff --git a/engines/xeen/resources.h b/engines/xeen/resources.h
index 61b6310874..4cf5212af4 100644
--- a/engines/xeen/resources.h
+++ b/engines/xeen/resources.h
@@ -24,7 +24,10 @@
#define XEEN_RESOURCES_H
#include "common/scummsys.h"
+#include "common/array.h"
#include "common/file.h"
+#include "graphics/surface.h"
+#include "xeen/xsurface.h"
namespace Xeen {
@@ -43,22 +46,24 @@ public:
*/
class File : public Common::File {
public:
- /**
- * Constructor
- */
File() : Common::File() {}
-
- /**
- * Constructor
- */
File(const Common::String &filename) { openFile(filename); }
+ virtual ~File() {}
- /**
- * Opens the given file, throwing an error if it can't be opened
- */
void openFile(const Common::String &filename);
};
-} // End of namespace MADS
+class SpriteResource {
+private:
+ Common::Array<XSurface> _frames;
+public:
+ SpriteResource(const Common::String &filename);
+
+ int size() const;
+
+ const XSurface &getFrame(int frame);
+};
+
+} // End of namespace Xeen
#endif /* MADS_RESOURCES_H */
diff --git a/engines/xeen/screen.cpp b/engines/xeen/screen.cpp
index d17e01063d..038222bfe2 100644
--- a/engines/xeen/screen.cpp
+++ b/engines/xeen/screen.cpp
@@ -31,8 +31,73 @@ Screen::Screen(XeenEngine *vm) : _vm(vm) {
}
void Screen::update() {
- g_system->copyRectToScreen(getPixels(), pitch, 0, 0, w, h);
+ // Merge the dirty rects
+ mergeDirtyRects();
+
+ // Loop through copying dirty areas to the physical screen
+ Common::List<Common::Rect>::iterator i;
+ for (i = _dirtyRects.begin(); i != _dirtyRects.end(); ++i) {
+ const Common::Rect &r = *i;
+ const byte *srcP = (const byte *)getBasePtr(r.left, r.top);
+ g_system->copyRectToScreen(srcP, this->pitch, r.left, r.top,
+ r.width(), r.height());
+ }
+
+ // Signal the physical screen to update
g_system->updateScreen();
+ _dirtyRects.clear();
+}
+
+void Screen::addDirtyRect(const Common::Rect &r) {
+ _dirtyRects.push_back(r);
+}
+
+void Screen::transBlitFrom(const XSurface &src, const Common::Point &destPos) {
+ XSurface::transBlitFrom(src, destPos);
+ addDirtyRect(Common::Rect(destPos.x, destPos.y, destPos.x + src.w, destPos.y + src.h));
+}
+
+void Screen::blitFrom(const XSurface &src, const Common::Point &destPos) {
+ XSurface::blitFrom(src, destPos);
+ addDirtyRect(Common::Rect(destPos.x, destPos.y, destPos.x + src.w, destPos.y + src.h));
+}
+
+void Screen::mergeDirtyRects() {
+ Common::List<Common::Rect>::iterator rOuter, rInner;
+
+ // Ensure dirty rect list has at least two entries
+ rOuter = _dirtyRects.begin();
+ for (int i = 0; i < 2; ++i, ++rOuter) {
+ if (rOuter == _dirtyRects.end())
+ return;
+ }
+
+ // Process the dirty rect list to find any rects to merge
+ for (rOuter = _dirtyRects.begin(); rOuter != _dirtyRects.end(); ++rOuter) {
+ rInner = rOuter;
+ while (++rInner != _dirtyRects.end()) {
+
+ if ((*rOuter).intersects(*rInner)) {
+ // these two rectangles overlap or
+ // are next to each other - merge them
+
+ unionRectangle(*rOuter, *rOuter, *rInner);
+
+ // remove the inner rect from the list
+ _dirtyRects.erase(rInner);
+
+ // move back to beginning of list
+ rInner = rOuter;
+ }
+ }
+ }
+}
+
+bool Screen::unionRectangle(Common::Rect &destRect, const Common::Rect &src1, const Common::Rect &src2) {
+ destRect = src1;
+ destRect.extend(src2);
+
+ return !destRect.isEmpty();
}
} // End of namespace Xeen
diff --git a/engines/xeen/screen.h b/engines/xeen/screen.h
index 94dce60de9..491b702ded 100644
--- a/engines/xeen/screen.h
+++ b/engines/xeen/screen.h
@@ -25,19 +25,32 @@
#include "common/scummsys.h"
#include "common/system.h"
-#include "graphics/surface.h"
+#include "common/array.h"
+#include "common/rect.h"
+#include "xeen/xsurface.h"
namespace Xeen {
class XeenEngine;
-class Screen: public Graphics::Surface {
+class Screen: public XSurface {
private:
XeenEngine *_vm;
+ Common::List<Common::Rect> _dirtyRects;
+
+ void mergeDirtyRects();
+
+ bool unionRectangle(Common::Rect &destRect, const Common::Rect &src1, const Common::Rect &src2);
+public:
+ virtual void transBlitFrom(const XSurface &src, const Common::Point &destPos);
+
+ virtual void blitFrom(const XSurface &src, const Common::Point &destPos);
public:
Screen(XeenEngine *vm);
void update();
+
+ void addDirtyRect(const Common::Rect &r);
};
} // End of namespace Xeen
diff --git a/engines/xeen/xsurface.cpp b/engines/xeen/xsurface.cpp
new file mode 100644
index 0000000000..4ab8cf6331
--- /dev/null
+++ b/engines/xeen/xsurface.cpp
@@ -0,0 +1,75 @@
+/* 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 "xeen/xsurface.h"
+
+namespace Xeen {
+
+XSurface::XSurface(): Graphics::Surface() {
+}
+
+XSurface::XSurface(int w, int h) : Graphics::Surface() {
+ create(w, h);
+}
+
+void XSurface::create(uint16 w, uint16 h) {
+ Graphics::Surface::create(w, h, Graphics::PixelFormat::createFormatCLUT8());
+}
+
+void XSurface::transBlitFrom(const XSurface &src) {
+ transBlitFrom(src, Common::Point());
+}
+
+void XSurface::blitFrom(const XSurface &src) {
+ blitFrom(src, Common::Point());
+}
+
+void XSurface::transBlitFrom(const XSurface &src, const Common::Point &destPos) {
+ if (getPixels() == nullptr)
+ create(w, h);
+
+ for (int yp = 0; yp < src.h; ++yp) {
+ const byte *srcP = (const byte *)src.getBasePtr(0, yp);
+ byte *destP = (byte *)getBasePtr(destPos.x, destPos.y + yp);
+
+ for (int xp = 0; xp < this->w; ++xp, ++srcP, ++destP) {
+ if (*srcP != 0)
+ *destP = *srcP;
+ }
+ }
+}
+
+void XSurface::blitFrom(const XSurface &src, const Common::Point &destPos) {
+ if (getPixels() == nullptr)
+ create(w, h);
+
+ for (int yp = 0; yp < src.h; ++yp) {
+ const byte *srcP = (const byte *)src.getBasePtr(0, yp);
+ byte *destP = (byte *)getBasePtr(destPos.x, destPos.y + yp);
+
+ for (int xp = 0; xp < this->w; ++xp, ++srcP, ++destP) {
+ *destP = *srcP;
+ }
+ }
+}
+
+} // End of namespace Xeen
diff --git a/engines/xeen/xsurface.h b/engines/xeen/xsurface.h
new file mode 100644
index 0000000000..e547bd9139
--- /dev/null
+++ b/engines/xeen/xsurface.h
@@ -0,0 +1,51 @@
+/* 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 XEEN_XSURFACE_H
+#define XEEN_XSURFACE_H
+
+#include "common/scummsys.h"
+#include "common/system.h"
+#include "common/rect.h"
+#include "graphics/surface.h"
+
+namespace Xeen {
+
+class XSurface: public Graphics::Surface {
+public:
+ virtual void transBlitFrom(const XSurface &src, const Common::Point &destPos);
+
+ virtual void blitFrom(const XSurface &src, const Common::Point &destPos);
+public:
+ XSurface();
+ XSurface(int w, int h);
+
+ void create(uint16 w, uint16 h);
+
+ void transBlitFrom(const XSurface &src);
+
+ void blitFrom(const XSurface &src);
+};
+
+} // End of namespace Xeen
+
+#endif /* XEEN_XSURFACE_H */