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


C++ Create::setTo方法代码示例

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


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

示例1: handleMakeResponse

LocatedEntity * CreatorClient::make(const RootEntity & entity)
{
    Create op;
    op->setArgs1(entity);
    op->setFrom(getId());
    op->setTo(getId());
    OpVector result;
    if (sendAndWaitReply(op, result) != 0) {
        std::cerr << "No reply to make" << std::endl << std::flush;
        return NULL;
    }
    assert(!result.empty());
    const Operation & res = result.front();
    if (!res.isValid()) {
        std::cerr << "NULL reply to make" << std::endl << std::flush;
        return NULL;
    }
    // FIXME Make this more robust against an info response
    if (res->getClassNo() == Atlas::Objects::Operation::SIGHT_NO) {
        if (res->getArgs().empty()) {
            std::cerr << "Reply to make has no args" << std::endl << std::flush;
            return NULL;
        }
        RootOperation arg = smart_dynamic_cast<RootOperation>(res->getArgs().front());
        if (!arg.isValid()) {
            std::cerr << "Arg of reply to make is not an operation"
                      << std::endl << std::flush;
            return NULL;
        }
        if (arg->getClassNo() != Atlas::Objects::Operation::CREATE_NO) {
            std::cerr << "Reply to make isn't sight of create"
                      << std::endl << std::flush;
            return NULL;
        }
        return handleMakeResponse(arg, res->getSeconds());
    } else if (res->getClassNo() == Atlas::Objects::Operation::INFO_NO) {
        return handleMakeResponse(res, res->getSeconds());
    } else {
        std::cerr << "Reply to make isn't sight or info"
                  << std::endl << std::flush;
        return NULL;
    }
}
开发者ID:9cat,项目名称:cyphesis,代码行数:43,代码来源:CreatorClient.cpp

示例2: createNewEntity

void SpawnerProperty::createNewEntity(LocatedEntity * e, const Operation & op,
        OpVector & res, const std::string& locId)
{
    Anonymous create_arg;
    if (!m_entity.empty()) {
        create_arg = smart_dynamic_cast<Anonymous>(
                Factories::instance()->createObject(m_entity));
        if (!create_arg.isValid()) {
            log(ERROR,
                    "Could not parse 'entity' data on spawner into Entity instance.");
            return;
        }
    } else {
        create_arg->setParents(std::list<std::string>(1, m_type));
    }
    create_arg->setLoc(locId);

    WFMath::MTRand& rand = WFMath::MTRand::instance;
    if (m_mode_external) {
        if (!e->m_location.pos().isValid()) {
            log(ERROR,
                    "Tried to spawn entity for which parent has no valid position.");
            return;
        }
        //randomize position and rotation
        float angle = rand.randf(WFMath::numeric_constants<float>::pi() * 2);
        //place it between 0 and 2 meters away
        float distance = rand.randf(2.0f);
        //if we're solid we should make sure it's not within our own radius
        if (e->m_location.isSolid() && e->m_location.bBox().isValid()) {
            distance += e->m_location.radius();
        }
        //and finally make sure that it's not beyond the radius for checking
        if (m_radius != 0.0f) {
            distance = std::min(m_radius, distance);
        }

        float x = (distance * std::cos(angle));
        float y = (distance * std::sin(angle));

        ::addToEntity(
                WFMath::Point<3>(e->m_location.pos()).shift(
                        WFMath::Vector<3>(x, y, 0)), create_arg->modifyPos());
    } else {
        //If it's an internal spawner, spawn anywhere within the bounding box.
        const BBox bbox = e->m_location.m_bBox;
        if (bbox.isValid()) {
            float x = rand.rand(bbox.highCorner().x() - bbox.lowCorner().x())
                    + bbox.lowCorner().x();
            float y = rand.rand(bbox.highCorner().y() - bbox.lowCorner().y())
                    + bbox.lowCorner().y();
            ::addToEntity(WFMath::Point<3>(x, y, 0), create_arg->modifyPos());
        } else {
            ::addToEntity(WFMath::Point<3>::ZERO(), create_arg->modifyPos());
        }
    }
    float rotation = rand.randf(WFMath::numeric_constants<float>::pi() * 2);
    WFMath::Quaternion orientation(WFMath::Vector<3>(0, 0, 1), rotation);
    create_arg->setAttr("orientation", orientation.toAtlas());

    Create create;
    create->setTo(e->m_location.m_loc->getId());
    create->setArgs1(create_arg);
    res.push_back(create);

    debug(log(NOTICE, compose("Spawner belonging to entity %1 creating new"
            " entity of type %2", e->getId(), m_type))
    ;);
开发者ID:Arsakes,项目名称:cyphesis,代码行数:68,代码来源:SpawnerProperty.cpp

示例3: assert

LocatedEntity * CreatorClient::make(const RootEntity & entity)
{
    Create op;
    op->setArgs1(entity);
    op->setFrom(getId());
    op->setTo(getId());
    OpVector result;
    if (sendAndWaitReply(op, result) != 0) {
        std::cerr << "No reply to make" << std::endl << std::flush;
        return NULL;
    }
    assert(!result.empty());
    const Operation & res = result.front();
    if (!res.isValid()) {
        std::cerr << "NULL reply to make" << std::endl << std::flush;
        return NULL;
    }
    if (res->getClassNo() != Atlas::Objects::Operation::SIGHT_NO) {
        std::cerr << "Reply to make isn't sight" << std::endl << std::flush;
        return NULL;
    }
    if (res->getArgs().empty()) {
        std::cerr << "Reply to make has no args" << std::endl << std::flush;
        return NULL;
    }
    RootOperation arg = smart_dynamic_cast<RootOperation>(res->getArgs().front());
    if (!arg.isValid()) {
        std::cerr << "Arg of reply to make is not an operation"
                  << std::endl << std::flush;
        return NULL;
    }
    if (arg->getClassNo() != Atlas::Objects::Operation::CREATE_NO) {
        std::cerr << "Reply to make isn't sight of create"
                  << std::endl << std::flush;
        return NULL;
    }
    if (arg->getArgs().empty()) {
        std::cerr << "Arg of reply to make has no args"
                  << std::endl << std::flush;
        return NULL;
    }
    RootEntity created = smart_dynamic_cast<RootEntity>(arg->getArgs().front());
    if (!created.isValid()) {
        std::cerr << "Created argument is not an entity"
                  << std::endl << std::flush;
        return NULL;
    }
    if (!created->hasAttrFlag(Atlas::Objects::ID_FLAG)) {
        std::cerr << "Created entity has no id"
                  << std::endl << std::flush;
        return NULL;
    }
    const std::string & created_id = created->getId();
    if (created->getParents().empty()) {
        std::cerr << "Created entity " << created_id << " has no type"
                  << std::endl << std::flush;
        return NULL;
    }
    const std::string & created_type = created->getParents().front();
    std::cout << "Created: " << created_type << "(" << created_id << ")"
              << std::endl << std::flush;
    LocatedEntity * obj = m_map.updateAdd(created, res->getSeconds());
    return obj;
}
开发者ID:erikogenvik,项目名称:cyphesis,代码行数:64,代码来源:CreatorClient.cpp


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