diff --git a/libraries/chain/game_object.cpp b/libraries/chain/game_object.cpp index 5874fd9e..19f3613b 100644 --- a/libraries/chain/game_object.cpp +++ b/libraries/chain/game_object.cpp @@ -28,8 +28,6 @@ #include #include -#include -#include #include #include @@ -533,51 +531,6 @@ namespace graphene { namespace chain { my->state_machine.process_event(initiate_game(db, players)); } - void game_object::pack_impl(std::ostream& stream) const - { - boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - oa << my->state_machine; - } - - void game_object::unpack_impl(std::istream& stream) - { - boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - ia >> my->state_machine; - } - } } // graphene::chain -namespace fc { - // Manually reflect game_object to variant to properly reflect "state" - void to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth) - { - fc_elog(fc::logger::get("tournament"), "In game_obj to_variant"); - elog("In game_obj to_variant"); - fc::mutable_variant_object o; - o("id", fc::variant(game_obj.id, max_depth )) - ("match_id", fc::variant(game_obj.match_id, max_depth )) - ("players", fc::variant(game_obj.players, max_depth )) - ("winners", fc::variant(game_obj.winners, max_depth )) - ("game_details", fc::variant(game_obj.game_details, max_depth )) - ("next_timeout", fc::variant(game_obj.next_timeout, max_depth )) - ("state", fc::variant(game_obj.get_state(), max_depth )); - - v = o; - } - - // Manually reflect game_object to variant to properly reflect "state" - void from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth) - { - fc_elog(fc::logger::get("tournament"), "In game_obj from_variant"); - game_obj.id = v["id"].as( max_depth ); - game_obj.match_id = v["match_id"].as( max_depth ); - game_obj.players = v["players"].as >( max_depth ); - game_obj.winners = v["winners"].as >( max_depth ); - game_obj.game_details = v["game_details"].as( max_depth ); - game_obj.next_timeout = v["next_timeout"].as >( max_depth ); - graphene::chain::game_state state = v["state"].as( max_depth ); - const_cast(game_obj.my->state_machine.current_state())[0] = (int)state; - } -} //end namespace fc - diff --git a/libraries/chain/include/graphene/chain/game_object.hpp b/libraries/chain/include/graphene/chain/game_object.hpp index 863deff9..1f326b90 100644 --- a/libraries/chain/include/graphene/chain/game_object.hpp +++ b/libraries/chain/include/graphene/chain/game_object.hpp @@ -23,22 +23,9 @@ */ #pragma once -#include #include -#include -#include +#include #include -#include -#include - -namespace graphene { namespace chain { - class game_object; -} } - -namespace fc { - void to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth = 1); - void from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth = 1); -} //end namespace fc namespace graphene { namespace chain { class database; @@ -82,21 +69,6 @@ namespace graphene { namespace chain { void on_move(database& db, const game_move_operation& op); void on_timeout(database& db); void start_game(database& db, const std::vector& players); - - // serialization functions: - // for serializing to raw, go through a temporary sstream object to avoid - // having to implement serialization in the header file - template - friend Stream& operator<<( Stream& s, const game_object& game_obj ); - - template - friend Stream& operator>>( Stream& s, game_object& game_obj ); - - friend void ::fc::to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth); - friend void ::fc::from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth); - - void pack_impl(std::ostream& stream) const; - void unpack_impl(std::istream& stream); class impl; std::unique_ptr my; @@ -113,50 +85,6 @@ namespace graphene { namespace chain { member > > > > game_object_multi_index_type; typedef generic_index game_index; - - template - inline Stream& operator<<( Stream& s, const game_object& game_obj ) - { - // pack all fields exposed in the header in the usual way - // instead of calling the derived pack, just serialize the one field in the base class - // fc::raw::pack >(s, game_obj); - fc::raw::pack(s, game_obj.id); - fc::raw::pack(s, game_obj.match_id); - fc::raw::pack(s, game_obj.players); - fc::raw::pack(s, game_obj.winners); - fc::raw::pack(s, game_obj.game_details); - fc::raw::pack(s, game_obj.next_timeout); - - // fc::raw::pack the contents hidden in the impl class - std::ostringstream stream; - game_obj.pack_impl(stream); - std::string stringified_stream(stream.str()); - fc::raw::pack(s, stream.str()); - - return s; - } - - template - inline Stream& operator>>( Stream& s, game_object& game_obj ) - { - // unpack all fields exposed in the header in the usual way - //fc::raw::unpack >(s, game_obj); - fc::raw::unpack(s, game_obj.id); - fc::raw::unpack(s, game_obj.match_id); - fc::raw::unpack(s, game_obj.players); - fc::raw::unpack(s, game_obj.winners); - fc::raw::unpack(s, game_obj.game_details); - fc::raw::unpack(s, game_obj.next_timeout); - - // fc::raw::unpack the contents hidden in the impl class - std::string stringified_stream; - fc::raw::unpack(s, stringified_stream); - std::istringstream stream(stringified_stream); - game_obj.unpack_impl(stream); - - return s; - } - } } FC_REFLECT_ENUM(graphene::chain::game_state, @@ -171,4 +99,6 @@ FC_REFLECT_DERIVED(graphene::chain::game_object, (graphene::db::object), (players) (winners) (game_details) - (next_timeout)) \ No newline at end of file + (next_timeout)) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::game_object ) \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 701a4888..098e5dd1 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -577,6 +577,7 @@ FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_id_type ) FC_REFLECT_TYPENAME( graphene::chain::betting_market_position_id_type ) FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type ) FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::game_id_type ) FC_REFLECT_TYPENAME( graphene::chain::match_id_type ) FC_REFLECT_TYPENAME( graphene::chain::custom_permission_id_type ) FC_REFLECT_TYPENAME( graphene::chain::custom_account_authority_id_type ) diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 9c54fba3..ba0f5b79 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -74,5 +75,6 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_object GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_scheduler ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedule_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::worker_object ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::game_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::tournament_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::match_object )