コード例 #1
0
        protected override void GenerateMember(Node node, StringWriter stream, string indent)
        {
            base.GenerateMember(node, stream, indent);

            Behaviac.Design.Nodes.Action action = node as Behaviac.Design.Nodes.Action;

            if (action == null)
            {
                return;
            }

            if (action.Method != null && !isNullMethod(action.Method))
            {
                MethodCsExporter.GenerateClassMember(action.Method, stream, indent, "method");
            }
        }
コード例 #2
0
ファイル: ActionCppExporter.cs プロジェクト: cuixin/behaviac
        protected override void GenerateConstructor(Node node, StringWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            Behaviac.Design.Nodes.Action action = node as Behaviac.Design.Nodes.Action;

            if (action == null)
            {
                return;
            }

            if (action.Method != null)
            {
                MethodCppExporter.GenerateClassConstructor(node, action.Method, stream, indent, "method");
            }
        }
コード例 #3
0
        protected override void GenerateConstructor(Node node, StringWriter stream, string indent, string className)
        {
            base.GenerateConstructor(node, stream, indent, className);

            Behaviac.Design.Nodes.Action action = node as Behaviac.Design.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");
            }
        }
コード例 #4
0
        protected override void GenerateMethod(Node node, StringWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            Behaviac.Design.Nodes.Action action = node as Behaviac.Design.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);
        }
コード例 #5
0
 protected override bool ShouldGenerateClass(Node node)
 {
     Behaviac.Design.Nodes.Action action = node as Behaviac.Design.Nodes.Action;
     return(action != null);
 }
コード例 #6
0
ファイル: ActionCppExporter.cs プロジェクト: cuixin/behaviac
        protected override void GenerateMethod(Node node, StringWriter stream, string indent)
        {
            base.GenerateMethod(node, stream, indent);

            Behaviac.Design.Nodes.Action action = node as Behaviac.Design.Nodes.Action;

            if (action == null)
            {
                return;
            }

            stream.WriteLine("{0}\t\tvirtual EBTStatus update_impl(Agent* pAgent, EBTStatus childStatus)", indent);
            stream.WriteLine("{0}\t\t{{", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent);
            stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(childStatus);", indent);

            string resultStatus = "BT_SUCCESS";

            if (action.Method != null)
            {
                string method = MethodCppExporter.GenerateCode(node, action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method");

                if ("behaviac::EBTStatus" == action.Method.NativeReturnType)
                {
                    stream.WriteLine("{0}\t\t\t{1} result = {2};", indent, action.Method.NativeReturnType, method);
                    resultStatus = "result";

                    MethodCppExporter.PostGenerateCode(action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method");
                }
                else
                {
                    if (("void" == action.Method.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, action.Method.NativeReturnType, method);
                    }

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

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

                            if (action.ResultFunctor.Owner != VariableDef.kSelf)
                            {
                                agentName = "pAgent_functor";

                                stream.WriteLine("{0}Agent* {1} = Agent::GetInstance(pAgent, \"{2}\");", indent, agentName, action.ResultFunctor.Owner);
                                stream.WriteLine("{0}BEHAVIAC_ASSERT({1});", indent, agentName);
                            }

                            resultStatus = string.Format("(({0}*){1})->{2}(result)", action.ResultFunctor.ClassName, agentName, action.ResultFunctor.Name);
                        }
                    }
                }
            }

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