diff options
author | Ľubomír Remák | 2018-07-21 17:37:23 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-25 23:12:01 +0200 |
commit | 2e656e69b3b9416f5164f0963951df203f4978e5 (patch) | |
tree | 21320d109d41d6c3acd102aaddac3599d21c1b88 /engines/mutationofjb | |
parent | 6c4ae7f19883dd7fa6de4fc3234351f1e33ba7a3 (diff) | |
download | scummvm-rg350-2e656e69b3b9416f5164f0963951df203f4978e5.tar.gz scummvm-rg350-2e656e69b3b9416f5164f0963951df203f4978e5.tar.bz2 scummvm-rg350-2e656e69b3b9416f5164f0963951df203f4978e5.zip |
MUTATIONOFJB: Blit with threshold.
Diffstat (limited to 'engines/mutationofjb')
-rw-r--r-- | engines/mutationofjb/room.cpp | 14 | ||||
-rw-r--r-- | engines/mutationofjb/util.cpp | 2 | ||||
-rw-r--r-- | engines/mutationofjb/util.h | 36 |
3 files changed, 49 insertions, 3 deletions
diff --git a/engines/mutationofjb/room.cpp b/engines/mutationofjb/room.cpp index 1da2730a48..dd9a6dbab5 100644 --- a/engines/mutationofjb/room.cpp +++ b/engines/mutationofjb/room.cpp @@ -28,6 +28,7 @@ #include "mutationofjb/gamedata.h" #include "mutationofjb/util.h" +#include "common/rect.h" #include "common/str.h" #include "common/translation.h" @@ -117,6 +118,13 @@ bool Room::load(uint8 roomNumber, bool roomB) { return decoder.decode(&callback); } +// TODO: Take the threshold value from ATN data. +struct ThresholdBlitOperation { + bool operator()(const byte /*srcColor*/, const byte destColor) { + return destColor <= 0xBF; + } +}; + void Room::drawObjectAnimation(uint8 objectId, int animOffset) { Scene *const scene = _game->getGameData().getCurrentScene(); if (!scene) { @@ -129,8 +137,8 @@ void Room::drawObjectAnimation(uint8 objectId, int animOffset) { const int startFrame = _objectsStart[objectId - 1]; const int animFrame = startFrame + animOffset; - // TODO: Threshold. - _screen->blitFrom(_surfaces[animFrame], Common::Point(object->_x, object->_y)); + + blit_if(_surfaces[animFrame], *_screen, Common::Point(object->_x, object->_y), ThresholdBlitOperation()); } void Room::redraw() { @@ -140,7 +148,7 @@ void Room::redraw() { } Scene *const currentScene = _game->getGameData().getCurrentScene(); - for (int i = 0; i < currentScene->getNoObjects(); ++i) { + for (uint8 i = 0; i < currentScene->getNoObjects(); ++i) { Object *const obj = currentScene->getObject(i + 1); if (obj->_active) { drawObjectAnimation(i + 1, obj->_currentFrame - _objectsStart[i] - 1); diff --git a/engines/mutationofjb/util.cpp b/engines/mutationofjb/util.cpp index 6d7c02a293..72d2d0f7e1 100644 --- a/engines/mutationofjb/util.cpp +++ b/engines/mutationofjb/util.cpp @@ -21,8 +21,10 @@ */ #include "mutationofjb/util.h" + #include "common/str.h" #include "common/translation.h" + #include "engines/engine.h" namespace MutationOfJB { diff --git a/engines/mutationofjb/util.h b/engines/mutationofjb/util.h index 86ee10f82e..06d1a0b2a1 100644 --- a/engines/mutationofjb/util.h +++ b/engines/mutationofjb/util.h @@ -23,15 +23,51 @@ #ifndef MUTATIONOFJB_UTIL_H #define MUTATIONOFJB_UTIL_H +#include "common/rect.h" + +#include "graphics/managed_surface.h" +#include "graphics/surface.h" + namespace Common { class String; } + namespace MutationOfJB { void reportFileMissingError(const char *fileName); Common::String toUpperCP895(const Common::String &str); +template <typename BlitOp> +void blit_if(const Graphics::Surface &src, const Common::Rect &srcRect, Graphics::ManagedSurface &dest, const Common::Point &destPos, BlitOp blitOp) { + const Common::Rect srcBounds = srcRect; + const Common::Rect destBounds(destPos.x, destPos.y, destPos.x + srcRect.width(), destPos.y + srcRect.height()); + + assert(srcRect.isValidRect()); + assert(dest.format == src.format); + + for (int y = 0; y < srcBounds.height(); ++y) { + const byte *srcP = reinterpret_cast<const byte *>(src.getBasePtr(srcBounds.left, srcBounds.top + y)); + const byte *srcEndP = srcP + srcBounds.width(); + byte *destP = reinterpret_cast<byte *>(dest.getBasePtr(destBounds.left, destBounds.top + y)); + + while (srcP != srcEndP) { + if (blitOp(*srcP, *destP)) { + *destP = *srcP; + } + ++srcP; + ++destP; + } + } + + dest.getSubArea(destBounds); // This is a hack to invalidate the destination rectangle. +} + +template <typename BlitOp> +void blit_if(const Graphics::Surface &src, Graphics::ManagedSurface &dest, const Common::Point &destPos, BlitOp blitOp) { + blit_if(src, Common::Rect(0, 0, src.w, src.h), dest, destPos, blitOp); +} + } #endif |