• <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>

            天行健 君子當自強而不息

            游戲中物件的定義與使用(5)

             

            本篇是游戲中物件的定義與使用(4)的續篇。

             

            使用物品清單系統管理物件

            物件被分散在四處,玩家們找到這些物件只不過是一個時間問題。對于這種情況,玩家需要運用一種方法去管理物件,包括使用物品清單控制系統(inventory control system,ICS)來進行分類整理。

            請不要誤解,一個ICS并不只適用于玩家,它同樣適用于整個游戲世界。物件可以屬于一張地圖,一個角色,甚至是另一個物件(例如背包,有一些其他的物件在它里面),那就意味著物件需要指定它的所有者(ownership)。除此之外,一個所有者可以擁有一個物件的多個實例(multiple instance),例如貨幣。

            所有者的物件收藏稱之為物件清單列表(inventory list),任何物件都可以歸屬到這個列表中去(也包括物件的眾多實例)。所有者,物件清單列表,以及數量之間的關系如下表所示:


             

            ICS和MIL相互協調工作,MIL只保存了世界中每個物件惟一的實例,而ICS則使用了物件的眾多實例。每當ICS需要一個物件的信息時,它可以引用MIL。以這種方式,可以僅使用ICS保存MIL中的物件引用編號(如下圖所示),以節省大量內存。

            For your game’s maps and levels, a simple ICS (called a map ICS) consists of only a
            list of items and their locations within the map, which is just fine because you can
            place objects throughout—ready for characters to pick them up. The real problem
            comes when those characters pick them up and add them to their inventory.
            Multiple instances pile up, new items are added, and other items are used or
            dropped. Things quickly become a real jumble. Handling a collection of character’s
            objects is the job of a character ICS, which is a little more complicated than its map
            counterpart.

             

            開發一個地圖ICS

            The map ICS tracks items that are placed within levels, including items that are
            contained within other items—a sword contained within a treasure chest, for
            example. The type of map you use determines how you position items within the
            map. In 3-D maps, you use three coordinates for positioning an item—the X-, Y-,
            and Z- coordinates. Because each map is also unique (each part of the world has
            different maps), you can track each map’s items in separate files.

            You can represent the map ICS with a structure and a class:

            //==================================================================================
            // This structure contains map item information list.
            //==================================================================================
            typedef struct sMapItem
            {
                
            long    item_index;             // MIL item index
                long    quantity;               // quantity of item (ie coins)
                float   x_pos, y_pos, z_pos;    // map coordinates

                sMapItem*   prev;
                sMapItem*   next;

                
            long    index;          // map item index
                long    owner_index;

                sMapItem*   parent;     
            // parent of a contained item
                
                sMapItem()
                {
                    memset(
            this, 0, sizeof(*this));
                    owner_index = -1;
                }

                ~sMapItem()
                {
                    delete next;   
                }
            } *sMapItemPtr;

            //==================================================================================
            // This class encapsulate map inventory contrl system.
            //==================================================================================
            typedef class cMapIcs
            {
            private:
                
            long        m_num_items;
                sMapItemPtr m_root_item;

            private:
                
            long    get_next_long(FILE* fp);
                
            float   get_next_float(FILE* fp);

            public:
                cMapIcs();
                ~cMapIcs();

                
            bool load(const char* filename);
                
            bool save(const char* filename);
                
            void free();

                
            void add(long item_index, long quantity,
                         
            float x_pos, float y_pos, float z_pos,
                         sMapItemPtr owner_item);

                
            void remove(sMapItemPtr item);

                
            long get_num_items();
                sMapItemPtr get_root_item();
                sMapItemPtr get_item(
            long index);
            } *cMapIcsPtr;

            First, you see the sMapItem structure, which holds the information for every item in
            the map. item_index is the MIL item reference number (which ranges from 0 to 1,023
            if you used the MILEdit program), and quantity is the number of item_index (to allow
            things like a horde of coins to be represented as a single object). Then you see the
            item’s map coordinates x_pos, y_pos, and z_pos.

            Next comes the prev and next pointers. You insert them to track a linked list of
            sMapItem structures. The next couple of variables, index and owner_index, are used when
            loading and saving the items in a map. Index stores the current index number of
            an item in the linked list. If an item is owned by another item, the Owner variable
            holds the index number of the parent object (otherwise, Owner is set to -1). When
            loading (or adding) an object, you set the final variable in sMapItem (parent) to point
            to the actual owner item’s structure. You can see the sMapItem structure link list concept
            illustrated in Figure 15.8.

            The sMapItem uses both a constructor and destructor function called whenever a
            structure instance is allocated or reallocated. Both functions ensure that the linked
            list pointers are in check, and whenever a structure is deleted, all subsequent
            sMapItem structures in the linked list are deleted as well.

            CAUTION
            If you’re removing only a single instance of sMapItem from the linked list, you first have to
            set the instance’s Next variable to NULL. Doing so ensures that all subsequent instances in the
            linked list are not deleted as well.

            The cMapICS class has two private functions (get_next_long and get_next_float) used to read
            in text and convert it into a long or float value. The cMapICS class also has eight usable
            public functions. Take a closer look at those public functions.


            posted on 2007-11-07 18:31 lovedday 閱讀(240) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            人妻精品久久久久中文字幕69 | 色综合久久久久综合99| 久久最新免费视频| 亚洲精品无码专区久久久 | 亚洲国产天堂久久综合| 日韩乱码人妻无码中文字幕久久| 亚洲午夜久久久影院| 久久免费视频网站| 亚洲女久久久噜噜噜熟女| 996久久国产精品线观看| 99久久精品国产一区二区| 久久香蕉超碰97国产精品| 精品国产乱码久久久久久浪潮| 麻豆亚洲AV永久无码精品久久| 国产一级做a爰片久久毛片| 婷婷综合久久中文字幕蜜桃三电影| 久久夜色精品国产噜噜噜亚洲AV | 91精品国产91热久久久久福利| 香蕉久久夜色精品升级完成| 91亚洲国产成人久久精品| 18岁日韩内射颜射午夜久久成人| 国产精品内射久久久久欢欢| 久久国产免费观看精品| 亚洲伊人久久综合中文成人网| 久久精品成人免费看| 五月丁香综合激情六月久久| 亚洲美日韩Av中文字幕无码久久久妻妇 | 青青热久久综合网伊人| 亚洲欧洲日产国码无码久久99| 无码任你躁久久久久久| 久久99精品九九九久久婷婷| 久久国产精品成人免费| 精品久久久久久无码中文字幕一区 | 久久香蕉综合色一综合色88| 欧美牲交A欧牲交aⅴ久久| 91麻豆国产精品91久久久| 伊人久久久AV老熟妇色| 久久香综合精品久久伊人| 久久久久久精品免费看SSS| 久久一日本道色综合久久| 午夜久久久久久禁播电影|