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

天行健 君子當(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>
            久久不射中文字幕| 一区二区三区蜜桃网| 欧美一级片在线播放| 欧美日本免费| 国一区二区在线观看| 久久成人国产| 亚洲欧美日韩综合一区| 国产精品尤物| 欧美专区日韩专区| 性久久久久久久久| 精品1区2区| 亚洲大胆女人| 午夜精品三级视频福利| 国产日韩一区二区| 免费影视亚洲| 欧美xx视频| 一区二区三区鲁丝不卡| 亚洲午夜精品一区二区三区他趣| 国产精品久久久久久久久久妞妞 | 国产伦理一区| 裸体丰满少妇做受久久99精品| 制服丝袜亚洲播放| 国产欧美一区二区三区在线老狼 | 国产日韩精品一区二区三区在线| 久久精品女人的天堂av| 久久久人成影片一区二区三区观看| 亚洲国产成人午夜在线一区| 最新日韩欧美| 国产精品久久久久久久久久免费看 | 亚洲精品国产拍免费91在线| 亚洲剧情一区二区| 国产日韩一区二区三区| 欧美黄免费看| 国产精品美女www爽爽爽视频| 久久九九国产精品怡红院| 免费亚洲电影在线| 亚洲午夜精品在线| 欧美人与禽性xxxxx杂性| 亚洲一二三区视频在线观看| 久久久国产精品亚洲一区 | 狠狠色综合网| 亚洲欧美日韩成人| 亚洲伊人色欲综合网| 久久综合伊人77777| 久久精品亚洲一区| 国产精品视频观看| 一区二区三区视频观看| 一本一本久久| 欧美国产日本| 亚洲国产精品电影在线观看| 一区视频在线看| 久久国产精品72免费观看| 久久电影一区| 国产区精品在线观看| 亚洲一区国产| 午夜视频在线观看一区二区三区| 欧美区亚洲区| 亚洲精品一区二区三区99| 一本大道久久a久久综合婷婷| 另类av一区二区| 欧美黑人多人双交| 亚洲人体偷拍| 欧美精品在线播放| 亚洲精品一区在线观看| 一卡二卡3卡四卡高清精品视频| 欧美激情2020午夜免费观看| 亚洲大胆人体视频| 亚洲免费观看高清完整版在线观看熊| 欧美va亚洲va日韩∨a综合色| 蘑菇福利视频一区播放| 亚洲欧洲偷拍精品| 欧美伦理91i| 亚洲性人人天天夜夜摸| 欧美中文字幕不卡| 在线电影院国产精品| 看欧美日韩国产| 亚洲伦理在线| 欧美一区二区在线播放| 今天的高清视频免费播放成人| 久久一区二区三区av| 亚洲国产精品一区制服丝袜| 99精品国产福利在线观看免费 | 香蕉国产精品偷在线观看不卡| 久久精品首页| 亚洲欧洲午夜| 国产精品一区=区| 久久伊伊香蕉| 99热免费精品在线观看| 羞羞漫画18久久大片| 黄色精品在线看| 欧美日韩国产精品 | 亚洲第一色中文字幕| 一区二区三区日韩在线观看| 国产视频一区二区三区在线观看| 久久久在线视频| 一区二区三区福利| 免费在线国产精品| 亚洲男人的天堂在线| 一区在线播放视频| 欧美午夜精彩| 乱人伦精品视频在线观看| 亚洲图片你懂的| 欧美粗暴jizz性欧美20| 亚洲免费视频观看| 91久久中文字幕| 国产午夜精品理论片a级大结局 | 亚洲欧美日韩国产另类专区| 亚洲国产精品久久久久久女王| 性欧美1819sex性高清| 亚洲国产日韩精品| 国产综合久久久久影院| 欧美性猛片xxxx免费看久爱| 久久艳片www.17c.com| 亚洲一区二区三区欧美| 亚洲高清网站| 麻豆成人在线播放| 久久精品国产77777蜜臀| 一区二区三区欧美日韩| 亚洲国产精品t66y| 海角社区69精品视频| 国产精品日韩一区| 欧美日韩一区综合| 欧美噜噜久久久xxx| 美女国内精品自产拍在线播放| 欧美在线观看网址综合| 亚洲综合色激情五月| 一本久道久久综合狠狠爱| 亚洲二区在线观看| 欧美福利小视频| 免费毛片一区二区三区久久久| 久久久久综合| 久久国产欧美精品| 久久精品成人| 久久精品视频在线播放| 久久国产精品电影| 欧美一区二区免费| 欧美中文字幕| 久久久精品免费视频| 欧美专区在线观看一区| 欧美专区一区二区三区| 欧美在线精品免播放器视频| 久久99伊人| 久久频这里精品99香蕉| 久久青草久久| 蜜桃av一区二区三区| 欧美91大片| 亚洲精品黄色| 99精品久久久| 午夜精品久久久久久久久久久| 亚洲女性裸体视频| 久久精品二区| 欧美jizz19hd性欧美| 欧美日韩福利在线观看| 国产精品久久久久久久久婷婷| 国产精品欧美一区二区三区奶水| 国产精品腿扒开做爽爽爽挤奶网站| 国产精品美女久久福利网站| 国产视频久久| 亚洲国产精品精华液网站| 日韩一级精品视频在线观看| 亚洲影音先锋| 久久婷婷久久| 91久久国产综合久久蜜月精品| 亚洲精品一区在线观看香蕉| 亚洲免费人成在线视频观看| 欧美中文字幕第一页| 欧美肥婆在线| 国产精品一区二区久久久久| 黄色成人91| 亚洲视频在线观看网站| 久久黄色网页| 亚洲精品影院| 久久精品免费观看| 欧美日韩午夜在线| 黄色欧美日韩| 亚洲欧美国产日韩天堂区| 欧美91精品| 亚洲欧美精品一区| 欧美激情第3页| 国产综合亚洲精品一区二| 99热这里只有成人精品国产| 久久久久久久久久久久久9999| 亚洲人成网站在线播| 久久er精品视频| 国产精品海角社区在线观看| 亚洲成人在线免费| 性欧美video另类hd性玩具| 欧美国产先锋| 欧美一区二区三区在线看| 欧美日韩一卡| 亚洲人成人一区二区在线观看| 欧美专区在线播放| 一本色道久久综合一区| 免费在线亚洲欧美| 激情小说亚洲一区| 久久精品视频在线观看| 亚洲性av在线| 国产精品videosex极品| 99精品欧美一区二区三区综合在线| 久久免费视频在线观看|