[openjk] 09/130: Add method add_path
Simon McVittie
smcv at debian.org
Fri Oct 28 11:09:11 UTC 2016
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian/master
in repository openjk.
commit 73b2f7f26a39530a312b9788e765886cd57c1443
Author: bibendovsky <bibendovsky at NOSTROMO>
Date: Sun Jul 3 21:26:36 2016 +0300
Add method add_path
---
shared/qcommon/ojk_sg_archive.cpp | 53 ++++++++++++++++++++++++++++++++++---
shared/qcommon/ojk_sg_archive_fwd.h | 30 ++++++++++++++++++---
2 files changed, 75 insertions(+), 8 deletions(-)
diff --git a/shared/qcommon/ojk_sg_archive.cpp b/shared/qcommon/ojk_sg_archive.cpp
index d669e83..d31acc0 100644
--- a/shared/qcommon/ojk_sg_archive.cpp
+++ b/shared/qcommon/ojk_sg_archive.cpp
@@ -1,7 +1,6 @@
#include "ojk_sg_archive.h"
-#include <cstdio>
-#include <unordered_map>
#include "ojk_sg_archive_exception.h"
+#include "qcommon/qcommon.h"
namespace ojk {
@@ -9,6 +8,9 @@ namespace sg {
Archive::Archive() :
+ archive_mode_(),
+ paths_(get_max_path_count()),
+ path_index_(),
file_handle_(),
io_buffer_(),
io_buffer_offset_()
@@ -21,6 +23,7 @@ Archive::~Archive()
}
bool Archive::open(
+ ArchiveMode archive_mode,
const std::string& file_path)
{
throw ArchiveException(
@@ -28,6 +31,7 @@ bool Archive::open(
}
bool Archive::create(
+ ArchiveMode archive_mode,
const std::string& file_path)
{
throw ArchiveException(
@@ -55,8 +59,8 @@ void Archive::write_chunk(
}
void Archive::rename(
- const std::string& old_file_path,
- const std::string& new_file_path)
+ const std::string& old_file_path,
+ const std::string& new_file_path)
{
throw ArchiveException(
"Not implemented.");
@@ -75,6 +79,47 @@ Archive& Archive::get_instance()
return result;
}
+int Archive::get_max_path_count()
+{
+ return 8;
+}
+
+void Archive::validate_archive_mode(
+ ArchiveMode archive_mode)
+{
+ switch (archive_mode) {
+ case ArchiveMode::jedi_academy:
+ case ArchiveMode::jedi_outcast:
+ break;
+
+ default:
+ throw ArchiveException(
+ "Invalid mode.");
+ }
+}
+
+const std::string& Archive::add_path(
+ const std::string& path)
+{
+ auto next_path_index = (path_index_ + 1) % get_max_path_count();
+
+ auto normalized_path = path;
+
+ std::replace(
+ normalized_path.begin(),
+ normalized_path.end(),
+ '/',
+ '_');
+
+ auto new_path = "saves/" + normalized_path + ".sav";
+
+ paths_[path_index_] = new_path;
+
+ path_index_ = next_path_index;
+
+ return paths_[path_index_];
+}
+
} // sg
} // ojk
diff --git a/shared/qcommon/ojk_sg_archive_fwd.h b/shared/qcommon/ojk_sg_archive_fwd.h
index 31eca73..6106f00 100644
--- a/shared/qcommon/ojk_sg_archive_fwd.h
+++ b/shared/qcommon/ojk_sg_archive_fwd.h
@@ -14,14 +14,12 @@
#include "ojk_sg_archive_exception.h"
-using fileHandle_t = int32_t;
-
-
namespace ojk {
namespace sg {
enum class ArchiveMode {
+ none,
jedi_outcast,
jedi_academy,
}; // ArchiveMode
@@ -46,10 +44,12 @@ public:
// Creates a new saved game file for writing.
bool create(
+ ArchiveMode archive_mode,
const std::string& file_path);
// Opens an existing saved game file for reading.
bool open(
+ ArchiveMode archive_mode,
const std::string& file_path);
// Closes the current saved game file.
@@ -136,6 +136,8 @@ public:
private:
using Buffer = std::vector<uint8_t>;
using BufferOffset = Buffer::size_type;
+ using Paths = std::vector<std::string>;
+
// Tags for dispatching.
class BooleanTag { public: };
@@ -146,8 +148,18 @@ private:
class InplaceTag { public: };
class CastTag { public: };
+
+ // An archive mode.
+ ArchiveMode archive_mode_;
+
+ // Saved game paths.
+ Paths paths_;
+
+ // Current path index.
+ int path_index_;
+
// A handle to a file.
- fileHandle_t file_handle_;
+ int file_handle_;
// I/O buffer.
Buffer io_buffer_;
@@ -156,6 +168,16 @@ private:
BufferOffset io_buffer_offset_;
+ static constexpr int get_max_path_count();
+
+
+ void validate_archive_mode(
+ ArchiveMode archive_mode);
+
+ const std::string& add_path(
+ const std::string& path);
+
+
// Checks if there is enough data for reading in the I/O buffer.
template<typename T>
void check_io_buffer(
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/openjk.git
More information about the Pkg-games-commits
mailing list