aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/objects/saveable_object.cpp16
-rw-r--r--engines/titanic/objects/saveable_object.h30
-rw-r--r--engines/titanic/simple_file.cpp11
-rw-r--r--engines/titanic/simple_file.h14
-rw-r--r--engines/titanic/string.h8
5 files changed, 69 insertions, 10 deletions
diff --git a/engines/titanic/objects/saveable_object.cpp b/engines/titanic/objects/saveable_object.cpp
index b2384a56f2..caa5192d19 100644
--- a/engines/titanic/objects/saveable_object.cpp
+++ b/engines/titanic/objects/saveable_object.cpp
@@ -60,16 +60,22 @@ CSaveableObject *CSaveableObject::createInstance(const Common::String &name) {
return (*_classList)[name]();
}
-void CSaveableObject::proc4() {
-
+void CSaveableObject::save(SimpleFile *file, int indent) {
+ // Should always be overriden in descendents, so just write a dummy value
+ file->writeNumberLine(0, indent);
}
-void CSaveableObject::proc5() {
-
+void CSaveableObject::load(SimpleFile *file) {
+ // Should always be overriden in descendents, so just read a dummy value
+ file->readNumber();
}
-void CSaveableObject::proc6() {
+void CSaveableObject::saveHeader(SimpleFile *file, int indent) {
+ file->writeClassStart(getClassName(), indent);
+}
+void CSaveableObject::saveFooter(SimpleFile *file, int indent) {
+ file->writeClassEnd(indent);
}
} // End of namespace Titanic
diff --git a/engines/titanic/objects/saveable_object.h b/engines/titanic/objects/saveable_object.h
index 5253892f51..e99d8c5525 100644
--- a/engines/titanic/objects/saveable_object.h
+++ b/engines/titanic/objects/saveable_object.h
@@ -26,6 +26,7 @@
#include "common/scummsys.h"
#include "common/array.h"
#include "common/hash-str.h"
+#include "titanic/simple_file.h"
namespace Titanic {
@@ -49,9 +50,32 @@ public:
*/
static CSaveableObject *createInstance(const Common::String &name);
public:
- virtual void proc4();
- virtual void proc5();
- virtual void proc6();
+ /**
+ * Return the class name
+ */
+ virtual const char *getClassName() const { return "CSaveableObject"; }
+
+ /**
+ * Save the data for the class to file
+ */
+ virtual void save(SimpleFile *file, int indent);
+
+ /**
+ * Load the data for the class from file
+ */
+ virtual void load(SimpleFile *file);
+
+ /**
+ * Write out a header definition for the class to file
+ * prior to saving the actual data for the class
+ */
+ virtual void saveHeader(SimpleFile *file, int indent);
+
+ /**
+ * Writes out a footer for the class after it's data has
+ * been written to file
+ */
+ virtual void saveFooter(SimpleFile *file, int indent);
};
} // End of namespace Titanic
diff --git a/engines/titanic/simple_file.cpp b/engines/titanic/simple_file.cpp
index 5848fbee67..9f371b2009 100644
--- a/engines/titanic/simple_file.cpp
+++ b/engines/titanic/simple_file.cpp
@@ -244,6 +244,17 @@ void SimpleFile::writeQuotedString(const CString &str) {
write("\" ", 2);
}
+void SimpleFile::writeNumber(int val) {
+ CString str = CString::format("%ld ", val);
+ write(str.c_str(), str.size());
+}
+
+void SimpleFile::writeNumberLine(int val, int indent) {
+ writeIndent(indent);
+ writeNumber(val);
+ write("\n", 1);
+}
+
void SimpleFile::writeIndent(uint indent) {
for (uint idx = 0; idx < indent; ++idx)
write("\t", 1);
diff --git a/engines/titanic/simple_file.h b/engines/titanic/simple_file.h
index 45d700018a..17dd82a130 100644
--- a/engines/titanic/simple_file.h
+++ b/engines/titanic/simple_file.h
@@ -100,10 +100,12 @@ public:
double readFloat();
/**
- * Write a line
+ * Write a string line
*/
void writeLine(const CString &str);
+
+
/**
* Write a string
*/
@@ -115,6 +117,16 @@ public:
void writeQuotedString(const CString &str);
/**
+ * Write a number to file
+ */
+ void writeNumber(int val);
+
+ /**
+ * Write a number line to file
+ */
+ void writeNumberLine(int val, int indent);
+
+ /**
* Write out a number of tabs to form an indent in the output
*/
void writeIndent(uint indent);
diff --git a/engines/titanic/string.h b/engines/titanic/string.h
index 9b8cca0396..46cbb02ad5 100644
--- a/engines/titanic/string.h
+++ b/engines/titanic/string.h
@@ -29,7 +29,13 @@
namespace Titanic {
class CString : public Common::String {
-
+public:
+ CString() : Common::String() {}
+ CString(const char *str) : Common::String(str) {}
+ CString(const char *str, uint32 len) : Common::String(str, len) {}
+ CString(const char *beginP, const char *endP) : Common::String(beginP, endP) {}
+ CString(const String &str) : Common::String(str) {}
+ explicit CString(char c) : Common::String(c) {}
};
} // End of namespace Titanic