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

天行健 君子當自強而不息

Controlling Players and Characters(35)

You're coming to the end of the long haul. You’ve finished the private data and
functions, and the public functions are left:

public:
    cCharController()
    {
        ZeroMemory(
thissizeof(*this));
    }

    ~cCharController()
    {
        shutdown();
    }

    
void free()
    {
        delete m_root_char;
        m_root_char = NULL;

        m_num_char = 0;
    }

    
void shutdown()
    {
        free();

        delete[] m_mesh_anim;
        m_mesh_anim = NULL;
        m_num_mesh_anim = 0;

        delete[] m_char_anim;
        m_char_anim = NULL;
        m_num_char_anim = 0;

        m_spell_controller    = NULL;
        m_def_file[0]         = '\0';
        m_weapon_mesh_path[0] = '\0';
        m_texture_path[0]     = '\0';
    }
///////////////////////////////////////////////////////////////////////////////////////////////////

void cCharController::init(ID3DXFont* font, PCSTR def_file,
                           sItem* mil, sSpell* msl,
                           
long num_mesh_anim, PCSTR* mesh_names,
                           PCSTR weapon_mesh_path, PCSTR texture_path,
                           
long num_char_anim, sCharAnimInfo* char_anims)
{
    free();

    
if(mesh_names == NULL || def_file == NULL)
        
return;

    m_font = font;

    strcpy(m_def_file, def_file);

    m_mil = mil;
    m_msl = msl;

    
// copy over mesh path and texture path (or set default)
    strcpy(m_weapon_mesh_path, weapon_mesh_path ? weapon_mesh_path : ".\\");
    strcpy(m_texture_path, texture_path ? texture_path : ".\\");

    
// get mesh names
    if((m_num_mesh_anim = num_mesh_anim) != 0)
    {
        m_mesh_anim = 
new sMeshAnim[num_mesh_anim];

        
for(long i = 0; i < m_num_mesh_anim; i++)
            strcpy(m_mesh_anim[i].filename, mesh_names[i]);
    }

    
// get animation data
    if((m_num_char_anim = num_char_anim) != 0)
    {
        m_char_anim = 
new sCharAnimInfo[m_num_char_anim];

        
for(long i = 0; i < m_num_char_anim; i++)
            memcpy(&m_char_anim[i], &char_anims[i], 
sizeof(sCharAnimInfo));
    }
}

In addition to the typical class constructor and destructor are the init and shutdown pair
of functions. For the controller to operate, it must first be initialized with a call to init.
When you’re done with the character controller class, a call to shutdown is in order.

Somewhat similar in nature to shutdown, the free function completely
removes all characters in the list of active characters. This function is useful for
clearing the list when a character leaves a level and a whole new set of characters
need to be added to the list.

Speaking of adding characters to the list, here comes the function that does it all.

With the add_char function, you need to provide a unique identification number, the MCL
character definition number to use, the character’s type to assign (CHAR_PC, CHAR_NPC,
or CHAR_MONSTER), the artificial intelligence to use, and the character’s coordinates and
Y-axis angle used to point the character in a specific direction.

Following add_char are two functions that remove a character in the list. The remove function
takes a character’s unique identification number as an argument,
and the remove_char function takes a pointer to the character structure.

///////////////////////////////////////////////////////////////////////////////////////////////////

