[Scummvm-git-logs] scummvm master -> a97a14cc8918c7b60d94ec07ca4b214f3a7a2c93

LubomirR lubomirr at lubomirr.eu
Sat Jan 12 03:52:06 CET 2019


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a97a14cc89 MUTATIONOFJB: Add support for SETANIM command.


Commit: a97a14cc8918c7b60d94ec07ca4b214f3a7a2c93
    https://github.com/scummvm/scummvm/commit/a97a14cc8918c7b60d94ec07ca4b214f3a7a2c93
Author: Ľubomír Remák (lubomirr at lubomirr.eu)
Date: 2019-01-12T03:51:21+01:00

Commit Message:
MUTATIONOFJB: Add support for SETANIM command.

Changed paths:
  A engines/mutationofjb/commands/setobjectframecommand.cpp
  A engines/mutationofjb/commands/setobjectframecommand.h
    engines/mutationofjb/gamescreen.cpp
    engines/mutationofjb/module.mk
    engines/mutationofjb/room.cpp
    engines/mutationofjb/room.h
    engines/mutationofjb/script.cpp
    engines/mutationofjb/tasks/objectanimationtask.cpp
    engines/mutationofjb/widgets/gamewidget.cpp
    engines/mutationofjb/widgets/gamewidget.h


diff --git a/engines/mutationofjb/commands/setobjectframecommand.cpp b/engines/mutationofjb/commands/setobjectframecommand.cpp
new file mode 100644
index 0000000..54d9059
--- /dev/null
+++ b/engines/mutationofjb/commands/setobjectframecommand.cpp
@@ -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);
+}
+
+}
diff --git a/engines/mutationofjb/commands/setobjectframecommand.h b/engines/mutationofjb/commands/setobjectframecommand.h
new file mode 100644
index 0000000..b8c091b
--- /dev/null
+++ b/engines/mutationofjb/commands/setobjectframecommand.h
@@ -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
diff --git a/engines/mutationofjb/gamescreen.cpp b/engines/mutationofjb/gamescreen.cpp
index d92f418..024d7b6 100644
--- a/engines/mutationofjb/gamescreen.cpp
+++ b/engines/mutationofjb/gamescreen.cpp
@@ -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.
 }
 
diff --git a/engines/mutationofjb/module.mk b/engines/mutationofjb/module.mk
index 736e942..9e3b1d7 100644
--- a/engines/mutationofjb/module.mk
+++ b/engines/mutationofjb/module.mk
@@ -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 \
diff --git a/engines/mutationofjb/room.cpp b/engines/mutationofjb/room.cpp
index 6b868e7..e478a1c 100644
--- a/engines/mutationofjb/room.cpp
+++ b/engines/mutationofjb/room.cpp
@@ -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();
+	}
+}
+
 }
diff --git a/engines/mutationofjb/room.h b/engines/mutationofjb/room.h
index 0c29510..705e285 100644
--- a/engines/mutationofjb/room.h
+++ b/engines/mutationofjb/room.h
@@ -45,9 +45,11 @@ public:
 	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;
diff --git a/engines/mutationofjb/script.cpp b/engines/mutationofjb/script.cpp
index a931785..fc42f08 100644
--- a/engines/mutationofjb/script.cpp
+++ b/engines/mutationofjb/script.cpp
@@ -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
 	};
 
diff --git a/engines/mutationofjb/tasks/objectanimationtask.cpp b/engines/mutationofjb/tasks/objectanimationtask.cpp
index eab3d75..25b7ae1 100644
--- a/engines/mutationofjb/tasks/objectanimationtask.cpp
+++ b/engines/mutationofjb/tasks/objectanimationtask.cpp
@@ -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);
 		}
 	}
 }
diff --git a/engines/mutationofjb/widgets/gamewidget.cpp b/engines/mutationofjb/widgets/gamewidget.cpp
index 6037367..77375a7 100644
--- a/engines/mutationofjb/widgets/gamewidget.cpp
+++ b/engines/mutationofjb/widgets/gamewidget.cpp
@@ -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) {
diff --git a/engines/mutationofjb/widgets/gamewidget.h b/engines/mutationofjb/widgets/gamewidget.h
index c600d3a..29d44a6 100644
--- a/engines/mutationofjb/widgets/gamewidget.h
+++ b/engines/mutationofjb/widgets/gamewidget.h
@@ -48,6 +48,11 @@ public:
 		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 @@ protected:
 	virtual void draw(Graphics::ManagedSurface &);
 
 private:
-	enum {
-		DIRTY_MAP_SELECTION = 1 << 1
-	};
-
 	/**
 	 * Handling for normal (non-map) scenes.
 	 *





More information about the Scummvm-git-logs mailing list