青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

Working with Maps and Levels(5)

cTrigger::cTrigger and cTrigger::~cTrigger

Just as does every C++ class, cTrigger has a constructor and a destructor that set up
and free the data contained within the class. The only data tracked by the trigger
class that is not contained with the linked list is the number of triggers currently
held in the linked list and a pointer to that linked list. The constructor and
destructor ensure that the class is prepared for using those two variables to free
the class's data when destroyed (by calling the free function).

 

cTrigger::load and cTrigger::save

You typically design maps with a set of triggers all in their proper locations.
Loading a list of those triggers is the main priority of the trigger class. Once a list
of triggers is created or loaded, you also have the option to save that list of triggers
(to save the game state, for example).

The load function opens a text file and repeatedly reads in lines of text that define
the type, identification, location, and special properties of each trigger (as described
in the earlier section “Creating a Trigger Class”). When the end of file is reached,
the load function returns. Take a look at the load function code to see just what I’m
talking about:

bool cTrigger::load(const char* filename)
{
    free();

    FILE* fp = fopen(filename, "rb");
    
if(fp == NULL)
        
return false;

    
// start looping, reading in until EOF reached.
    for(;;)
    {
        
long id = get_next_long_2(fp);
        
if(id == -1)
            
break;

        
long type    = get_next_long_2(fp);
        
bool enabled = get_next_long_2(fp) ? true : false;

        
float x1, y1, z1, x2, y2, z2, x3, z3, radius;

        
// read in rest depending on type
        switch(type)
        {
        
case TRIGGER_SPHERE:
            x1     = get_next_float_2(fp);
            y1     = get_next_float_2(fp);
            z1     = get_next_float_2(fp);
            radius = get_next_float_2(fp);

            add_sphere(id, enabled, x1, y1, z1, radius);
            
break;

        
case TRIGGER_BOX:
            x1 = get_next_float_2(fp);
            y1 = get_next_float_2(fp);
            z1 = get_next_float_2(fp);
            x2 = get_next_float_2(fp);
            y2 = get_next_float_2(fp);
            z2 = get_next_float_2(fp);

            add_box(id, enabled, x1, y1, z1, x2, y2, z2);
            
break;

        
case TRIGGER_CYLINDER:
            x1     = get_next_float_2(fp);
            y1     = get_next_float_2(fp);
            z1     = get_next_float_2(fp);
            radius = get_next_float_2(fp);
            y2     = get_next_float_2(fp);

            add_cylinder(id, enabled, x1, y1, z1, radius, y2);
            
break;

        
case TRIGGER_TRIANGLE:
            x1 = get_next_float_2(fp);
            z1 = get_next_float_2(fp);
            x2 = get_next_float_2(fp);
            z2 = get_next_float_2(fp);
            x3 = get_next_float_2(fp);
            z3 = get_next_float_2(fp);
            y1 = get_next_float_2(fp);
            y2 = get_next_float_2(fp);

            add_triangle(id, enabled, x1, z1, x2, z2, x3, z3, y1, y2);
            
break;

        
default:    // some error occurred
            fclose(fp);
            free();
            
return false;
        }
    }

    fclose(fp);
    
return true;
}

At this point, the trigger data file is open and ready to begin reading in a list of
trigger definitions. For each trigger, remember that the text line uses the following
order: the trigger identification number, the type (0=sphere, 1=box, and so on), the
default enabled status (0=trigger disabled, 1=enabled), and the specific data based on
the type of trigger being read.

Once past reading in the identification number, type, and enabled flag of each trigger,
a single switch...case code block takes care of loading in each trigger type’s data.
As each trigger’s data is read in, a separate function is called (based on the trigger’s
type) to insert the trigger into the linked list. Those functions are add_sphere, add_box,
add_cylinder, and add_triangle.

Moving past the load function, you see the save function, which scans the linked list
of triggers and saves each trigger’s data to a file, using the same format for each
line of text that defines a trigger. Take a look:

