Game Development Reference
In-Depth Information
The remaining systems are more useful during game development. Modern game toolsets and
engines provide the ability to update game data at runtime. Player properties such as health or the
amount of damage dealt by weapons can be updated by game designers while the game is running.
This is made possible using serialization to convert data from the tool into a data stream that the
game can then use to update its current state. This form of serialization can speed up the iteration
process of game design. I've even worked with a tool that allows designers to update all of the
current connected players in a multiplayer session midround.
These aren't the only forms of serialization you will encounter during game development, but they
are likely to be the most common. This chapter focuses on serializing game data out and in using
the C++ classes ofstream and ifstream . These classes provide the ability to serialize C++'s built-in
types to and from files stored in your device's file system. This chapter shows you how to create
classes that are aware of how to write out and read in their data using ifstream and ofstream . It
will also show you a method for managing which objects need to be serialized and how to refer to
relationships between objects using unique object IDs.
The Serialization Manager
The SerializationManager class is a Singleton that is responsible for keeping track of every object
in the game that can have its state streamed out or is referenced by another savable object. Listing
24-1 covers the class definition for the SerializationManager .
Listing 24-1. The SerializationManager Class
class SerializationManager
: public Singleton<SerializationManager>
{
private:
using Serializables = std::unordered_map<unsigned int, Serializable*>;
Serializables m_serializables;
const char* const m_filename{"Save.txt"};
public:
void RegisterSerializable(Serializable* pSerializable);
void RemoveSerializable(Serializable* pSerializable);
Serializable* GetSerializable(unsigned int serializableId) const;
void ClearSave();
void Save();
bool Load();
};
 
Search WWH ::




Custom Search