首页 > 代码库 > MoveManager管理类

MoveManager管理类

MoveManager:移动管理类struct MoveOpt{    int cur_seq;    ObjecInfo* obj;};std::map<ObjID, MoveOpt> m_move_objs;//主要容器//加入移动标记void MoveManager::add_mask(ObjecInfo* obj){    auto& objId = obj->objId;    MoveOpt mov_opt = {m_move_seq++, obj};    m_move_objs[objId] = mov_opt;}主要函数//每个玩家都有std::vector<ObjTgtPos> tmpPos;临时位置//用于保存附近玩家的移动信息,所有当一个玩家或者NPC移动时addMask()这样其就加入到m_move_objsvoid MoveManager::run(){    time_t tb = GetTickCount();    if(m_move_objs.empty())        return ;    //需要通知的player    std::map<int, PlayerInfo*> tmpPlayers;     for(auto it = m_move_objs.begin(); it != m_move_objs.end(); ++it)//遍历移动玩家列表    {        auto objex = (ObjecInfoEx*)it->second.obj;        ObjTgtPos pos;        pos.seq = it->second.cur_seq; //顺序变量        pos.speed = objex->speed;        pos.objId = objex->objId;        pos.player.tgtPos = objex->tgtPos;        pos.player.curPos = objex->curPos;        pos.mov_face = objex->mov_face;        pos.dir = objex->dir;        if(it->first.type == ObjID_Player)        {            auto player = (PlayerInfo*)objex;            auto& near_pls = player->nearby_players;             for(auto p : near_pls)            {                //将玩家的移动位置和顺序变量加入到其附近玩家的tmpPos                p.second->tmpPos.push_back(pos);//临时位置,我在想为什么要搞个向量保存,每次只保存一个还要向量?                tmpPlayers[p.first] = p.second;            }        }        else        {            //NPC也是将其位置加入到附近玩家的tmpPos            auto monster = (I_NPC*)objex;            auto& near_players = monster->map_nearby_player;            for(auto p : near_players)            {                p.second->tmpPos.push_back(pos);                tmpPlayers[p.first] = p.second;            }        }    }    //然后向附近玩家发送位置信息,然后客户端表现就行了    for(auto it = tmpPlayers.begin(); it != tmpPlayers.end(); it++)    {            it->second->send_mul_pos(it->second->tmpPos);//std::vector<playerTgtPos> tmpPos        it->second->tmpPos.clear();    }    this->clear();//清除本次移动记录将m_move_objs.clear()和m_move_seq这个m_move_seq到底什么用?    time_t te = GetTickCount() - tb;}

 

MoveManager管理类