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

天行健 君子當自強而不息

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>
            亚洲黄色成人| 欧美日韩四区| 欧美黄色aaaa| 麻豆精品一区二区综合av| 久久大香伊蕉在人线观看热2| 亚洲伊人网站| 午夜精品国产更新| 久久精品99国产精品日本 | 国产欧美日韩亚洲精品| 国产精品最新自拍| 在线观看欧美日韩| 一本色道久久综合亚洲精品不| 亚洲免费人成在线视频观看| 久久精品夜夜夜夜久久| 免费观看国产成人| 亚洲清纯自拍| 亚洲毛片在线| 亚洲欧美精品在线观看| 久久女同互慰一区二区三区| 欧美理论视频| 国内精品久久久久影院色 | 亚洲一区免费视频| 久久国产欧美| 亚洲国产一区二区a毛片| 亚洲午夜精品17c| 免费成人黄色片| 国产精品美女www爽爽爽视频| 国内精品久久久久久久影视蜜臀| 日韩视频在线一区| 久久综合色88| 先锋影音久久久| 欧美午夜激情视频| 亚洲精品麻豆| 欧美+亚洲+精品+三区| 91久久精品国产| 久久久久久久综合| 一区二区三区视频观看| 蜜臀99久久精品久久久久久软件| 国产精品免费久久久久久| 亚洲区一区二| 欧美成人午夜77777| 性刺激综合网| 国产嫩草一区二区三区在线观看 | 国外成人性视频| 亚洲综合成人婷婷小说| 欧美成人精品一区二区| 欧美一区二区免费| 国产精品扒开腿做爽爽爽视频| 亚洲大片av| 久久精品国产亚洲一区二区| 一区二区三区日韩精品| 欧美激情久久久| 最近中文字幕日韩精品 | 久久成人精品视频| 亚洲视频在线观看三级| 欧美日韩国产综合视频在线观看中文 | 欧美一区视频在线| 国产精品扒开腿做爽爽爽软件| 亚洲国产成人精品久久久国产成人一区| 亚洲自拍偷拍网址| 日韩一区二区电影网| 欧美日韩免费区域视频在线观看| 在线播放豆国产99亚洲| 久久一区二区视频| 性欧美video另类hd性玩具| 国产精品综合av一区二区国产馆| 正在播放欧美一区| 一本综合久久| 国产精品久久999| 亚洲综合精品四区| 亚洲线精品一区二区三区八戒| 欧美日一区二区三区在线观看国产免 | 最新国产成人在线观看| 亚洲电影免费在线观看| 久久尤物视频| 亚洲日本成人在线观看| 亚洲第一免费播放区| 欧美电影在线播放| 一区二区国产精品| 久久久999成人| 欧美在线你懂的| 亚洲黄色av| 一本大道久久a久久精二百| 国产精品蜜臀在线观看| 久久久久.com| 久久综合激情| 一本色道久久综合亚洲91| 亚洲视频www| 国产视频亚洲| 亚洲电影免费| 国产精品卡一卡二卡三| 久久亚洲二区| 欧美日韩在线观看视频| 久久精品国产一区二区电影| 久久久久国产精品厨房| 日韩一级在线观看| 亚洲在线中文字幕| 91久久精品国产91久久性色tv| 亚洲国产精品日韩| 国产欧美韩日| 日韩午夜中文字幕| 黑人一区二区三区四区五区| 亚洲精一区二区三区| 国产日产高清欧美一区二区三区| 蜜桃久久av| 国产精品最新自拍| 亚洲国产综合在线| 激情久久综艺| 午夜在线一区二区| 在线一区视频| 男女av一区三区二区色多| 午夜亚洲一区| 欧美日韩另类国产亚洲欧美一级| 欧美中文在线免费| 欧美日韩亚洲精品内裤| 欧美成人国产| 国产香蕉97碰碰久久人人| 亚洲免费激情| 亚洲乱码国产乱码精品精98午夜| 欧美永久精品| 欧美在线视频观看| 国产精品久久看| 99视频精品全部免费在线| 亚洲国产一成人久久精品| 午夜精品久久一牛影视| 亚洲欧美不卡| 国产精品国产一区二区| 日韩网站免费观看| 亚洲精品日韩在线观看| 久久久亚洲人| 另类图片国产| 韩日欧美一区二区三区| 欧美影院久久久| 欧美一区二区三区四区高清 | 久久精品免费看| 欧美一区二区三区免费观看| 欧美日本一道本| 91久久国产精品91久久性色| 亚洲国产精品电影| 嫩草影视亚洲| 亚洲人久久久| 亚洲一二区在线| 国产精品成人一区二区三区吃奶 | 亚洲欧洲一区二区在线观看| 亚洲高清免费视频| 久久综合九色九九| 亚洲二区在线| 亚洲视频中文字幕| 国产精品久久中文| 亚洲欧美在线一区二区| 久久久www成人免费无遮挡大片| 国产婷婷色一区二区三区四区| 欧美一区二区免费| 欧美高清在线一区二区| 99国产欧美久久久精品| 欧美日韩在线另类| 亚洲图片欧美一区| 久久成人免费网| 尹人成人综合网| 欧美日韩免费精品| 欧美国产先锋| 在线视频你懂得一区二区三区| 亚洲综合色网站| 经典三级久久| 欧美极品在线播放| 亚洲视频狠狠| 久久综合中文字幕| 亚洲人体大胆视频| 国产精品久久久久久久久久久久久久 | 午夜精品影院| 亚洲国产成人久久| 欧美午夜一区二区福利视频| 亚洲在线视频网站| 欧美高清在线视频| 欧美在线免费观看亚洲| 最近中文字幕日韩精品 | 亚洲综合社区| 欧美高清你懂得| 午夜久久久久久| 亚洲电影欧美电影有声小说| 国产精品jvid在线观看蜜臀| 久久国产精品久久久久久久久久 | 欧美性色视频在线| 性欧美精品高清| 欧美国产精品久久| 欧美一区国产二区| 欧美freesex交免费视频| 亚洲无线一线二线三线区别av| 国产综合激情| 国产精品久久久久久av下载红粉| 鲁大师影院一区二区三区| 一区二区三区高清在线观看| 久久综合色播五月| 亚洲欧美日韩一区二区三区在线观看| 悠悠资源网亚洲青| 国产欧美短视频| 国产精品久久久一本精品| 欧美肥婆bbw| 久久一区激情| 久久激情网站|