예제 #1
0
//属性同步
T_VECTOR_OBJECT* CRpcUtil::DecodeEntityAttriSync(CPluto& u)
{
    uint32_t eid;
    uint16_t etype, nPropId;
    u >> eid >> etype >> nPropId;

    const SEntityDef* pDef = GetWorld()->GetDefParser().GetEntityDefByType(etype);
    if(pDef)
    {
        const string& strPropName = pDef->m_propertiesMap.GetStrByInt(nPropId);
        map<string, _SEntityDefProperties*>::const_iterator iter = pDef->m_properties.find(strPropName);
        if(iter != pDef->m_properties.end())
        {
            if(u.GetDecodeErrIdx() == 0)
            {
                _SEntityDefProperties* pProp = iter->second;

                VOBJECT* v = new VOBJECT;
                u.FillVObject(pProp->m_nType, *v);

                if(u.GetDecodeErrIdx() == 0)
                {
                    T_VECTOR_OBJECT* ll = new T_VECTOR_OBJECT;

                    VOBJECT* v2 = new VOBJECT;
                    v2->vt = V_UINT32;
                    v2->vv.u32 = eid;
                    ll->push_back(v2);

                    v2 = new VOBJECT;
                    v2->vt = V_STR;
                    v2->vv.s = new string(strPropName);
                    ll->push_back(v2);

                    ll->push_back(v);

                    //如果带client标记,多添加一个值给world.from_rpc_call
                    if(IsClientFlag(pProp->m_nFlags))
                    {
                        v2 = new VOBJECT;
                        v2->vt = V_UINT16;
                        v2->vv.u16 = nPropId;
                        ll->push_back(v2);
                    }

                    return ll;
                }
                else
                {
                    delete v;
                    return NULL;
                }
            }
        }

    }

    return NULL;
}
예제 #2
0
    bool CEntityBase::PickleClientToPluto(CPluto& u)
    {
        //类似于CEntityParent::pickle_to_pluto,打包所有需要存盘的字段
        //打包所有待client标记的字段
        const SEntityDef* pDef = this->GetEntityDef();
        if(pDef)
        {
            u << m_etype << m_id << m_dbid;              //必须包含entity_type,以便接包时查询def数据
            LogDebug("CEntityBase::PickleClientToPluto", "m_etype=%d;m_id=%d;m_dbid=%d", m_etype, m_id, m_dbid);
            map<string, _SEntityDefProperties*>::const_iterator iter = pDef->m_properties.begin();
            for(; iter != pDef->m_properties.end(); ++iter)
            {
                _SEntityDefProperties* p = iter->second;
                if(IsClientFlag(p->m_nFlags))
                {
                    const string& strEntityName = iter->first;
                    map<string, VOBJECT*>::const_iterator iter2 = m_data.find(strEntityName);
                    if(iter2 == m_data.end())
                    {
                        //todo warning...
                        continue;
                    }

                    //u << iter2->first.c_str();
                    uint16_t attr_id = (uint16_t)(pDef->m_propertiesMap.GetIntByStr(iter2->first));
                    u << attr_id;

                    //LogDebug("CEntityBase::PickleClientToPluto", "attr_id=%d;first=%s", attr_id, iter2->first.c_str());

                    u.FillPluto(*(iter2->second));
                }
            }
            //print_hex_pluto(u);
        }

        return pDef != NULL;
    }