18 #include "precompiled.h"
56 std::map<entity_id_t, std::map<ComponentTypeId, IComponent*> > components;
59 std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> >::const_iterator ctit =
m_ComponentsByTypeId.begin();
62 std::map<entity_id_t, IComponent*>::const_iterator eit = ctit->second.begin();
63 for (; eit != ctit->second.end(); ++eit)
65 components[eit->first][ctit->first] = eit->second;
69 std::map<entity_id_t, std::map<ComponentTypeId, IComponent*> >::const_iterator cit = components.begin();
70 for (; cit != components.end(); ++cit)
73 n <<
"- id: " << cit->first;
79 std::map<ComponentTypeId, IComponent*>::const_iterator ctit = cit->second.begin();
80 for (; ctit != cit->second.end(); ++ctit)
86 ctit->second->Serialize(serializer);
109 std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> >::const_iterator cit =
m_ComponentsByTypeId.begin();
117 bool needsSerialization =
false;
118 for (std::map<entity_id_t, IComponent*>::const_iterator eit = cit->second.begin(); eit != cit->second.end(); ++eit)
124 needsSerialization =
true;
128 if (!needsSerialization)
133 for (std::map<entity_id_t, IComponent*>::const_iterator eit = cit->second.begin(); eit != cit->second.end(); ++eit)
140 eit->second->Serialize(serializer);
183 std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> >::const_iterator cit;
186 std::set<ComponentTypeId> serializedComponentTypes;
191 bool needsSerialization =
false;
192 for (std::map<entity_id_t, IComponent*>::const_iterator eit = cit->second.begin(); eit != cit->second.end(); ++eit)
198 needsSerialization =
true;
202 if (!needsSerialization)
206 serializedComponentTypes.insert(cit->first);
213 if (serializedComponentTypes.find(cit->first) == serializedComponentTypes.end())
216 std::map<ComponentTypeId, ComponentType>::const_iterator ctit =
m_ComponentTypesById.find(cit->first);
223 serializer.
StringASCII(
"name", ctit->second.name, 0, 255);
227 for (std::map<entity_id_t, IComponent*>::const_iterator eit = cit->second.begin(); eit != cit->second.end(); ++eit)
240 for (std::map<entity_id_t, IComponent*>::const_iterator eit = cit->second.begin(); eit != cit->second.end(); ++eit)
247 eit->second->Serialize(serializer);
277 for (
size_t i = 0; i < numComponentTypes; ++i)
285 LOGERROR(L
"Deserialization saw unrecognised component type '%hs'", ctname.c_str());
292 for (
size_t j = 0; j < numComponents; ++j)
318 if (stream.peek() != EOF)
320 LOGERROR(L
"Deserialization didn't reach EOF");
An entity initialisation parameter node.
virtual void StringASCII(const char *name, std::string &out, uint32_t minlength, uint32_t maxlength)
void ResetState()
Resets the dynamic simulation state (deletes all entities, resets entity ID counters; doesn't unload/...
#define ENTITY_IS_LOCAL(id)
std::string SerializeRNG(const boost::rand48 &rng)
virtual void NumberU32_Unbounded(const char *name, uint32_t &out)
Serialize to a human-readable YAML-like format.
bool SerializeState(std::ostream &stream)
entity_id_t m_NextEntityId
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
CEntityHandle LookupEntityHandle(entity_id_t ent, bool allowCreate=false)
Returns a CEntityHandle with id ent.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
std::map< ComponentTypeId, std::map< entity_id_t, IComponent * > > m_ComponentsByTypeId
void StringASCII(const char *name, const std::string &value, uint32_t minlength, uint32_t maxlength)
Serialize an ASCII string.
boost::mt19937 rng
Random number generator (Boost Mersenne Twister)
bool ComputeStateHash(std::string &outHash, bool quick)
virtual const char * what() const
ScriptInterface m_ScriptInterface
void InitSystemEntity()
Set up an empty SYSTEM_ENTITY.
void TextLine(const std::string &text)
void NumberU32_Unbounded(const char *name, uint32_t value)
Serialize a number.
bool DeserializeState(std::istream &stream)
virtual void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize)=0
std::string LookupComponentTypeName(ComponentTypeId cid) const
bool DumpDebugState(std::ostream &stream, bool includeDebugInfo)
IComponent * ConstructComponent(CEntityHandle ent, ComponentTypeId cid)
Allocates a component object of type 'cid', and attaches it to entity 'ent'.
Template manager: Handles the loading of entity template files for the initialisation and deserializa...
std::vector< entity_id_t > m_DestructionQueue
ComponentTypeId LookupCID(const std::string &cname) const
std::map< ComponentTypeId, ComponentType > m_ComponentTypesById
void DeserializeRNG(const std::string &str, boost::rand48 &rng)
void NumberI32_Unbounded(const char *name, int32_t value)
Serialize a number.
#define debug_warn(expr)
display the error dialog with the given text.
virtual const CParamNode * LoadLatestTemplate(entity_id_t ent)=0
Returns the template most recently specified for the entity 'ent'.
u32 entity_id_t
Entity ID type.