Skip to content

Commit

Permalink
ZVISION: Animation nodes now scaleable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisa-Chan committed Nov 24, 2013
1 parent f877410 commit 4cb006f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 9 deletions.
4 changes: 2 additions & 2 deletions engines/zvision/actions.cpp
Expand Up @@ -361,7 +361,7 @@ ActionPlayAnimation::ActionPlayAnimation(ZVision *engine, const Common::String &
// The two %*u are always 0 and dont seem to have a use
sscanf(line.c_str(),
"%*[^:]:%*[^:]:%u(%25s %u %u %u %u %u %u %d %*u %*u %d %d)",
&_key, fileName, &_x, &_y, &_width, &_height, &_start, &_end, &_loopCount, &_mask, &_framerate);
&_key, fileName, &_x, &_y, &_x2, &_y2, &_start, &_end, &_loopCount, &_mask, &_framerate);

if (_mask > 0) {
byte r, g, b;
Expand All @@ -386,7 +386,7 @@ bool ActionPlayAnimation::execute() {
nod->stop();

if (nod)
nod->addPlayNode(_key, _x, _y, _width, _height, _start, _end, _loopCount);
nod->addPlayNode(_key, _x, _y, _x2, _y2, _start, _end, _loopCount);

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions engines/zvision/actions.h
Expand Up @@ -257,8 +257,8 @@ class ActionPlayAnimation : public ResultAction {
Common::String _fileName;
uint32 _x;
uint32 _y;
uint32 _width;
uint32 _height;
uint32 _x2;
uint32 _y2;
uint32 _start;
uint32 _end;
int32 _mask;
Expand Down
45 changes: 41 additions & 4 deletions engines/zvision/animation_node.cpp
Expand Up @@ -69,9 +69,13 @@ AnimationNode::~AnimationNode() {
_engine->getScriptManager()->setStateValue(_key, 2);

PlayNodes::iterator it = _playList.begin();
if (it != _playList.end())
if (it != _playList.end()) {
_engine->getScriptManager()->setStateValue((*it).slot, 2);

if ((*it)._scaled)
delete(*it)._scaled;
}

_playList.clear();
}

Expand Down Expand Up @@ -108,6 +112,8 @@ bool AnimationNode::process(uint32 deltaTimeInMillis) {
if (nod->loop == 0) {
if (nod->slot >= 0)
_engine->getScriptManager()->setStateValue(nod->slot, 2);
if (nod->_scaled)
delete nod->_scaled;
_playList.erase(it);
return _DisposeAfterUse;
}
Expand All @@ -129,6 +135,33 @@ bool AnimationNode::process(uint32 deltaTimeInMillis) {
}

if (frame) {

uint32 dstw;
uint32 dsth;
if (_engine->getRenderManager()->getRenderTable()->getRenderState() == RenderTable::PANORAMA) {
dstw = nod->pos.height();
dsth = nod->pos.width();
} else {
dstw = nod->pos.width();
dsth = nod->pos.height();
}

if (frame->w != dstw || frame->h != dsth) {
if (nod->_scaled)
if (nod->_scaled->w != dstw || nod->_scaled->h != dsth) {
delete nod->_scaled;
nod->_scaled = NULL;
}

if (!nod->_scaled) {
nod->_scaled = new Graphics::Surface;
nod->_scaled->create(dstw, dsth, frame->format);
}

_engine->getRenderManager()->scaleBuffer(frame->getPixels(), nod->_scaled->getPixels(), frame->w, frame->h, frame->format.bytesPerPixel, dstw, dsth);
frame = nod->_scaled;
}

if (_engine->getRenderManager()->getRenderTable()->getRenderState() == RenderTable::PANORAMA) {
Graphics::Surface *transposed = RenderManager::tranposeSurface(frame);
if (_mask > 0)
Expand All @@ -151,22 +184,26 @@ bool AnimationNode::process(uint32 deltaTimeInMillis) {



void AnimationNode::addPlayNode(int32 slot, int x, int y, int w, int h, int start_frame, int end_frame, int loops) {
void AnimationNode::addPlayNode(int32 slot, int x, int y, int x2, int y2, int start_frame, int end_frame, int loops) {
playnode nod;
nod.loop = loops;
nod.pos = Common::Rect(x, y, x + w - 1, y + h - 1);
nod.pos = Common::Rect(x, y, x2 + 1, y2 + 1);
nod.start = start_frame;
nod.stop = end_frame;
nod.slot = slot;
nod._cur_frm = -1;
nod._delay = 0;
nod._scaled = NULL;
_playList.push_back(nod);
}

bool AnimationNode::stop() {
PlayNodes::iterator it = _playList.begin();
if (it != _playList.end())
if (it != _playList.end()) {
_engine->getScriptManager()->setStateValue((*it).slot, 2);
if ((*it)._scaled)
delete(*it)._scaled;
}

_playList.clear();

Expand Down
3 changes: 2 additions & 1 deletion engines/zvision/animation_node.h
Expand Up @@ -58,6 +58,7 @@ class AnimationNode : public SideFX {
int32 loop;
int32 _cur_frm;
int32 _delay;
Graphics::Surface *_scaled;
};

private:
Expand All @@ -84,7 +85,7 @@ class AnimationNode : public SideFX {
public:
bool process(uint32 deltaTimeInMillis);

void addPlayNode(int32 slot, int x, int y, int w, int h, int start_frame, int end_frame, int loops = 1);
void addPlayNode(int32 slot, int x, int y, int x2, int y2, int start_frame, int end_frame, int loops = 1);

bool stop();
};
Expand Down
27 changes: 27 additions & 0 deletions engines/zvision/render_manager.cpp
Expand Up @@ -694,4 +694,31 @@ Graphics::Surface *RenderManager::tranposeSurface(const Graphics::Surface *surfa
return tranposedSurface;
}

void RenderManager::scaleBuffer(const void *src, void *dst, uint32 srcWidth, uint32 srcHeight, byte bytesPerPixel, uint32 dstWidth, uint32 dstHeight) {
assert(bytesPerPixel == 1 || bytesPerPixel == 2);

const float xscale = (float)srcWidth / (float)dstWidth;
const float yscale = (float)srcHeight / (float)dstHeight;

if (bytesPerPixel == 1) {
const byte *srcPtr = (const byte *)src;
byte *dstPtr = (byte *)dst;
for (uint32 y = 0; y < dstHeight; ++y) {
for (uint32 x = 0; x < dstWidth; ++x) {
*dstPtr = srcPtr[(int)(x * xscale) + (int)(y * yscale) * srcWidth];
dstPtr++;
}
}
} else if (bytesPerPixel == 2) {
const uint16 *srcPtr = (const uint16 *)src;
uint16 *dstPtr = (uint16 *)dst;
for (uint32 y = 0; y < dstHeight; ++y) {
for (uint32 x = 0; x < dstWidth; ++x) {
*dstPtr = srcPtr[(int)(x * xscale) + (int)(y * yscale) * srcWidth];
dstPtr++;
}
}
}
}

} // End of namespace ZVision
2 changes: 2 additions & 0 deletions engines/zvision/render_manager.h
Expand Up @@ -367,6 +367,8 @@ class RenderManager {
*/
static Graphics::Surface *tranposeSurface(const Graphics::Surface *surface);

void scaleBuffer(const void *src, void *dst, uint32 srcWidth, uint32 srcHeight, byte bytesPerPixel, uint32 dstWidth, uint32 dstHeight);

private:
/**
* Renders a subRectangle of an image to the backbuffer. The destinationRect and SubRect
Expand Down

0 comments on commit 4cb006f

Please sign in to comment.