Permalink
Browse files

MUTATIONOFJB: Add support for SETANIM command.

  • Loading branch information...
LubomirR committed Jan 12, 2019
1 parent 9d5bfdd commit a97a14cc8918c7b60d94ec07ca4b214f3a7a2c93
@@ -0,0 +1,63 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "mutationofjb/commands/setobjectframecommand.h"
#include "mutationofjb/game.h"
#include "mutationofjb/gamedata.h"
#include "mutationofjb/room.h"
#include "mutationofjb/script.h"

/** @file
* "SETANIM " <objectId> " " <frame>
*
* Sets the frame for the specified object and redraws it.
* If the object is active, it is deactivated.
*/

namespace MutationOfJB {

bool SetObjectFrameCommandParser::parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) {
if (line.size() < 13 || !line.hasPrefix("SETANIM "))
return false;

const uint8 objectId = (uint8) atoi(line.c_str() + 8);
const uint8 frame = (uint8) atoi(line.c_str() + 11);

command = new SetObjectFrameCommand(objectId, frame);
return true;
}


Command::ExecuteResult SetObjectFrameCommand::execute(ScriptExecutionContext &scriptExecCtx) {
Object *const object = scriptExecCtx.getGameData().getCurrentScene()->getObject(_objectId);

object->_active = 0;
scriptExecCtx.getGame().getRoom().drawObject(_objectId);

return Finished;
}

Common::String SetObjectFrameCommand::debugString() const {
return Common::String::format("SETOBJECTFRAME %u %u", (unsigned int) _objectId, (unsigned int) _frame);
}

}
@@ -0,0 +1,51 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#ifndef MUTATIONOFJB_SETOBJECTFRAMECOMMAND_H
#define MUTATIONOFJB_SETOBJECTFRAMECOMMAND_H

#include "mutationofjb/commands/seqcommand.h"
#include "common/str.h"

namespace MutationOfJB {

class SetObjectFrameCommandParser : public SeqCommandParser {
public:
SetObjectFrameCommandParser() {}

virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command);
};

class SetObjectFrameCommand : public SeqCommand {
public:
SetObjectFrameCommand(uint8 objectId, uint8 frame) : _objectId(objectId), _frame(frame) {}

virtual ExecuteResult execute(ScriptExecutionContext &scriptExecCtx) override;
virtual Common::String debugString() const override;
private:
uint8 _objectId;
uint8 _frame;
};

}

#endif
@@ -220,7 +220,7 @@ void GameScreen::refreshAfterSceneChanged() {
event.mouse = _game.getEngine().getEventManager()->getMousePos();
_gameWidget->handleEvent(event);

_gameWidget->markDirty();
_gameWidget->markDirty(GameWidget::DIRTY_AFTER_SCENE_CHANGE);
_gameWidget->update(*_screen); // Force immediate update.
}

@@ -24,6 +24,7 @@ MODULE_OBJS := \
commands/saycommand.o \
commands/seqcommand.o \
commands/setcolorcommand.o \
commands/setobjectframecommand.o \
commands/specialshowcommand.o \
commands/switchpartcommand.o \
commands/talkcommand.o \
@@ -144,6 +144,15 @@ void Room::drawObjectAnimation(uint8 objectId, int animOffset) {
const int animFrame = startFrame + animOffset;

blit_if(_surfaces[animFrame], *_screen, Common::Point(object->_x, object->_y), ThresholdBlitOperation());
if (!_game->isCurrentSceneMap())
blit_if(_surfaces[animFrame], _background, Common::Point(object->_x, object->_y), ThresholdBlitOperation());
}

void Room::drawObject(uint8 objectId) {
Scene *const currentScene = _game->getGameData().getCurrentScene();
Object *const object = currentScene->getObject(objectId);

drawObjectAnimation(objectId, object->_currentFrame - _objectsStart[objectId - 1] - 1);
}

