//private Buffer _parameterBuffer = null; private void Update(EvaluationContext context) { var id = Id.GetValue(context); var previousMap = context.PrbPrefilteredSpecular; var tex = PrefilteredSpecularMap.GetValue(context) ?? PbrContextSettings.WhitePixelTexture; var hadPreviousTexture = context.ContextTextures.TryGetValue(id, out var previousTexture); context.ContextTextures[id] = tex; // { // // } // // if (tex != null) // { // context.PrbPrefilteredSpecular = tex; // } SubTree.GetValue(context); if (hadPreviousTexture) { context.ContextTextures[id] = previousMap; } else { context.ContextTextures.Remove(id); } }
public static void Main() { TrippleSum.Do(); ConnectNodesAtTheSameLevel.Do(); JumpingNumbers.Do(); LongestValidSubstring.Do(); SizeOfSubarrayWithMaximumSum.Do(); SubarrayWithSumNonNegative.Do(); SubArrayWithNegativeSum.Do(); SmallestPositiveInteger.Do(); CommonAncestor.Do(); BinaryTreeIsBST.Do(); BalancedBinaryTree.Do(); ReverseList.Do(); SumToGivenValue.Do(); Rectangle.Do(); Parentheses.Do(); FindTripplets.Do(); SubTree.Do(); NumberOfIntInArray.Do(); MinimumArrayOfSumGreater.Do(); ReplaceNumbers.Do(); SubArrayWithSum.Do(); SmallestPositiveInteger.Do(); }
/// <summary> /// Choose player to respond on current rod and action to perform /// </summary> /// <param name="rod">Current rod</param> /// <param name="bfc">Ball Future Coordinates</param> /// <param name="respondingPlayer">Responding Player index (1 based) on current rod [out]</param> /// <returns>Rod Action to be performed</returns> protected RodAction DefineActionAndRespondingPlayer(IRod rod, BallCoordinates bfc, out int respondingPlayer) { if (rod == null) { throw new ArgumentException(String.Format( "[{0}] Unable to define action and responding player while rod argument is NULL!", MethodBase.GetCurrentMethod().Name)); } if (bfc == null || !bfc.IsDefined) { throw new ArgumentException(String.Format( "[{0}] Unable to define action and responding player while ball coordinates are NULL or UNDEFINED!", MethodBase.GetCurrentMethod().Name)); } RodAction action = null; respondingPlayer = -1; switch (_helper.IsBallInSector(bfc.X, rod.RodXCoordinate, rod.DynamicSector)) { //Ball is in Current Rod Sector case eXPositionSectorRelative.IN_SECTOR: action = SubTree.Decide(rod, bfc); respondingPlayer = SubTree.RespondingPlayer; break; /* OLD : * //The Big Sub Tree * action = EnterDecisionTreeBallInSector(rod, bfc, out respondingPlayer); */ //Ball is ahead of Current Rod Sector case eXPositionSectorRelative.AHEAD_SECTOR: //Ball Vector Direction is TO Current Rod and we have intersection point if (_helper.IsBallVectorToRod(bfc.Vector) && rod.Intersection.IsDefined) { action = new RodAction(rod.RodType, eRotationalMove.DEFENCE, eLinearMove.VECTOR_BASED); //Define responding player index BallYPositionToPlayerYCoordinate(bfc.Y, rod); respondingPlayer = this.RespondingPlayer; } else { //Ball Vector Direction is FROM Current Rod action = new RodAction(rod.RodType, eRotationalMove.DEFENCE, eLinearMove.BEST_EFFORT); } break; //Ball is behind Current Rod Sector case eXPositionSectorRelative.BEHIND_SECTOR: action = new RodAction(rod.RodType, eRotationalMove.RISE, eLinearMove.BEST_EFFORT); break; } return(action); }
private void Update(EvaluationContext context) { var previousTime = context.TimeInBars; context.TimeInBars = NewTime.GetValue(context); // Execute subtree //SubTree.DirtyFlag.Invalidate(); Result.Value = SubTree.GetValue(context); //Log.Debug($"old:{previousTime} / new:{context.TimeInBars}"); context.TimeInBars = previousTime; //SubTree.DirtyFlag.Clear(); }
private void Update(EvaluationContext context) { if (!_initialized) { if (Parent?.Symbol == null) { Log.Warning("Can't register Preset blending for undefined parent", this.SymbolChildId); return; } BlendSettingForCompositionIds[Parent.Symbol.Id] = _blendSetting; _initialized = true; } // Evaluate subtree SubTree.GetValue(context); var wasUpdated = false; var groupIndex = GroupIndex.GetValue(context); if (groupIndex != _blendSetting.GroupIndex) { wasUpdated = true; _blendSetting.GroupIndex = groupIndex; } var presetA = PresetA.GetValue(context); if (presetA != _blendSetting.PresetAIndex) { wasUpdated = true; _blendSetting.PresetAIndex = presetA; } var presetB = PresetB.GetValue(context); if (presetB != _blendSetting.PresetBIndex) { wasUpdated = true; _blendSetting.PresetBIndex = presetB; } var blendFactor = BlendFactor.GetValue(context); if (Math.Abs(blendFactor - _blendSetting.BlendFactor) > 0.001f) { wasUpdated = true; _blendSetting.BlendFactor = blendFactor; } _blendSetting.WasActivatedLastFrame = wasUpdated; }
private void Update(EvaluationContext context) { // Parameters var parameterBufferContent = new PbrMaterialParams { BaseColor = BaseColor.GetValue(context), EmissiveColor = EmissiveColor.GetValue(context), Roughness = Roughness.GetValue(context), Specular = Specular.GetValue(context), Metal = Metal.GetValue(context) }; ResourceManager.Instance().SetupConstBuffer(parameterBufferContent, ref _parameterBuffer); // Textures var resourceManager = ResourceManager.Instance(); var device = resourceManager.Device; Utilities.Dispose(ref _baseColorMapSrv); var tex = BaseColorMap.GetValue(context) ?? PbrContextSettings.WhitePixelTexture; _baseColorMapSrv = new ShaderResourceView(device, tex); context.PbrMaterialTextures.AlbedoColorMap = _baseColorMapSrv; Utilities.Dispose(ref _normalMapSrv); var tex2 = NormalMap.GetValue(context) ?? PbrContextSettings.NormalFallbackTexture; _normalMapSrv = new ShaderResourceView(device, tex2); context.PbrMaterialTextures.NormalMap = _normalMapSrv; Utilities.Dispose(ref _rsmoMapSrv); var tex3 = RoughnessSpecularMetallicOcclusionMap.GetValue(context) ?? PbrContextSettings.RsmoFallbackTexture; _rsmoMapSrv = new ShaderResourceView(device, tex3); context.PbrMaterialTextures.RoughnessSpecularMetallicOcclusionMap = _rsmoMapSrv; Utilities.Dispose(ref _emissiveColorMapSrv); var tex4 = EmissiveColorMap.GetValue(context) ?? PbrContextSettings.WhitePixelTexture; _emissiveColorMapSrv = new ShaderResourceView(device, tex4); context.PbrMaterialTextures.EmissiveColorMap = _emissiveColorMapSrv; var previousParameters = context.PbrMaterialParams; context.PbrMaterialParams = _parameterBuffer; SubTree.GetValue(context); context.PbrMaterialParams = previousParameters; }
private void Update(EvaluationContext context) { //Log.Debug("Setting Particle system"); var previousSystem = context.ParticleSystem; var particleSystemForContext = ParticleSystem.GetValue(context); if (particleSystemForContext != null) { context.ParticleSystem = particleSystemForContext; } // Execute subtree Result.Value = SubTree.GetValue(context); context.ParticleSystem = previousSystem; }
private void Update(EvaluationContext context) { var previousKeyframeTime = context.LocalTime; var previousEffectTime = context.LocalFxTime; var newTime = NewTime.GetValue(context); context.LocalTime = newTime; context.LocalFxTime = newTime; // Execute subtree Result.Value = SubTree.GetValue(context); context.LocalTime = previousKeyframeTime; context.LocalFxTime = previousEffectTime; }
private void Update(EvaluationContext context) { BeatTapTriggered = false; var triggerTap = TriggerBeatTap.GetValue(context); if (triggerTap != _wasBeatTriggered) { _wasBeatTriggered = triggerTap; BeatTapTriggered = triggerTap; } ResyncTriggered = false; var triggerResync = TriggerResync.GetValue(context); if (triggerResync != _wasResyncTriggered) { _wasResyncTriggered = triggerResync; ResyncTriggered = triggerResync; } // Evaluate subtree SubTree.GetValue(context); }
public void Init() { _subTree = new SubTree<int>(new Node<int>(5, 0), null); }
public void Visit(SubTree <TContext> obj) { PrintNode(obj); VisitChild(obj); }
private void ProcessEvents(Event e) { switch (e.type) { case EventType.MouseDown: if (e.button == 0) { // Reset flag nodeMoved = false; // Frist check if any node handle was clicked NodeHandle handle = FindHandle(e.mousePosition); if (handle != null) { currentHandle = handle; e.Use(); break; } Node node = FindNode(e.mousePosition); // Select node if contains point if (node != null) { DeselectNode(); SelectNode(node); if (e.clickCount == 2 && node is SubTree) { SubTree subTree = node as SubTree; if (subTree.tree != null) { Selection.activeGameObject = subTree.tree.gameObject; } } } else { DeselectNode(); } e.Use(); } else if (e.button == 1) { Node node = FindNode(e.mousePosition); // Open proper context menu if (node != null) { OpenNodeMenu(e.mousePosition, node); } else { DeselectNode(); OpenNodeFinder(new Rect(e.mousePosition.x, e.mousePosition.y, 1, 1)); } e.Use(); } break; case EventType.MouseDrag: // Drag node, workspace or connection if (e.button == 0) { if (currentHandle != null) { // Let PaintConnections draw lines } else if (selectedNode != null) { Undo.RecordObject(selectedNode, "Move Node"); selectedNode.rect.position += Event.current.delta; // Move whole branch when Ctrl is pressed if (e.control) { List <Node> movedNodes = selectedNode.GetAllSuccessors(); for (int i = 0; i < movedNodes.Count; i++) { Undo.RecordObject(movedNodes[i], "Move Node"); movedNodes[i].rect.position += Event.current.delta; } } nodeMoved = true; } else { workspaceOffset += Event.current.delta; } GUI.changed = true; e.Use(); } break; case EventType.MouseUp: if (currentHandle != null) { TryConnectNodes(currentHandle, e.mousePosition); } // Reorder or snap nodes in case any of them was moved if (nodeMoved && selectedNode != null) { // Snap nodes if option is enabled if (snapNodesToGrid) { Undo.RecordObject(selectedNode, "Move Node"); selectedNode.rect.position = SnapPositionToGrid(selectedNode.rect.position); // When control is pressed snap successors too if (e.control) { List <Node> movedNodes = selectedNode.GetAllSuccessors(); for (int i = 0; i < movedNodes.Count; i++) { Undo.RecordObject(movedNodes[i], "Move Node"); movedNodes[i].rect.position = SnapPositionToGrid(movedNodes[i].rect.position); } } } // Reorder siblings if selected node has parent if (selectedNode.parent != null) { Undo.RecordObject(selectedNode.parent, "Move Node"); selectedNode.parent.SortChildren(); } } nodeMoved = false; currentHandle = null; GUI.changed = true; break; } }
protected bool NodeToXml(Node node, XmlElement xmlParentElement) { bool bSuccess = true; var enumConnection = node.outConnections.GetEnumerator(); XmlElement xmlNode = null; if (typeof(Sequencer).IsInstanceOfType(node)) { xmlNode = xmlParentElement.OwnerDocument.CreateElement("sequencer"); xmlNode.SetAttribute("name", "sequencer" + node.ID); } else if (typeof(Selector).IsInstanceOfType(node)) { xmlNode = xmlParentElement.OwnerDocument.CreateElement("selector"); xmlNode.SetAttribute("name", "selector" + node.ID); } else if (typeof(Inverter).IsInstanceOfType(node)) { xmlNode = xmlParentElement.OwnerDocument.CreateElement("inverter"); xmlNode.SetAttribute("name", "inverter" + node.ID); } else if (typeof(ITaskAssignable).IsInstanceOfType(node)) { xmlNode = xmlParentElement.OwnerDocument.CreateElement("action"); Task task = (node as ITaskAssignable).task; if (task != null) { string typeName = task.GetType().FriendlyName(); xmlNode.SetAttribute("classname", typeName); xmlNode.SetAttribute("name", typeName); FieldInfo[] fields = task.GetType().GetFields(); foreach (FieldInfo field in fields) { object fieldVar = field.GetValue(task); if (fieldVar.GetType().IsSubclassOf(typeof(BBParameter))) { BBParameter param = fieldVar as BBParameter; string varName = field.Name; if (field.IsDefined(typeof(ExportNameAttribute), false)) { object[] attrs = field.GetCustomAttributes(typeof(ExportNameAttribute), false); if (attrs != null) { ExportNameAttribute attr = attrs.FirstOrDefault() as ExportNameAttribute; if (attr != null) { varName = attr.exportName; } } } XmlElement xmlParam = xmlParentElement.OwnerDocument.CreateElement("param"); xmlParam.SetAttribute("name", varName); xmlParam.SetAttribute("type", Variable.GetTypeName(param.varType)); if (param.useBlackboard) { xmlParam.SetAttribute("ref", param.name); } else { string valueStr = null; if (param.varType.IsEnum) { valueStr = System.Convert.ToString((int)param.value); } else { valueStr = System.Convert.ToString(param.value).ToLower(); } xmlParam.SetAttribute("value", valueStr); } xmlNode.AppendChild(xmlParam); } } } else { bSuccess = false; Debug.LogError("ActionNode without Action, Condition node without Condition! " + node.name); } } else if (typeof(SubTree).IsInstanceOfType(node)) { //todo 递归插入subtree node SubTree st = node as SubTree; st.Init(); if (st.subTree) { NodeToXml(st.subTree.primeNode, xmlParentElement); } else { Debug.LogError("can not find the subtree : id = " + node.ID); } } else if (typeof(ConditionNode).IsInstanceOfType(node)) { //xmlNode = xmlParentElement.OwnerDocument.CreateElement("condition"); bSuccess = false; Debug.LogError("Unsupported type used: " + node.name); } else { bSuccess = false; Debug.LogError("Unsupported type used: " + node.name); } if (xmlNode != null) { xmlNode.SetAttribute("id", System.Convert.ToString(node.ID)); while (enumConnection.MoveNext() && bSuccess) { bSuccess = NodeToXml(enumConnection.Current.targetNode, xmlNode); } if (bSuccess) { xmlParentElement.AppendChild(xmlNode); } } return(bSuccess); }