aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/bladerunner/bladerunner.cpp17
-rw-r--r--engines/bladerunner/bladerunner.h6
-rw-r--r--engines/bladerunner/module.mk2
-rw-r--r--engines/bladerunner/mouse.cpp250
-rw-r--r--engines/bladerunner/mouse.h63
-rw-r--r--engines/bladerunner/shape.cpp132
-rw-r--r--engines/bladerunner/shape.h54
7 files changed, 522 insertions, 2 deletions
diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp
index 13ccae7fed..aa2850a1c9 100644
--- a/engines/bladerunner/bladerunner.cpp
+++ b/engines/bladerunner/bladerunner.cpp
@@ -28,19 +28,22 @@
#include "bladerunner/audio_speech.h"
#include "bladerunner/chapters.h"
#include "bladerunner/clues.h"
-#include "bladerunner/gameinfo.h"
#include "bladerunner/gameflags.h"
+#include "bladerunner/gameinfo.h"
#include "bladerunner/image.h"
+#include "bladerunner/mouse.h"
#include "bladerunner/outtake.h"
#include "bladerunner/scene.h"
#include "bladerunner/script/init.h"
#include "bladerunner/script/script.h"
#include "bladerunner/settings.h"
+#include "bladerunner/shape.h"
#include "bladerunner/slice_animations.h"
#include "bladerunner/slice_renderer.h"
#include "bladerunner/text_resource.h"
#include "bladerunner/vqa_decoder.h"
+#include "common/array.h"
#include "common/error.h"
#include "common/events.h"
#include "common/system.h"
@@ -66,6 +69,7 @@ BladeRunnerEngine::BladeRunnerEngine(OSystem *syst)
_gameInfo = nullptr;
_gameFlags = new GameFlags();
_gameVars = nullptr;
+ _mouse = new Mouse(this);
_scene = new Scene(this);
_script = new Script(this);
_settings = new Settings(this);
@@ -168,6 +172,13 @@ bool BladeRunnerEngine::startup() {
if (!r)
return false;
+ for (int i = 0; i != 43; ++i) {
+ Shape *shape = new Shape(this);
+ shape->readFromContainer("SHAPES.SHP", i);
+ _shapes.push_back(shape);
+ }
+ _mouse->setCursor(0);
+
r = _sliceAnimations->open("INDEX.DAT");
if (!r)
return false;
@@ -299,6 +310,10 @@ void BladeRunnerEngine::gameTick() {
// TODO: Draw item pickup (understood, drawing works in Replicant)
// TODO: Draw dialogue menu
// TODO: Draw mouse (understood)
+
+ Common::Point p = _eventMan->getMousePos();
+ _mouse->draw(_surface2, p.x, p.y);
+
// TODO: Process AUD (audio in Replicant)
// TODO: Footstep sound
diff --git a/engines/bladerunner/bladerunner.h b/engines/bladerunner/bladerunner.h
index b0df9bdca0..06a1a7ae34 100644
--- a/engines/bladerunner/bladerunner.h
+++ b/engines/bladerunner/bladerunner.h
@@ -43,9 +43,11 @@ class Chapters;
class Clues;
class GameInfo;
class GameFlags;
+class Mouse;
class Scene;
class Script;
class Settings;
+class Shape;
class SliceAnimations;
class SliceRenderer;
class TextResource;
@@ -60,8 +62,9 @@ public:
AudioSpeech *_audioSpeech;
Chapters *_chapters;
Clues *_clues;
- GameInfo *_gameInfo;
GameFlags *_gameFlags;
+ GameInfo *_gameInfo;
+ Mouse *_mouse;
Scene *_scene;
Script *_script;
Settings *_settings;
@@ -70,6 +73,7 @@ public:
int *_gameVars;
TextResource *_actorNames;
+ Common::Array<Shape*> _shapes;
int in_script_counter;
diff --git a/engines/bladerunner/module.mk b/engines/bladerunner/module.mk
index fd23e94cbb..8cd9ba4054 100644
--- a/engines/bladerunner/module.mk
+++ b/engines/bladerunner/module.mk
@@ -18,6 +18,7 @@ MODULE_OBJS = \
gameinfo.o \
image.o \
matrix.o \
+ mouse.o \
outtake.o \
scene.o \
script/init.o \
@@ -25,6 +26,7 @@ MODULE_OBJS = \
script/script.o \
set.o \
settings.o \
+ shape.o \
slice_animations.o \
slice_renderer.o \
text_resource.o \
diff --git a/engines/bladerunner/mouse.cpp b/engines/bladerunner/mouse.cpp
new file mode 100644
index 0000000000..8a259fd76f
--- /dev/null
+++ b/engines/bladerunner/mouse.cpp
@@ -0,0 +1,250 @@
+/* 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 "bladerunner/mouse.h"
+
+#include "bladerunner/bladerunner.h"
+#include "bladerunner/shape.h"
+
+#include "graphics/surface.h"
+
+namespace BladeRunner {
+
+Mouse::Mouse(BladeRunnerEngine *vm)
+ : _vm(vm)
+{
+ _cursor = 0;
+ _frame = 3;
+ _hotspotX = 0;
+ _hotspotY = 0;
+ _x = 0;
+ _y = 0;
+ _disabledCounter = 0;
+ _lastFrameTime = 0;
+}
+
+Mouse::~Mouse() {
+}
+
+void Mouse::setCursor(int cursor) {
+ assert(cursor >= 0 && cursor <= 16);
+ if (cursor == _cursor) {
+ return;
+ }
+
+ _cursor = cursor;
+
+ switch (_cursor) {
+ case 0:
+ _frame = 3;
+ _hotspotX = 0;
+ _hotspotY = 0;
+ break;
+ case 1:
+ _frame = 4;
+ _hotspotX = 0;
+ _hotspotY = 0;
+ break;
+ case 2:
+ _frame = 12;
+ _hotspotX = 12;
+ _hotspotY = 0;
+ break;
+ case 3:
+ _frame = 15;
+ _hotspotX = 23;
+ _hotspotY = 12;
+ break;
+ case 4:
+ _frame = 13;
+ _hotspotX = 12;
+ _hotspotY = 23;
+ break;
+ case 5:
+ _frame = 14;
+ _hotspotX = 0;
+ _hotspotY = 12;
+ break;
+ case 6:
+ _frame = 16;
+ _hotspotX = 19;
+ _hotspotY = 19;
+ break;
+ case 7:
+ _frame = 17;
+ _hotspotX = 19;
+ _hotspotY = 19;
+ break;
+ case 8:
+ _frame = 25;
+ _hotspotX = 19;
+ _hotspotY = 19;
+ break;
+ case 9:
+ _frame = 26;
+ _hotspotX = 19;
+ _hotspotY = 19;
+ break;
+ case 10:
+ _frame = 34;
+ _hotspotX = 19;
+ _hotspotY = 19;
+ break;
+ case 11:
+ _frame = 35;
+ _hotspotX = 19;
+ _hotspotY = 19;
+ break;
+ case 12:
+ _frame = 12;
+ _hotspotX = 12;
+ _hotspotY = 0;
+ _animCounter = 0;
+ break;
+ case 13:
+ _frame = 15;
+ _hotspotX = 23;
+ _hotspotY = 12;
+ _animCounter = 0;
+ break;
+ case 14:
+ _frame = 13;
+ _hotspotX = 12;
+ _hotspotY = 23;
+ _animCounter = 0;
+ break;
+ case 15:
+ _frame = 14;
+ _hotspotX = 0;
+ _hotspotY = 12;
+ _animCounter = 0;
+ break;
+ case 16:
+ _frame = 0;
+ _hotspotX = 11;
+ _hotspotY = 11;
+ }
+}
+
+void Mouse::disable() {
+ ++_disabledCounter;
+}
+
+void Mouse::enable() {
+ if (--_disabledCounter <= 0) {
+ _disabledCounter = 0;
+ }
+}
+
+bool Mouse::isDisabled() {
+ return _disabledCounter > 0;
+}
+
+void Mouse::draw(Graphics::Surface &surface, int x, int y) {
+ if (_disabledCounter) {
+ return;
+ }
+
+ _x = CLIP(x, 0, surface.w - 1);
+ _y = CLIP(y, 0, surface.h - 1);
+
+
+ if (_cursor < 0 || (uint)_cursor >= _vm->_shapes.size()) {
+ return;
+ }
+
+ Shape *cursorShape = _vm->_shapes[_frame];
+
+ cursorShape->draw(surface, _x - _hotspotX, _y - _hotspotY);
+
+ updateCursorFrame();
+}
+
+void Mouse::updateCursorFrame() {
+ uint32 now = _vm->getTotalPlayTime();
+ const int offset[4] = { 0, 6, 12, 6 };
+
+ if (now - _lastFrameTime < 66) {
+ return;
+ }
+ _lastFrameTime = now;
+
+ switch (_cursor) {
+ case 0:
+ break;
+ case 1:
+ if (++_frame > 11)
+ _frame = 4;
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ break;
+ case 7:
+ if (++_frame > 24)
+ _frame = 17;
+ break;
+ case 8:
+ break;
+ case 9:
+ if (++_frame > 33)
+ _frame = 26;
+ break;
+ case 10:
+ break;
+ case 11:
+ if (++_frame > 42)
+ _frame = 35;
+ break;
+ case 12:
+ if (++_animCounter >= 4) {
+ _animCounter = 0;
+ }
+ _hotspotY = -offset[_animCounter];
+ break;
+ case 13:
+ if (++_animCounter >= 4) {
+ _animCounter = 0;
+ }
+ _hotspotX = 23 + offset[_animCounter];
+ break;
+ case 14:
+ if (++_animCounter >= 4) {
+ _animCounter = 0;
+ }
+ _hotspotY = 23 + offset[_animCounter];
+ break;
+ case 15:
+ if (++_animCounter >= 4) {
+ _animCounter = 0;
+ }
+ _hotspotX = -offset[_animCounter];
+ break;
+ case 16:
+ if (++_frame > 2)
+ _frame = 0;
+ }
+}
+
+} // End of namespace BladeRunner
diff --git a/engines/bladerunner/mouse.h b/engines/bladerunner/mouse.h
new file mode 100644
index 0000000000..33f231484f
--- /dev/null
+++ b/engines/bladerunner/mouse.h
@@ -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.
+ *
+ */
+
+#ifndef BLADERUNNER_MOUSE_H
+#define BLADERUNNER_MOUSE_H
+
+namespace Graphics {
+ struct Surface;
+}
+
+namespace BladeRunner {
+
+class BladeRunnerEngine;
+
+class Mouse {
+ BladeRunnerEngine *_vm;
+
+ int _cursor;
+ int _frame;
+ int _hotspotX;
+ int _hotspotY;
+ int _x;
+ int _y;
+ int _disabledCounter;
+ int _lastFrameTime;
+ int _animCounter;
+
+public:
+ Mouse(BladeRunnerEngine *vm);
+ ~Mouse();
+
+ void setCursor(int cursor);
+
+ void disable();
+ void enable();
+ bool isDisabled();
+
+ void draw(Graphics::Surface &surface, int x, int y);
+ void updateCursorFrame();
+};
+
+} // End of namespace BladeRunner
+
+#endif
diff --git a/engines/bladerunner/shape.cpp b/engines/bladerunner/shape.cpp
new file mode 100644
index 0000000000..be4db1ecee
--- /dev/null
+++ b/engines/bladerunner/shape.cpp
@@ -0,0 +1,132 @@
+/* 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 "bladerunner/shape.h"
+
+#include "bladerunner/bladerunner.h"
+
+#include "common/debug.h"
+#include "common/ptr.h"
+#include "common/util.h"
+
+#include "graphics/surface.h"
+
+namespace BladeRunner {
+
+Shape::Shape(BladeRunnerEngine *vm)
+ : _vm(vm), _data(0)
+{
+}
+
+Shape::~Shape() {
+ delete[] _data;
+}
+
+bool Shape::readFromContainer(const Common::String &container, int index) {
+ Common::ScopedPtr<Common::SeekableReadStream> stream(_vm->getResourceStream(container));
+ if (!stream) {
+ debug("Shape::readFromContainer failed to open '%s'", container.c_str());
+ return false;
+ }
+
+ uint32 count = stream->readUint32LE();
+ if (index < 0 || (uint32)index >= count) {
+ debug("Shape::readFromContainer invalid index %d (count %u)", index, count);
+ return false;
+ }
+
+ uint32 size, width, height;
+ for (int i = 0; i <= index; ++i) {
+ width = stream->readUint32LE();
+ height = stream->readUint32LE();
+ size = stream->readUint32LE();
+
+ if (size != width * height * 2) {
+ debug("Shape::readFromContainer size mismatch (w %d, h %d, sz %d)", width, height, size);
+ return false;
+ }
+
+ if (i != index) {
+ stream->skip(size);
+ }
+ }
+
+ // Enfoce a reasonable size limit
+ if (width >= 2048 || height >= 2048) {
+ warning("Shape::readFromContainer shape too big (%d, %d)", width, height);
+ }
+
+ _width = width;
+ _height = height;
+ _data = new byte[size];
+
+ if (stream->read(_data, size) != size) {
+ debug("Shape::readFromContainer error reading shape %d (w %d, h %d, sz %d)", index, width, height, size);
+ return false;
+ }
+
+ return true;
+}
+
+void Shape::draw(Graphics::Surface &surface, int x, int y) {
+ // debug("x=%d, y=%d", x, y);
+ // debug("w=%d, h=%d", _width, _height);
+
+ int src_x = CLIP(-x, 0, _width);
+ int src_y = CLIP(-y, 0, _height);
+
+ // debug("src_x=%d, src_y=%d", src_x, src_y);
+
+ int dst_x = CLIP<int>(x, 0, surface.w);
+ int dst_y = CLIP<int>(y, 0, surface.h);
+
+ // debug("dst_x=%d, dst_y=%d", dst_x, dst_y);
+
+ int rect_w = MIN(CLIP(_width + x, 0, _width), surface.w - x);
+ int rect_h = MIN(CLIP(_height + y, 0, _height), surface.h - y);
+
+ // debug("rect_w=%d, rect_h=%d", rect_w, rect_h);
+
+ if (rect_w == 0 || rect_h == 0) {
+ return;
+ }
+
+ byte *src_p = _data + 2 * (src_y * _width + src_x);
+ byte *dst_p = (byte*)surface.getBasePtr(dst_x, dst_y);
+
+ for (int yi = 0; yi != rect_h; ++yi) {
+ for (int xi = 0; xi != rect_w; ++xi) {
+ uint16 color = READ_LE_UINT16(src_p);
+ if ((color & 0x8000) == 0) {
+ *(uint16*)dst_p = color;
+ }
+
+ src_p += 2;
+ dst_p += 2;
+ }
+
+ src_p += 2 * (_width - rect_w);
+ dst_p += surface.pitch - 2*rect_w;
+ }
+}
+
+} // End of namespace BladeRunner
diff --git a/engines/bladerunner/shape.h b/engines/bladerunner/shape.h
new file mode 100644
index 0000000000..782d20f278
--- /dev/null
+++ b/engines/bladerunner/shape.h
@@ -0,0 +1,54 @@
+/* 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 BLADERUNNER_SHAPE_H
+#define BLADERUNNER_SHAPE_H
+
+#include "common/substream.h"
+
+namespace Graphics {
+ struct Surface;
+}
+
+namespace BladeRunner {
+
+class BladeRunnerEngine;
+
+class Shape {
+ BladeRunnerEngine *_vm;
+
+ int _width;
+ int _height;
+ byte *_data;
+
+public:
+ Shape(BladeRunnerEngine *vm);
+ ~Shape();
+
+ bool readFromContainer(const Common::String &container, int index);
+
+ void draw(Graphics::Surface &surface, int x, int y);
+};
+
+} // End of namespace BladeRunner
+
+#endif