diff options
author | richiesams | 2013-07-24 11:33:58 -0500 |
---|---|---|
committer | richiesams | 2013-08-04 13:32:34 -0500 |
commit | ed4490730902780923bf1e91ed3617d56efb7c24 (patch) | |
tree | 0ce96cdfad9a0d858309e2e94d0554ab251db891 | |
parent | cd51b646f39fb826f5d618c6d61c996844f628dd (diff) | |
download | scummvm-rg350-ed4490730902780923bf1e91ed3617d56efb7c24.tar.gz scummvm-rg350-ed4490730902780923bf1e91ed3617d56efb7c24.tar.bz2 scummvm-rg350-ed4490730902780923bf1e91ed3617d56efb7c24.zip |
ZVISION: Move rendering logic from ZVision class to RenderManager class
-rw-r--r-- | engines/zvision/events.cpp | 11 | ||||
-rw-r--r-- | engines/zvision/render_manager.cpp | 60 | ||||
-rw-r--r-- | engines/zvision/render_manager.h | 77 | ||||
-rw-r--r-- | engines/zvision/video.cpp | 26 | ||||
-rw-r--r-- | engines/zvision/zvision.cpp | 23 | ||||
-rw-r--r-- | engines/zvision/zvision.h | 10 |
6 files changed, 101 insertions, 106 deletions
diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index afa2d95207..a01ea74cd0 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -27,6 +27,7 @@ #include "common/events.h" #include "engines/util.h" +#include "zvision/render_manager.h" namespace ZVision { @@ -61,13 +62,9 @@ void ZVision::processEvents() { quitGame(); break; case Common::KEYCODE_ESCAPE: - if (_currentVideo != 0) { - initGraphics(_width, _height, true, &_pixelFormat); - delete _currentVideo; - _currentVideo = 0; - delete[] _scaledVideoFrameBuffer; - _scaledVideoFrameBuffer = 0; - } + if (_renderManager->isVideoPlaying()) + _renderManager->cancelVideo(); + break; default: break; diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 2a8ed1274e..8c3d37a160 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -24,8 +24,8 @@ #include "common/file.h" #include "common/system.h" -#include "common/rect.h" +#include "engines/util.h" #include "graphics/decoders/tga.h" #include "zvision/render_manager.h" @@ -37,9 +37,29 @@ RenderManager::RenderManager(OSystem *system, const int width, const int height) : _system(system), _width(width), _height(height), + _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), // RGB555 + _currentVideo(0), + _scaledVideoFrameBuffer(0), _renderTable(width, height) { } +/** + * Initialize graphics + */ +void RenderManager::initialize() { + initGraphics(_width, _height, true, &_pixelFormat); +} + +void RenderManager::updateScreen(bool isConsoleActive) { + if (_currentVideo != 0) + continueVideo(); + + if (_needsScreenUpdate || isConsoleActive) { + _system->updateScreen(); + _needsScreenUpdate = false; + } +} + void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y) { Common::File file; @@ -86,40 +106,8 @@ void RenderManager::renderImageToScreen(const Common::String &fileName, uint32 x _needsScreenUpdate = true; } -void RenderManager::generatePanoramaLookupTable() { - float fieldOfView = _panoramaOptions.fieldOfView; - float scale = _panoramaOptions.linearScale; - _renderTable.clear(); - - double halfWidth = (double)_width / 2.0; - double halfHeight = (double)_height / 2.0; - - double fovRadians = (fieldOfView * 3.14159265 / 180.0); - double halfHeightOverTan = halfHeight / tan(fovRadians); - double tanOverHalfHeight = tan(fovRadians) / halfHeight; - - for (int32 x = 0; x < _width; x++) { - // Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen) - double xPos = (double)x - halfWidth + 0.01; - - double tempX = atan(xPos*tanOverHalfHeight); - double scaledX = scale * halfHeightOverTan * tempX; - double nn = cos(tempX); - double newHalfWidth = halfHeight * nn * halfHeightOverTan * tanOverHalfHeight*2.0; - - int32 newX = floor(scaledX);// + half_w); - - double yScale = newHalfWidth / (double)_height; - double et2 = ((double)_height - newHalfWidth) / 2.0; - - for (int32 y = 0; y < _height; y++) { - double et1 = (double)y*yScale; - - _renderTable(x, y).x = newX; //pixel index - - int32 newY = floor(et2 + et1); - _renderTable(x, y).y = newY; //pixel index - } - } +void RenderManager::setRenderState(RenderTable::RenderState state) { + _renderTable.setRenderState(state); } + } // End of namespace ZVision diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index e481c26666..f2f1dd72e4 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -24,14 +24,20 @@ #define ZVISION_RENDER_MANAGER_H #include "common/types.h" +#include "common/rect.h" -#include "zvision/dense_2d_array.h" +#include "graphics/pixelformat.h" + +#include "zvision/render_table.h" class OSystem; namespace Common { class String; -class Point; +} + +namespace Video { +class VideoDecoder; } namespace ZVision { @@ -40,37 +46,62 @@ class RenderManager { public: RenderManager(OSystem *system, const int width, const int height); -public: - enum RenderState { - PANORAMA, - TILT, - FLAT - }; - private: OSystem *_system; const int _width; const int _height; - RenderState _renderState; - - struct { - uint16 fieldOfView; - uint16 linearScale; - } _panoramaOptions; + const Graphics::PixelFormat _pixelFormat; + RenderTable _renderTable; - // TODO: See if tilt and panorama need to have separate options - struct { - uint16 fieldOfView; - uint16 linearScale; - } _tiltOptions; - - Dense2DArray<Common::Point> _renderTable; + Video::VideoDecoder *_currentVideo; + byte *_scaledVideoFrameBuffer; bool _needsScreenUpdate; public: + void initialize(); + void updateScreen(bool isConsoleActive); + + /** + * Start a video playing. It will also load the first frame of the video. + * + * @param videoDecoder The video to play + */ + void startVideo(Video::VideoDecoder *videoDecoder); + /** + * @return Is a video currently being played + */ + bool isVideoPlaying() { return _currentVideo == 0; } + /** + * Cancels a video prematurely. Any sound remaining in the queue will continue to play. + * The last frame of the video will remain on the screen until something else overwrites it + */ + void cancelVideo(); + + /** + * Blits the image to the screen. Actual screen updates won't happen until the end of the frame. + * The image will be clipped to fit inside the window. + * + * @param fileName Name of the image file + * @param x X position where the image should be put + * @param y Y position where the image should be put + */ void renderImageToScreen(const Common::String &fileName, uint32 x, uint32 y); - void generatePanoramaLookupTable(); + + /** + * Set how the frame should be rendered + * + * @param state One of the RenderStates + */ + void setRenderState(RenderTable::RenderState state); + + bool needsScreenUpdate() { return _needsScreenUpdate; }; + +private: + /** + * Checks the time since the last video frame, and blits the next frame to the screen + */ + void continueVideo(); }; } // End of namespace ZVision diff --git a/engines/zvision/video.cpp b/engines/zvision/video.cpp index 0428090003..c0b575b23b 100644 --- a/engines/zvision/video.cpp +++ b/engines/zvision/video.cpp @@ -23,11 +23,11 @@ #include "common/scummsys.h" #include "common/system.h" +#include "video/video_decoder.h" #include "engines/util.h" - #include "graphics/surface.h" -#include "zvision/zvision.h" +#include "zvision/render_manager.h" namespace ZVision { @@ -71,7 +71,7 @@ void scale2x(const byte *src, byte *dst, int16 srcWidth, int16 srcHeight, byte b } } -void ZVision::startVideo(Video::VideoDecoder *videoDecoder) { +void RenderManager::startVideo(Video::VideoDecoder *videoDecoder) { if (!videoDecoder) return; @@ -89,12 +89,7 @@ void ZVision::startVideo(Video::VideoDecoder *videoDecoder) { continueVideo(); } -void ZVision::continueVideo() { - if (_currentVideo == 0) { - warning("No video loaded. Nothing to continue"); - return; - } - +void RenderManager::continueVideo() { byte bytesPerPixel = _currentVideo->getPixelFormat().bytesPerPixel; uint16 width = _currentVideo->getWidth(); uint16 height = _currentVideo->getHeight(); @@ -115,13 +110,16 @@ void ZVision::continueVideo() { } } } else { - initGraphics(_width, _height, true, &_pixelFormat); - delete _currentVideo; - _currentVideo = 0; - delete[] _scaledVideoFrameBuffer; - _scaledVideoFrameBuffer = 0; + cancelVideo(); } +} +void RenderManager::cancelVideo() { + initGraphics(_width, _height, true, &_pixelFormat); + delete _currentVideo; + _currentVideo = 0; + delete[] _scaledVideoFrameBuffer; + _scaledVideoFrameBuffer = 0; } } // End of namespace ZVision diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 57c9dea211..8cd7343368 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -46,9 +46,6 @@ namespace ZVision { ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc), - _pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), // RGB555 - _currentVideo(0), - _scaledVideoFrameBuffer(0), _width(640), _height(480) { // Put your engine in a sane state, but do nothing big yet; @@ -104,7 +101,7 @@ void ZVision::initialize() { SearchMan.add(name, archive); } - initGraphics(_width, _height, true, &_pixelFormat); + _renderManager->initialize(); _scriptManager->initialize(); @@ -127,19 +124,13 @@ Common::Error ZVision::run() { uint32 deltaTime = currentTime - lastTime; lastTime = currentTime; - if (_currentVideo != 0) - continueVideo(); - else { - _scriptManager->updateNodes(deltaTime); - _scriptManager->checkPuzzleCriteria(); - } - - if (_needsScreenUpdate || _console->isActive()) { - _system->updateScreen(); - _needsScreenUpdate = false; - } + _scriptManager->updateNodes(deltaTime); + _scriptManager->checkPuzzleCriteria(); + + // Render a frame + _renderManager->updateScreen(_console->isActive()); - // Calculate the frame delay based off a desired frame rate + // Calculate the frame delay based off a desired frame time int delay = desiredFrameTime - (currentTime - _system->getMillis()); // Ensure non-negative delay = delay < 0 ? 0 : delay; diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 7740dba6dc..2e6ec11a53 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -27,8 +27,6 @@ #include "common/random.h" #include "common/events.h" -#include "video/video_decoder.h" - #include "engines/engine.h" #include "zvision/detection.h" @@ -58,7 +56,6 @@ public: private: Console *_console; const ZVisionGameDescription *_gameDescription; - const Graphics::PixelFormat _pixelFormat; const int _width; const int _height; @@ -71,10 +68,6 @@ private: // To prevent allocation every time we process events Common::Event _event; - bool _needsScreenUpdate; - - Video::VideoDecoder *_currentVideo; - byte *_scaledVideoFrameBuffer; public: uint32 getFeatures() const; Common::Language getLanguage() const; @@ -84,9 +77,6 @@ public: Common::RandomSource *getRandomSource() const; ZVisionGameId getGameId() const; - void startVideo(Video::VideoDecoder *videoDecoder); - void continueVideo(); - private: void initialize(); |