This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian/master
in repository openjk.

commit 8f2c8d9ab551ab596c46b246b2f52327a93e9182
Author: bibendovsky <bibendov...@hotmail.com>
Date:   Wed Aug 31 21:03:02 2016 +0300

    SG: Move cplane_t's archive methods into separate header
---
 code/game/CMakeLists.txt                        |  1 +
 code/rd-vanilla/CMakeLists.txt                  |  1 +
 codeJK2/game/CMakeLists.txt                     |  1 +
 shared/qcommon/ojk_saved_game_class_archivers.h | 54 ++++++++++++++++++++++
 shared/qcommon/ojk_saved_game_helper.h          | 61 +++++++++++++++++++++++++
 shared/qcommon/ojk_saved_game_helper_fwd.h      | 57 +++++++++++++++++++++++
 shared/qcommon/q_math.h                         | 26 -----------
 7 files changed, 175 insertions(+), 26 deletions(-)

diff --git a/code/game/CMakeLists.txt b/code/game/CMakeLists.txt
index c54a67f..c86eb42 100644
--- a/code/game/CMakeLists.txt
+++ b/code/game/CMakeLists.txt
@@ -260,6 +260,7 @@ set(SPGameCommonFiles
        "${SPDir}/qcommon/q_shared.cpp"
        "${SPDir}/qcommon/q_shared.h"
        "${SharedDir}/qcommon/ojk_i_saved_game.h"
+       "${SharedDir}/qcommon/ojk_saved_game_class_archivers.h"
        "${SharedDir}/qcommon/ojk_saved_game_helper.h"
        "${SharedDir}/qcommon/ojk_saved_game_helper_fwd.h"
        "${SharedDir}/qcommon/ojk_scope_guard.h"
diff --git a/code/rd-vanilla/CMakeLists.txt b/code/rd-vanilla/CMakeLists.txt
index 1dc0b57..e25c389 100644
--- a/code/rd-vanilla/CMakeLists.txt
+++ b/code/rd-vanilla/CMakeLists.txt
@@ -78,6 +78,7 @@ if(BuildSPRdVanilla OR BuildJK2SPRdVanilla)
                "${SPDir}/qcommon/q_shared.cpp"
                "${SPDir}/qcommon/q_shared.h"
                "${SharedDir}/qcommon/ojk_i_saved_game.h"
+               "${SharedDir}/qcommon/ojk_saved_game_class_archivers.h"
                "${SharedDir}/qcommon/ojk_saved_game_helper.h"
                "${SharedDir}/qcommon/ojk_saved_game_helper_fwd.h"
                "${SharedDir}/qcommon/ojk_scope_guard.h"
diff --git a/codeJK2/game/CMakeLists.txt b/codeJK2/game/CMakeLists.txt
index a757e29..782071a 100644
--- a/codeJK2/game/CMakeLists.txt
+++ b/codeJK2/game/CMakeLists.txt
@@ -232,6 +232,7 @@ set(JK2SPGameCommonFiles
        "${SPDir}/qcommon/q_shared.h"
        "${SPDir}/qcommon/strippublic.h"
        "${SharedDir}/qcommon/ojk_i_saved_game.h"
+       "${SharedDir}/qcommon/ojk_saved_game_class_archivers.h"
        "${SharedDir}/qcommon/ojk_saved_game_helper.h"
        "${SharedDir}/qcommon/ojk_saved_game_helper_fwd.h"
        "${SharedDir}/qcommon/ojk_scope_guard.h"
diff --git a/shared/qcommon/ojk_saved_game_class_archivers.h 
b/shared/qcommon/ojk_saved_game_class_archivers.h
new file mode 100644
index 0000000..8f4f8ce
--- /dev/null
+++ b/shared/qcommon/ojk_saved_game_class_archivers.h
@@ -0,0 +1,54 @@
+//
+// Saved game specialized archivers
+//
+
+
+#ifndef OJK_SAVED_GAME_CLASS_ARCHIVERS_INCLUDED
+#define OJK_SAVED_GAME_CLASS_ARCHIVERS_INCLUDED
+
+
+#include "q_math.h"
+#include "ojk_saved_game_helper_fwd.h"
+
+
+namespace ojk
+{
+
+
+template<>
+class SavedGameClassArchiver<cplane_t>
+{
+public:
+       static constexpr bool is_implemented()
+       {
+               return true;
+       }
+
+       static void sg_export(
+               SavedGameHelper& saved_game,
+               const cplane_t& instance)
+       {
+               saved_game.write<float>(instance.normal);
+               saved_game.write<float>(instance.dist);
+               saved_game.write<uint8_t>(instance.type);
+               saved_game.write<uint8_t>(instance.signbits);
+               saved_game.write<uint8_t>(instance.pad);
+       }
+
+       static void sg_import(
+               SavedGameHelper& saved_game,
+               cplane_t& instance)
+       {
+               saved_game.read<float>(instance.normal);
+               saved_game.read<float>(instance.dist);
+               saved_game.read<uint8_t>(instance.type);
+               saved_game.read<uint8_t>(instance.signbits);
+               saved_game.read<uint8_t>(instance.pad);
+       }
+};
+
+
+} // ojk
+
+
+#endif // OJK_SAVED_GAME_CLASS_ARCHIVERS_INCLUDED
diff --git a/shared/qcommon/ojk_saved_game_helper.h 
b/shared/qcommon/ojk_saved_game_helper.h
index 0cf8426..bab0227 100644
--- a/shared/qcommon/ojk_saved_game_helper.h
+++ b/shared/qcommon/ojk_saved_game_helper.h
@@ -11,6 +11,7 @@
 #include <type_traits>
 #include "ojk_saved_game_helper_fwd.h"
 #include "ojk_scope_guard.h"
+#include "ojk_saved_game_class_archivers.h"
 
 
 namespace ojk
@@ -393,12 +394,43 @@ bool SavedGameHelper::try_read(
                std::is_same<TSrc, void>::value,
                "Unsupported types.");
 
+       using Tag = typename std::conditional<
+               SavedGameClassArchiver<TDst>::is_implemented(),
+               ExternalTag,
+               InternalTag
+       >::type;
+
+       return try_read<TSrc>(
+               dst_value,
+               ClassTag(),
+               Tag());
+}
+
+template<typename TSrc, typename TDst>
+bool SavedGameHelper::try_read(
+       TDst& dst_value,
+       ClassTag,
+       InternalTag)
+{
        dst_value.sg_import(
                *this);
 
        return !saved_game_->is_failed();
 }
 
+template<typename TSrc, typename TDst>
+bool SavedGameHelper::try_read(
+       TDst& dst_value,
+       ClassTag,
+       ExternalTag)
+{
+       SavedGameClassArchiver<TDst>::sg_import(
+               *this,
+               dst_value);
+
+       return !saved_game_->is_failed();
+}
+
 template<typename TSrc, typename TDst, int TCount>
 bool SavedGameHelper::try_read(
        TDst(&dst_values)[TCount],
@@ -643,10 +675,39 @@ void SavedGameHelper::write(
                std::is_same<TDst, void>::value,
                "Unsupported types.");
 
+       using Tag = typename std::conditional<
+               SavedGameClassArchiver<TSrc>::is_implemented(),
+               ExternalTag,
+               InternalTag
+       >::type;
+
+       write<TDst>(
+               src_value,
+               ClassTag(),
+               Tag());
+}
+
+template<typename TDst, typename TSrc>
+void SavedGameHelper::write(
+       const TSrc& src_value,
+       ClassTag,
+       InternalTag)
+{
        src_value.sg_export(
                *this);
 }
 
+template<typename TDst, typename TSrc>
+void SavedGameHelper::write(
+       const TSrc& src_value,
+       ClassTag,
+       ExternalTag)
+{
+       SavedGameClassArchiver<TSrc>::sg_export(
+               *this,
+               src_value);
+}
+
 template<typename TDst, typename TSrc, int TCount>
 void SavedGameHelper::write(
        const TSrc(&src_values)[TCount],
diff --git a/shared/qcommon/ojk_saved_game_helper_fwd.h 
b/shared/qcommon/ojk_saved_game_helper_fwd.h
index 387398d..6c06559 100644
--- a/shared/qcommon/ojk_saved_game_helper_fwd.h
+++ b/shared/qcommon/ojk_saved_game_helper_fwd.h
@@ -174,6 +174,8 @@ private:
        class Array2dTag { public: };
        class InplaceTag { public: };
        class CastTag { public: };
+       class InternalTag { public: };
+       class ExternalTag { public: };
 
 
        template<typename TSrc, typename TDst>
@@ -196,6 +198,18 @@ private:
                TDst& dst_value,
                ClassTag);
 
+       template<typename TSrc, typename TDst>
+       bool try_read(
+               TDst& dst_value,
+               ClassTag,
+               InternalTag);
+
+       template<typename TSrc, typename TDst>
+       bool try_read(
+               TDst& dst_value,
+               ClassTag,
+               ExternalTag);
+
        template<typename TSrc, typename TDst, int TCount>
        bool try_read(
                TDst(&dst_values)[TCount],
@@ -235,6 +249,18 @@ private:
                const TSrc& src_value,
                ClassTag);
 
+       template<typename TDst, typename TSrc>
+       void write(
+               const TSrc& src_value,
+               ClassTag,
+               InternalTag);
+
+       template<typename TDst, typename TSrc>
+       void write(
+               const TSrc& src_value,
+               ClassTag,
+               ExternalTag);
+
        template<typename TDst, typename TSrc, int TCount>
        void write(
                const TSrc(&src_values)[TCount],
@@ -260,6 +286,37 @@ private:
 }; // SavedGameHelper
 
 
+template<typename T>
+class SavedGameClassArchiver
+{
+public:
+       static constexpr bool is_implemented()
+       {
+               return false;
+       }
+
+       static void sg_export(
+               SavedGameHelper& saved_game,
+               const T& instance)
+       {
+               static_cast<void>(saved_game);
+               static_cast<void>(instance);
+
+               static_assert(false, "Not implemented.");
+       }
+
+       static void sg_import(
+               SavedGameHelper& saved_game,
+               T& instance)
+       {
+               static_cast<void>(saved_game);
+               static_cast<void>(instance);
+
+               static_assert(false, "Not implemented.");
+       }
+};
+
+
 } // ojk
 
 
