Skip to content

Commit

Permalink
Make serialization of Meter less intrusive
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbroher committed Jul 15, 2020
1 parent 43d6333 commit fcf7a53
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
22 changes: 1 addition & 21 deletions universe/Meter.h
Expand Up @@ -3,9 +3,6 @@


#include <string>
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/version.hpp>
#include "../util/Export.h"


Expand Down Expand Up @@ -52,26 +49,9 @@ class FO_COMMON_API Meter {
float m_current_value = DEFAULT_VALUE;
float m_initial_value = DEFAULT_VALUE;

friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive& ar, const unsigned int version);
friend void serialize(Archive&, Meter&, unsigned int const);
};

BOOST_CLASS_VERSION(Meter, 1)


template <typename Archive>
void Meter::serialize(Archive& ar, const unsigned int version)
{
if (Archive::is_loading::value && version < 1) {
ar & BOOST_SERIALIZATION_NVP(m_current_value)
& BOOST_SERIALIZATION_NVP(m_initial_value);
} else {
// use minimum size NVP label to reduce archive size bloat for very-often serialized meter values...
ar & boost::serialization::make_nvp("c", m_current_value)
& boost::serialization::make_nvp("i", m_initial_value);
}
}


#endif
10 changes: 10 additions & 0 deletions util/Serialize.h
Expand Up @@ -11,6 +11,7 @@

#include "Export.h"

class Meter;
class OrderSet;
class Universe;
class UniverseObject;
Expand Down Expand Up @@ -120,6 +121,15 @@ extern template FO_COMMON_API void serialize<freeorion_xml_iarchive>(freeorion_x
extern template FO_COMMON_API void serialize<freeorion_xml_oarchive>(freeorion_xml_oarchive&, GalaxySetupData&, unsigned int const);


template <typename Archive>
void serialize(Archive&, Meter&, unsigned int const);

extern template FO_COMMON_API void serialize<freeorion_bin_oarchive>(freeorion_bin_oarchive&, Meter&, unsigned int const);
extern template FO_COMMON_API void serialize<freeorion_bin_iarchive>(freeorion_bin_iarchive&, Meter&, unsigned int const);
extern template FO_COMMON_API void serialize<freeorion_xml_oarchive>(freeorion_xml_oarchive&, Meter&, unsigned int const);
extern template FO_COMMON_API void serialize<freeorion_xml_iarchive>(freeorion_xml_iarchive&, Meter&, unsigned int const);


struct MultiplayerLobbyData;

BOOST_CLASS_VERSION(MultiplayerLobbyData, 2);
Expand Down
24 changes: 24 additions & 0 deletions util/SerializeUniverse.cpp
Expand Up @@ -36,6 +36,30 @@ BOOST_CLASS_VERSION(ShipDesign, 2)
BOOST_CLASS_EXPORT(Universe)
BOOST_CLASS_VERSION(Universe, 1)


BOOST_CLASS_VERSION(Meter, 1)

template <typename Archive>
void serialize(Archive& ar, Meter& m, unsigned int const version)
{
using namespace boost::serialization;

if (Archive::is_loading::value && version < 1) {
ar & make_nvp("m_current_value", m.m_current_value)
& make_nvp("m_initial_value", m.m_initial_value);
} else {
// use minimum size NVP label to reduce archive size bloat for very-often serialized meter values...
ar & make_nvp("c", m.m_current_value)
& make_nvp("i", m.m_initial_value);
}
}

template void serialize<freeorion_bin_oarchive>(freeorion_bin_oarchive&, Meter&, unsigned int const);
template void serialize<freeorion_xml_oarchive>(freeorion_xml_oarchive&, Meter&, unsigned int const);
template void serialize<freeorion_bin_iarchive>(freeorion_bin_iarchive&, Meter&, unsigned int const);
template void serialize<freeorion_xml_iarchive>(freeorion_xml_iarchive&, Meter&, unsigned int const);


template <typename Archive>
void ObjectMap::serialize(Archive& ar, const unsigned int version)
{
Expand Down

0 comments on commit fcf7a53

Please sign in to comment.