• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Cpper
            C/C++高級工程師 Android高級軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿
            在蓋莫游戲引擎的書寫過程中先后書寫了資源管理器,場景管理器,模型管理器等管理器類.之后感覺很有必要寫一個泛型的管理器類了.這個可以少做一些重復性的工作了。
            管理器類無非就是獲取當前對象個數,對象生成,對象按名索取等等
            經過考慮,草料書寫如下:
             1 namespace core
             2 {
             3 
             4 ////////////////////////////////////////////////////////////
             5 //! 定義引擎泛型管理器類
             6 //////////////////////////////////////////////////////////// 
             7 template<class Obj = Object, class Type = std::string>
             8 class Manager  
             9 {        
            10 public:     
            11     typedef Type                                          ThisType;
            12     typedef Obj                                           ThisObj;
            13     typedef std::map<ThisType,RefPtr<ThisObj> >           Table;
            14     //! typedef std::map<ThisType,RefPtr<ThisObj> >::iterator TableItr; 
            15     
            16     ////////////////////////////////////////////////////////
            17     //! 構造,析構場景管理器
            18     //////////////////////////////////////////////////////// 
            19     Manager(){}
            20     virtual ~Manager() = 0
            21 public:     
            22                                           
            23     ////////////////////////////////////////////////////////////
            24     /// 獲取當前管理器中的對象個數
            25     ////////////////////////////////////////////////////////////                                         
            26     inline uint32 GetObjectNumber()const{return objects.size();}
            27     
            28     ////////////////////////////////////////////////////////////
            29     /// 檢測當前管理器中是否存在對象
            30     ////////////////////////////////////////////////////////////      
            31     inline bool   HasObject()const{return !objects.empty();}
            32     
            33     ////////////////////////////////////////////////////////////
            34     /// 獲取給定索引的對象(如果對象不存在則生成一個新的對象)
            35     ////////////////////////////////////////////////////////////       
            36     inline RefPtr<Object> GetObject(const Type& name)
            37     {
            38         if(objects.find(name) != objects.end())
            39             return objects[name];
            40         return     NULL;
            41     }
            42     
            43     ////////////////////////////////////////////////////////////
            44     /// 生成一個新的對象
            45     ////////////////////////////////////////////////////////////     
            46     virtual RefPtr<ThisObj> CreateObject(const Type& name) = 0
            47     
            48     ////////////////////////////////////////////////////////////
            49     /// 銷毀指定名字的對象
            50     ////////////////////////////////////////////////////////////
            51     inline bool KillObject(const Type& name)
            52     {    
            53         std::map<std::string,RefPtr<Model> >::iterator itr = objects.find(name);
            54         if(itr == objects.end())
            55             return false;
            56         objects.erase(name);
            57         return NULL;         
            58     }     
            59 
            60     ////////////////////////////////////////////////////////////
            61     /// 管理器對象清空
            62     ////////////////////////////////////////////////////////////    
            63     inline void ClearObject(){objects.clear();}
            64 protected:
            65     Table    objects;     
            66 };
            67 
            68 template<class Obj, class Type>
            69 Manager<Obj,Type>::~Manager()
            70 {
            71     ClearObject();                      
            72 
            73 
            其中使用std::map作為基本的管理器容器
            同時其中CreateObject函數是一個虛擬函數需要重載之
            然后我們就可以這樣寫具體的的管理器了.
            比如:
            1 class ModelManager : public Manager<Model,std::string>
            2 {
            3 public:
            4      RefPtr<Model> CreateObject(const std::string &);    
            5 };



            posted on 2010-03-08 20:49 ccsdu2009 閱讀(1272) 評論(8)  編輯 收藏 引用 所屬分類: Game引擎
            Comments
            • # re: 蓋莫游戲引擎中的范管理器類
              ccsdu2009
              Posted @ 2010-03-08 20:53
              ////////////////////////////////////////////////////////////
              49 /// 銷毀指定名字的對象
              50 ////////////////////////////////////////////////////////////
              51 inline bool KillObject(const Type& name)
              52 {
              53 std::map<std::string,RefPtr<Model> >::iterator itr = objects.find(name);
              54 if(itr == objects.end())
              55 return false;
              56 objects.erase(name);
              57 return true;
              58 }   回復  更多評論   
            • # re: 蓋莫游戲引擎中的范管理器類
              陳梓瀚(vczh)
              Posted @ 2010-03-09 00:32
              跟一個map沒區別……  回復  更多評論   
            • # re: 蓋莫游戲引擎中的范管理器類
              東北證券官方網站
              Posted @ 2010-03-09 02:08
              收藏了。。。





              http://www.keybeta.com/quote/  回復  更多評論   
            • # re: 蓋莫游戲引擎中的范管理器類
              凡客領帶
              Posted @ 2010-03-09 10:00
              很好12363546+6.36552  回復  更多評論   
            • # re: 蓋莫游戲引擎中的范管理器類
              cui
              Posted @ 2010-03-09 10:20
              你這效率也太低了吧

              36 inline RefPtr<Object> GetObject(const Type& name)
              37 {
              38 itertor itor = objects.find(name);
              if (itor != objects.end())
              39 return itor->second;
              40 return RefPtr<Object>() ;
              41 }


              inline bool KillObject(const Type& name)
              52 {
              53 return objects.erase (name) > 0;
              58 }   回復  更多評論   
            • # re: 蓋莫游戲引擎中的范管理器類
              ccsdu2009
              Posted @ 2010-03-09 10:58
              @cui
              謝謝
              完成功能是第一要務
              效率是其次的  回復  更多評論   
            • # re: 蓋莫游戲引擎中的范管理器類
              cui
              Posted @ 2010-03-09 15:20
              @ccsdu2009

              強詞奪理! 這種代碼需要費神的思考嗎?比你的舊代碼行數多嗎?  回復  更多評論   
            • # re: 蓋莫游戲引擎中的范管理器類
              ccsdu2009
              Posted @ 2010-03-09 15:51
              map的erase有三個版本
               1 關于map的erase
               2       void
               3       erase(iterator __position)
               4       { _M_t.erase(__position); }
               5 
               6       /**
               7        *  @brief Erases elements according to the provided key.
               8        *  @param  x  Key of element to be erased.
               9        *  @return  The number of elements erased.
              10        *
              11        *  This function erases all the elements located by the given key from
              12        *  a %map.
              13        *  Note that this function only erases the element, and that if
              14        *  the element is itself a pointer, the pointed-to memory is not touched
              15        *  in any way.  Managing the pointer is the user's responsibilty.
              16        */
              17       size_type
              18       erase(const key_type& __x)
              19       { return _M_t.erase(__x); }
              20 
              21       /**
              22        *  @brief Erases a [first,last) range of elements from a %map.
              23        *  @param  first  Iterator pointing to the start of the range to be
              24        *                 erased.
              25        *  @param  last  Iterator pointing to the end of the range to be erased.
              26        *
              27        *  This function erases a sequence of elements from a %map.
              28        *  Note that this function only erases the element, and that if
              29        *  the element is itself a pointer, the pointed-to memory is not touched
              30        *  in any way.  Managing the pointer is the user's responsibilty.
              31        */
              32       void
              33       erase(iterator __first, iterator __last)
              34       { _M_t.erase(__first, __last); }
              我以前只注意到map.erase(itr);
              謝謝提醒O(∩_∩)O~
                回復  更多評論   
             
            91久久九九无码成人网站| 一本久久免费视频| 91久久九九无码成人网站| 国产精品永久久久久久久久久| 国内精品欧美久久精品| 一本久久a久久精品综合香蕉| 久久久久波多野结衣高潮| 久久精品国产第一区二区三区| 国内精品久久久久久野外| 精品久久人人做人人爽综合| 亚洲精品综合久久| 久久精品国产亚洲AV电影| 国内精品伊人久久久久网站| 日韩人妻无码一区二区三区久久99 | 99久久这里只精品国产免费| 影音先锋女人AV鲁色资源网久久| 国产午夜免费高清久久影院| 精品久久久久国产免费| 97久久国产露脸精品国产| 欧美久久综合性欧美| 久久精品国产色蜜蜜麻豆| 久久777国产线看观看精品| 一级做a爰片久久毛片免费陪| 亚洲精品无码久久久久去q| 66精品综合久久久久久久| 久久天天躁狠狠躁夜夜2020一| 国产成人精品久久免费动漫| 午夜福利91久久福利| 久久99国产综合精品| 亚洲精品美女久久久久99小说| 成人国内精品久久久久影院| 欧美精品丝袜久久久中文字幕 | 久久精品免费一区二区三区| 久久精品极品盛宴观看| 亚洲精品国产成人99久久| 亚洲国产另类久久久精品黑人| 精品久久久久久久久久中文字幕| 久久久久人妻一区精品色| 色婷婷噜噜久久国产精品12p| 97久久天天综合色天天综合色hd| 无码任你躁久久久久久老妇 |