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

天行健 君子當(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>
            欧美激情第9页| av成人免费| 亚洲经典在线看| 国产午夜一区二区三区| 国产日韩在线视频| 伊人久久大香线蕉av超碰演员| 在线免费观看成人网| 亚洲欧洲中文日韩久久av乱码| 国产一区二区精品在线观看| 伊人影院久久| 一本久久综合| 欧美一级成年大片在线观看| 久久久精品动漫| 亚洲缚视频在线观看| 欧美激情bt| 亚洲视频 欧洲视频| 欧美在线观看网址综合| 欧美精品v日韩精品v韩国精品v| 欧美视频一二三区| 亚洲夫妻自拍| 性色av一区二区三区红粉影视| 另类激情亚洲| 亚洲视频在线免费观看| 老司机aⅴ在线精品导航| 欧美四级电影网站| 亚洲夫妻自拍| 久久www成人_看片免费不卡| 亚洲电影中文字幕| 欧美亚洲视频在线看网址| 欧美黄色日本| 激情国产一区| 欧美一区二区高清| 99精品欧美一区二区三区| 久久视频这里只有精品| 国产精品免费在线| 99热免费精品在线观看| 裸体丰满少妇做受久久99精品| 一本色道精品久久一区二区三区| 久久综合伊人| 狠狠色狠狠色综合日日五| 亚洲一区二区在线免费观看视频| 免费成人av在线| 欧美日韩专区| 欧美淫片网站| 国产精品久久国产精麻豆99网站| 亚洲国产美女| 久久综合久久88| 亚洲亚洲精品三区日韩精品在线视频 | 在线日本成人| 欧美专区福利在线| 亚洲视频www| 国产精品xxxxx| 亚洲网站视频| 夜夜嗨av一区二区三区| 欧美成人性网| 亚洲美女在线视频| 亚洲激情av在线| 欧美极品色图| 亚洲网友自拍| 亚洲欧美电影在线观看| 国产精品美女久久久久久2018 | 亚洲欧美日韩精品| 国产精品一级| 久久国产夜色精品鲁鲁99| 亚洲综合欧美日韩| 国产一本一道久久香蕉| 米奇777在线欧美播放| 久热精品视频在线观看| 亚洲日韩欧美一区二区在线| 日韩视频精品| 国产精品免费在线| 久久久久成人精品| 久久综合久色欧美综合狠狠| 亚洲国产高清一区二区三区| 欧美激情中文字幕一区二区| 欧美另类视频| 亚洲欧美日韩另类精品一区二区三区| 亚洲图片在线| 国内精品伊人久久久久av影院| 久久―日本道色综合久久| 久久精品一区二区三区中文字幕| 影音先锋中文字幕一区| 亚洲国内高清视频| 国产精品嫩草影院av蜜臀| 久久久国产成人精品| 久久亚洲综合| 亚洲一区三区电影在线观看| 欧美一级视频精品观看| 亚洲精品免费电影| 亚洲伊人久久综合| 91久久精品美女高潮| 亚洲视频在线观看| 精品动漫av| 99国产麻豆精品| 狠狠色狠狠色综合日日91app| 亚洲黄网站在线观看| 国产三级欧美三级日产三级99| 亚洲欧美色一区| 国产精品拍天天在线| 麻豆av福利av久久av| 欧美激情一区二区三区在线视频| 亚洲欧美成人精品| 久久视频在线视频| 亚洲欧美国产高清| 欧美aⅴ99久久黑人专区| 午夜精品成人在线| 欧美激情综合色综合啪啪| 久久久成人精品| 欧美三日本三级三级在线播放| 久久夜色精品国产欧美乱| 欧美午夜视频在线| 欧美第一黄色网| 国产日韩欧美一区在线| 亚洲精选国产| 亚洲激情自拍| 久久久久久久久蜜桃| 欧美在线国产精品| 国产精品户外野外| 亚洲精品日韩综合观看成人91| 在线观看视频一区二区欧美日韩| 亚洲男人天堂2024| 亚洲淫性视频| 欧美视频在线观看一区| 亚洲国产影院| 亚洲全部视频| 能在线观看的日韩av| 欧美高清hd18日本| 亚洲国产日韩一级| 久久中文在线| 欧美成人亚洲| 91久久综合| 欧美激情1区| 91久久中文| 一二三四社区欧美黄| 欧美日韩国产91| 99v久久综合狠狠综合久久| 这里只有精品视频在线| 欧美日韩在线大尺度| 一道本一区二区| 亚洲性线免费观看视频成熟| 欧美日韩一区高清| 一区二区三区日韩欧美精品| 亚洲欧美在线一区二区| 国产精品卡一卡二| 性欧美video另类hd性玩具| 久久九九99| 亚洲国产中文字幕在线观看| 欧美国产大片| 亚洲视频1区2区| 久久久99久久精品女同性| 亚洲第一福利社区| 欧美www视频| 在线视频中文亚洲| 久久久久久久一区二区三区| 在线日本欧美| 欧美理论电影在线观看| 亚洲午夜久久久久久久久电影院| 欧美一区二区高清在线观看| 国产午夜精品全部视频在线播放| 久久久国产91| 亚洲日本va午夜在线电影| 亚洲欧美在线另类| 在线观看视频一区| 国产精品v片在线观看不卡| 性欧美超级视频| 亚洲第一久久影院| 亚洲福利av| 国产精品视频xxx| 亚洲福利视频网| 亚洲一区二区在线免费观看视频| 国产一级久久| 欧美久久久久久久| 久久爱www久久做| 亚洲精品久久久久| 久久久精彩视频| 一区二区三区视频在线看| 国色天香一区二区| 欧美精品久久天天躁| 性色av一区二区三区| 亚洲日本中文字幕免费在线不卡| 欧美一区二区黄色| 一区二区动漫| 亚洲国产成人久久综合一区| 国产精品一二三| 欧美日韩国产综合视频在线观看 | 亚洲经典自拍| 国产女同一区二区| 欧美精品一区二区在线观看| 久久久精品动漫| 亚洲欧美日韩电影| 亚洲最新在线| 亚洲黄色小视频| 欧美sm视频| 麻豆国产精品va在线观看不卡| 午夜精品成人在线| 亚洲一区欧美激情| 中文有码久久| 夜夜爽99久久国产综合精品女不卡| 亚洲第一福利在线观看| 一区视频在线看|