diff options
author | RichieSams | 2013-09-06 22:29:19 -0500 |
---|---|---|
committer | RichieSams | 2013-09-06 22:29:19 -0500 |
commit | 2dab04e14b82a110ea8b49b2f6778b5a5fe79375 (patch) | |
tree | 163dfd13ab58b7b9bb4b391b2243d01afea2b664 | |
parent | 1697a9c83114b181074f43d9f872f6e5c43c0a5f (diff) | |
download | scummvm-rg350-2dab04e14b82a110ea8b49b2f6778b5a5fe79375.tar.gz scummvm-rg350-2dab04e14b82a110ea8b49b2f6778b5a5fe79375.tar.bz2 scummvm-rg350-2dab04e14b82a110ea8b49b2f6778b5a5fe79375.zip |
ZVISION: Do full working window warp instead of image at a time
-rw-r--r-- | engines/zvision/render_manager.cpp | 77 | ||||
-rw-r--r-- | engines/zvision/render_manager.h | 17 | ||||
-rw-r--r-- | engines/zvision/render_table.cpp | 50 | ||||
-rw-r--r-- | engines/zvision/render_table.h | 2 | ||||
-rw-r--r-- | engines/zvision/zvision.cpp | 5 |
5 files changed, 96 insertions, 55 deletions
diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index e394baf504..6c0e8d24f6 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -34,7 +34,7 @@ namespace ZVision { -RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat) +RenderManager::RenderManager(OSystem *system, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat) : _system(system), _workingWidth(workingWindow.width()), _workingHeight(workingWindow.height()), @@ -49,12 +49,14 @@ RenderManager::RenderManager(OSystem *system, const Common::Rect workingWindow, _accumulatedVelocityMilliseconds(0), _renderTable(_workingWidth, _workingHeight) { - _workingWindowBuffer = new uint16[_workingWidth *_workingHeight]; + _workingWindowBuffer.create(_workingWidth, _workingHeight, _pixelFormat); + _backBuffer.create(windowWidth, windowHeight, pixelFormat); } RenderManager::~RenderManager() { - delete[] _workingWindowBuffer; + _workingWindowBuffer.free(); _currentBackground.free(); + _backBuffer.free(); } void RenderManager::update(uint deltaTimeInMillis) { @@ -75,14 +77,29 @@ void RenderManager::update(uint deltaTimeInMillis) { } } -void RenderManager::clearWorkingWindowToColor(uint16 color) { +void RenderManager::renderBackbufferToScreen() { + //RenderTable::RenderState state = _renderTable.getRenderState(); + //if (state == RenderTable::PANORAMA || state == RenderTable::TILT) { + // _renderTable.mutateImage((uint16 *)_workingWindowBuffer.getPixels(), (uint16 *)_backBuffer.getBasePtr(_workingWindow.left, _workingWindow.top), _backBuffer.w); + //} else { + //_system->copyRectToScreen(_workingWindowBuffer.getPixels(), _workingWindowBuffer.pitch, _workingWindow.left, _workingWindow.top, _workingWindowBuffer.w, _workingWindowBuffer.h); + //} + + // TODO: Add menu rendering + + //_system->copyRectToScreen(_backBuffer.getPixels(), _backBuffer.pitch, 0, 0, _backBuffer.w, _backBuffer.h); +} + +void RenderManager::clearWorkingWindowTo555Color(uint16 color) { uint32 workingWindowSize = _workingWidth * _workingHeight; + byte r, g, b; + Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0).colorToRGB(color, r, g, b); + uint16 colorIn565 = _pixelFormat.RGBToColor(r, g, b); + uint16 *bufferPtr = (uint16 *)_workingWindowBuffer.getPixels(); for (uint32 i = 0; i < workingWindowSize; i++) { - _workingWindowBuffer[i] = color; + bufferPtr[i] = color; } - - _system->copyRectToScreen(_workingWindowBuffer, _workingWidth * sizeof(uint16), _workingWindow.left, _workingWindow.top, _workingWidth, _workingHeight); } void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 destinationX, int16 destinationY, bool wrap) { @@ -136,13 +153,7 @@ void RenderManager::renderSubRectToScreen(Graphics::Surface &surface, int16 dest if (!subRect.isValidRect() || subRect.isEmpty()) return; - if (_renderTable.getRenderState() == RenderTable::FLAT) { - _system->copyRectToScreen(surface.getBasePtr(subRect.left, subRect.top), surface.pitch, destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); - } else { - _renderTable.mutateImage((uint16 *)surface.getPixels(), _workingWindowBuffer, surface.w, surface.h, destinationX, destinationY, subRect, wrap); - - _system->copyRectToScreen(_workingWindowBuffer, _workingWidth * sizeof(uint16), destinationX + _workingWindow.left, destinationY + _workingWindow.top, subRect.width(), subRect.height()); - } + _system->copyRectToScreen(surface.getBasePtr(subRect.left, subRect.top), surface.pitch, destinationX, destinationY, subRect.width(), subRect.height()/*, wrap*/); } void RenderManager::renderImageToScreen(const Common::String &fileName, int16 destinationX, int16 destinationY, bool wrap) { @@ -250,6 +261,44 @@ void RenderManager::readImageToSurface(const Common::String &fileName, Graphics: destination.convertToInPlace(_pixelFormat); } +void RenderManager::renderRectToWorkingWindow(uint16 *buffer, int32 destX, int32 destY, int32 width, int32 height, bool wrap) { + uint32 destOffset = 0; + uint16 *workingWindowBufferPtr = (uint16 *)_workingWindowBuffer.getBasePtr(destX, destY); + + for (int32 y = 0; y < height; y++) { + for (int32 x = 0; x < width; x++) { + int32 sourceYIndex = y; + int32 sourceXIndex = x; + + if (wrap) { + while (sourceXIndex >= width) { + sourceXIndex -= width; + } + while (sourceXIndex < 0) { + sourceXIndex += width; + } + + while (sourceYIndex >= height) { + sourceYIndex -= height; + } + while (sourceYIndex < 0) { + sourceYIndex += height; + } + } else { + // Clamp the yIndex to the size of the image + sourceYIndex = CLIP<int16>(sourceYIndex, 0, height - 1); + + // Clamp the xIndex to the size of the image + sourceXIndex = CLIP<int16>(sourceXIndex, 0, width - 1); + } + + workingWindowBufferPtr[destOffset + x] = buffer[sourceYIndex * width + sourceXIndex]; + } + + destOffset += _workingWidth; + } +} + const Common::Point RenderManager::screenSpaceToImageSpace(const Common::Point &point) { // Convert from screen space to working window space Common::Point newPoint(point - Common::Point(_workingWindow.left, _workingWindow.top)); diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 1dcbf76d8c..bf44c884e8 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -45,7 +45,7 @@ namespace ZVision { class RenderManager { public: - RenderManager(OSystem *system, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat); + RenderManager(OSystem *system, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat); ~RenderManager(); private: @@ -54,7 +54,8 @@ private: // A buffer the exact same size as the workingWindow // It's used for panorama/tilt warping and for clearing the workingWindow to a single color - uint16 *_workingWindowBuffer; + Graphics::Surface _workingWindowBuffer; + Graphics::Surface _backBuffer; /** Width of the working window. Saved to prevent extraneous calls to _workingWindow.width() */ const int _workingWidth; @@ -90,9 +91,6 @@ private: /** Holds any 'leftover' milliseconds between frames */ uint _accumulatedVelocityMilliseconds; - // TODO: Potentially merge this buffer and _workingWindowBuffer - byte *_scaledVideoFrameBuffer; - public: void initialize(); /** @@ -103,11 +101,16 @@ public: void update(uint deltaTimeInMillis); /** + * Renders the current state of the backbuffer to the screen + */ + void renderBackbufferToScreen(); + + /** * Fills the entire workingWindow with the specified color * * @param color The color to fill the working window with. (In RGB 555) */ - void clearWorkingWindowToColor(uint16 color); + void clearWorkingWindowTo555Color(uint16 color); /** * Blits the image or a portion of the image to the backbuffer. Actual screen updates won't happen until the end of the frame. @@ -186,6 +189,8 @@ private: void readImageToSurface(const Common::String &fileName, Graphics::Surface &destination); + void renderRectToWorkingWindow(uint16 *buffer, int32 x, int32 y, int32 width, int32 height, bool wrap); + void moveBackground(int offset); }; diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index 5fd7a16cac..c72775b1ab 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -100,45 +100,29 @@ uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { return returnColor; } -void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap) { - for (int16 y = subRect.top; y < subRect.bottom; y++) { - int16 normalizedY = y - subRect.top; - int32 internalColumnIndex = (normalizedY + destinationY) * _numColumns; - int32 destColumnIndex = normalizedY * _numColumns; +void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint16 destWidth) { + uint32 destColumnOffset = 0; - for (int16 x = subRect.left; x < subRect.right; x++) { - int16 normalizedX = x - subRect.left; + for (int16 y = 0; y < _numRows; y++) { + int32 sourceColumnOffset = y * _numColumns; - int32 index = internalColumnIndex + normalizedX + destinationX; + for (int16 x = 0; x < _numColumns; x++) { + int32 index = sourceColumnOffset + x; // RenderTable only stores offsets from the original coordinates - int16 sourceYIndex = y + _internalBuffer[index].y; - int16 sourceXIndex = x + _internalBuffer[index].x; - - if (wrap) { - while (sourceXIndex >= imageWidth) { - sourceXIndex -= imageWidth; - } - while (sourceXIndex < 0) { - sourceXIndex += imageWidth; - } - - while (sourceYIndex >= imageHeight) { - sourceYIndex -= imageHeight; - } - while (sourceYIndex < 0) { - sourceYIndex += imageHeight; - } - } else { - // Clamp the yIndex to the size of the image - sourceYIndex = CLIP<int16>(sourceYIndex, 0, imageHeight - 1); - - // Clamp the xIndex to the size of the image - sourceXIndex = CLIP<int16>(sourceXIndex, 0, imageWidth - 1); - } + int32 sourceYIndex = y + _internalBuffer[index].y; + int32 sourceXIndex = x + _internalBuffer[index].x; + + // Clamp the yIndex to the size of the image + sourceYIndex = CLIP<int32>(sourceYIndex, 0, _numRows - 1); + + // Clamp the xIndex to the size of the image + sourceXIndex = CLIP<int32>(sourceXIndex, 0, _numColumns - 1); - destBuffer[destColumnIndex + normalizedX] = sourceBuffer[sourceYIndex * imageWidth + sourceXIndex]; + destBuffer[destColumnOffset + x] = sourceBuffer[sourceYIndex * _numColumns + sourceXIndex]; } + + destColumnOffset += destWidth; } } diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index e5820803cb..737fc84bfc 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, int16 imageWidth, int16 imageHeight, int16 destinationX, int16 destinationY, const Common::Rect &subRect, bool wrap); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint16 destWidth); void generateRenderTable(); void setPanoramaFoV(float fov); diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 85e357e80f..f8580703ca 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -69,7 +69,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) // Create managers _scriptManager = new ScriptManager(this); - _renderManager = new RenderManager(_system, _workingWindow, _pixelFormat); + _renderManager = new RenderManager(_system, WINDOW_WIDTH, WINDOW_HEIGHT, _workingWindow, _pixelFormat); debug("ZVision::ZVision"); } @@ -141,6 +141,9 @@ Common::Error ZVision::run() { _renderManager->update(deltaTime); _scriptManager->update(deltaTime); + // Render the backBuffer to the screen + _renderManager->renderBackbufferToScreen(); + // Update the screen _system->updateScreen(); |