• 关于地图加载


    关于地图加载
    .map文件记录了格子大小为107*160,关于.map文件时如何生成的我也不清楚,.map文件中已经有二维大小以及整个阻挡信息(0:无阻挡,1:阻挡,2:透明0)
    /**
     *m_nMapWidth 地图宽
     *m_nMapHight 地图高
     *m_dvecCollsion 地图阻挡信息
     */
    info->get_collsion(m_nMapWidth, m_nMapHight, m_dvecCollsion);
    他这个获取.map是这样的
    ^
    |------------->
    |------------->
    |------------->
    从下往上的
    
    
    
    enum BaseCellBlockType
    {
        eBaseCellBlockType_None        = 0,    ///< 空
        eBaseCellBlockType_Block    = 1,    ///< 阻塞
        eBaseCellBlockType_Shadow    = 2,    ///< 阴影
    };
    struct MapCellInfo
    {
        BaseCellBlockType        m_eBaseBlockType;    ///< 地图基础阻塞信息对应枚举 BaseCellBlockType
        std::list<CellObject*>* m_pObjList;            ///< 单元格上的对象列表
    };
    std::vector<std::vector<MapCellInfo> >    m_vecMapCell;        ///< 单元格信息初始化单元格管理,这部分从来没看过
    void MapCellMgr::Init(const std::vector<std::vector<int> >& mapBaseBlockInfo)
    {
        m_nWidth = mapBaseBlockInfo.size();
        m_nHight = mapBaseBlockInfo[0].size();
    
        m_vecMapCell.resize(m_nWidth);
        for(int x = 0; x < m_nWidth; ++x)
        {
            m_vecMapCell[x].resize(m_nHight);
            for(int y = 0; y < m_nHight; ++y)
            {
                auto& cell = m_vecMapCell[x][y];
                cell.m_eBaseBlockType = (BaseCellBlockType)mapBaseBlockInfo[x][y];
                cell.m_pObjList = nullptr;//对象列表
            }
        }
    }
    这个初始化时这样的
    ^^^
    |||
    |||
    |||
    
    48*32是每个单元格的宽和高像素大小
    划分block格子
    int nAllWidth = m_nMapWidth * HeadNode.map_size_item.base_size.x;//整个地图大小宽(像素)
    int nAllHidth = m_nMapHight * HeadNode.map_size_item.base_size.y;//整个地图高(像素)
    //计算整张地图大小(block),他是把屏幕划分成3*3的格子
    int nWidthBlcokNum = nAllWidth / (screen_area.x / 3) + 4; //多出4格预防外围(满足7x7范围控制),对于为什么+4不太清楚,好像是处理边界问题
    int nHightBlcokNum = nAllHidth / (screen_area.y / 3) + 4;
    
    m_MapCellMgr.m_vecRolesBlock.resize(nWidthBlcokNum);  //角色
    m_MapCellMgr.m_vecSpellsBlock.resize(nWidthBlcokNum); //魔法
    //    m_MapCellMgr.m_vecItemsBlock.resize(nWidthBlcokNum);  //道具物品
    m_MapCellMgr.m_vecPropsBlock.resize(nWidthBlcokNum);  //道具物品(新)
    for (int i = 0; i < nWidthBlcokNum; i++)
    {
        m_MapCellMgr.m_vecSpellsBlock[i].resize(nHightBlcokNum);
    //        m_MapCellMgr.m_vecItemsBlock[i].resize(nHightBlcokNum);
        m_MapCellMgr.m_vecRolesBlock[i].resize(nHightBlcokNum);
        m_MapCellMgr.m_vecPropsBlock[i].resize(nHightBlcokNum);
    }
    对于角色,魔法,道具都是每个格子进行管理的
    
    //对于装饰物是单独管理的,没有放到单元格管理器中
    m_BlockOrnamentalMap.resize(nWidthBlcokNum);
    
    for (int i = 0; i < nWidthBlcokNum; ++i)
    {
        //m_droProp_block[i].resize(block_h_num);
        m_BlockOrnamentalMap[i].resize(nHightBlcokNum);
    }
    
    void Map::InitOrnamemtal()//初始化装饰物信息
    {
        std::vector<mapinfo::role_node> vecOrnamental;
        m_spMapInfo->get_ornamentals(vecOrnamental);
        for (unsigned int i = 0; i < vecOrnamental.size(); i++)
        {
            mapinfo::role_node Node = vecOrnamental[i];
            unsigned long uid = AllocateUID();
            pos2d pos = m_spBase->GetPos(Node.point.x, Node.point.y);
            Node.point.x = pos.x;
            Node.point.y = pos.y;
            pos2d block_pos = m_spBase->GetBlockPos(pos);//mpos->bpos
            m_BlockOrnamentalMap[block_pos.x][block_pos.y][uid] = Node;//将装饰物信息放入map容器中
    //        SetMapColl(Node.point.x, Node.point.y, true);
        }
    }
    
    void Map::InitRegions()
    {
        mapinfo::area_node SafeArea, FightArea;
        m_spMapInfo->get_safearea(SafeArea);
        m_spMapInfo->get_fightarea(FightArea);
    
        pos2d safe_begin = {SafeArea.begin_point.x, SafeArea.begin_point.y},
            safe_end = {SafeArea.end_point.x, SafeArea.end_point.y};
        //------[注]:暂时.map文件中无摆摊区概念,暂时用定值模拟,后期修正 --by lyq
        pos2d sell_begin = m_spBase->GetMapPos(4120, 3870),//{4120, 3870},
            sell_end = m_spBase->GetMapPos(5120, 5120);//{5120, 5120};
        pos2d fight_begin = {FightArea.begin_point.x, FightArea.begin_point.y},
            fight_end = {FightArea.end_point.x, FightArea.end_point.y};
    #if 0
        setRegion(RegionOpt::REGION_SAFE, safe_begin, safe_end);
        setRegion(RegionOpt::REGION_SELL, sell_begin, sell_end);
        setRegion(RegionOpt::REGION_SELL, sell_begin, sell_end);
    #endif
    
        m_MapCellMgr.CreateSafeRegion(::RectRegion(safe_begin, safe_end));//初始化安全区
        m_MapCellMgr.CreateFinghtRegion(::RectRegion(fight_begin, fight_end));//初始化战斗区
    }
  • 相关阅读:
    Tensorflow的对二次函数的神经网络训练
    ubuntu16.04的Anaconda下的tensorflow安装py3.5
    数字信号处理C语言(3) ------FFT
    数字信号处理C语言(2) ------带高斯噪声的sin函数和组合sin函数
    数字信号处理C语言(1) ------均匀分布和高斯分布随机数
    CCIE学习笔记 ----TSHOOT
    CCIE学习笔记 ----BGP
    CCIE学习笔记 ----GRE over IPsec
    调试
    Java protobuf框架使用向导
  • 原文地址:https://www.cnblogs.com/zzyoucan/p/4166164.html
Copyright © 2020-2023  润新知