struct SNetObjectID { const uint16 InvalidId = ~uint16(0); uint16 id; uint16 salt; enum ESerializationTarget { eST_SaveGame, eST_Network, eST_Script }; struct ISerializeUpdateFunction { }; template <class F_Update> class CSerializeUpdateFunction : public ISerializeUpdateFunction; struct SSerializeString { }; struct ISerialize { const int ENUM_POLICY_TAG = 0xe0000000; }; template <class TISerialize> class CSerializeWrapper; struct ISerializable { }; struct SSerializeScopedBeginGroup { }; };
ISerialize.h
Unfortunately this needs to be here - should be in CryNetwork somewhere.
template <class F_Update> class CSerializeUpdateFunction : public ISerializeUpdateFunction;
ISerialize.h
concrete implementation of IUpdateFunction for a general functor class
CSerializeUpdateFunction(F_Update& update);
virtual void Execute();
template <class TISerialize> class CSerializeWrapper;
ISerialize.h
this class provides a wrapper so that ISerialize can be used much more easily; it is a template so that if we need to wrap a more specific ISerialize implementation we can do so easily
void BeginGroup(const char * szName);
// we can request that a functor be called whenever our values // are being updated by calling this function template
bool BeginOptionalGroup(const char * szName, bool condition);
CONTAINER_VALUE(VectorSet, insert);
CONTAINER_VALUE(std::deque, push_back);
CONTAINER_VALUE(std::list, push_back);
CONTAINER_VALUE(std::set, insert);
CONTAINER_VALUE(std::vector, push_back);
CSerializeWrapper(TISerialize * pSerialize);
template <typename T_Value> void DummyValues(uint32 numDummyValues);
void EndGroup();
template <typename T_Value, class T_Class> void EnumValue(const char * szName, T_Class * pClass, T_Value (T_Class::*GetValue)() const, void (T_Class::*SetValue)(T_Value), T_Value first, T_Value last);
template <typename T_Value> void EnumValue(const char * szName, T_Value& value, T_Value first, T_Value last);
ESerializationTarget GetSerializationTarget() const;
fetch the serialization target
HASH_CONTAINER_VALUE(stl::hash_map);
bool IsReading() const;
bool IsWriting() const;
MAP_CONTAINER_VALUE(VectorMap);
MAP_CONTAINER_VALUE(std::map);
MAP_CONTAINER_VALUE(std::multimap);
template <typename T_Value, uint8 N, class T_Map> void MappedValue(const char * name, MiniQueue& cont, const T_Map& mapper);
template <class T_Key, class T_Map> void MappedValue(const char * szName, T_Key& value, const T_Map& mapper);
a value that is written by referring to a map of key/value pairs - we receive the key, and write the value
bool Ok() const;
PAIR_CONTAINER_VALUE(std::list, push_back);
PAIR_CONTAINER_VALUE(std::vector, push_back);
bool ShouldCommitValues() const;
template <class T> void Value(const char * name, CountedValue& countedValue);
template <class T> void Value(const char * name, CountedValue& countedValue, int policy);
template <typename T> void Value(const char * szName, const CryStringLocalT& value);
template <typename T> void Value(const char * szName, const CryStringLocalT& value, int policy);
void Value(const char * name, IScriptTable * pTable);
template <typename T_Value, uint8 N> void Value(const char * name, MiniQueue& cont);
void Value(const char * name, SmartScriptTable& pTable);
template <class T_Class, typename T_Value> void Value(const char * szName, T_Class * pInst, T_Value (T_Class::*get)() const, void (T_Class::*set)(T_Value));
template <class T_Class, typename T_Value, class T_SerializationPolicy> void Value(const char * szName, T_Class * pInst, T_Value (T_Class::*get)() const, void (T_Class::*set)(T_Value), const T_SerializationPolicy& policy);
template <typename T_Value> void Value(const char * szName, T_Value& value);
template <typename T_Value> void Value(const char * szName, T_Value& value, int policy);
the value function allows us to declare that a value needs to be serialized/deserialized; we can pass a serialization policy in order to compress the value, and an update function to allow us to be informed of when this value is changed
void Value(const char * szName, const string& value);
void Value(const char * szName, const string& value, int policy);
templatevoid Value(const char* szName, CryFixedStringT & value);
templatevoid Value(const char* szName, CryFixedStringT & value, int policy);
template <class T, class TT> void Value(const char* name, InterpolatedValue_tpl& val);
template <class T, class TT> void Value(const char* name, InterpolatedValue_tpl& val, int policy);
bool ValueChar(const char * name, char * buffer, int len);
template <typename T> void ValueWithDefault(const char * name, T& x, const T & defaultValue);
void ValueWithDefault(const char * szName, string& value, const string& defaultValue);
friend TISerialize * GetImpl( CSerializeWrapperser ) { return ser.m_pSerialize; } void FlagPartialRead() { m_pSerialize->FlagPartialRead(); } operator CSerializeWrapper<ISerialize>() { return CSerializeWrapper<ISerialize>( m_pSerialize ); } SSerializeString& SetSharedSerializeString(const string& str) { ScopedSwitchToGlobalHeap useGlobalHeap; static SSerializeString serializeString; serializeString.set_string(str); return serializeString; } template SSerializeString& SetSharedSerializeString(const CryFixedStringT & str) { ScopedSwitchToGlobalHeap useGlobalHeap; static SSerializeString serializeString; serializeString.set_string(str); return serializeString; } private: TISerialize * m_pSerialize;
enum ESerializationTarget { eST_SaveGame, eST_Network, eST_Script };
ISerialize.h
this enumeration details what "kind" of serialization we are performing, so that classes that want to, for instance, tailor the data they present depending on where data is being written to can do so
struct ISerializable { };
ISerialize.h
simple struct to declare something serializable... useful for exposition
virtual ~ISerializable();
virtual void SerializeWith(TSerialize) = 0;
struct ISerialize { const int ENUM_POLICY_TAG = 0xe0000000; };
ISerialize.h
the ISerialize is intended to be implemented by objects that need to read and write from various data sources, in such a way that different tradeoffs can be balanced by the object that is being serialized, and so that objects being serialized need only write a single function in order to be read from and written to
const int ENUM_POLICY_TAG = 0xe0000000;
virtual ~ISerialize();
virtual void BeginGroup(const char * szName) = 0;
Begins a serialization group - must be matched by an EndGroup szName is preferably as short as possible for performance reasons Spaces in szName cause undefined behaviour, use alpha characters,underscore and numbers only for a name.
virtual bool BeginOptionalGroup(const char * szName, bool condition) = 0;
virtual void EndGroup() = 0;
virtual void FlagPartialRead() = 0;
for network updates: notify the network engine that this value was only partially read and we should re-request an update from the server soon
virtual ESerializationTarget GetSerializationTarget() const = 0;
ISerialize();
virtual bool IsReading() const = 0;
virtual bool Ok() const = 0;
virtual void ReadStringValue(const char * name, SSerializeString & curValue, uint32 policy = 0) = 0;
this is for string values -- they need special support
SERIALIZATION_TYPE(SSerializeString);
virtual bool ShouldCommitValues() const = 0;
virtual void Update(ISerializeUpdateFunction * pUpdate) = 0;
this function should be implemented to call the passed in interface if we are reading, and to not call it if we are writing
template <class B> SERIALIZATION_TYPE void Value(const char * name, B& x);
template <class B> void Value(const char * name, B& x, uint32 policy);
template <class B> void ValueWithDefault(const char * name, B& x, const B& defaultValue);
Based off ValueWithDefault in SimpleSerialize.h
virtual void WriteStringValue(const char * name, SSerializeString& buffer, uint32 policy = 0) = 0;
struct ISerializeUpdateFunction { };
ISerialize.h
this inner class defines an interface so that OnUpdate functions can be passed abstractly through to concrete serialization classes
virtual ~ISerializeUpdateFunction();
virtual void Execute() = 0;
struct SSerializeScopedBeginGroup { };
ISerialize.h
Used to automatically Begin/End group in serialization stream
SSerializeScopedBeginGroup(TSerialize & ser, const char * sGroupName);
struct SSerializeString { };
ISerialize.h
Temporary class for string serialization.
bool operator !=(const SSerializeString & src);
~SSerializeString();
SSerializeString& operator =(const SSerializeString & src);
operator const char* () const { return m_str;
SSerializeString& operator =(const char * src);
const char* c_str() const;
operator const string() const;
bool empty() const;
size_t length() const;
void reserve(int sz);
void resize(int sz);
templatevoid set_string(const CryFixedStringT & s);
void set_string(const string & s);
size_t size() const;
AUTO_STRUCT_INFO SSerializeString();
SSerializeString(const SSerializeString & src);
SSerializeString(const char * s);
Casting to const char
explicit SSerializeString(const char * sbegin, const char * send);
uint16 id;
uint16 salt;
bool operator !() const;
bool operator !=(const SNetObjectID& rhs) const;
bool operator <(const SNetObjectID& rhs) const;
bool operator ==(const SNetObjectID& rhs) const;
bool operator >(const SNetObjectID& rhs) const;
uint32 GetAsUint32() const;
void GetMemoryUsage(ICrySizer * pSizer) const;
const char * GetText(char * tmpBuf = 0) const;
bool IsLegal() const;
SNetObjectID();
uint16(SNetObjectID::* unknown_bool_type);
operator unknown_bool_type() const;
typedef CSerializeWrapper<ISerialize> TSerialize;
default serialize class to use!!