diff --git a/shared/qcommon/q_math.h b/shared/qcommon/q_math.h
index 4005e58..bf337f4 100644
--- a/shared/qcommon/q_math.h
+++ b/shared/qcommon/q_math.h
@@ -24,9 +24,6 @@ along with this program; if not, see 
<http://www.gnu.org/licenses/>.
 
 #include "q_platform.h"
 
-#ifdef __cplusplus
-#include "ojk_saved_game_helper_fwd.h"
-#endif // __cplusplus
 
 #if defined(__cplusplus)
 extern "C" {
@@ -184,29 +181,6 @@ typedef struct cplane_s {
        byte    type;                   // for fast side tests: 0,1,2 = axial, 
3 = nonaxial
        byte    signbits;               // signx + (signy<<1) + (signz<<2), 
used as lookup during collision
        byte    pad[2];
-
-
-#ifdef __cplusplus
-       void sg_export(
-               ojk::SavedGameHelper& saved_game) const
-       {
-               saved_game.write<float>(normal);
-               saved_game.write<float>(dist);
-               saved_game.write<uint8_t>(type);
-               saved_game.write<uint8_t>(signbits);
-               saved_game.write<uint8_t>(pad);
-       }
-
-       void sg_import(
-               ojk::SavedGameHelper& saved_game)
-       {
-               saved_game.read<float>(normal);
-               saved_game.read<float>(dist);
-               saved_game.read<uint8_t>(type);
-               saved_game.read<uint8_t>(signbits);
-               saved_game.read<uint8_t>(pad);
-       }
-#endif // __cplusplus
 } cplane_t;
 
 void SetPlaneSignbits( cplane_t *out );

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-games/openjk.git

_______________________________________________
Pkg-games-commits mailing list
Pkg-games-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

Reply via email to