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

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

Controlling Players and Characters(16)

 

Creating a Derived Script Class

I’m going to assume that you are comfortable working with action templates and
scripts at this point. The following action template provides an example of using a
derived script class:

“End”
“If flag ~ equals ~ then”
  INT 0 255
  BOOL
“Else”
“EndIf”
“Set flag ~ to ~”
  INT 0 255
  BOOL
“Print ~”
TEXT

Now, using the preceding action template, include the following
script (I list it in text form here to make it easier to understand):

If flag 0 equals TRUE then
  Print “Flag is TRUE”
  Set flag 0 to FALSE
Else
  Print “Flag is FALSE”
  Set flag 0 to TRUE
EndIf

A brief reading shows that the preceding script displays the message “Flag is FALSE”
first (because all script flags are reset to FALSE when initialized); when executed
again, the script displays “Flag is TRUE”.

CAUTION
Remember that the example script shown here is in text form, but when used
as a Mad Lib Script, the format is based on values. For example, the if...then
action is represented by the value 1, whereas the EndIf action uses the value 3.

 

The Derived Class
 

The next step to processing the script is to derive a class from cScript:

class cGameScript : public cScript
{
private:
  BOOL m_Flags[256]; // The internal flags

  // The script function prototypes
  sScript *Script_End(sScript*);
  sScript *Script_IfFlagThen(sScript*);
  sScript *Script_Else(sScript*);

  sScript *Script_EndIf(sScript*);
  sScript *Script_SetFlag(sScript*);
  sScript *Script_Print(sScript*);

  // The overloaded process function
  sScript *Process(sScript *Script);

public:
  cGameScript();
};

The derived class shown here (cGameScript) uses an array of BOOL values that represents
the internal flags the scripts can use. Following the single variable declaration
is a list of function prototypes.


The script function prototypes are the bread and butter of the script processor.
Each script action has an associated function that is called during the Process function.
The Process function is overridden to call upon those script functions, as you
soon see in this section.

Aside from those private function calls, there is the constructor, which clears the
m_Flags array to all FALSE values.

cGameScript::cGameScript()
{
  // Clear all internal flags to FALSE
  for(short i=0;i<256;i++)
    m_Flags[i] = FALSE;
}

Jumping back a bit, take a look at the overridden Process function. As you can see
from the following code, cGameScript::Process takes only the current script action
type and jumps to the appropriate function. Upon the return of each action function,
a pointer to the next script action is returned. If a value of NULL is returned,
script execution halts.

sScript *cGameScript::Process(sScript *Script)
{
  // Jump to function based on action type
  switch(Script->Type) {
    case 0: return Script_End(Script);
    case 1: return Script_IfFlagThen(Script);
    case 2: return Script_Else(Script);
    case 3: return Script_EndIf(Script);
    case 4: return Script_SetFlag(Script);
    case 5: return Script_Print(Script);
  }

  return NULL; // Error executing
}

Now that you’ve overridden the Process function (and filled in the switch statement
with the action’s function calls), you can continue by programming all of the actions’
functions, as follows:

sScript *cGameScript::Script_End(sScript *Script)
{
  return NULL; // Force script to stop processing
}

sScript *cGameScript::Script_IfFlagThen(sScript *Script)
{
  BOOL Skipping; // Flag for if...then condition

  // See if a flag matches second entry
  if(m_Flags[Script->Entries[0].lValue % 256] == Script->Entries[1].bValue)
    Skipping = FALSE; // Don’t skip following actions
  else
    Skipping = TRUE; // Skip following actions

  // At this point, Skipping states if the script actions
  // need to be skipped due to a conditional if..then statement.
  // Actions are further processed if skipped = FALSE, looking
  // for an else to flip the skip mode, or an endif to end
  // the conditional block.

  Script = Script->Next; // Go to next action to process

  while(Script != NULL) {
    // if else, flip skip mode
    if(Script->Type == 2)
      Skipping = (Skipping == TRUE) ? FALSE : TRUE;

    // break on end if
    if(Script->Type == 3)
      return Script->Next;

    // Process script function in conditional block
    // making sure to skip actions when condition not met.
    if(Skipping == TRUE)
      Script = Script->Next;
    else {
      if((Script = Process(Script)) == NULL)
      return NULL;
    }
  }

  return NULL; // End of script reached
}

