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


C++ EntityBase::entityInit方法代码示例

本文整理汇总了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;
}
开发者ID:Jan123457,项目名称:d3basejumper,代码行数:77,代码来源:EntityMgr.cpp


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