Пример #1
0
        protected virtual void GenerateMethod(Node node, StreamWriter stream, string indent)
        {
            // enter
            if (node.EnterAction != null && node.EnterAction.Name != "null_method")
            {
                stream.WriteLine("{0}\t\tpublic override bool enteraction_impl(Agent pAgent)", indent);
                stream.WriteLine("{0}\t\t{{", indent);

                string retStr = MethodCsExporter.GenerateCode(node.EnterAction, stream, indent + "\t\t\t", node.EnterAction.NativeReturnType, string.Empty, "EnterAction");
                stream.WriteLine("{0}\t\t\t{1};", indent, retStr);

                MethodCsExporter.PostGenerateCode(node.EnterAction, stream, indent + "\t\t\t", node.EnterAction.NativeReturnType, string.Empty, "EnterAction");

                stream.WriteLine("{0}\t\t\treturn true;", indent);
                stream.WriteLine("{0}\t\t}}", indent);
            }

            // exit
            if (node.ExitAction != null && node.ExitAction.Name != "null_method")
            {
                stream.WriteLine("{0}\t\tpublic override bool exitaction_impl(Agent pAgent)", indent);
                stream.WriteLine("{0}\t\t{{", indent);

                string retStr = MethodCsExporter.GenerateCode(node.ExitAction, stream, indent + "\t\t\t", node.ExitAction.NativeReturnType, string.Empty, "ExitAction");
                stream.WriteLine("{0}\t\t\t{1};", indent, retStr);

                MethodCsExporter.PostGenerateCode(node.ExitAction, stream, indent + "\t\t\t", node.ExitAction.NativeReturnType, string.Empty, "ExitAction");

                stream.WriteLine("{0}\t\t\treturn true;", indent);
                stream.WriteLine("{0}\t\t}}", indent);
            }
        }
