aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/mutationofjb/game.cpp11
-rw-r--r--engines/mutationofjb/module.mk1
-rw-r--r--engines/mutationofjb/tasks/objectanimationtask.cpp91
-rw-r--r--engines/mutationofjb/tasks/objectanimationtask.h47
-rw-r--r--engines/mutationofjb/tasks/saytask.cpp2
-rw-r--r--engines/mutationofjb/tasks/saytask.h5
-rw-r--r--engines/mutationofjb/timer.cpp2
-rw-r--r--engines/mutationofjb/timer.h2
8 files changed, 155 insertions, 6 deletions
diff --git a/engines/mutationofjb/game.cpp b/engines/mutationofjb/game.cpp
index 0cb6f53fe1..652336fff2 100644
--- a/engines/mutationofjb/game.cpp
+++ b/engines/mutationofjb/game.cpp
@@ -21,16 +21,19 @@
*/
#include "mutationofjb/game.h"
-#include "mutationofjb/gamedata.h"
+
+#include "mutationofjb/commands/command.h"
#include "mutationofjb/encryptedfile.h"
+#include "mutationofjb/gamedata.h"
#include "mutationofjb/mutationofjb.h"
#include "mutationofjb/room.h"
#include "mutationofjb/script.h"
+#include "mutationofjb/tasks/objectanimationtask.h"
#include "mutationofjb/util.h"
-#include "mutationofjb/commands/command.h"
-#include "common/util.h"
+
#include "common/str.h"
#include "common/translation.h"
+#include "common/util.h"
namespace MutationOfJB {
@@ -57,6 +60,8 @@ Game::Game(MutationOfJBEngine *vm)
_room = new Room(this, _vm->getScreen());
_gui.init();
+
+ _taskManager.addTask(new ObjectAnimationTask);
}
Common::RandomSource &Game::getRandomSource() {
diff --git a/engines/mutationofjb/module.mk b/engines/mutationofjb/module.mk
index 2ac4fabbdb..1913fc62cd 100644
--- a/engines/mutationofjb/module.mk
+++ b/engines/mutationofjb/module.mk
@@ -23,6 +23,7 @@ MODULE_OBJS := \
commands/talkcommand.o \
commands/randomcommand.o \
tasks/conversationtask.o \
+ tasks/objectanimationtask.o \
tasks/saytask.o \
tasks/taskmanager.o \
widgets/buttonwidget.o \
diff --git a/engines/mutationofjb/tasks/objectanimationtask.cpp b/engines/mutationofjb/tasks/objectanimationtask.cpp
new file mode 100644
index 0000000000..75c15bf624
--- /dev/null
+++ b/engines/mutationofjb/tasks/objectanimationtask.cpp
@@ -0,0 +1,91 @@
+/* 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/tasks/objectanimationtask.h"
+
+#include "mutationofjb/tasks/taskmanager.h"
+#include "mutationofjb/game.h"
+#include "mutationofjb/gamedata.h"
+#include "mutationofjb/room.h"
+
+namespace MutationOfJB {
+
+static const int TICK_MILLIS = 100;
+
+ObjectAnimationTask::ObjectAnimationTask() : _timer(TICK_MILLIS) {
+}
+
+void ObjectAnimationTask::start() {
+ setState(RUNNING);
+ _timer.start();
+}
+
+void ObjectAnimationTask::update() {
+ _timer.update();
+ if (_timer.isFinished()) {
+ _timer.start();
+ updateObjects();
+ }
+}
+
+void ObjectAnimationTask::updateObjects() {
+ Scene *const scene = getTaskManager()->getGame().getGameData().getCurrentScene();
+ if (!scene) {
+ return;
+ }
+
+ for (uint8 i = 1; i <= scene->getNoObjects(); ++i) {
+ Object *const object = scene->getObject(i);
+ // Skip if object animation not active.
+ if (!object->_AC)
+ continue;
+
+ // Number of framers must be higher than 1.
+ if (object->_NA <= 1)
+ continue;
+
+ const uint8 currentAnimOffset = object->_CA - object->_FA;
+
+ const bool randomized = object->_FR != 0;
+ const bool belowRandomFrame = currentAnimOffset < (object->_FR - 1);
+
+ uint8 maxAnimOffset = object->_NA - 1;
+ if (randomized && belowRandomFrame) {
+ maxAnimOffset = object->_FR - 2;
+ }
+
+ uint8 nextAnimationOffset = currentAnimOffset + 1;
+ if (currentAnimOffset == maxAnimOffset) {
+ if (randomized && object->_unknown != 0 && getTaskManager()->getGame().getRandomSource().getRandomNumber(object->_unknown) == 0)
+ nextAnimationOffset = object->_FR - 1;
+ else
+ nextAnimationOffset = 0;
+ }
+
+ // TODO: Hardcoded animations.
+
+ object->_CA = nextAnimationOffset + object->_FA;
+ getTaskManager()->getGame().getRoom().drawObjectAnimation(i, nextAnimationOffset);
+ }
+}
+
+}
diff --git a/engines/mutationofjb/tasks/objectanimationtask.h b/engines/mutationofjb/tasks/objectanimationtask.h
new file mode 100644
index 0000000000..39f80a3a51
--- /dev/null
+++ b/engines/mutationofjb/tasks/objectanimationtask.h
@@ -0,0 +1,47 @@
+/* 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_OBJECTANIMATIONTASK_H
+#define MUTATIONOFJB_OBJECTANIMATIONTASK_H
+
+#include "mutationofjb/tasks/task.h"
+
+#include "mutationofjb/timer.h"
+
+namespace MutationOfJB {
+
+class ObjectAnimationTask : public Task {
+public:
+ ObjectAnimationTask();
+
+ virtual void start() override;
+ virtual void update() override;
+
+ void updateObjects();
+
+private:
+ Timer _timer;
+};
+
+}
+
+#endif
diff --git a/engines/mutationofjb/tasks/saytask.cpp b/engines/mutationofjb/tasks/saytask.cpp
index fcef6c3211..c9c2a95ad8 100644
--- a/engines/mutationofjb/tasks/saytask.cpp
+++ b/engines/mutationofjb/tasks/saytask.cpp
@@ -45,7 +45,7 @@ void SayTask::start() {
void SayTask::update() {
_timer.update();
- if (_timer.isFnished()) {
+ if (_timer.isFinished()) {
getTaskManager()->getGame().getRoom().redraw(); // TODO: Only redraw the area occupied by the text.
setState(FINISHED);
return;
diff --git a/engines/mutationofjb/tasks/saytask.h b/engines/mutationofjb/tasks/saytask.h
index ef66f5beb4..17e773defc 100644
--- a/engines/mutationofjb/tasks/saytask.h
+++ b/engines/mutationofjb/tasks/saytask.h
@@ -20,6 +20,9 @@
*
*/
+#ifndef MUTATIONOFJB_SAYTASK_H
+#define MUTATIONOFJB_SAYTASK_H
+
#include "mutationofjb/tasks/task.h"
#include "mutationofjb/timer.h"
@@ -46,3 +49,5 @@ private:
};
}
+
+#endif
diff --git a/engines/mutationofjb/timer.cpp b/engines/mutationofjb/timer.cpp
index 8375445c08..d5a306aaff 100644
--- a/engines/mutationofjb/timer.cpp
+++ b/engines/mutationofjb/timer.cpp
@@ -34,7 +34,7 @@ void Timer::start() {
_state = RUNNING;
}
-bool Timer::isFnished() const {
+bool Timer::isFinished() const {
return _state == FINISHED;
}
diff --git a/engines/mutationofjb/timer.h b/engines/mutationofjb/timer.h
index b12fe2278c..313823af89 100644
--- a/engines/mutationofjb/timer.h
+++ b/engines/mutationofjb/timer.h
@@ -30,7 +30,7 @@ public:
void start();
- bool isFnished() const;
+ bool isFinished() const;
bool isRunning() const;
void update();