/// <summary> /// Set throw branches from current point into specified program points. These branches contain /// catch point and handles given ThrowInfo values. /// </summary> /// <param name="branches">ThrowInfo values specifiing udpates/creations/deletions of throw branches</param> /// <param name="removeFlowChildren">If true flow children will be removed, otherwise no other than catch point children are affected</param> public void SetThrowBranching(IEnumerable <ThrowInfo> branches, bool removeFlowChildren = false) { //create indexed structure for branches var indexed = new Dictionary <CatchBlockDescription, ThrowInfo>(); foreach (var branch in branches) { indexed.Add(branch.Catch, branch); } //update already existing branches var childrenCopy = CurrentProgramPoint.FlowChildren.ToArray(); foreach (var child in childrenCopy) { var catchChild = child as CatchPoint; if (catchChild == null) { if (removeFlowChildren) { CurrentProgramPoint.RemoveFlowChild(child); } continue; } ThrowInfo info; if (indexed.TryGetValue(catchChild.CatchDescription, out info)) { catchChild.ReThrow(info); //remove branch from index because it is already complete indexed.Remove(catchChild.CatchDescription); } else { //no more it contains branch for this catch child //disconnect it from graph CurrentProgramPoint.RemoveFlowChild(catchChild); catchChild.RemoveFlowChild(catchChild.TargetPoint); } } //add new branches foreach (var throwInfo in indexed.Values) { //create catch point according to specified throw info var catchPoint = new CatchPoint(CurrentProgramPoint, throwInfo.Catch); InitializeNewPoint(catchPoint, catchPoint.TargetPoint.OwningPPGraph); catchPoint.ReThrow(throwInfo); //connect branch into graph CurrentProgramPoint.AddFlowChild(catchPoint); catchPoint.AddFlowChild(catchPoint.TargetPoint); } }
public override void Catch(CatchPoint catchPoint, FlowOutputSet outSet) { //TODO this is simple catch demonstration - there should be catch stack unrolling var catchVariable = catchPoint.CatchDescription.CatchVariable; var hasCatchVariable = catchVariable != null; if (hasCatchVariable) { var catchVar = outSet.GetVariable(catchPoint.CatchDescription.CatchVariable); catchVar.WriteMemory(outSet.Snapshot, catchPoint.ThrowedValue); } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player") { if (lastActivated == this) { return; } lastActivated = this; GameObject.FindGameObjectWithTag("Flag").GetComponent <CatchMasterFlag>().moveToNext(); } }
private void ShootCatchPoint() { CatchPoint catchPoint = PrepareCatchPoint(); if (catchPoint == null) { Debug.LogWarning("prepared rune is null"); return; } catchPoint.transform.parent = transform.root; var currentSkill = GameMaster.Hero.CurrentHeroSkill; var targets = GetPossibleTargets(currentSkill); catchPoint.Shoot(targets.Count > 0 ? targets[0].Position : GetMissShoot(GameMaster.Hero.CurrentHeroSkill)); GameMaster.Hero.Stats.Power -= currentSkill.PowerCost; }
/// <inheritdoc /> public override void Catch(CatchPoint catchPoint, FlowOutputSet outSet) { if (catchPoint.CatchDescription.CatchedType.QualifiedName.Equals(new QualifiedName(new Name("")))) { return; } var catchBlocks = outSet.GetControlVariable(new VariableName(".catchBlocks")); var stack = new List <HashSet <CatchBlockDescription> >(); foreach (var value in catchBlocks.ReadMemory(outSet.Snapshot).PossibleValues) { if (stack.Count == 0) { for (int i = 0; i < (value as InfoValue <TryBlockStack>).Data.blocks.Count; i++) { stack.Add(new HashSet <CatchBlockDescription>()); } } for (int i = 0; i < (value as InfoValue <TryBlockStack>).Data.blocks.Count; i++) { foreach (var block in (value as InfoValue <TryBlockStack>).Data.blocks[i]) { stack[i].Add(block); } } } for (int i = stack.Count - 1; i >= 0; i--) { if (stack[i].Where(a => a.CatchedType.QualifiedName.Equals(catchPoint.CatchDescription.CatchedType.QualifiedName)).Count() > 0) { stack.RemoveLast(); break; } stack.RemoveLast(); } outSet.GetControlVariable(new VariableName(".catchBlocks")).WriteMemory(outSet.Snapshot, new MemoryEntry(outSet.CreateInfo(new TryBlockStack(stack)))); outSet.GetVariable(catchPoint.CatchDescription.CatchVariable).WriteMemory(outSet.Snapshot, catchPoint.ThrowedValue); }
/// <summary> /// Process catch statement according to given catch block /// </summary> /// <param name="catchPoint">Point describing state of current catch block</param> /// <param name="outSet">Flow output set</param> public abstract void Catch(CatchPoint catchPoint, FlowOutputSet outSet);