Permalink
Browse files

MUTATIONOFJB: Blit with threshold.

  • Loading branch information...
LubomirR committed Jul 21, 2018
1 parent 562e257 commit b73d1585f6430b80d6c108d469f7e2997c70578b
Showing with 49 additions and 3 deletions.
  1. +11 −3 engines/mutationofjb/room.cpp
  2. +2 −0 engines/mutationofjb/util.cpp
  3. +36 −0 engines/mutationofjb/util.h
@@ -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);
@@ -21,8 +21,10 @@
*/

#include "mutationofjb/util.h"

#include "common/str.h"
#include "common/translation.h"

#include "engines/engine.h"

namespace MutationOfJB {
@@ -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

0 comments on commit b73d158

Please sign in to comment.