aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorrichiesams2013-08-15 13:35:39 -0500
committerrichiesams2013-08-15 14:15:48 -0500
commit08a8ab885bf6a2eea1f0eb9d7526cdbe240561e6 (patch)
tree84fd7a261e18e90d25eb9f344efe4ce9c3aa6c6f /engines
parentc0305d9534763d69223cb6a5ea20d20101236401 (diff)
downloadscummvm-rg350-08a8ab885bf6a2eea1f0eb9d7526cdbe240561e6.tar.gz
scummvm-rg350-08a8ab885bf6a2eea1f0eb9d7526cdbe240561e6.tar.bz2
scummvm-rg350-08a8ab885bf6a2eea1f0eb9d7526cdbe240561e6.zip
ZVISION: Apply panorama/tilt warping after all images have been rendered to a backbuffer
This makes wrapped warping much easier as well as allowing changeLocation offsets to work properly
Diffstat (limited to 'engines')
-rw-r--r--engines/zvision/console.cpp4
-rw-r--r--engines/zvision/render_manager.cpp125
-rw-r--r--engines/zvision/render_manager.h22
-rw-r--r--engines/zvision/render_table.cpp21
-rw-r--r--engines/zvision/render_table.h2
-rw-r--r--engines/zvision/zvision.cpp2
6 files changed, 95 insertions, 81 deletions
diff --git a/engines/zvision/console.cpp b/engines/zvision/console.cpp
index f1b192fce1..6c7ac94181 100644
--- a/engines/zvision/console.cpp
+++ b/engines/zvision/console.cpp
@@ -57,9 +57,9 @@ Console::Console(ZVision *engine) : GUI::Debugger(), _engine(engine) {
bool Console::cmdLoadImage(int argc, const char **argv) {
if (argc == 4)
- _engine->getRenderManager()->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3]));
+ _engine->getRenderManager()->renderImageToBackbuffer(argv[1], atoi(argv[2]), atoi(argv[3]));
else if (argc == 8)
- _engine->getRenderManager()->renderImageToScreen(argv[1], atoi(argv[2]), atoi(argv[3]), Common::Rect(atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atoi(argv[7])));
+ _engine->getRenderManager()->renderImageToBackbuffer(argv[1], atoi(argv[2]), atoi(argv[3]), Common::Rect(atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atoi(argv[7])));
else {
DebugPrintf("Use loadimage <fileName> <destinationX> <destinationY> [ <subRectX1> <subRectY2> <subRectX2> <subRectY2> ] to load an image to the screen\n");
return true;
diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp
index 78fcf59a56..05536f3fbe 100644
--- a/engines/zvision/render_manager.cpp
+++ b/engines/zvision/render_manager.cpp
@@ -34,23 +34,28 @@
namespace ZVision {
-RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow)
- : _system(system),
- _workingWidth(workingWindow.width()),
- _workingHeight(workingWindow.height()),
- _workingWindow(workingWindow),
- _currentBackground(0),
- _backgroundWidth(0),
- _backgroundHeight(0),
- _backgroundInverseVelocity(0),
- _accumulatedVelocityMilliseconds(0),
- _renderTable(workingWindow.width(), workingWindow.height()) {
+RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat)
+ : _system(system),
+ _workingWidth(workingWindow.width()),
+ _workingHeight(workingWindow.height()),
+ _workingWindow(workingWindow),
+ _pixelFormat(pixelFormat),
+ _currentBackground(0),
+ _backgroundWidth(0),
+ _backgroundHeight(0),
+ _backgroundInverseVelocity(0),
+ _accumulatedVelocityMilliseconds(0),
+ _renderTable(workingWindow.width(), workingWindow.height()) {
+ _backbuffer.create(_workingWidth, _workingHeight, pixelFormat);
+ _warpedBackbuffer = new uint16[_workingWidth *_workingHeight];
}
RenderManager::~RenderManager() {
if (_currentBackground != 0) {
delete _currentBackground;
}
+
+ _backbuffer.free();
}
void RenderManager::update(uint deltaTimeInMillis) {
@@ -62,7 +67,7 @@ void RenderManager::update(uint deltaTimeInMillis) {
int absVelocity = abs(_backgroundInverseVelocity);
- uint numberOfSteps = 0;
+ int numberOfSteps = 0;
while (_accumulatedVelocityMilliseconds >= absVelocity) {
_accumulatedVelocityMilliseconds -= absVelocity;
numberOfSteps++;
@@ -70,17 +75,23 @@ void RenderManager::update(uint deltaTimeInMillis) {
// Choose the direction of movement using the sign of the velocity
moveBackground(_backgroundInverseVelocity < 0 ? -numberOfSteps : numberOfSteps);
+
+ // Warp the entire backbuffer
+ _renderTable.mutateImage((uint16 *)_backbuffer.getBasePtr(0, 0), _warpedBackbuffer, _workingWidth, _workingHeight);
+
+ // Blit the backbuffer to the screen
+ _system->copyRectToScreen(_backbuffer.getBasePtr(0, 0), _backbuffer.pitch, _workingWindow.left, _workingWindow.top, _backbuffer.w, _backbuffer.h);
}
-void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) {
+void RenderManager::renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap, bool isTransposed) {
if (wrap) {
- _backgroundWidth = imageWidth;
- _backgroundHeight = imageHeight;
+ _backgroundWidth = surface.w;
+ _backgroundHeight = surface.h;
}
// If subRect is empty, use the entire image
if (subRectangle.isEmpty())
- subRectangle = Common::Rect(subRectangle.left, subRectangle.top, subRectangle.left + imageWidth, subRectangle.top + imageHeight);
+ subRectangle = Common::Rect(subRectangle.left, subRectangle.top, subRectangle.left + surface.w, subRectangle.top + surface.h);
// Clip destRect to working window bounds
Common::Rect destRect(destinationX, destinationY, destinationX + subRectangle.width(), destinationY + subRectangle.height());
@@ -91,7 +102,7 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin
subRectangle.setHeight(destRect.height());
// Clip to image bounds
Common::Point subRectOrigOrigin(subRectangle.left, subRectangle.top);
- subRectangle.clip(imageWidth, imageHeight);
+ subRectangle.clip(surface.w, surface.h);
// If the image is to be wrapped, check if it's smaller than destRect
// If it is, then call renderSubRectToScreen with a subRect representing wrapping
@@ -110,7 +121,7 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin
wrapSubRect = Common::Rect(_backgroundWidth - subRectangle.width(), 0, _backgroundWidth - 1, subRectangle.bottom);
}
- renderSubRectToScreen(buffer, imageWidth, imageHeight, horizontalPitch, wrapDestX, wrapDestY, wrapSubRect, false);
+ renderSubRectToBackbuffer(surface, wrapDestX, wrapDestY, wrapSubRect, false, isTransposed);
} else if (wrap && subRectangle.height() < destRect.height()) {
uint32 wrapDestX;
uint32 wrapDestY;
@@ -126,32 +137,38 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin
wrapSubRect = Common::Rect(0, _backgroundHeight - subRectangle.height(), subRectangle.right, _backgroundHeight - 1);
}
- renderSubRectToScreen(buffer, imageWidth, imageHeight, horizontalPitch, wrapDestX, wrapDestY, wrapSubRect, false);
+ renderSubRectToBackbuffer(surface, wrapDestX, wrapDestY, wrapSubRect, false, isTransposed);
+ } else {
+ // Clip destRect to image bounds
+ destRect.translate(subRectangle.left - subRectOrigOrigin.x, subRectangle.top - subRectOrigOrigin.y);
+ destRect.setWidth(subRectangle.width());
+ destRect.setHeight(subRectangle.height());
}
- // Clip destRect to image bounds
- destRect.translate(subRectangle.left - subRectOrigOrigin.x, subRectangle.top - subRectOrigOrigin.y);
- destRect.setWidth(subRectangle.width());
- destRect.setHeight(subRectangle.height());
-
// Check all Rects for validity
if (!subRectangle.isValidRect() || subRectangle.isEmpty() || !destRect.isValidRect() || destRect.isEmpty())
return;
- if (_renderTable.getRenderState() == RenderTable::FLAT) {
- // Convert destRect to screen space by adding _workingWindowOffset
- _system->copyRectToScreen(buffer + subRectangle.top * horizontalPitch + subRectangle.left, horizontalPitch, destRect.left + _workingWindow.left, destRect.top + _workingWindow.top, destRect.width(), destRect.height());
+ if (isTransposed) {
+ copyTransposedRectToBackbuffer((uint16 *)surface.getBasePtr(subRectangle.left, subRectangle.right), surface.w, destRect.left, destRect.top, destRect.width(), destRect.height());
} else {
- uint16 *destBuffer = new uint16[destRect.width() * destRect.height()];
- _renderTable.mutateImage((uint16 *)buffer, destBuffer, imageWidth, imageHeight, subRectangle, destRect);
+ _backbuffer.copyRectToSurface(surface.getBasePtr(subRectangle.left, subRectangle.right), surface.pitch, destRect.left, destRect.top, destRect.width(), destRect.height());
+ }
+}
- // Convert destRect to screen space by adding _workingWindow offset
- _system->copyRectToScreen(destBuffer, subRectangle.width() * sizeof(uint16), destRect.left + _workingWindow.left, destRect.top + _workingWindow.top, destRect.width(), destRect.height());
- delete[] destBuffer;
+void RenderManager::copyTransposedRectToBackbuffer(const uint16 *buffer, int imageHeight, int x, int y, int width, int height) {
+ uint16 *dest = (uint16 *)_backbuffer.getBasePtr(x, y);
+
+ for (int x = 0; x < width; x++) {
+ int columnOffset = x * imageHeight;
+ for (int y = 0; y < height; y++) {
+ *dest = buffer[columnOffset + y];
+ dest++;
+ }
}
}
-void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) {
+void RenderManager::renderImageToBackbuffer(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) {
Common::File file;
if (!file.open(fileName)) {
@@ -159,10 +176,10 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 d
return;
}
- renderImageToScreen(file, destinationX, destinationY, subRectangle);
+ renderImageToBackbuffer(file, destinationX, destinationY, subRectangle);
}
-void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) {
+void RenderManager::renderImageToBackbuffer(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap) {
// Read the magic number
// Some files are true TGA, while others are TGZ
uint32 fileType;
@@ -179,17 +196,21 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint
byte *buffer = new byte[decompressedSize];
lzssStream.read(buffer, decompressedSize);
- uint32 horizontalPitch = imageWidth * sizeof(uint16);
+ uint32 pitch = imageWidth * sizeof(uint16);
+ bool isTransposed = _renderTable.getRenderState() == RenderTable::PANORAMA;
- // Panoramas are transposed
- // The actual data is transposed in mutateImage
- if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) {
- uint32 temp = imageHeight;
+ if (isTransposed) {
+ uint16 temp = imageHeight;
imageHeight = imageWidth;
imageWidth = temp;
}
- renderSubRectToScreen((uint16 *)buffer, imageWidth, imageHeight, horizontalPitch, destinationX, destinationY, subRectangle, wrap);
+ Graphics::Surface surface;
+ surface.init(imageWidth, imageHeight, pitch, buffer, _pixelFormat);
+
+ renderSubRectToBackbuffer(surface, destinationX, destinationY, subRectangle, wrap, isTransposed);
+
+ // We have to use delete[] instead of calling surface.free() because we created the memory with new[]
delete[] buffer;
} else {
// Reset the cursor
@@ -202,20 +223,16 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint
return;
}
- const Graphics::Surface *tgaSurface = tga.getSurface();
+ Graphics::Surface tgaSurface = *(tga.getSurface());
+ bool isTransposed = _renderTable.getRenderState() == RenderTable::PANORAMA;
- uint32 imageWidth = tgaSurface->w;
- uint32 imageHeight = tgaSurface->h;
-
- // Panoramas are transposed
- // The actual data is transposed in mutateImage
- if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) {
- uint32 temp = imageHeight;
- imageHeight = imageWidth;
- imageWidth = temp;
+ if (isTransposed) {
+ uint16 temp = tgaSurface.h;
+ tgaSurface.h = tgaSurface.w;
+ tgaSurface.w = temp;
}
- renderSubRectToScreen((uint16 *)tgaSurface->pixels, tgaSurface->w, tgaSurface->h, tgaSurface->pitch, destinationX, destinationY, subRectangle, wrap);
+ renderSubRectToBackbuffer(tgaSurface, destinationX, destinationY, subRectangle, wrap, isTransposed);
tga.destroy();
}
}
@@ -255,7 +272,7 @@ void RenderManager::setBackgroundImage(const Common::String &fileName) {
_currentBackground = file;
// Purposely make the subRectangle empty. renderImageToScreen will then set the width and height automatically.
- renderImageToScreen(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true);
+ renderImageToBackbuffer(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true);
}
void RenderManager::setBackgroundPosition(int offset) {
@@ -297,7 +314,7 @@ void RenderManager::moveBackground(int offset) {
_currentBackground->seek(0);
// Purposely make the subRectangle empty. renderImageToScreen will then set the width and height automatically.
- renderImageToScreen(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true);
+ renderImageToBackbuffer(*_currentBackground, 0, 0, Common::Rect(_backgroundOffset.x, _backgroundOffset.y, _backgroundOffset.x, _backgroundOffset.y), true);
}
} // End of namespace ZVision
diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h
index 073a2f61e0..d5bf61f6a0 100644
--- a/engines/zvision/render_manager.h
+++ b/engines/zvision/render_manager.h
@@ -26,6 +26,8 @@
#include "common/types.h"
#include "common/rect.h"
+#include "graphics/surface.h"
+
#include "zvision/render_table.h"
class OSystem;
@@ -43,11 +45,15 @@ namespace ZVision {
class RenderManager {
public:
- RenderManager(OSystem *system, const Common::Rect workingWindow);
+ RenderManager(OSystem *system, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat);
~RenderManager();
private:
OSystem *_system;
+ const Graphics::PixelFormat _pixelFormat;
+
+ Graphics::Surface _backbuffer;
+ uint16 *_warpedBackbuffer;
/** Width of the working window. Saved to prevent extraneous calls to _workingWindow.width() */
const int _workingWidth;
@@ -90,7 +96,7 @@ public:
void update(uint deltaTimeInMillis);
/**
- * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame.
+ * Blits the image or a portion of the image to the backbuffer. Actual screen updates won't happen until the end of the frame.
* The image will be clipped to fit inside the working window. Coords are in working window space, not screen space!
*
* @param fileName Name of the image file
@@ -98,10 +104,10 @@ public:
* @param destinationY Y position where the image should be put. Coords are in working window space, not screen space!
* @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. Coords are in working window space, not screen space!
*/
- void renderImageToScreen(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false);
+ void renderImageToBackbuffer(const Common::String &fileName, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false);
/**
- * Blits the image or a portion of the image to the screen. Actual screen updates won't happen until the end of the frame.
+ * Blits the image or a portion of the image to the backbuffer. Actual screen updates won't happen until the end of the frame.
* The image will be clipped to fit inside the working window. Coords are in working window space, not screen space!
*
* @param stream Stream to read the image data from
@@ -109,7 +115,7 @@ public:
* @param destinationY Y position where the image should be put. Coords are in working window space, not screen space!
* @param subRectangle The subrectangle of the image that should be rendered. If this is an empty rectangle, it will blit the entire image. Coords are in working window space, not screen space!
*/
- void renderImageToScreen(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false);
+ void renderImageToBackbuffer(Common::SeekableReadStream &stream, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle = Common::Rect(0, 0, 0, 0), bool wrap = false);
/**
* Sets the current background image to be used by the RenderManager and immediately
@@ -151,7 +157,7 @@ public:
private:
/**
- * Renders a subRectangle of an image to the screen. The destinationRect and SubRect
+ * Renders a subRectangle of an image to the backbuffer. The destinationRect and SubRect
* will be clipped to image bound and to working window bounds
*
* @param buffer Pointer to (0, 0) of the image data
@@ -163,7 +169,9 @@ private:
* @param subRectangle A rectangle representing the part of the image that should be rendered
* @param wrap Should the image wrap (tile) if it doesn't completely fill the screen?
*/
- void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap);
+ void renderSubRectToBackbuffer(Graphics::Surface &surface, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool wrap, bool isTransposed);
+
+ void copyTransposedRectToBackbuffer(const uint16 *buffer, int imageHeight, int x, int y, int width, int height);
void moveBackground(int offset);
};
diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp
index 3bd0103054..a28f82baa6 100644
--- a/engines/zvision/render_table.cpp
+++ b/engines/zvision/render_table.cpp
@@ -98,16 +98,10 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) {
return returnColor;
}
-void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle) {
- bool isTransposed = _renderState == RenderTable::PANORAMA || _renderState == RenderTable::TILT;
-
- for (int y = subRectangle.top; y < subRectangle.bottom; y++) {
- uint normalizedY = y - subRectangle.top;
-
- for (int x = subRectangle.left; x < subRectangle.right; x++) {
- uint normalizedX = x - subRectangle.left;
-
- uint32 index = (normalizedY + destRectangle.top) * _numColumns + (normalizedX + destRectangle.left);
+void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight) {
+ for (uint32 y = 0; y < imageHeight; y++) {
+ for (uint32 x = 0; x < imageWidth; x++) {
+ uint32 index = y * _numColumns + x;
// RenderTable only stores offsets from the original coordinates
uint32 sourceYIndex = y + _internalBuffer[index].y;
@@ -119,12 +113,7 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 i
// Clamp the xIndex to the size of the image
sourceXIndex = CLIP<uint32>(sourceXIndex, 0, imageWidth - 1);
- // TODO: Figure out a way to not have branching every loop. The only way that comes to mind is to have a whole separate set of for loops for isTransposed, but that's ugly. The compiler might do this anyway in the end
- if (isTransposed) {
- destBuffer[normalizedY * subRectangle.width() + normalizedX] = sourceBuffer[sourceXIndex * imageHeight + sourceYIndex];
- } else {
- destBuffer[normalizedY * subRectangle.width() + normalizedX] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex];
- }
+ destBuffer[index] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex];
}
}
}
diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h
index c38b5a6f0b..7c04564cd0 100644
--- a/engines/zvision/render_table.h
+++ b/engines/zvision/render_table.h
@@ -66,7 +66,7 @@ public:
const Common::Point convertWarpedCoordToFlatCoord(const Common::Point &point);
- void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle);
+ void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight);
void generateRenderTable();
void setPanoramaFoV(float fov);
diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp
index 2090d8abfe..ff234bf3fe 100644
--- a/engines/zvision/zvision.cpp
+++ b/engines/zvision/zvision.cpp
@@ -68,7 +68,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc)
// Create managers
_scriptManager = new ScriptManager(this);
- _renderManager = new RenderManager(_system, _workingWindow);
+ _renderManager = new RenderManager(_system, _workingWindow, _pixelFormat);
_cursorManager = new CursorManager(this, &_pixelFormat);
debug("ZVision::ZVision");