bool cCharController::add_char(long id, long def, long type, long ai,
                               
float pos_x, float pos_y, float pos_z,
                               
float direction)
{
    FILE* fp;
    
if((fp = fopen(m_def_file, "rb")) == NULL)
        
return false;

    sCharacter* character = 
new sCharacter;

    character->def           = def;
    character->id            = id;
    character->type          = type;
    character->ai            = ai;
    character->pos_x         = pos_x;
    character->pos_y         = pos_y;
    character->pos_z         = pos_z;
    character->direction     = direction;
    character->update_enable = 
true;
    character->charge        = rand()%101;

    sCharDef& char_def = character->char_def;

    fseek(fp, 
sizeof(sCharDef) * def, SEEK_SET);
    fread(&char_def, 1, 
sizeof(sCharDef), fp);
    fclose(fp);

    character->health_points = char_def.health_points;
    character->mana_points   = char_def.mana_points;

    
// load character ics
    if(char_def.item_filename)
    {
        character->char_ics = 
new cCharIcs;
        character->char_ics->load(char_def.item_filename);
    }

    sMeshAnim& mesh_anim = m_mesh_anim[char_def.mesh_index];

    
// load mesh and animation if needed
    if(mesh_anim.count == 0)
    {
        mesh_anim.mesh.load(mesh_anim.filename, m_texture_path);
        mesh_anim.anim.load(mesh_anim.filename, &mesh_anim.mesh);
        
        
for(long i = 0; i < m_num_char_anim; i++)
            mesh_anim.anim.set_loop(m_char_anim[i].is_loop, m_char_anim[i].name);
    }

    character->
object.create(&mesh_anim.mesh);
    mesh_anim.count++;

    
// load and configure weapon (if any)
    if(m_mil && char_def.weapon != -1 && m_mil[char_def.weapon].mesh_filename)
    {
        
char path[MAX_PATH];
        sprintf(path, "%s%s", m_weapon_mesh_path, m_mil[char_def.weapon].mesh_filename);
        character->weapon_mesh.load(path, m_texture_path);

        character->weapon_object.create(&character->weapon_mesh);
        character->weapon_object.attach_to_object(&character->
object, "WeaponHand");
    }

    
// link into head of list
    if(m_root_char)
        m_root_char->prev = character;

    character->next = m_root_char;
    m_root_char = character;

    
return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////

void cCharController::remove_char(sCharacter* character)
{
    
if(character == NULL)
        
return;

    
// decrease mesh count and release if no more

    sMeshAnim& mesh_anim = m_mesh_anim[character->char_def.mesh_index];

    
if(--mesh_anim.count == 0)
    {
        mesh_anim.mesh.free();
        mesh_anim.anim.free();
    }

    
// remove from list
    if(character->prev)
        character->prev->next = character->next;
    
else
        m_root_char = character->next;

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

    character->prev = character->next = NULL;
    delete character;
}

///////////////////////////////////////////////////////////////////////////////////////////////////

void remove(long char_id)
{
     
return remove_char(get_char(char_id));
}

posted on 2007-12-04 17:27 lovedday 閱讀(230) 評論(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>
            亚洲第一区在线| 91久久久精品| 午夜综合激情| 亚洲在线日韩| 国产视频自拍一区| 麻豆9191精品国产| 免费观看久久久4p| 中文在线资源观看网站视频免费不卡| 亚洲大胆人体视频| 亚洲欧美另类久久久精品2019| 亚洲乱码久久| 国产精品麻豆va在线播放| 久久国产精品久久精品国产| 欧美一区二区三区婷婷月色 | 欧美精品大片| 一区二区三区免费看| 亚洲在线中文字幕| 黄色成人在线观看| 亚洲国产精品一区二区www| 欧美日韩国产精品一区二区亚洲| 亚洲天堂男人| 久久精品亚洲一区二区| 亚洲精品护士| 亚洲欧美激情视频| 91久久精品一区| 亚洲一区尤物| 最新国产成人在线观看| 亚洲综合日韩在线| 亚洲欧洲精品一区二区三区波多野1战4| 亚洲精品国产日韩| 国产一区二区三区久久| 亚洲精品国产精品久久清纯直播 | 午夜激情一区| 日韩午夜在线电影| 午夜欧美电影在线观看| 日韩视频在线播放| 久久爱www.| 亚洲欧美日韩在线| 欧美激情va永久在线播放| 久久精品国亚洲| 欧美亚州一区二区三区| 欧美激情视频一区二区三区在线播放| 国产精品美腿一区在线看| 欧美国产91| 激情视频一区二区| 亚洲一区日韩在线| 亚洲婷婷在线| 欧美激情中文字幕一区二区| 久久综合色综合88| 国产午夜精品久久久| 中文一区在线| 中文日韩在线| 欧美日韩国产va另类| 欧美国产第一页| 国内外成人免费激情在线视频| 亚洲视频欧洲视频| 一区二区三区国产精华| 欧美黑人多人双交| 欧美激情一区| 亚洲青色在线| 欧美不卡在线视频| 欧美激情一区二区三区在线 | 欧美亚洲第一页| 亚洲精品午夜| av成人毛片| 欧美乱妇高清无乱码| 亚洲三级视频在线观看| 亚洲伦理精品| 欧美日韩国产高清视频| 亚洲精品孕妇| 亚洲在线网站| 国产精品久久久久免费a∨大胸| 日韩一区二区福利| 亚洲午夜三级在线| 国产精品久久久一区二区| 亚洲伊人色欲综合网| 香蕉乱码成人久久天堂爱免费| 国产精品久久久久久户外露出| 妖精成人www高清在线观看| 亚洲午夜视频在线| 国产欧美 在线欧美| 欧美一区二区三区在线免费观看 | 久久精品视频播放| 在线观看欧美激情| 欧美成人在线免费视频| 日韩系列在线| 欧美在线一级视频| 韩日精品视频| 欧美国产日韩a欧美在线观看| 日韩亚洲成人av在线| 香蕉久久夜色| 亚洲国产裸拍裸体视频在线观看乱了 | 久久久99国产精品免费| 永久域名在线精品| 欧美日本亚洲| 羞羞视频在线观看欧美| 欧美国产日韩精品| 亚洲欧美日韩精品一区二区| 韩国av一区| 欧美日韩精品在线视频| 欧美一区二区国产| 91久久黄色| 久久久久成人精品免费播放动漫| 亚洲欧洲日韩女同| 国产精品入口福利| 免费亚洲网站| 羞羞漫画18久久大片| 亚洲国产日韩一区二区| 久久成人18免费观看| 最新日韩在线| 国产在线不卡精品| 欧美日韩午夜激情| 久久亚洲欧洲| 午夜国产精品视频| 亚洲精品网站在线播放gif| 久久免费一区| 午夜精品久久久久久久男人的天堂 | 国产色综合久久| 欧美另类在线播放| 久久久人成影片一区二区三区| 9久草视频在线视频精品| 欧美xxx在线观看| 欧美主播一区二区三区美女 久久精品人| 亚洲福利在线视频| 国内精品一区二区| 国产乱码精品一区二区三| 欧美日韩精品一区二区| 久热精品视频在线观看| 欧美在线网站| 亚洲欧美一区二区三区极速播放| 日韩写真在线| 亚洲精品影视在线观看| 欧美国产精品劲爆| 六月婷婷一区| 久热精品视频在线观看| 久久精品在这里| 欧美在线观看一二区| 午夜精品一区二区三区四区| 亚洲视频免费在线| 在线视频精品一| 一区二区三区精品| 日韩午夜在线视频| 一本久久青青| 亚洲天堂av高清| 亚洲一区二区成人| 亚洲一区二区精品在线观看| 亚洲网站在线播放| 亚洲午夜三级在线| 午夜精品国产更新| 欧美一区激情| 久久亚洲精品网站| 免费欧美电影| 亚洲国产精品久久久久婷婷老年| 亚洲国产精品一区制服丝袜| 亚洲欧洲日本专区| 亚洲免费精品| 亚洲欧美日韩一区二区三区在线观看| 亚洲制服欧美中文字幕中文字幕| 亚洲午夜影视影院在线观看| 亚洲欧美日韩系列| 久久天堂精品| 欧美日本国产视频| 国产精品久久午夜夜伦鲁鲁| 国产视频精品网| 亚洲国产精品一区二区三区| 亚洲精品一区二区网址| 亚洲一区二区精品视频| 欧美中文日韩| 欧美高清视频一区二区| 99亚洲视频| 久久福利一区| 欧美精品一区二| 国产精品一区二区久久久久| 激情婷婷欧美| 中文在线资源观看网站视频免费不卡 | 亚洲欧美日韩一区在线| 久久久精品日韩欧美| 欧美激情自拍| 国产偷国产偷亚洲高清97cao| 亚洲国产成人精品视频| 亚洲一级网站| 免费不卡在线观看av| 日韩写真在线| 久久色中文字幕| 国产精品免费aⅴ片在线观看| 在线观看欧美激情| 亚洲女女女同性video| 欧美成人精品激情在线观看| 亚洲四色影视在线观看| 欧美aa在线视频| 国产亚洲在线| 亚洲午夜视频在线观看| 免费在线亚洲| 午夜精品久久久久久久| 欧美久久久久中文字幕| 精品99一区二区| 午夜精品视频一区| 亚洲精品久久| 开心色5月久久精品| 国产亚洲精品一区二区|