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

天行健 君子當自強而不息

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) 評論(0)  編輯 收藏 引用

公告

導航

統(tǒng)計

常用鏈接

隨筆分類(178)

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

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            一区二区三区波多野结衣在线观看| 亚洲国产日韩美| 亚洲视频在线观看网站| 欧美日韩中文| 欧美在线视频在线播放完整版免费观看 | 艳妇臀荡乳欲伦亚洲一区| 欧美日韩免费一区二区三区| 亚洲一区二区三| 亚洲欧美一级二级三级| 国产专区一区| 亚洲国产三级网| 国产精品久久久久77777| 欧美一区二区三区啪啪| 久久久久久精| 亚洲精品国产精品国自产观看浪潮| 亚洲精品久久久久久久久久久久久| 国产精品久久久久久久久久久久久久| 午夜精品久久久久99热蜜桃导演| 久久av一区二区| 日韩午夜一区| 香蕉久久夜色精品| 亚洲人妖在线| 亚洲欧美在线看| 亚洲人成网站精品片在线观看| 一本大道久久a久久精二百| 国产在线高清精品| 亚洲伦理中文字幕| 依依成人综合视频| 亚洲婷婷在线| 亚洲裸体俱乐部裸体舞表演av| 亚洲在线播放电影| 日韩午夜在线播放| 久久国产一区二区| 亚洲欧美成人网| 欧美成年人视频网站| 久久精品国产精品亚洲综合 | 一区二区国产日产| 91久久在线视频| 欧美亚洲综合在线| 亚洲一区二区三区四区五区黄| 久热综合在线亚洲精品| 欧美在线一级视频| 欧美日韩成人在线| 亚洲第一福利社区| 在线播放国产一区中文字幕剧情欧美| 亚洲视频免费观看| 99riav国产精品| 免费日韩成人| 美女视频黄a大片欧美| 国产日韩成人精品| 亚洲制服少妇| 午夜在线精品| 国产精品白丝av嫩草影院| 亚洲国产精品久久人人爱蜜臀 | 国产老肥熟一区二区三区| 亚洲日本理论电影| 亚洲日本免费| 欧美国产极速在线| 亚洲高清视频的网址| 亚洲成色精品| 男人插女人欧美| 欧美aⅴ99久久黑人专区| 在线不卡a资源高清| 欧美专区在线观看| 久久躁狠狠躁夜夜爽| 伊大人香蕉综合8在线视| 久久成人在线| 免费亚洲一区二区| 亚洲激情欧美激情| 欧美激情第六页| 99国产精品私拍| 午夜一级在线看亚洲| 国产欧美日韩亚洲一区二区三区| 性欧美精品高清| 久久永久免费| 亚洲人线精品午夜| 欧美日韩免费观看一区=区三区| 99国内精品久久| 欧美亚洲免费| 狠狠色综合日日| 欧美成人首页| 99日韩精品| 久久精品盗摄| 最新国产の精品合集bt伙计| 欧美日韩第一区| 亚洲男人影院| 欧美激情bt| 亚洲少妇一区| 国产一区二区三区免费不卡| 美女主播一区| 亚洲天堂av在线免费| 老鸭窝91久久精品色噜噜导演| 亚洲日本中文| 国产精品视频观看| 裸体丰满少妇做受久久99精品| 亚洲伦理网站| 久久久夜精品| 亚洲午夜视频在线观看| 国产一区二区在线观看免费播放| 欧美aⅴ一区二区三区视频| 一区二区三区 在线观看视| 久久一区二区视频| 亚洲网站视频| 亚洲大胆av| 国产精品久久久久久影视| 久久综合九色综合久99| 亚洲午夜电影网| 欧美bbbxxxxx| 久久国产精品电影| 一区二区三区精品在线| 在线精品福利| 国产亚洲毛片| 国产精品电影在线观看| 农村妇女精品| 久久深夜福利| 欧美怡红院视频| 亚洲视频一区二区| 亚洲日本中文字幕区| 另类国产ts人妖高潮视频| 欧美一区2区三区4区公司二百| 亚洲免费观看| 91久久夜色精品国产网站| 樱花yy私人影院亚洲| 国产婷婷色一区二区三区在线| 欧美丝袜一区二区三区| 欧美精品在线播放| 欧美成年人网| 久久综合色8888| 久久精品女人| 欧美在线免费一级片| 亚洲欧美日韩精品久久久久| 亚洲午夜精品| 亚洲特级毛片| 亚洲免费在线观看| 亚洲性线免费观看视频成熟| 狠狠色狠狠色综合日日小说| 国产精品户外野外| 国产精品久久久久av| 国产精品国产a| 欧美亚洲不卡| 国产精品区一区二区三| 国产精品老女人精品视频| 国产精品国产精品| 国产精品久久久| 国产精品三区www17con| 国产女主播一区| 国产日韩欧美综合| 国产一二三精品| 亚洲男女自偷自拍图片另类| 亚洲欧美电影院| 久久超碰97人人做人人爱| 久久久久国产精品人| 玖玖视频精品| 欧美精品一区在线观看| 欧美性大战久久久久| 国产精品一区二区三区免费观看 | 欧美精品二区| 欧美视频在线观看视频极品| 国产精品久久久久aaaa九色| 国产日韩欧美一区二区| 亚洲成人自拍视频| 一区二区三区高清| 欧美在线视频免费播放| 欧美 日韩 国产在线| 亚洲国产日日夜夜| 亚洲一区一卡| 久久久精品一区二区三区| 欧美激情综合在线| 国产麻豆精品theporn| 一区二区三区自拍| 中文久久精品| 久久精品在线免费观看| 欧美激情区在线播放| 一区二区日韩| 久久中文字幕导航| 国产精品成人午夜| 在线看一区二区| 亚洲免费中文| 欧美成人网在线| 亚洲字幕在线观看| 欧美激情精品久久久久久蜜臀 | 免费美女久久99| 国产精品日韩在线| 亚洲精品久久久久久下一站| 西瓜成人精品人成网站| 欧美激情一区二区在线| 亚洲欧美国产日韩天堂区| 欧美黄免费看| 在线欧美影院| 久久精品国产第一区二区三区| 最新亚洲电影| 久久综合久久美利坚合众国| 国产精品尤物福利片在线观看| 亚洲美女精品久久| 久久综合999| 亚洲欧美日韩中文播放| 欧美日韩一区二区三区视频| 亚洲国产精品激情在线观看| 欧美精品一区二区精品网| 在线观看日韩欧美|