bool cTrigger::save(const char* filename)
{
    
if(m_num_triggers == 0)
        
return false;

    FILE* fp = fopen(filename, "wb");
    
if(fp == NULL)
        
return false;

    
// write out all triggers
    for(sTrigger* trigger = m_root_trigger; trigger != NULL; trigger = trigger->next)
    {
        
int enabled = trigger->enabled ? 1 : 0;

        
switch(trigger->type)
        {
        
case TRIGGER_SPHERE:
            fprintf(fp, "%lu %lu %lu %lf %lf %lf %lf\r\n",
                    trigger->id, trigger->type, enabled,
                    trigger->x1, trigger->y1, trigger->z1,
                    trigger->radius);

            
break;

        
case TRIGGER_BOX:
            fprintf(fp, "%lu %lu %lu %lf %lf %lf %lf %lf %lf\r\n",
                    trigger->id, trigger->type, enabled,
                    trigger->x1, trigger->y1, trigger->z1,
                    trigger->x2, trigger->y2, trigger->z2);

            
break;

        
case TRIGGER_CYLINDER:
            fprintf(fp, "%lu %lu %lu %lf %lf %lf %lf %lf\r\n",
                    trigger->id, trigger->type, enabled,
                    trigger->x1, trigger->y1, trigger->z1,
                    trigger->radius, trigger->y2);

            
break;

        
case TRIGGER_TRIANGLE:
            fprintf(fp, "%lu %lu %lu %lf %lf %lf %lf %lf %lf %lf %lf\r\n",
                    trigger->id, trigger->type, enabled,
                    trigger->x1, trigger->z1,
                    trigger->x2, trigger->z2,
                    trigger->x3, trigger->z3,
                    trigger->y1, trigger->y2);

            
break;
        }
    }

    fclose(fp);
    
return true;
}

