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


C++ DatagramPtr::add_location方法代码示例

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


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

示例1: annihilate

void DistributedObject::annihilate(channel_t sender, bool notify_parent)
{
    unordered_set<channel_t> targets;
    if(m_parent_id) {
        targets.insert(location_as_channel(m_parent_id, m_zone_id));
        // Leave parent on explicit delete ram
        if(notify_parent) {
            DatagramPtr dg = Datagram::create(m_parent_id, sender, STATESERVER_OBJECT_CHANGING_LOCATION);
            dg->add_doid(m_do_id);
            dg->add_location(INVALID_DO_ID, 0);
            dg->add_location(m_parent_id, m_zone_id);
            route_datagram(dg);
        }
    }
    if(m_owner_channel) {
        targets.insert(m_owner_channel);
    }
    if(m_ai_channel) {
        targets.insert(m_ai_channel);
    }
    DatagramPtr dg = Datagram::create(targets, sender, STATESERVER_OBJECT_DELETE_RAM);
    dg->add_doid(m_do_id);
    route_datagram(dg);

    delete_children(sender);

    m_stateserver->m_objs.erase(m_do_id);
    m_log->debug() << "Deleted.\n";

    terminate();
}
开发者ID:Astron,项目名称:Astron,代码行数:31,代码来源:DistributedObject.cpp

示例2: append_required_data

void DistributedObject::append_required_data(DatagramPtr dg, bool client_only, bool also_owner)
{
    dg->add_doid(m_do_id);
    dg->add_location(m_parent_id, m_zone_id);
    dg->add_uint16(m_dclass->get_id());
    size_t field_count = m_dclass->get_num_fields();
    for(size_t i = 0; i < field_count; ++i) {
        const Field *field = m_dclass->get_field(i);
        if(field->has_keyword("required") && !field->as_molecular() && (!client_only
                || field->has_keyword("broadcast") || field->has_keyword("clrecv")
                || (also_owner && field->has_keyword("ownrecv")))) {
            dg->add_data(m_required_fields[field]);
        }
    }
}
开发者ID:Astron,项目名称:Astron,代码行数:15,代码来源:DistributedObject.cpp

示例3: handle_datagram


//.........这里部分代码省略.........
        break;
    }
    case STATESERVER_OBJECT_LOCATION_ACK: {
        doid_t r_parent_id = dgi.read_doid();
        zone_t r_zone_id = dgi.read_zone();
        if(r_parent_id != m_parent_id) {
            m_log->trace() << "Received location acknowledgement from " << r_parent_id
                           << " but my parent_id is " << m_parent_id << ".\n";
        } else if(r_zone_id != m_zone_id) {
            m_log->trace() << "Received location acknowledgement for zone " << r_zone_id
                           << " but my zone_id is " << m_zone_id << ".\n";
        } else {
            m_log->trace() << "Parent acknowledged my location change.\n";
            m_parent_synchronized = true;
        }
        break;
    }
    case STATESERVER_OBJECT_SET_LOCATION: {
        doid_t new_parent = dgi.read_doid();
        zone_t new_zone = dgi.read_zone();
        m_log->trace() << "Updating location to Parent: " << new_parent
                       << ", Zone: " << new_zone << ".\n";

        handle_location_change(new_parent, new_zone, sender);

        break;
    }
    case STATESERVER_OBJECT_GET_LOCATION: {
        uint32_t context = dgi.read_uint32();

        DatagramPtr dg = Datagram::create(sender, m_do_id, STATESERVER_OBJECT_GET_LOCATION_RESP);
        dg->add_uint32(context);
        dg->add_doid(m_do_id);
        dg->add_location(m_parent_id, m_zone_id);
        route_datagram(dg);

        break;
    }
    case STATESERVER_OBJECT_GET_LOCATION_RESP: {
        // This case occurs immediately after object creation.
        // A parent expects to receive a location_resp from each
        // of its pre-existing children.

        if(dgi.read_uint32() != STATESERVER_CONTEXT_WAKE_CHILDREN) {
            m_log->warning() << "Received unexpected GetLocationResp from "
                             << dgi.read_uint32() << ".\n";
            break;
        }

        // Get DOID of our child
        doid_t doid = dgi.read_doid();

        // Get location
        doid_t r_parent = dgi.read_doid();
        zone_t r_zone = dgi.read_zone();

        // Update the child count
        if(r_parent == m_do_id) {
            m_zone_objects[r_zone].insert(doid);
        }
        break;
    }
    case STATESERVER_OBJECT_GET_ALL: {
        uint32_t context = dgi.read_uint32();
        if(dgi.read_doid() != m_do_id) {
            return;    // Not meant for this object!
开发者ID:Astron,项目名称:Astron,代码行数:67,代码来源:DistributedObject.cpp

示例4: handle_location_change

void DistributedObject::handle_location_change(doid_t new_parent, zone_t new_zone, channel_t sender)
{
    doid_t old_parent = m_parent_id;
    zone_t old_zone = m_zone_id;

    // Set of channels that must be notified about location_change
    unordered_set<channel_t> targets;

    // Notify AI of changing location
    if(m_ai_channel) {
        targets.insert(m_ai_channel);
    }

    // Notify Owner of changing location
    if(m_owner_channel) {
        targets.insert(m_owner_channel);
    }

    if(new_parent == m_do_id) {
        m_log->warning() << "Object cannot be parented to itself.\n";
        return;
    }

    // Handle parent change
    if(new_parent != old_parent) {
        // Unsubscribe from the old parent's child-broadcast channel.
        if(old_parent) { // If we have an old parent
            unsubscribe_channel(parent_to_children(m_parent_id));
            // Notify old parent of changing location
            targets.insert(old_parent);
            // Notify old location of changing location
            targets.insert(location_as_channel(old_parent, old_zone));
        }

        m_parent_id = new_parent;
        m_zone_id = new_zone;

        // Subscribe to new one...
        if(new_parent) { // If we have a new parent
            subscribe_channel(parent_to_children(m_parent_id));
            if(!m_ai_explicitly_set) {
                // Ask the new parent what its AI is.
                DatagramPtr dg = Datagram::create(m_parent_id, m_do_id, STATESERVER_OBJECT_GET_AI);
                dg->add_uint32(m_next_context++);
                route_datagram(dg);
            }
            targets.insert(new_parent); // Notify new parent of changing location
        } else if(!m_ai_explicitly_set) {
            m_ai_channel = 0;
        }
    } else if(new_zone != old_zone) {
        m_zone_id = new_zone;
        // Notify parent of changing zone
        targets.insert(m_parent_id);
        // Notify old location of changing location
        targets.insert(location_as_channel(m_parent_id, old_zone));
    } else {
        return; // Not actually changing location, no need to handle.
    }

    // Send changing location message
    DatagramPtr dg = Datagram::create(targets, sender, STATESERVER_OBJECT_CHANGING_LOCATION);
    dg->add_doid(m_do_id);
    dg->add_location(new_parent, new_zone);
    dg->add_location(old_parent, old_zone);
    route_datagram(dg);

    // At this point, the new parent (which may or may not be the same as the
    // old parent) is unaware of our existence in this zone.
    m_parent_synchronized = false;

    // Send enter location message
    if(new_parent) {
        send_location_entry(location_as_channel(new_parent, new_zone));
    }
}
开发者ID:Astron,项目名称:Astron,代码行数:76,代码来源:DistributedObject.cpp


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