• <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 閱讀(1279) 評論(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~
                回復  更多評論   
             
            理论片午午伦夜理片久久 | 久久久精品日本一区二区三区| 亚洲国产香蕉人人爽成AV片久久| 国产午夜福利精品久久2021| 中文字幕亚洲综合久久菠萝蜜| 国产精品久久久久乳精品爆| 久久99精品久久久久久久不卡 | 亚洲精品无码久久毛片| 精品无码人妻久久久久久| 99久久综合狠狠综合久久止| 久久精品亚洲中文字幕无码麻豆| 欧美噜噜久久久XXX| 久久久婷婷五月亚洲97号色| 久久久久人妻一区二区三区 | 国产精品免费久久久久电影网| 美女写真久久影院| 天天久久狠狠色综合| 丰满少妇高潮惨叫久久久| 久久久久久国产精品免费无码| 久久精品国产亚洲AV无码偷窥| 精品久久无码中文字幕| 丁香久久婷婷国产午夜视频| a级毛片无码兔费真人久久| 国产高清国内精品福利99久久| 久久国产热这里只有精品| 欧美亚洲日本久久精品| 欧美日韩精品久久免费| 亚洲精品乱码久久久久66| 欧美一区二区精品久久| 久久久噜噜噜久久中文字幕色伊伊| 亚洲精品无码专区久久同性男| 亚洲精品无码久久一线| 97久久天天综合色天天综合色hd | 久久精品国产亚洲AV无码麻豆| 99久久精品国产一区二区三区| 久久久久久久综合狠狠综合| 亚洲AV无码久久精品蜜桃| 激情综合色综合久久综合| 久久精品国产99久久久古代| 国产精品久久久久天天影视| 色狠狠久久综合网|