本文整理汇总了C++中EntityBase::entityInit方法的典型用法代码示例。如果您正苦于以下问题:C++ EntityBase::entityInit方法的具体用法?C++ EntityBase::entityInit怎么用?C++ EntityBase::entityInit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityBase
的用法示例。
在下文中一共展示了EntityBase::entityInit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createEntity
entid_t EntityMgr::createEntity(const char * type, entid_t idParent, Object * param) {
if (NULL==type) throw Exception("core: Invalid entity type [NULL]");
if (-1!=idParent) checkId(idParent);
// Get component
ComponentMgr * comgr = SingleComponentMgr::getInstance();
IComponent * c = comgr->getComponentForType(type);
// Try to create entity
EntityBase * e = NULL;
try {
// Find creator
const EntityTypeInfo * t = c->getTypeInfo();
for (; t && t->typeName; ++t) {
if (stricmp(t->typeName, type)==0) {
if (t->creator==NULL) break;
e = t->creator();
break;
}
}
if (NULL==e) throw Exception("core: Unable to find entity creator");
}
catch(const Exception& e) {
SingleCore::getInstance()->logMessage("core: Exception while creating entity '%s' -->>\n%s", type, (const char*)e);
throw;
}
catch(...) {
SingleCore::getInstance()->logMessage("core: Unknown exception while creating entity '%s'", type);
throw;
}
if (e==NULL) throw Exception("core: Error creating entity %s", type);
// Find type chunk if the one exists; if not, create it
typeid_t typeId = -1;
MapTypeId::const_iterator it=mapTypeId.find(type);
if (it==mapTypeId.end()) {
typeId = createChunkType(c, type);
mapTypeId[type]=typeId;
}
else typeId = it->second;
// Add entity information
entid_t id = createChunkEntity(e, typeId);
chunkType[typeId].instances.push_back(id);
if (-1!=idParent) {
EntityChunk& ecParent=chunkEntity[idParent];
ecParent.children.back()=id;
ecParent.children.push_back(-1);
const_cast<const entid_t*&>(ecParent.entity->childId) = &ecParent.children[0];
}
EntityChunk& ec = chunkEntity[id];
const_cast<entid_t&>(e->entityId) = id;
const_cast<entid_t&>(e->parentId) = idParent;
const_cast<const entid_t*&>(e->childId) = &ec.children[0];
const_cast<ICore*&>(e->icore) = SingleCore::getInstance();
// Try to init entity
bool init=false;
try {
e->entityInit(param);
init=true;
}
catch(const Exception& e) {
SingleCore::getInstance()->logMessage("core: Exception in %s::entityInit() -->>\n%s", type, (const char*)e);
destroyEntity(id);
throw;
}
catch(...) {
SingleCore::getInstance()->logMessage("core: Unknown exception in %s::entityInit()", type);
destroyEntity(id);
throw;
}
// Notify subscribers that entity has been created
TrigEntityLife::Param trigParam;
trigParam.eid = id;
trigParam.lifeTime = entityCreated;
trigParam.param = param;
trigParam.entityType = chunkType[chunkEntity[id].typeId].name;
getCore()->activate(TrigEntityLife::tid,&trigParam);
return id;
}