void Room::drawBitmap(uint8 bitmapId) {
@@ -172,21 +181,28 @@ void Room::drawFrames(uint8 fromFrame, uint8 toFrame, const Common::Rect &area,

const Common::String fileName = Common::String::format("room%d%s.dat", gameData._currentScene, gameData._partB ? "b" : "");

AnimationDecoder decoder(fileName, *_screen);
decoder.setPartialMode(fromFrame, toFrame, area, threshold);
decoder.decode(nullptr);
if (!area.isEmpty())
_screen->getSubArea(area); // Add dirty rect.
else
_screen->makeAllDirty();
}
{
AnimationDecoder decoder(fileName, *_screen);
decoder.setPartialMode(fromFrame, toFrame, area, threshold);
decoder.decode(nullptr);
if (!area.isEmpty())
_screen->getSubArea(area); // Add dirty rect.
else
_screen->makeAllDirty();
}

void Room::redraw() {
if (!_game->isCurrentSceneMap()) {
Common::Rect rect(0, 0, GAME_AREA_WIDTH, GAME_AREA_HEIGHT);
_screen->blitFrom(_background.rawSurface(), rect, Common::Point(0, 0));
AnimationDecoder decoder(fileName, _background);
decoder.setPartialMode(fromFrame, toFrame, area, threshold);
decoder.decode(nullptr);
if (!area.isEmpty())
_screen->getSubArea(area); // Add dirty rect.
else
_screen->makeAllDirty();
}
}

void Room::initialDraw() {
Scene *const currentScene = _game->getGameData().getCurrentScene();
for (uint8 i = 0; i < currentScene->getNoObjects(); ++i) {
Object *const obj = currentScene->getObject(i + 1);
@@ -203,4 +219,13 @@ void Room::redraw() {
}
}

void Room::redraw(bool useBackgroundBuffer) {
if (useBackgroundBuffer && !_game->isCurrentSceneMap()) {
Common::Rect rect(0, 0, GAME_AREA_WIDTH, GAME_AREA_HEIGHT);
_screen->blitFrom(_background.rawSurface(), rect, Common::Point(0, 0));
} else {
initialDraw();
}
}

}
@@ -45,9 +45,11 @@ class Room {
Room(Game *game, Graphics::Screen *screen);
bool load(uint8 roomNumber, bool roomB);
void drawObjectAnimation(uint8 objectId, int animOffset);
void drawObject(uint8 objectId);
void drawBitmap(uint8 bitmapId);
void drawFrames(uint8 fromFrame, uint8 toFrame, const Common::Rect &area = Common::Rect(), uint8 threshold = 0xFF);
void redraw();
void initialDraw();
void redraw(bool useBackgroundBuffer = true);
private:
Game *_game;
Graphics::Screen *_screen;
@@ -51,6 +51,7 @@
#include "mutationofjb/commands/loadplayercommand.h"
#include "mutationofjb/commands/bitmapvisibilitycommand.h"
#include "mutationofjb/commands/playanimationcommand.h"
#include "mutationofjb/commands/setobjectframecommand.h"
#include "mutationofjb/game.h"

namespace MutationOfJB {
@@ -85,6 +86,7 @@ static CommandParser **getParsers() {
new LoadPlayerCommandParser,
new BitmapVisibilityCommandParser,
new PlayAnimationCommandParser,
new SetObjectFrameCommandParser,
nullptr
};

@@ -86,7 +86,7 @@ void ObjectAnimationTask::updateObjects() {

const bool drawObject = handleHardcodedAnimation(object);
if (drawObject) {
getTaskManager()->getGame().getRoom().drawObjectAnimation(i, nextAnimationOffset);
getTaskManager()->getGame().getRoom().drawObject(i);
}
}
}
@@ -57,6 +57,18 @@ void GameWidget::clearState() {
void GameWidget::draw(Graphics::ManagedSurface &) {
Room &room = _gui.getGame().getRoom();

// Full redraw using background buffer.
if (_dirtyBits == DIRTY_ALL) {
room.redraw();
return;
}

// Full redraw without background buffer.
if (_dirtyBits & DIRTY_AFTER_SCENE_CHANGE) {
room.redraw(false); // Don't use background buffer.
return;
}

// Only selection changed.
if (_dirtyBits & DIRTY_MAP_SELECTION) {
if (_currentMapObjectId != _nextMapObjectId) {
@@ -69,12 +81,6 @@ void GameWidget::draw(Graphics::ManagedSurface &) {
_currentMapObjectId = _nextMapObjectId;
}
}

// Full redraw.
if (_dirtyBits == DIRTY_ALL) {
room.redraw();
return;
}
}

void GameWidget::handleNormalScene(const Common::Event &event) {
@@ -48,6 +48,11 @@ class GameWidget : public Widget {
GAME_FULL_AREA_HEIGHT = 200
};

enum DirtyFlags {
DIRTY_AFTER_SCENE_CHANGE = 1 << 1,
DIRTY_MAP_SELECTION = 1 << 2
};

GameWidget(GuiScreen &gui);
void setCallback(GameWidgetCallback *callback) {
_callback = callback;
@@ -60,10 +65,6 @@ class GameWidget : public Widget {
virtual void draw(Graphics::ManagedSurface &);

private:
enum {
DIRTY_MAP_SELECTION = 1 << 1
};

/**
* Handling for normal (non-map) scenes.
*

0 comments on commit a97a14c

Please sign in to comment.