sScript *cGameScript::Script_Else(sScript *Script)
{
  return Script->Next; // Go to next script action
}

sScript *cGameScript::Script_EndIf(sScript *Script)
{
  return Script->Next; // Go to next script action
}

sScript *cGameScript::Script_SetFlag(sScript *Script)
{
  // Set boolean value
  m_Flags[Script->Entries[0].lValue % 256] = Script->Entries[1].bValue;

  return Script->Next; // Go to next script action
}

sScript *cGameScript::Script_Print(sScript *Script)
{
  // Display some text in a message box
  MessageBox(NULL, Script->Entries[0].Text, “Text”, MB_OK);

  return Script->Next; // Go to next script action
}

 

Using the Derived Class


To test the cGameScript class, instance it and run the example script that I showed
you earlier in the section “Creating a Derived Script Class.” Assuming that you
saved that script to a file named test.mls, the following example shows the script
class functionality:

cGameScript Script;

Script.Execute(“test.mls”); // Prints a Flag is FALSE message

// At this point, the script’s internal flags are maintained,
// so the next call would take the new flag states into account.
Script.Execute(“test.mls”); // Prints a Flag is TRUE message

Although this is a quick and dirty example of the derived cGameScript class, there really
isn’t much difference between this class and a full-fledged script parser that uses a huge
action template. You merely need to add each action-processing function into the class
and call that function via the Parse function.


