本文整理汇总了C++中CEntity::add方法的典型用法代码示例。如果您正苦于以下问题:C++ CEntity::add方法的具体用法?C++ CEntity::add怎么用?C++ CEntity::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CEntity
的用法示例。
在下文中一共展示了CEntity::add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onStartElement
void CEntityParser::onStartElement(const std::string &elem, MKeyValue &atts) {
if (!hasToParse(elem)) return;
if (curr_prefab_compiler) {
CPrefabCompiler::TCall c;
c.is_start = true;
c.elem = elem;
c.atts = atts;
curr_prefab_compiler->calls.push_back(c);
}
else if (curr_slept_compiler && elem != "tags") {
CPrefabCompiler::TCall c;
c.is_start = true;
c.elem = elem;
c.atts = atts;
curr_slept_compiler->calls.push_back(c);
}
if (elem == "entities") {
return;
}
CHandle new_h;
bool reusing_component = false;
// Check if we find a new entity with the prefab attr
if (elem == "entity") {
curr_entity_permanent = atts.getBool("permanent", false);
curr_entity_reload = atts.getBool("reload", false);
curr_entity_temp = atts.getBool("temp", false);
curr_entity_keyboard = atts.getBool("only_keyboard", false);
curr_entity_pad = atts.getBool("only_pad", false);
//entity_load_accum = 0.f;
if (!hasToCreate()) {
curr_entity = CHandle();
return;
}
else {
curr_entity_id = atts.getInt("id", -1);
curr_entity_slept = atts.getBool("slept", false);
if (curr_entity_slept) curr_slept_compiler = new CPrefabCompiler;
auto prefab = atts["prefab"];
if (!prefab.empty()) new_h = createPrefab(prefab);
}
}
if (!hasToCreate()) return;
// Inside an entity...?
if (curr_entity.isValid()) {
auto hm = CHandleManager::getByName(elem.c_str());
// Check if the current entity already has this type
// of component...
CEntity* e = curr_entity;
IdEntities::saveIdEntity(CHandle(e), curr_entity_id);
e->setPermanent(curr_entity_permanent);
e->setReload(curr_entity_reload);
e->setTemp(curr_entity_temp);
new_h = e->getByCompIndex(hm->getType());
reusing_component = new_h.isValid();
}
// If not prefab has been generated... create one of the
// type of the tag
if (!new_h.isValid()) {
if (MUST_ADD_COMPONENT) {
auto hm = CHandleManager::getByName(elem.c_str());
new_h = hm->createHandle();
}
}
if (elem == "entity") {
curr_entity = new_h;
}
// Estoy parseando un component
else {
assert(curr_entity.isValid());
CEntity* e = curr_entity;
new_h.load(atts);
if (!curr_slept_compiler && elem == "rigidbody" && atts["type_collision"] == "static") {
collisionables.push_back(curr_entity);
}
if (!reusing_component && MUST_ADD_COMPONENT) {
e->add(new_h);
}
}
}
示例2: onEndElement
void CEntityParser::onEndElement(const std::string &elem) {
//if (loading_control) GameController->AddLoadingState(0.f); // for update
if (!hasToParse(elem)) return;
if (curr_prefab_compiler) {
CPrefabCompiler::TCall c;
c.is_start = false;
c.elem = elem;
curr_prefab_compiler->calls.push_back(c);
}
if (MUST_COMPILE_SNOOZER) {
CPrefabCompiler::TCall c;
c.is_start = false;
c.elem = elem;
curr_slept_compiler->calls.push_back(c);
}
//dbg("Bye from %s\n", elem.c_str());
if (elem == "entity") {
if (!curr_entity.isValid()) return;
handles.push_back(curr_entity);
if (curr_slept_compiler) {
auto hmSnoozer = CHandleManager::getByName("snoozer");
CHandle snoozer = hmSnoozer->createHandle();
CEntity * e = curr_entity;
e->add(snoozer);
TMsgPreload msgPreload;
msgPreload.comps = curr_slept_compiler;
e->sendMsg(msgPreload);
}
// Keep track of the first entity found in the file
if (!root_entity.isValid())
root_entity = curr_entity;
curr_entity = CHandle();
curr_slept_compiler = nullptr;
if (loading_control)
GameController->AddLoadingState(entity_load_value);
//GameController->AddLoadingState(entity_load_value - entity_load_accum);
}
//else {
// float to_add = 0.1 * entity_load_value;
// if (to_add + entity_load_accum > entity_load_value)
// to_add = entity_load_value - entity_load_accum;
// entity_load_accum += to_add;
// GameController->AddLoadingState(to_add);
//}
if (elem == "entities" || elem == "prefab") {
for (auto h : handles) {
CEntity*e = h;
dbg("Entity created!! [%s]\n", e->getName());
e->sendMsg(TMsgEntityCreated());
}
// Send the group has been created msg
TMsgEntityGroupCreated msg = { &handles };
for (auto h : handles)
((CEntity*)h)->sendMsg(msg);
}
}
示例3: start
//.........这里部分代码省略.........
SUBSCRIBE(bt_scientist, TMsgAISetPossessed, onSetPossessed);
SUBSCRIBE(bt_scientist, TMsgAISetStunned, onSetStunned);
SUBSCRIBE(player_controller_cientifico, TMsgControllerSetEnable, onSetEnable);
SUBSCRIBE(player_controller_cientifico, TMsgGetWhoAmI, onGetWhoAmI);
SUBSCRIBE(player_controller_cientifico, TMsgCanRechargeDrone, onCanRepairDrone);
//..Mole
SUBSCRIBE(bt_mole, TMsgAISetPossessed, onSetPossessed);
SUBSCRIBE(bt_mole, TMsgAISetStunned, onSetStunned);
SUBSCRIBE(player_controller_mole, TMsgControllerSetEnable, onSetEnable);
SUBSCRIBE(player_controller_mole, TMsgGetWhoAmI, onGetWhoAmI);
//..PJ Principal
SUBSCRIBE(player_controller, TMsgPossessionLeave, onLeaveFromPossession);
SUBSCRIBE(player_controller, TMsgGetWhoAmI, onGetWhoAmI);
//Guard
SUBSCRIBE(bt_guard, TMsgGetWhoAmI, onGetWhoAmI);
//Dead
//anything for now
/*SUBSCRIBE(player_controller, TMsgDie, onDie);
SUBSCRIBE(player_controller_cientifico, TMsgDie, onDie);
SUBSCRIBE(player_controller_mole, TMsgDie, onDie);*/
//Damage
SUBSCRIBE(TCompLife, TMsgEntityCreated, onCreate); //init damage scales
SUBSCRIBE(TCompLife, TMsgDamageSave, onSetSaveDamage);
SUBSCRIBE(TCompLife, TMsgDamage, onDamage);
SUBSCRIBE(TCompLife, TMsgSetDamage, onReciveDamage);
SUBSCRIBE(TCompLife, TMsgStopDamage, onStopDamage);
SUBSCRIBE(player_controller_cientifico, TMsgUnpossesDamage, onForceUnPosses);
SUBSCRIBE(player_controller_mole, TMsgUnpossesDamage, onForceUnPosses);
SUBSCRIBE(bt_scientist, TMsgUnpossesDamage, onForceUnPosses);
SUBSCRIBE(bt_mole, TMsgUnpossesDamage, onForceUnPosses);
SUBSCRIBE(TCompCameraMain, TMsgGetCullingViewProj, onGetViewProj);
SUBSCRIBE(TCompLightDirShadows, TMsgGetCullingViewProj, onGetViewProj);
SUBSCRIBE(TCompLightDirShadowsDynamic, TMsgGetCullingViewProj, onGetViewProj);
SUBSCRIBE(TCompCamera, TMsgGetCullingViewProj, onGetViewProj);
//Control
SUBSCRIBE(player_controller, TMsgSetControllable, onSetControllable);
SUBSCRIBE(player_controller_cientifico, TMsgSetControllable, onSetControllable);
SUBSCRIBE(player_controller_mole, TMsgSetControllable, onSetControllable);
SUBSCRIBE(TCompController3rdPerson, TMsgSetControllable, onSetControllable);
SUBSCRIBE(player_controller, TMsgSetOnlySense, onSetOnlySense);
SUBSCRIBE(player_controller_cientifico, TMsgSetOnlySense, onSetOnlySense);
SUBSCRIBE(player_controller_mole, TMsgSetOnlySense, onSetOnlySense);
//Go And Look
SUBSCRIBE(player_controller, TMsgGoAndLook, onGoAndLook);
SUBSCRIBE(player_controller_cientifico, TMsgGoAndLook, onGoAndLook);
SUBSCRIBE(player_controller_mole, TMsgGoAndLook, onGoAndLook);
//SUBSCRIBE(bt_guard, TMsgGoAndLookAs, onGoAndLook);
//SUBSCRIBE(bt_mole, TMsgGoAndLookAs, onGoAndLook);
//Fx
SUBSCRIBE(TCompFadeScreen, TMsgEntityCreated, onCreate);
//System
SUBSCRIBE(bt_guard, TMsgDifficultyChanged, onDifficultyChanged);
SUBSCRIBE(player_controller, TMsgDifficultyChanged, onDifficultyChanged);
//Gui
SUBSCRIBE(TCompGui, TMsgEntityCreated, onCreate); //Este onCreate se encarga de llamar al resto de creates de gui!
//SUBSCRIBE(TCompGuiSelector, TMsgEntityCreated, onCreate);
//SUBSCRIBE(TCompLoadingScreen, TMsgEntityCreated, onCreate);
SUBSCRIBE(TCompGuiCursor, TMsgOverButton, onButton);
SUBSCRIBE(TCompGuiCursor, TMsgEntityCreated, onCreate);
SUBSCRIBE(TCompGuiButton, TMsgEntityCreated, onCreate);
SUBSCRIBE(TCompGuiButton, TMsgClicked, onClick);
SUBSCRIBE(TCompGuiButton, TMsgGuiSetListener, onSetListener);
SUBSCRIBE(TCompGuiSelector, TMsgGuiNotify, onGuiNotify);
//SUBSCRIBE(TCompGuiSelector, TMsgLanguageChanged, onLanguageChanged);
SUBSCRIBE(TCompGuiDrag, TMsgEntityCreated, onCreate);
SUBSCRIBE(TCompText, TMsgLanguageChanged, onLanguageChanged);
SUBSCRIBE(TCompFadingMessage, TMsgLanguageChanged, onLanguageChanged);
SUBSCRIBE(TCompText, TMsgControlsChanged, onControlsChanged);
SUBSCRIBE(TCompFadingMessage, TMsgControlsChanged, onControlsChanged);
auto hm = CHandleManager::getByName("entity");
CHandle new_hp = hm->createHandle();
CEntity* entity = new_hp;
auto hm1 = CHandleManager::getByName("name");
CHandle new_hn = hm1->createHandle();
MKeyValue atts1;
atts1.put("name", "playerTalk");
new_hn.load(atts1);
entity->add(new_hn);
auto hm3 = CHandleManager::getByName("helper_message");
CHandle new_hl = hm3->createHandle();
entity->add(new_hl);
entity->setPermanent(true);
return true;
}