aboutsummaryrefslogtreecommitdiff
path: root/engines/mutationofjb/room.cpp
diff options
context:
space:
mode:
authorĽubomír Remák2018-02-14 21:41:09 +0100
committerEugene Sandulenko2018-08-25 23:12:01 +0200
commit95cd6b74426b555e58577be0c46006a60fd77979 (patch)
tree574a1eff3f142e92c1f9ef511f27acc5e9adb674 /engines/mutationofjb/room.cpp
parent764ee3a5a3f9f600b8d369d8474d2702b22f73f7 (diff)
downloadscummvm-rg350-95cd6b74426b555e58577be0c46006a60fd77979.tar.gz
scummvm-rg350-95cd6b74426b555e58577be0c46006a60fd77979.tar.bz2
scummvm-rg350-95cd6b74426b555e58577be0c46006a60fd77979.zip
MUTATIONOFJB: Load and draw scene background
Diffstat (limited to 'engines/mutationofjb/room.cpp')
-rw-r--r--engines/mutationofjb/room.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/engines/mutationofjb/room.cpp b/engines/mutationofjb/room.cpp
new file mode 100644
index 0000000000..e927971858
--- /dev/null
+++ b/engines/mutationofjb/room.cpp
@@ -0,0 +1,129 @@
+/* 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/room.h"
+#include "mutationofjb/encryptedfile.h"
+#include "graphics/screen.h"
+#include "engines/engine.h"
+#include "common/translation.h"
+
+namespace MutationOfJB {
+
+Room::Room(Graphics::Screen *screen) : _screen(screen) {}
+
+bool Room::load(uint8 roomNumber, bool roomB) {
+ EncryptedFile file;
+ Common::String fileName = Common::String::format("room%d%s.dat", roomNumber, roomB ? "b" : "");
+
+ file.open(fileName);
+
+ if (!file.isOpen()) {
+ Common::String errorMessage = Common::String::format(_("Unable to locate the '%s' engine data file."), fileName.c_str());
+ GUIErrorMessage(errorMessage);
+ warning("%s", errorMessage.c_str());
+
+ return false;
+ }
+
+ file.seek(0x80);
+
+ while (!file.eos()) {
+ // Record.
+ const uint32 length = file.readUint32LE();
+ uint8 info[4] = {0};
+ file.read(info, 4);
+
+ // TODO Find out what these are.
+ uint32 unknown;
+ unknown = file.readUint32LE();
+ unknown = file.readUint32LE();
+
+ // Subrecords.
+ if (info[0] == 0xFA && info[1] == 0xF1) {
+ for (int i = 0; i < info[2]; ++i) {
+ const uint32 subLength = file.readUint32LE();
+ const uint16 type = file.readUint16LE();
+
+ if (type == 0x0B) {
+ loadPalette(file);
+ } else if (type == 0x0F) {
+ loadBackground(file, subLength - 6);
+ }
+ }
+ }
+ }
+
+ file.close();
+
+ return true;
+}
+
+void Room::loadPalette(EncryptedFile &file) {
+ uint32 unknown;
+
+ // TODO Find out what this is.
+ unknown = file.readUint32LE();
+
+ uint8 palette[PALETTE_SIZE];
+ file.read(palette, PALETTE_SIZE);
+
+ for (int j = 0; j < PALETTE_SIZE; ++j) {
+ palette[j] <<= 2; // Uses 6-bit colors.
+ }
+
+ _screen->setPalette(palette);
+}
+
+void Room::loadBackground(EncryptedFile &file, uint32 size) {
+ _screen->clear();
+
+ uint8 * const pixels = static_cast<uint8 *>(_screen->getPixels());
+ uint8 *ptr = pixels;
+ uint32 readBytes = 0;
+
+ while (readBytes != size) {
+ uint8 no = file.readByte();
+ readBytes++;
+ while (no--) {
+ uint8 n = file.readByte();
+ readBytes++;
+ if (n < 0x80) {
+ // RLE - Copy color n times.
+ uint8 color = file.readByte();
+ readBytes++;
+ while(n--) {
+ *ptr++ = color;
+ }
+ } else {
+ // Take next 0x100 - n bytes as they are.
+ const uint32 rawlen = 0x100 - n;
+ file.read(ptr, rawlen);
+ readBytes += rawlen;
+ ptr += rawlen;
+ }
+ }
+ }
+
+ _screen->update();
+}
+
+}