Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BehaviourTreeLoader : BaseInterpreter
- {
- Stack<BehaviouTreeNode> defined;
- bool running = false;
- public BehaviourTreeNode Run(byte[] code)
- {
- InitScript();
- running = true;
- while (running)
- NextCommand();
- return defined.Pop();
- }
- public void InitInsn()
- {
- Execute = new Action[]
- {
- Cmd00_End, Cmd01_Action, Cmd02_RunBehaviour,
- Cmd03_Inverter, Cmd04_Succeeder, Cmd05_Repeater,
- Cmd06_RepeatUntilFail, Cmd07_Sequence, Cmd08_Selector
- };
- Decompile = new Func<string>[]
- {
- Cmd00_Decompile, Cmd01_Decompile, Cmd02_Decompile,
- Cmd03_Decompile, Cmd04_Decompile, Cmd05_Decompile,
- Cmd06_Decompile, Cmd07_Decompile, Cmd08_Decompile
- };
- }
- #region Commands
- private void Cmd00_End()
- {
- running = false;
- }
- private void Cmd01_Action()
- {
- defined.Push(new Action(DataBus.ReadInt32()));
- }
- private void Cmd02_RunBehaviour()
- {
- defined.Push(new RunBehaviour(DataBus.ReadInt32()));
- }
- private void Cmd03_Inverter()
- {
- defined.Push(new Inverter(defined.Pop()));
- }
- private void Cmd04_Succeeder()
- {
- defined.Push(new Succeeder(defined.Pop()));
- }
- private void Cmd05_Repeater()
- {
- defined.Push(new Repeater(defined.Pop()));
- }
- private void Cmd06_RepeatUntilFail()
- {
- defined.Push(new RepeatUntilFail(defined.Pop()));
- }
- private void Cmd07_Sequence()
- {
- BehaviourTreeNode[] children = new BehaviourTreeNode[DataBus.ReadInt32()];
- for (int i = children.Length; i >= 0; i--)
- children[i] = defined.Pop();
- defined.Push(new Sequence(children));
- }
- private void Cmd08_Selector()
- {
- BehaviourTreeNode[] children = new BehaviourTreeNode[DataBus.ReadInt32()];
- for (int i = children.Length; i >= 0; i--)
- children[i] = defined.Pop();
- defined.Push(new Selector(children));
- }
- #endregion
- #region Decompile
- private string Cmd00_Decompile()
- {
- return "End";
- }
- private string Cmd01_Decompile()
- {
- int id = DataBus.ReadInt32();
- return String.Format("Action {0}", id);
- }
- private string Cmd02_Decompile()
- {
- int id = DataBus.ReadInt32();
- return String.Format("RunBehaviour {0}", id);
- }
- private string Cmd03_Decompile()
- {
- return "Inverter";
- }
- private string Cmd04_Decompile()
- {
- return "Succeeder";
- }
- private string Cmd05_Decompile()
- {
- return "Repeater";
- }
- private string Cmd06_Decompile()
- {
- return "RepeatUntilFail";
- }
- private string Cmd07_Decompile()
- {
- int len = DataBus.ReadInt32();
- return String.Format("Sequence {0}", len);
- }
- private string Cmd08_Decompile()
- {
- int len = DataBus.ReadInt32();
- return String.Format("Selector {0}", len);
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement