示例#1
0
 public BehaverBridge(Behaver _behaverFront, BridgeHelperFactoryBridge _helperFactory)
 {
     helperFactory          = _helperFactory;
     behaverFront           = _behaverFront;
     matchAttributeCallback = (newAttributeGBlockPtr) => {
         try {
             var gBlock = NativeGrammarBlockUtils.GBlockPtrToGBlock(newAttributeGBlockPtr);
             var bf     = this.behaverFront;
             return((int)behaverFront.MatchAttribue(gBlock));
         } catch (System.Exception e) {
             Debug.LogError(e);
             return((int)AttributeMatchResult.NEUTRAL);
         }
     };
     setBehaviorCallback = (behaviorExpression, listener) => {
         try {
             var gBlock = NativeGrammarBlockUtils.GBlockPtrToGBlock(behaviorExpression);
             behaverFront.ReadyBehavior(GrammarBlockUtils.GBlockToBExpression(gBlock), new NativeBehaviorRequestListener(listener, helperFactory));
             Debug.Log("READY Set Behaver Front behavior: " + gBlock.cluster.blocks[1].unit.word);
         } catch (Exception e) {
             Debug.LogError(e);
         }
     };
     checkBehaviorCallback = (behaviorExpression, listener) => {
         try {
             var gBlock = NativeGrammarBlockUtils.GBlockPtrToGBlock(behaviorExpression);
             behaverFront.ReadyCheckBehavior(GrammarBlockUtils.GBlockToBExpression(gBlock), new NativeBehaviorCheckRequestListener(listener, helperFactory));
             Debug.Log("READY Check Behaver Front behavior: " + gBlock.cluster.blocks[1].unit.word);
         } catch (Exception e) { Debug.LogError(e); }
     };
 }
示例#2
0
 void SyntacticProcessor.PerformSyntacticProcess(byte[] behaviorExpression, Taker <GrammarBlock> listener)
 {
     try {
         System.IntPtr marshalArray = Marshal.AllocHGlobal(behaviorExpression.Length);
         Marshal.Copy(behaviorExpression, 0, marshalArray, behaviorExpression.Length);
         var gBlockPtr = PerformSyntacticProcess(fAnalyser.implPtr, gAnalyser.implPtr, marshalArray, behaviorExpression.Length);
         Marshal.FreeHGlobal(marshalArray);
         listener.Take(NativeGrammarBlockUtils.GBlockPtrToGBlock(gBlockPtr));
         listener.OnFinish();
     } catch (Exception e) {
         Debug.Log(e);
         listener.OnFinish();
     }
 }
示例#3
0
 public BehaverFactoryBridge(ImmediateGiver <Behaver, GrammarBlock> _behaverGiver, BridgeHelperFactoryBridge _helperFactory)
 {
     behaverGiver = _behaverGiver;
     behaverFrontFactoryCallback = (factoryAgent, baseAttributeGBlock) => {
         try {
             var picked = behaverGiver.PickBestElement(NativeGrammarBlockUtils.GBlockPtrToGBlock(baseAttributeGBlock));
             if (picked != null)
             {
                 behavers.Add(new BehaverBridge(picked, _helperFactory));
                 ReadyBehaver(factoryAgent, behavers.Last().matchAttributeCallback, behavers.Last().setBehaviorCallback, behavers.Last().checkBehaviorCallback);
             }
         } catch (System.Exception e) {
             Debug.LogError(e);
         }
     };
     nativeFactoryPtr = _helperFactory.NewBehaverFactory(behaverFrontFactoryCallback);
 }