posted on 2007-11-14 20:24 lovedday 閱讀(223) 評(píng)論(0)  編輯 收藏 引用


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


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

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

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            一本色道久久88综合亚洲精品ⅰ| 亚洲欧美日韩一区二区在线| 国产精品成人v| 欧美激情一区二区三区高清视频 | 久久久免费精品视频| 亚洲在线观看视频网站| 欧美精品在线免费播放| 亚洲大胆女人| 精品成人在线观看| 久久久久久69| 噜噜噜91成人网| 在线欧美电影| 久久免费精品视频| 男人的天堂亚洲| 精品福利av| 久久天天躁狠狠躁夜夜av| 另类av一区二区| 在线精品视频在线观看高清| 久久久亚洲高清| 欧美 亚欧 日韩视频在线| 原创国产精品91| 免费观看久久久4p| 久久久视频精品| 亚洲国产免费| 亚洲免费播放| 欧美视频你懂的| 欧美一区二区三区精品| 亚洲一品av免费观看| 亚洲人精品午夜在线观看| 亚洲综合国产| 一本色道久久综合亚洲精品按摩 | 亚洲天堂av图片| 91久久在线播放| 久久成人免费| 午夜精品在线| 欧美精品国产精品日韩精品| 久久综合中文色婷婷| 国产精品美女www爽爽爽视频| 鲁大师影院一区二区三区| 国产精品网曝门| 日韩一级片网址| 夜夜嗨av一区二区三区中文字幕| 久久久精品一区二区三区| 亚洲欧美日韩直播| 久久久久一区二区| 欧美高清在线视频| 亚洲自拍偷拍一区| 在线免费不卡视频| 欧美体内she精视频在线观看| 香蕉久久夜色精品国产| 欧美激情a∨在线视频播放| 亚洲午夜极品| 尤物九九久久国产精品的特点 | 亚洲精品乱码久久久久久蜜桃麻豆| 中文精品视频一区二区在线观看| 欧美成人国产一区二区| 亚洲在线中文字幕| 在线欧美小视频| 国产精品久久久久久久久久妞妞| 久久精品国产亚洲一区二区三区 | 一区二区三区成人| 韩国精品在线观看| 欧美偷拍另类| 午夜在线精品偷拍| 亚洲精品无人区| 麻豆九一精品爱看视频在线观看免费| 中文av字幕一区| 91久久久久久国产精品| 国产欧美韩国高清| 欧美片在线观看| 久久一区二区三区av| 午夜精品久久久久久久99水蜜桃 | 一区二区高清视频在线观看| 蜜臀久久久99精品久久久久久 | 亚洲欧美在线高清| 久久精品国产精品| 黄色欧美成人| 欧美高清免费| 亚洲一区二区三区中文字幕在线| 欧美一区三区三区高中清蜜桃| 国产一区二区三区四区五区美女| 久久婷婷久久一区二区三区| 亚洲国产日韩欧美在线动漫| 一区二区免费在线观看| 国产精品爽爽爽| 久久一区二区三区av| 一本高清dvd不卡在线观看| 欧美在线日韩| 亚洲精选一区二区| 国产精品色婷婷久久58| 久久九九热re6这里有精品| 欧美成人蜜桃| 亚洲中字黄色| 亚洲国产精品国自产拍av秋霞 | 蜜臀av性久久久久蜜臀aⅴ| 亚洲日本aⅴ片在线观看香蕉| 亚洲啪啪91| 国产精品免费电影| 欧美成在线观看| 亚洲一二三四久久| 欧美国产精品中文字幕| 午夜一区不卡| 亚洲毛片在线观看| 国产日韩欧美一区二区三区四区| 久久久综合香蕉尹人综合网| 亚洲国产精品123| 欧美在线视频导航| 一区二区三区偷拍| 在线精品视频在线观看高清| 国产精品毛片在线看| 免费成人毛片| 久久精品国产精品亚洲综合| 99精品视频网| 亚洲激情在线| 久久综合色播五月| 亚洲女人小视频在线观看| 亚洲美女在线观看| 在线欧美小视频| 国内精品久久久| 国产精品―色哟哟| 欧美日韩国产经典色站一区二区三区| 久久精品一本| 欧美在线免费一级片| 亚洲一区精品电影| 夜夜嗨av一区二区三区网站四季av| 欧美成人有码| 你懂的成人av| 在线欧美小视频| 亚洲一区二区视频在线观看| 亚洲综合不卡| 免费在线看成人av| 亚洲视频自拍偷拍| 久久精品二区| 欧美人与性动交α欧美精品济南到 | 久久青草久久| 国产精品国产a级| 在线精品视频一区二区三四| 中文国产成人精品久久一| 久久女同互慰一区二区三区| 亚洲电影在线看| 亚洲影院免费| 免费高清在线视频一区·| 国产精品国产a级| 亚洲高清视频在线观看| 亚洲一区二区欧美日韩| 久久在精品线影院精品国产| 亚洲巨乳在线| 久久成人精品电影| 国产精品国产三级国产普通话蜜臀 | 久久综合狠狠| 国产精品久久久999| 亚洲成在线观看| 午夜国产精品影院在线观看| 欧美一区久久| 亚洲国产精选| 久久成人综合视频| 国产精品美女黄网| 一本色道久久99精品综合| 蜜桃av综合| 午夜精品网站| 国产精品高潮粉嫩av| 亚洲精品日韩综合观看成人91 | 亚洲一区二区三区久久| 久久精品一区中文字幕| 一区二区三区日韩| 欧美日韩精品免费观看视频| 亚洲国产成人精品久久| 久久精品视频免费观看| 亚洲天堂网站在线观看视频| 欧美日韩国产一区精品一区| 亚洲国产精品一区二区久| 久久激情中文| 西瓜成人精品人成网站| 国产精品国产精品| 一本色道久久88综合亚洲精品ⅰ | 欧美日韩国产综合在线| 亚洲激情网址| 亚洲国产精品一区| 免费视频最近日韩| 亚洲精品五月天| 亚洲国产国产亚洲一二三| 欧美成人有码| 99re6热只有精品免费观看| 亚洲高清av| 欧美激情第三页| 99精品国产一区二区青青牛奶| 亚洲第一精品影视| 欧美激情亚洲自拍| 亚洲午夜激情网站| 亚洲一区在线观看视频| 国产日本欧美一区二区三区| 久久国产88| 久久精品二区三区| 亚洲激情偷拍| 日韩视频久久| 国产精品一级在线| 久久视频在线免费观看| 免费欧美日韩| 中文精品在线| 亚洲欧美日韩国产|