• <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~
                回復  更多評論   
             
            久久精品免费一区二区| 国产免费久久精品丫丫| 久久精品无码一区二区无码| 久久精品9988| 久久www免费人成看片| 久久精品无码一区二区日韩AV| 狠狠色噜噜色狠狠狠综合久久| 久久综合欧美成人| 精品久久久久久中文字幕| 中文字幕无码久久精品青草| segui久久国产精品| 亚洲一本综合久久| 精品一区二区久久久久久久网站| 久久国产精品-久久精品| 色偷偷久久一区二区三区| 婷婷伊人久久大香线蕉AV| 久久99精品国产自在现线小黄鸭| 亚洲精品乱码久久久久久不卡| 国产精品九九久久免费视频 | 99久久这里只精品国产免费| 久久天天躁狠狠躁夜夜2020老熟妇| 7777久久久国产精品消防器材| 精品水蜜桃久久久久久久| 久久久久无码中| 久久精品中文字幕无码绿巨人| 中文字幕久久欲求不满| 亚洲欧美日韩久久精品第一区| 麻豆亚洲AV永久无码精品久久| 99久久精品国内| 久久www免费人成看片| 久久伊人亚洲AV无码网站| 久久国产高清一区二区三区| 天天综合久久久网| 久久精品免费观看| 狠狠久久综合伊人不卡| 久久91精品国产91久| 国产999精品久久久久久| 亚洲中文久久精品无码| 综合久久精品色| 伊人伊成久久人综合网777| 久久亚洲综合色一区二区三区|