Пример #1
0
    int EntityManager::deserializeEntity(Packet& packet)
    {
        // **************************************
        // Create the entity

        int ID = getNewEntityID();
        mEntityCount++;

        packet >> mUniqueIDs[ID];

        // Tell the observers that this entity has been created.
        for (auto observer : mObservers)
            observer->onEntityCreated(createEntityRef(ID));

        // **************************************
        // Deserialize the entity's components

        ComponentType componentCount;
        packet >> componentCount;

        for (std::size_t i = 0; i < static_cast<std::size_t>(componentCount); i++)
        {
            ComponentType type;
            packet >> type;

            addComponentToEntity(ID, type);
            mComponents[type][ID]->deserialize(packet, *this);
        }

        return ID;
    }
Пример #2
0
bool WSWorld::init()
{
	m_worldPopulation = 0;
	if( !loadTerrain( WSApp::instance()->getSetting("/config/WorldCfg")) )
		return false;

	TiXmlDocument	doc;
	CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlInfo,__FUNCTION__, _("Loading mobs info..."));
	doc.LoadFile("../data/zones/teeran/mobs.xml");
	if (doc.Error())
	{
		CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlError,__FUNCTION__, _("XML parser returned an error: %s\n"), doc.ErrorDesc());
		return false;
	}


	TiXmlElement* mobsxml = doc.FirstChildElement("mobs");
	CWorldCharMob::setDefaults(mobsxml);

	TiXmlNode* childNode;
	for ( childNode = mobsxml->FirstChild(); childNode != 0; childNode = childNode->NextSibling() )
		if (childNode->Type() == TiXmlNode::ELEMENT)
			if (!strcmp(childNode->Value(), "mob"))
//			{
				insertEntity(WSEntityPtr(new CWorldCharMob(getNewEntityID(), childNode->ToElement())));
//			 	CharMobPtr mob(new CWorldCharMob(childNode->ToElement()));
//				insertCharMob(mob);
//			}
			else if (!strcmp(childNode->Value(), "flock"))
//			{
				insertEntity(WSEntityPtr(new CMobFlock(getNewEntityID(), childNode->ToElement())));
//				MobFlockPtr flock(new CMobFlock(childNode->ToElement()));
//				m_flocks.push_back(flock);
//			}

	CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlInfo,__FUNCTION__, _("WSWorld.init: Done."));
	return true;
};
Пример #3
0
    int EntityManager::createEntity(bool giveUniqueID)
    {
        int ID = getNewEntityID();

        if (giveUniqueID)
        {
            mUniqueIDs[ID] = mNextUniqueID++;
        }

        mEntityCount++;

        // Tell the observers that this entity has been created.
        for (auto observer : mObservers)
            observer->onEntityCreated(createEntityRef(ID));

        return ID;
    }