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

            天行健 君子當(dāng)自強(qiáng)而不息

            Working with Maps and Levels(6)

            cTrigger::add_trigger

            add_trigger is the heart of all the other functions that add a trigger. This function
            allocates a sTrigger structure, sets its type, identification number, and enable flag,
            and then links the structure into the linked list of triggers. Once you allocate your
            program using the add_trigger function, the program can fill in the returned sTrigger
            structure with the coordinates, radius, height, or whatever other information the
            trigger needs to have defined.

            Keeping in mind that the add_trigger function allocates only a sTrigger structure and
            fills it with the minimal data as just mentioned.

             

            cTrigger::add_sphere, cTrigger::add_box, cTrigger::add_cylinder, cTrigger::add_triangle

            This group of functions adds a trigger of a specific type to the linked list of triggers.
            Each function has its own list of arguments to use for creation (you can
            check the comments preceding each function to see what each argument does).
            Regardless of the type of trigger, each function first calls the add_trigger function
            to get a sTrigger structure with which to work.

            Let’s start with the add_sphere function, which takes, in addition to the trigger’s identification
            number and default enabled state (as each of the four functions here
            do), the sphere’s radius and the X-, Y-, and Z-coordinates for the sphere.

            Short and to the point, the add_sphere function calls on the add_trigger function to
            allocate and link in a sTrigger structure to the linked list. Once created, the sTrigger
            structure instance is filled with the sphere trigger’s coordinates and radius.

            add_box, add_cylinder, and add_triangle operate in much the same way the add_sphere function
            does. The add_box function takes the identification number and default enabled
            state, as well as the coordinates for the opposing corners of the box.

            The add_cylinder function uses the lower-middle coordinates of the cylinder, the
            radius, and height for the trigger.

            Wrapping up the bunch is add_triangle, which takes the three pairs of X- and Zcoordinates
            that define each of the triangle’s three corners. The Y-coordinate to
            use for those three corners, as well as the height of the triangular trigger shape,
            follows.

            NOTE
            All functions that use a radius as an argument square the value when it is stored in the structure.This speeds
            up distance checks later on. How does the trigger class speed up distance checks? A standard distance check
            uses a sqrt call to calculate the correct distance. Tossing out the sqrt speeds up the engine, but then
            you must square the values to match the distance.

             

            cTrigger::remove and cTrigger::free

            These two functions remove triggers from the linked list by referring to the identification
            number of the trigger to remove in the remove function or by allowing the
            class to remove all triggers in the list using the free function.

            The remove function operates by scanning the entire linked list—for each trigger
            that shares the same identification number as the number passed in the ID argument,
            the remove function removes the structure from the linked list and frees the
            structure’s memory:

            void cTrigger::remove(long id)
            {
                sTrigger* trigger = m_root_trigger;

                
            // scan through list of triggers
                while(trigger != NULL)
                {
                    sTrigger* next_trigger = trigger->next;

                    
            if(trigger->id == id)
                    {
                        
            // remove from list

                        
            if(trigger->prev)
                            trigger->prev->next = trigger->next;
                        
            else
                            m_root_trigger = trigger->next;

                        
            if(trigger->next)
                            trigger->next->prev = trigger->prev;

                        trigger->next = NULL;
                        delete trigger;

                        m_num_triggers--;
                    }

                    trigger = next_trigger;
                }
            }

            At this point, the linked list of sTrigger structures is being scanned. Now you store
            a pointer to the next structure in the linked list and check the currently iterated
            sTrigger structure for a match in the identification number being removed.

            Once it is determined that a structure needs to be removed, the code
            alters the linked list’s pointers and releases the structure’s memory resources.

            From this point on, the number of triggers stored in the linked list is reduced and the
            loop that scans for structures to remove continues until all structures are scanned.

            Whereas the remove function removes triggers according to their identification numbers,
            the free function can skip all the hoopla and delete the entire linked list in
            one fell swoop.


            posted on 2007-12-10 10:58 lovedday 閱讀(172) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評論

            国产精品成人99久久久久| 久久久久亚洲AV成人网人人网站| 色综合久久天天综合| 性欧美大战久久久久久久 | 亚洲国产精久久久久久久| 欧美成a人片免费看久久| 国产亚洲精品美女久久久| 四虎影视久久久免费观看| 久久精品国产亚洲综合色| 亚洲精品乱码久久久久久中文字幕 | 久久久国产99久久国产一| 狠狠色婷婷综合天天久久丁香 | 久久精品国产亚洲AV高清热| 国产成人综合久久精品尤物| 久久久国产精品亚洲一区| 2020国产成人久久精品| 国内精品久久久久久不卡影院| 久久久免费精品re6| 国内精品久久久久久久久电影网| 久久er国产精品免费观看8| 国产成人精品久久二区二区| 亚洲国产精品无码成人片久久| 色播久久人人爽人人爽人人片aV| 色综合久久88色综合天天| 好久久免费视频高清| 99久久精品国内| 久久99久久99精品免视看动漫| 囯产极品美女高潮无套久久久| 亚洲午夜无码AV毛片久久| 亚洲欧美一级久久精品| 久久精品国产99久久香蕉| 很黄很污的网站久久mimi色| 国产精品久久久久乳精品爆| 99精品伊人久久久大香线蕉| 国产亚洲精午夜久久久久久| 品成人欧美大片久久国产欧美| 伊人久久大香线焦综合四虎 | 丁香狠狠色婷婷久久综合| 2021久久精品国产99国产精品| 99久久久精品| 99久久婷婷国产一区二区|