本文整理汇总了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;
}
示例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;
}