aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-02-18 19:40:12 -0500
committerPaul Gilbert2016-02-18 19:40:12 -0500
commit7818eecaff50fc78b1ac084b6eeaf11adcea0a63 (patch)
treeeeae1bda844447e198ebbd49f63763e4fa43b5c1
parent1e4de9a3232127f72c7d832548343699aa1088cc (diff)
downloadscummvm-rg350-7818eecaff50fc78b1ac084b6eeaf11adcea0a63.tar.gz
scummvm-rg350-7818eecaff50fc78b1ac084b6eeaf11adcea0a63.tar.bz2
scummvm-rg350-7818eecaff50fc78b1ac084b6eeaf11adcea0a63.zip
TITANIC: Split SimpleFile and CompressedFile into different files
-rw-r--r--engines/titanic/compressed_file.cpp (renamed from engines/titanic/files.cpp)154
-rw-r--r--engines/titanic/compressed_file.h (renamed from engines/titanic/files.h)58
-rw-r--r--engines/titanic/module.mk3
-rw-r--r--engines/titanic/objects/project_item.cpp2
-rw-r--r--engines/titanic/objects/project_item.h2
-rw-r--r--engines/titanic/simple_file.cpp177
-rw-r--r--engines/titanic/simple_file.h89
-rw-r--r--engines/titanic/string.cpp2
8 files changed, 276 insertions, 211 deletions
diff --git a/engines/titanic/files.cpp b/engines/titanic/compressed_file.cpp
index 2f5b1b511e..7c0d9872d3 100644
--- a/engines/titanic/files.cpp
+++ b/engines/titanic/compressed_file.cpp
@@ -20,163 +20,11 @@
*
*/
-#include "titanic/files.h"
#include "common/util.h"
+#include "titanic/compressed_file.h"
namespace Titanic {
-SimpleFile::SimpleFile(): _stream(nullptr) {
-}
-
-SimpleFile::~SimpleFile() {
- _file.close();
-}
-
-void SimpleFile::open(const Common::String &name, FileMode mode) {
- assert(mode == FILE_READ);
- if (!_file.open(name))
- error("Could not find file - %s", name.c_str());
-}
-
-void SimpleFile::open(Common::SeekableReadStream *stream, FileMode mode) {
- close();
- _stream = stream;
-}
-
-void SimpleFile::close() {
- _file.close();
- _stream = nullptr;
-}
-
-void SimpleFile::safeRead(void *dst, size_t count) {
- assert(_stream);
- if (unsafeRead(dst, count) != count)
- error("Could not read %d bytes", count);
-}
-
-size_t SimpleFile::unsafeRead(void *dst, size_t count) {
- return _stream->read(dst, count);
-}
-
-CString SimpleFile::readString() {
- char c;
- CString result;
- bool backslashFlag = false;
-
- // First skip any spaces
- do {
- safeRead(&c, 1);
- } while (Common::isSpace(c));
-
- // Ensure we've found a starting quote for the string
- if (c != '"')
- error("Could not find starting quote");
-
- bool endFlag = false;
- while (!endFlag) {
- // Read the next character
- safeRead(&c, 1);
-
- if (backslashFlag) {
- backslashFlag = false;
- switch (c) {
- case 'n':
- result += '\n';
- break;
- case 'r':
- result += '\r';
- break;
- case '\t':
- result += '\t';
- break;
- default:
- result += c;
- break;
- }
- } else {
- switch (c) {
- case '"':
- endFlag = true;
- break;
- case '\\':
- backslashFlag = true;
- break;
- default:
- result += c;
- break;
- }
- }
- }
-
- // Return the string
- return result;
-}
-
-int SimpleFile::readNumber() {
- char c;
- int result = 0;
- bool minusFlag = false;
-
- // First skip any spaces
- do {
- safeRead(&c, 1);
- } while (Common::isSpace(c));
-
- // Check for prefix sign
- if (c == '+' || c == '-') {
- minusFlag = c == '-';
- safeRead(&c, 1);
- }
-
- // Read in the number
- if (!Common::isDigit(c))
- error("Invalid number");
-
- while (Common::isDigit(c)) {
- result = result * 10 + (c - '0');
- safeRead(&c, 1);
- }
-
- // Finally, if it's a minus value, then negate it
- if (minusFlag)
- result = -result;
-
- return result;
-}
-
-double SimpleFile::readFloat() {
- char c;
- Common::String result;
-
- // First skip any spaces
- do {
- safeRead(&c, 1);
- } while (Common::isSpace(c));
-
- // Check for prefix sign
- if (c == '+' || c == '-') {
- result += c;
- safeRead(&c, 1);
- }
-
- // Read in the number
- if (!Common::isDigit(c))
- error("Invalid number");
-
- while (Common::isDigit(c) || c == '.') {
- result += c;
- safeRead(&c, 1);
- }
-
- // Convert to a float and return it
- float floatValue;
- sscanf(result.c_str(), "%f", &floatValue);
-
- return floatValue;
-}
-
-/*------------------------------------------------------------------------*/
-
DecompressorData::DecompressorData() {
_field0 = 0;
_field4 = 0;
diff --git a/engines/titanic/files.h b/engines/titanic/compressed_file.h
index 0f72f60270..814a1ab812 100644
--- a/engines/titanic/files.h
+++ b/engines/titanic/compressed_file.h
@@ -20,70 +20,20 @@
*
*/
-#ifndef TITANIC_FILES_H
-#define TITANIC_FILES_H
+#ifndef TITANIC_COMPRESSED_FILE_H
+#define TITANIC_COMPRESSED_FILE_H
#include "common/scummsys.h"
#include "common/file.h"
#include "common/queue.h"
+#include "titanic/simple_file.h"
#include "titanic/string.h"
namespace Titanic {
-enum FileMode { FILE_READ = 1, FILE_WRITE = 2 };
-
class Decompressor;
class DecompressorData;
-class SimpleFile {
-protected:
- Common::File _file;
- Common::SeekableReadStream *_stream;
-public:
- SimpleFile();
- virtual ~SimpleFile();
-
- /**
- * Open a file for access
- */
- virtual void open(const Common::String &name, FileMode mode = FILE_READ);
-
- /**
- * Set up a stream for access
- */
- virtual void open(Common::SeekableReadStream *stream, FileMode mode = FILE_READ);
-
- /**
- * Close the file
- */
- virtual void close();
-
- /**
- * Read from the file with validation
- */
- virtual void safeRead(void *dst, size_t count);
-
- /**
- * Read from the file
- */
- virtual size_t unsafeRead(void *dst, size_t count);
-
- /**
- * Read a string from the file
- */
- virtual CString readString();
-
- /**
- * Read a number from the file
- */
- virtual int readNumber();
-
- /**
- * Read a floating point number from the file
- */
- virtual double readFloat();
-};
-
typedef DecompressorData *(Decompressor::*DecompressorCreateFn)(int v1, int v2, int v3);
typedef void(Decompressor::*DecompressorDestroyFn)(DecompressorData *ptr);
typedef void(Decompressor::*Method3Fn)();
@@ -167,4 +117,4 @@ public:
} // End of namespace Titanic
-#endif /* TITANIC_FILES_H */
+#endif /* TITANIC_COMPRESSED_FILE_H */
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk
index 6cb4fc14ec..17805e171a 100644
--- a/engines/titanic/module.mk
+++ b/engines/titanic/module.mk
@@ -1,13 +1,14 @@
MODULE := engines/titanic
MODULE_OBJS := \
+ compressed_file.o \
detection.o \
direct_draw.o \
- files.o \
font.o \
image.o \
main_game_window.o \
screen_manager.o \
+ simple_file.o \
string.o \
titanic.o \
video_surface.o \
diff --git a/engines/titanic/objects/project_item.cpp b/engines/titanic/objects/project_item.cpp
index 80596ec15c..90f85d97b9 100644
--- a/engines/titanic/objects/project_item.cpp
+++ b/engines/titanic/objects/project_item.cpp
@@ -22,7 +22,7 @@
#include "common/savefile.h"
#include "titanic/titanic.h"
-#include "titanic/files.h"
+#include "titanic/compressed_file.h"
#include "titanic/objects/project_item.h"
namespace Titanic {
diff --git a/engines/titanic/objects/project_item.h b/engines/titanic/objects/project_item.h
index 2856f42110..93f6e17ef0 100644
--- a/engines/titanic/objects/project_item.h
+++ b/engines/titanic/objects/project_item.h
@@ -24,7 +24,7 @@
#define TITANIC_PROJECT_ITEM_H
#include "common/scummsys.h"
-#include "titanic/files.h"
+#include "titanic/simple_file.h"
#include "titanic/objects/file_item.h"
namespace Titanic {
diff --git a/engines/titanic/simple_file.cpp b/engines/titanic/simple_file.cpp
new file mode 100644
index 0000000000..038603c2d1
--- /dev/null
+++ b/engines/titanic/simple_file.cpp
@@ -0,0 +1,177 @@
+/* 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 "titanic/simple_file.h"
+
+namespace Titanic {
+
+SimpleFile::SimpleFile(): _stream(nullptr) {
+}
+
+SimpleFile::~SimpleFile() {
+ _file.close();
+}
+
+void SimpleFile::open(const Common::String &name, FileMode mode) {
+ assert(mode == FILE_READ);
+ if (!_file.open(name))
+ error("Could not find file - %s", name.c_str());
+}
+
+void SimpleFile::open(Common::SeekableReadStream *stream, FileMode mode) {
+ close();
+ _stream = stream;
+}
+
+void SimpleFile::close() {
+ _file.close();
+ _stream = nullptr;
+}
+
+void SimpleFile::safeRead(void *dst, size_t count) {
+ assert(_stream);
+ if (unsafeRead(dst, count) != count)
+ error("Could not read %d bytes", count);
+}
+
+size_t SimpleFile::unsafeRead(void *dst, size_t count) {
+ return _stream->read(dst, count);
+}
+
+CString SimpleFile::readString() {
+ char c;
+ CString result;
+ bool backslashFlag = false;
+
+ // First skip any spaces
+ do {
+ safeRead(&c, 1);
+ } while (Common::isSpace(c));
+
+ // Ensure we've found a starting quote for the string
+ if (c != '"')
+ error("Could not find starting quote");
+
+ bool endFlag = false;
+ while (!endFlag) {
+ // Read the next character
+ safeRead(&c, 1);
+
+ if (backslashFlag) {
+ backslashFlag = false;
+ switch (c) {
+ case 'n':
+ result += '\n';
+ break;
+ case 'r':
+ result += '\r';
+ break;
+ case '\t':
+ result += '\t';
+ break;
+ default:
+ result += c;
+ break;
+ }
+ } else {
+ switch (c) {
+ case '"':
+ endFlag = true;
+ break;
+ case '\\':
+ backslashFlag = true;
+ break;
+ default:
+ result += c;
+ break;
+ }
+ }
+ }
+
+ // Return the string
+ return result;
+}
+
+int SimpleFile::readNumber() {
+ char c;
+ int result = 0;
+ bool minusFlag = false;
+
+ // First skip any spaces
+ do {
+ safeRead(&c, 1);
+ } while (Common::isSpace(c));
+
+ // Check for prefix sign
+ if (c == '+' || c == '-') {
+ minusFlag = c == '-';
+ safeRead(&c, 1);
+ }
+
+ // Read in the number
+ if (!Common::isDigit(c))
+ error("Invalid number");
+
+ while (Common::isDigit(c)) {
+ result = result * 10 + (c - '0');
+ safeRead(&c, 1);
+ }
+
+ // Finally, if it's a minus value, then negate it
+ if (minusFlag)
+ result = -result;
+
+ return result;
+}
+
+double SimpleFile::readFloat() {
+ char c;
+ Common::String result;
+
+ // First skip any spaces
+ do {
+ safeRead(&c, 1);
+ } while (Common::isSpace(c));
+
+ // Check for prefix sign
+ if (c == '+' || c == '-') {
+ result += c;
+ safeRead(&c, 1);
+ }
+
+ // Read in the number
+ if (!Common::isDigit(c))
+ error("Invalid number");
+
+ while (Common::isDigit(c) || c == '.') {
+ result += c;
+ safeRead(&c, 1);
+ }
+
+ // Convert to a float and return it
+ float floatValue;
+ sscanf(result.c_str(), "%f", &floatValue);
+
+ return floatValue;
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/simple_file.h b/engines/titanic/simple_file.h
new file mode 100644
index 0000000000..6720d9455f
--- /dev/null
+++ b/engines/titanic/simple_file.h
@@ -0,0 +1,89 @@
+/* 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 TITANIC_SIMPLE_FILE_H
+#define TITANIC_SIMPLE_FILE_H
+
+#include "common/scummsys.h"
+#include "common/file.h"
+#include "common/queue.h"
+#include "titanic/string.h"
+
+namespace Titanic {
+
+enum FileMode { FILE_READ = 1, FILE_WRITE = 2 };
+
+class Decompressor;
+class DecompressorData;
+
+class SimpleFile {
+protected:
+ Common::File _file;
+ Common::SeekableReadStream *_stream;
+public:
+ SimpleFile();
+ virtual ~SimpleFile();
+
+ /**
+ * Open a file for access
+ */
+ virtual void open(const Common::String &name, FileMode mode = FILE_READ);
+
+ /**
+ * Set up a stream for access
+ */
+ virtual void open(Common::SeekableReadStream *stream, FileMode mode = FILE_READ);
+
+ /**
+ * Close the file
+ */
+ virtual void close();
+
+ /**
+ * Read from the file with validation
+ */
+ virtual void safeRead(void *dst, size_t count);
+
+ /**
+ * Read from the file
+ */
+ virtual size_t unsafeRead(void *dst, size_t count);
+
+ /**
+ * Read a string from the file
+ */
+ virtual CString readString();
+
+ /**
+ * Read a number from the file
+ */
+ virtual int readNumber();
+
+ /**
+ * Read a floating point number from the file
+ */
+ virtual double readFloat();
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_SIMPLE_FILE_H */
diff --git a/engines/titanic/string.cpp b/engines/titanic/string.cpp
index cdc251d9c3..55b7f8ca52 100644
--- a/engines/titanic/string.cpp
+++ b/engines/titanic/string.cpp
@@ -20,7 +20,7 @@
*
*/
-#include "titanic/files.h"
+#include "titanic/string.h"
namespace Titanic {