Пример #2
0
        protected override void GenerateMethod(Node node, StringWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            State state = node as State;

            if (state == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);

            if (state.Method != null && !isNullMethod(state.Method))
            {
                string method = MethodCsExporter.GenerateCode(node, state.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method");
                stream.WriteLine("{0}\t\t\t{1};", indent, method);

                MethodCsExporter.PostGenerateCode(state.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method");
            }

            stream.WriteLine("{0}\t\t\treturn behaviac.EBTStatus.BT_RUNNING;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Пример #3
0
        protected virtual void GenerateMember(Node node, StreamWriter stream, string indent)
        {
            if (node.EnterAction != null && node.EnterAction.Name != "null_method")
            {
                MethodCsExporter.GenerateClassMember(node.EnterAction, stream, indent, "EnterAction");
            }

            if (node.ExitAction != null && node.ExitAction.Name != "null_method")
            {
                MethodCsExporter.GenerateClassMember(node.ExitAction, stream, indent, "ExitAction");
            }
        }
Пример #4
0
        protected override void GenerateMember(Node node, StreamWriter stream, string indent)
        {
            base.GenerateMember(node, stream, indent);

            Action action = node as Action;

            Debug.Check(action != null);

            if (action.Method != null)
            {
                MethodCsExporter.GenerateClassMember(action.Method, stream, indent, "method");
            }
        }
Пример #5
0
        protected override void GenerateMember(Node node, StringWriter stream, string indent)
        {
            base.GenerateMember(node, stream, indent);

            State state = node as State;

            if (state == null)
            {
                return;
            }

            if (state.Method != null && !isNullMethod(state.Method))
            {
                MethodCsExporter.GenerateClassMember(state.Method, stream, indent, "method");
            }
        }
Пример #6
0
        protected override void GenerateMember(Node node, StringWriter stream, string indent)
        {
            base.GenerateMember(node, stream, indent);

            Nodes.Action action = node as Nodes.Action;

            if (action == null)
            {
                return;
            }

            if (action.Method != null && !isNullMethod(action.Method))
            {
                MethodCsExporter.GenerateClassMember(action.Method, stream, indent, "method");
            }
        }
Пример #7
0
        protected override void GenerateConstructor(Node node, StringWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            State state = node as State;

            if (state == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\t\tthis.m_bIsEndState = {1};", indent, state.IsEndState ? "true" : "false");

            if (state.Method != null && !isNullMethod(state.Method))
            {
                MethodCsExporter.GenerateClassConstructor(node, state.Method, stream, indent, "method");
            }
        }
Пример #8
0
        protected override void GenerateConstructor(Node node, StringWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            Nodes.Action action = node as Nodes.Action;

            if (action == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\t\tthis.m_resultOption = {1};", indent, getResultOptionStr(action.ResultOption));

            if (action.Method != null && !isNullMethod(action.Method))
            {
                MethodCsExporter.GenerateClassConstructor(node, action.Method, stream, indent, "method");
            }
        }
Пример #9
0
        protected override void GenerateMethod(Behaviac.Design.Attachments.Attachment attachment, StreamWriter stream, string indent)
        {
            base.GenerateMethod(attachment, stream, indent);

            AttachAction attach = attachment as AttachAction;

            if (attach == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tEBTStatus result = EBTStatus.BT_SUCCESS;", indent);

            if (attach.IsAction())
            {
                string method = MethodCsExporter.GenerateCode(attachment, attach.Opl.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl");

                stream.WriteLine("{0}\t\t\t{1};", indent, method);
                MethodCsExporter.PostGenerateCode(attach.Opl.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "opl");
            }
            else if (attach.IsAssign())
            {
                if (attach.Opl != null && !attach.Opl.IsMethod && attach.Opl.Var != null && attach.Opr2 != null)
                {
                    PropertyDef prop = attach.Opl.Var.Property;
                    if (prop != null)
                    {
                        RightValueCsExporter.GenerateCode(attachment, attach.Opr2, stream, indent + "\t\t\t", attach.Opr2.NativeType.Replace("::", "."), "opr2", "opr2");

                        string property = PropertyCsExporter.GetProperty(attachment, prop, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "attach");
                        string propName = prop.BasicName.Replace("[]", "");

                        if (prop.IsArrayElement && attach.Opl.Var.ArrayIndexElement != null)
                        {
                            ParameterCsExporter.GenerateCode(attachment, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "attach_opl");
                            property = string.Format("({0})[opl_index]", property);
                        }

                        string propBasicName = prop.BasicName.Replace("[]", "");

                        if (!prop.IsArrayElement && (prop.IsPar || prop.IsCustomized))
                        {
                            uint   id           = Behaviac.Design.CRC32.CalcCRC(propBasicName);
                            string oplAgentName = PropertyCsExporter.GetGenerateAgentName(prop, "opl", "attach");

                            stream.WriteLine("{0}\t\t\t{1}.SetVariable(\"{2}\", {3}u, opr2);", indent, oplAgentName, propBasicName, id);
                        }
                        else
                        {
                            if (prop.IsPublic)
                            {
                                stream.WriteLine("{0}\t\t\t{1} = opr2;", indent, property);
                            }
                            else
                            {
                                string agentName = PropertyCsExporter.GetGenerateAgentName(prop, "opr2", "opr2");
                                stream.WriteLine("{0}\t\t\tAgentExtra_Generated.SetProperty({1}, \"{2}\", opr2);", indent, agentName, propBasicName);
                            }
                        }

                        if (attach.Opr2.IsMethod)
                        {
                            RightValueCsExporter.PostGenerateCode(attach.Opr2, stream, indent + "\t\t\t", attach.Opr2.NativeType.Replace("::", "."), "opr2", string.Empty);
                        }
                    }
                }
            }
            else if (attach.IsCompare())
            {
                ConditionCsExporter.GenerateOperand(attachment, stream, indent + "\t\t\t", attach.Opl, "opl", "");
                ConditionCsExporter.GenerateOperand(attachment, stream, indent + "\t\t\t", attach.Opr2, "opr2", "");

                switch (attach.Operator)
                {
                case OperatorTypes.Equal:
                    stream.WriteLine("{0}\t\t\tbool op = (opl == opr2);", indent);
                    break;

                case OperatorTypes.NotEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl != opr2);", indent);
                    break;

                case OperatorTypes.Greater:
                    stream.WriteLine("{0}\t\t\tbool op = (opl > opr2);", indent);
                    break;

                case OperatorTypes.GreaterEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl >= opr2);", indent);
                    break;

                case OperatorTypes.Less:
                    stream.WriteLine("{0}\t\t\tbool op = (opl < opr2);", indent);
                    break;

                case OperatorTypes.LessEqual:
                    stream.WriteLine("{0}\t\t\tbool op = (opl <= opr2);", indent);
                    break;

                default:
                    stream.WriteLine("{0}\t\t\tbool op = false;", indent);
                    break;
                }
                stream.WriteLine("{0}\t\t\tif (!op)", indent);
                stream.WriteLine("{0}\t\t\t\tresult = EBTStatus.BT_FAILURE;", indent);
            }
            else if (attach.IsCompute())
            {
                if (attach.Opl != null && !attach.Opl.IsMethod && attach.Opl.Var != null && attach.Opr1 != null && attach.Opr2 != null)
                {
                    PropertyDef prop = attach.Opl.Var.Property;
                    if (prop != null)
                    {
                        string typeName = Plugin.GetNativeTypeName(attach.Opr1.ValueType);
                        typeName = typeName.Replace("::", ".");

                        RightValueCsExporter.GenerateCode(attachment, attach.Opr1, stream, indent + "\t\t\t", typeName, "opr1", "opr1");
                        RightValueCsExporter.GenerateCode(attachment, attach.Opr2, stream, indent + "\t\t\t", typeName, "opr2", "opr2");

                        string oprStr = string.Empty;
                        switch (attach.Operator)
                        {
                        case OperatorTypes.Add:
                            oprStr = "opr1 + opr2";
                            break;

                        case OperatorTypes.Sub:
                            oprStr = "opr1 - opr2";
                            break;

                        case OperatorTypes.Mul:
                            oprStr = "opr1 * opr2";
                            break;

                        case OperatorTypes.Div:
                            oprStr = "opr1 / opr2";
                            break;

                        default:
                            Debug.Check(false, "The operator is wrong!");
                            break;
                        }

                        oprStr = string.Format("({0})({1})", typeName, oprStr);

                        string property = PropertyCsExporter.GetProperty(attachment, prop, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "opl", "attach");
                        string propName = prop.BasicName.Replace("[]", "");

                        if (prop.IsArrayElement && attach.Opl.Var.ArrayIndexElement != null)
                        {
                            ParameterCsExporter.GenerateCode(attachment, attach.Opl.Var.ArrayIndexElement, stream, indent + "\t\t\t", "int", "opl_index", "attach_opl");
                            property = string.Format("({0})[opl_index]", property);
                        }

                        string propBasicName = prop.BasicName.Replace("[]", "");
                        string agentName     = PropertyCsExporter.GetGenerateAgentName(prop, "opl", "attach");

                        if (!prop.IsArrayElement && (prop.IsPar || prop.IsCustomized))
                        {
                            uint id = Behaviac.Design.CRC32.CalcCRC(propBasicName);

                            stream.WriteLine("{0}\t\t\t{1}.SetVariable(\"{2}\", {3}u, {4});", indent, agentName, propBasicName, id, oprStr);
                        }
                        else if (prop.IsPublic)
                        {
                            stream.WriteLine("{0}\t\t\t{1} = {2};", indent, property, oprStr);
                        }
                        else
                        {
                            stream.WriteLine("{0}\t\t\tAgentExtra_Generated.SetProperty({1}, \"{2}\", {3});", indent, agentName, propBasicName, oprStr);
                        }

                        if (attach.Opr1.IsMethod)
                        {
                            RightValueCsExporter.PostGenerateCode(attach.Opr1, stream, indent + "\t\t\t", typeName, "opr1", string.Empty);
                        }

                        if (attach.Opr2.IsMethod)
                        {
                            RightValueCsExporter.PostGenerateCode(attach.Opr2, stream, indent + "\t\t\t", typeName, "opr2", string.Empty);
                        }
                    }
                }
            }

            stream.WriteLine("{0}\t\t\treturn result;", indent);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Пример #10
0
        protected override void GenerateMethod(Node node, StringWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            Nodes.Action action = node as Nodes.Action;

            if (action == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);

            string resultStatus = getResultOptionStr(action.ResultOption);

            if (action.Method != null && !isNullMethod(action.Method))
            {
                string nativeReturnType = DataCsExporter.GetGeneratedNativeType(action.Method.NativeReturnType);
                string method           = MethodCsExporter.GenerateCode(node, action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method");

                if ("behaviac.EBTStatus" == nativeReturnType)
                {
                    resultStatus = "result";

                    stream.WriteLine("{0}\t\t\t{1} result = {2};", indent, nativeReturnType, method);
                    MethodCsExporter.PostGenerateCode(action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method");
                }
                else
                {
                    if (("void" == nativeReturnType) || (EBTStatus.BT_INVALID != action.ResultOption) || action.ResultFunctor == null)
                    {
                        stream.WriteLine("{0}\t\t\t{1};", indent, method);
                    }
                    else
                    {
                        stream.WriteLine("{0}\t\t\t{1} result = {2};", indent, nativeReturnType, method);
                    }

                    MethodCsExporter.PostGenerateCode(action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method");

                    if (EBTStatus.BT_INVALID != action.ResultOption)
                    {
                        resultStatus = getResultOptionStr(action.ResultOption);
                    }
                    else if (Plugin.IsMatchedStatusMethod(action.Method, action.ResultFunctor))
                    {
                        if ("void" == nativeReturnType)
                        {
                            resultStatus = MethodCsExporter.GenerateCode(node, action.ResultFunctor, stream, indent + "\t\t\t", string.Empty, string.Empty, "functor");
                        }
                        else
                        {
                            string agentName = "pAgent";

                            if (action.ResultFunctor.Owner != VariableDef.kSelf &&
                                (!action.ResultFunctor.IsPublic || !action.ResultFunctor.IsStatic))
                            {
                                string instanceName = action.ResultFunctor.Owner.Replace("::", ".");
                                agentName = "pAgent_functor";

                                stream.WriteLine("{0}behaviac.Agent {1} = behaviac.Utils.GetParentAgent(pAgent, \"{2}\");", indent, agentName, instanceName);
                                //stream.WriteLine("{0}Debug.Check(!System.Object.ReferenceEquals({1}, null) || Utils.IsStaticClass(\"{2}\"));", indent, agentName, instanceName);
                            }

                            if (action.ResultFunctor.IsPublic)
                            {
                                string className = action.ResultFunctor.ClassName.Replace("::", ".");

                                if (action.ResultFunctor.IsStatic)
                                {
                                    resultStatus = string.Format("{0}.{1}(result)", className, action.ResultFunctor.BasicName);
                                }
                                else
                                {
                                    resultStatus = string.Format("(({0}){1}).{2}(result)", className, agentName, action.ResultFunctor.BasicName);
                                }
                            }
                            else
                            {
                                resultStatus = string.Format("AgentMetaVisitor.ExecuteMethod({0}, \"{1}\", new object[] {{ result }})", agentName, action.ResultFunctor.BasicName);
                            }
                        }

                        resultStatus = string.Format("(EBTStatus){0}", resultStatus);
                    }
                }
            }

            stream.WriteLine("{0}\t\t\treturn {1};", indent, resultStatus);
            stream.WriteLine("{0}\t\t}}", indent);
        }
Пример #11
0
        protected override void GenerateMethod(Node node, StreamWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            Action action = node as Action;

            if (action == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);

            string resultStatus = getResultOptionStr(action.ResultOption);

            if (action.Method != null && !isNullMethod(action.Method))
            {
                string nativeReturnType = DataCsExporter.GetGeneratedNativeType(action.Method.NativeReturnType);
                string typeConvertStr   = (nativeReturnType == "void") ? string.Empty : "(" + nativeReturnType + ")";
                string method           = MethodCsExporter.GenerateCode(action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method");

                if ("behaviac.EBTStatus" == nativeReturnType)
                {
                    resultStatus = "result";

                    stream.WriteLine("{0}\t\t\t{1} result = {2}{3};", indent, nativeReturnType, typeConvertStr, method);
                    MethodCsExporter.PostGenerateCode(action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method");
                }
                else
                {
                    if (("void" == nativeReturnType) || (EBTStatus.BT_INVALID != action.ResultOption) || action.ResultFunctor == null)
                    {
                        stream.WriteLine("{0}\t\t\t{1};", indent, method);
                    }
                    else
                    {
                        stream.WriteLine("{0}\t\t\t{1} result = {2}{3};", indent, nativeReturnType, typeConvertStr, method);
                    }
                    MethodCsExporter.PostGenerateCode(action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method");

                    if (EBTStatus.BT_INVALID != action.ResultOption)
                    {
                        resultStatus = getResultOptionStr(action.ResultOption);
                    }
                    else if (Plugin.IsMatchedStatusMethod(action.Method, action.ResultFunctor))
                    {
                        if ("void" == nativeReturnType)
                        {
                            resultStatus = MethodCsExporter.GenerateCode(action.ResultFunctor, stream, indent + "\t\t\t", string.Empty, string.Empty, "functor");
                        }
                        else
                        {
                            string agentName = "pAgent";
                            if (action.ResultFunctor.Owner != VariableDef.kSelf &&
                                (!action.ResultFunctor.IsPublic || !action.ResultFunctor.IsStatic))
                            {
                                agentName = "pAgent_functor";

                                stream.WriteLine("{0}behaviac.Agent {1} = behaviac.Agent.GetInstance(\"{2}\", pAgent.GetContextId());", indent, agentName, action.ResultFunctor.Owner.Replace("::", "."));
                                stream.WriteLine("{0}Debug.Check({1} != null);", indent, agentName);
                            }

                            if (action.ResultFunctor.IsPublic)
                            {
                                string className = action.ResultFunctor.ClassName.Replace("::", ".");
                                if (action.ResultFunctor.IsStatic)
                                {
                                    resultStatus = string.Format("{0}.{1}(result)", className, action.ResultFunctor.BasicName);
                                }
                                else
                                {
                                    resultStatus = string.Format("(({0}){1}).{2}(result)", className, agentName, action.ResultFunctor.BasicName);
                                }
                            }
                            else
                            {
                                resultStatus = string.Format("AgentExtra_Generated.ExecuteMethod({0}, \"{1}\", new object[] {{ result }})", agentName, action.ResultFunctor.BasicName);
                            }
                        }

                        resultStatus = string.Format("(EBTStatus){0}", resultStatus);
                    }
                }
            }

            stream.WriteLine("{0}\t\t\treturn {1};", indent, resultStatus);
            stream.WriteLine("{0}\t\t}}", indent);
        }