当前位置: 首页>>代码示例>>C++>>正文


C++ CEntity::AddComponent方法代码示例

本文整理汇总了C++中CEntity::AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ CEntity::AddComponent方法的具体用法?C++ CEntity::AddComponent怎么用?C++ CEntity::AddComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CEntity的用法示例。


在下文中一共展示了CEntity::AddComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CEntity

CEntity * CEntityFactory::CreateEntity(EntityId id){
	String buffer = String::Read(m_entitiesInfo);
	//Analizamos el XML
	xml_document<> doc;
	doc.parse<0>((char*)buffer.ToCString());
	//Dependiendo del id buscamos la entidad adecuada
	String entityName;

	switch (id){
		case EDREADNOUGHT:
			entityName = "dreadnought";
			break;
		case EAVATAR:
			entityName = "avatar";
			break;
		case EDREADNOUGHTSHOT1:
			entityName = "dreadnoughtshot1";
			break;
		case EDREADNOUGHTSHOT2:
			entityName = "dreadnoughtshot2";
			break;
		case EAVATARSHOT1:
			entityName = "avatarshot1";
			break;
		case EAVATARTRACTOR:
			entityName = "avatartractor";
			break;
		case EFIGHTERSHOT:
			entityName = "fightershot";
			break;
	}

	//Accedemos al nodo de la entidad
	xml_node<>* entityNode = doc.first_node()->first_node(entityName.ToCString());
	CEntity * entity = new CEntity(id);
	//Accedemos al nodo componentes
	xml_node<>* componentsNode = entityNode->first_node("components");
	//Accedemos al primer componente
	xml_node<>* componentNode = componentsNode->first_node();
	//Buscamos todas las componentes
	while (componentNode != nullptr){
		String name = componentNode->name();
		//Creamos el nuevo componente
		Component * component = NewComponent(name, entity, entityName);
		//Lo añadimos a la entidad
		if (component){
			entity->AddComponent(component);
		}

		componentNode = componentNode->next_sibling();
	}

	m_entities.Add(entity);
	return entity;
}
开发者ID:godilopa,项目名称:StarControl,代码行数:55,代码来源:entityFactory.cpp

示例2: is

CEntity * CEntitiesFactory::SpawnEntity(const SEntityParams * params) {
	CEntity * et = new CEntity(params->GetSide(), m_world);
	if(params->GetType() == EET_SHIP) {
		//hotfix: create controls and register to InputManager if not AI
		AddComponents(et, params);
		//if (!static_cast<const SShipParams *>(params)->IsAI()) {
		InitEntityControls(et);

		/* LOOKING INSIDE init_world.json and setting position/rotation */
		CCompTransform * transform = new CCompTransform(et, 0, 0, 0);
		et->AddComponent(transform); //will be set when init_world.json is parsed

		FILE * wFile = fopen("data/conf/init_world.json", "rb");
		char buffer[65536];
		assert(wFile != nullptr && "CEntitiesFactory::SpawnEntity()");
		rapidjson::FileReadStream is(wFile, buffer, sizeof(buffer));
		rapidjson::Document cDoc;
		cDoc.ParseStream<0, rapidjson::UTF8<>, rapidjson::FileReadStream>(is);
		assert(!cDoc.HasParseError());

		rapidjson::Value player;
		if (et->GetSide() == EGS_PLAYER_1) {
			player = cDoc["player1"];
		} else if (et->GetSide() == EGS_PLAYER_2) {
			player = cDoc["player2"];
		}

		for (rapidjson::Value::ConstMemberIterator itr = player.MemberBegin();
		itr != player.MemberEnd(); ++itr) {
			if (!strcmp(itr->name.GetString(), "position")) {
				SSetPosMsg posMsg(itr->value["x"].GetFloat(), itr->value["y"].GetFloat());
				et->ReceiveMessage(posMsg);
			} else if (!strcmp(itr->name.GetString(), "rotation")) {
				SSetRotMsg rotMsg(itr->value.GetFloat());
				et->ReceiveMessage(rotMsg);
			}
		}
		fclose(wFile);
	} else if(params->GetType() == EET_PROJECTILE) {
		AddComponents(et, params);
	} else if (params->GetType() == EET_EXPLOSION) {
		AddComponents(et, params);
	} else if (params->GetType() == EET_DECOY) {
		AddComponents(et, params);
	} else if (params->GetType() == EET_BOT) {
		AddComponents(et, params);
	}

	return et;
}
开发者ID:jjimenezg93,项目名称:star-control2,代码行数:50,代码来源:entities_factory.cpp


注:本文中的CEntity::AddComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。