posted on 2007-12-09 16:11 lovedday 閱讀(200) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            小辣椒精品导航| 久久久久久久久岛国免费| 欧美精品尤物在线| 亚洲人成精品久久久久| 欧美凹凸一区二区三区视频| 狂野欧美一区| 亚洲区中文字幕| 亚洲精品黄色| 国产精品国产自产拍高清av王其| 亚洲一区二区三区高清 | 亚洲丝袜av一区| 亚洲最新中文字幕| 国产精品va在线| 午夜精品在线| 久久精品国产精品亚洲精品| 亚洲国产精品传媒在线观看| 91久久一区二区| 国产精品高潮呻吟久久av无限| 亚洲欧美日韩一区| 久久久久久亚洲精品中文字幕| 亚洲另类视频| 亚洲男人的天堂在线| 狠狠色伊人亚洲综合网站色| 亚洲国产欧美在线人成| 国产精品毛片在线| 久久综合色婷婷| 欧美视频一区二区三区在线观看| 久久成人人人人精品欧| 免费成人激情视频| 欧美一区二区三区免费在线看| 久久久久久久网| 一区二区av在线| 久久久国产一区二区三区| 日韩亚洲欧美综合| 欧美伊人久久大香线蕉综合69| 日韩系列欧美系列| 欧美一站二站| 亚洲午夜影视影院在线观看| 久久久人人人| 欧美在线视频一区二区三区| 欧美国产精品日韩| 乱中年女人伦av一区二区| 欧美午夜免费电影| 亚洲国产精品va在线看黑人动漫| 国产手机视频一区二区| 99亚洲一区二区| 亚洲日韩视频| 玖玖玖国产精品| 久久精品99国产精品日本| 欧美日韩免费高清一区色橹橹| 狼人社综合社区| 国产美女精品一区二区三区| 亚洲区第一页| 亚洲欧洲在线看| 久久天天综合| 久久久青草青青国产亚洲免观| 国产精品激情av在线播放| 亚洲狠狠婷婷| 最新亚洲一区| 毛片一区二区三区| 毛片一区二区| 一区免费视频| 久久久久久久国产| 久久一区免费| 一区一区视频| 久久久噜噜噜久久| 老鸭窝亚洲一区二区三区| 国产一区二区精品久久| 性欧美办公室18xxxxhd| 久久精品国产综合| 国产综合久久久久久鬼色| 香蕉久久久久久久av网站| 欧美在线精品一区| 国产亚洲制服色| 久久精品最新地址| 免费一级欧美片在线播放| 亚洲黄网站黄| 欧美久色视频| 亚洲无玛一区| 久久精品毛片| 亚洲国产精品一区二区第四页av| 免费中文日韩| 日韩视频免费观看| 亚洲欧美清纯在线制服| 国产日韩精品久久| 久久婷婷综合激情| 亚洲国产综合在线看不卡| 亚洲网站视频| 国产亚洲二区| 裸体女人亚洲精品一区| 亚洲美女av黄| 久久成人免费| 亚洲国产成人久久| 欧美日韩 国产精品| 亚洲综合电影| 欧美波霸影院| 中文网丁香综合网| 国产亚洲电影| 欧美日韩成人综合天天影院| 亚洲在线观看视频| 欧美承认网站| 欧美一级黄色录像| 亚洲国产视频a| 国产精品视频精品| 麻豆成人在线播放| 亚洲一区国产一区| 欧美激情91| 久久国产精品毛片| av不卡在线| 尤物九九久久国产精品的分类| 欧美三级视频| 乱中年女人伦av一区二区| 亚洲伊人网站| 亚洲黄色免费电影| 久久国产精品电影| 一区二区三区视频免费在线观看| 国产三级欧美三级| 欧美日韩免费| 男女精品网站| 欧美中文字幕在线视频| 一本色道婷婷久久欧美| 欧美二区不卡| 噜噜噜在线观看免费视频日韩 | 黄色在线一区| 国产精品欧美日韩一区| 欧美成人一品| 久久综合伊人77777蜜臀| 午夜日韩在线| 亚洲女人天堂成人av在线| 亚洲日本va午夜在线电影| 麻豆国产精品777777在线| 欧美一区二区视频97| 中国av一区| 99国产精品99久久久久久| 有坂深雪在线一区| 国产精品视频久久| 国产精品jizz在线观看美国| 欧美久久久久久蜜桃| 欧美成人精品激情在线观看| 久久夜色撩人精品| 久久国产日韩| 久久精品国产在热久久| 欧美一级专区| 久久精品2019中文字幕| 先锋影音一区二区三区| 亚洲欧美日韩精品一区二区| 亚洲无线视频| 亚洲影院在线观看| 亚洲午夜未删减在线观看| 亚洲一区亚洲| 欧美一区免费视频| 欧美亚洲专区| 久久九九全国免费精品观看| 久久精品女人天堂| 久久天天综合| 欧美激情视频在线播放| 欧美日韩hd| 国产精品久久久久久久久久免费看| 国产精品久久久久av免费| 国产精品久久久久久五月尺| 国产精品综合网站| 国产亚洲激情视频在线| 伊伊综合在线| 日韩午夜精品| 先锋影音网一区二区| 久久人体大胆视频| 亚洲第一黄网| 一本一本久久| 久久久999成人| 欧美精品一区二区三区在线看午夜| 欧美日韩久久不卡| 国产精品一香蕉国产线看观看| 狠狠噜噜久久| 在线中文字幕一区| 久久精品国产一区二区三区免费看| 裸体丰满少妇做受久久99精品| 欧美激情在线观看| 亚洲特色特黄| 开元免费观看欧美电视剧网站| 欧美日韩八区| 极品裸体白嫩激情啪啪国产精品 | 欧美日韩中文字幕综合视频| 国产精品午夜视频| 亚洲激情第一区| 欧美一区二区三区免费大片| 免费不卡中文字幕视频| aa级大片欧美三级| 久久精品中文字幕一区二区三区| 欧美日韩国产精品成人| 国产亚洲精品资源在线26u| 亚洲乱码国产乱码精品精天堂 | 在线亚洲激情| 免费成人av在线看| 亚洲一级在线观看| 麻豆九一精品爱看视频在线观看免费 | 久久性色av| 中文日韩在线| 欧美成ee人免费视频| 国产一区二区三区免费观看| 亚洲午夜高清视频|