// go through all polygon nodes and cure small local self-intersections private static Node CureLocalIntersections(Node start, LightList <int> triangles) { var p = start; do { var a = p.prev; var b = p.next.next; if (!Equals(a, b) && Intersects(a, p, p.next, b) && LocallyInside(a, b) && LocallyInside(b, a)) { triangles.Add(a.i / 2); triangles.Add(p.i / 2); triangles.Add(b.i / 2); // remove two nodes involved RemoveNode(p); RemoveNode(p.next); p = start = b; } p = p.next; } while (p != start); return(p); }
public void PushScope() { currentDepth++; if (currentDepth > maxDepth) { maxDepth = currentDepth; ParameterExpression variable = Expression.Parameter(typeof(UIElement), "targetElement_" + currentDepth); variables.Add(variable); hierarchyStack.Push(variable); } else { string targetName = "targetElement_" + currentDepth; for (int i = 0; i < variables.size; i++) { if (variables[i].Type == typeof(UIElement) && variables[i].Name == targetName) { hierarchyStack.Push(variables[i]); return; } } throw new ArgumentOutOfRangeException(); } }
public void HandleDragMoveChild(DragEvent evt, int index) { if (evt is TestDragEvent textEvt) { dragList.Add($"move:child{index}:{textEvt.sourceName}"); } }
private static Expression[] MakeArray(params object[] expressions) { LightList <Expression> seq = new LightList <Expression>(); for (int i = 0; i < expressions.Length; i++) { object expression = expressions[i]; if (expression == null) { continue; } if (expression is Expression expr) { seq.Add(expr); } else if (expression is IEnumerable <Expression> exprs) { foreach (Expression ex in exprs) { seq.Add(ex); } } else { throw new ArgumentException(); } } return(seq.ToArray()); }
public void CreateContextWithReferences() { LightList <StyleASTNode> nodes = new LightList <StyleASTNode>(); nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("x", StyleASTNodeFactory.ConstReferenceNode("y")))); nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("y", StyleASTNodeFactory.ConstReferenceNode("z")))); var stringValue = StyleASTNodeFactory.StringLiteralNode("you win!"); nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("z", stringValue))); var context = new StyleSheetConstantImporter(new StyleSheetImporter(null, null)).CreateContext(nodes, default); Assert.AreEqual(3, context.constants.Count); Assert.AreEqual("x", context.constants[2].name); Assert.AreEqual(stringValue, context.constants[2].value); Assert.True(context.constants[2].exported); Assert.AreEqual("y", context.constants[1].name); Assert.AreEqual(stringValue, context.constants[1].value); Assert.True(context.constants[1].exported); Assert.AreEqual("z", context.constants[0].name); Assert.AreEqual(stringValue, context.constants[0].value); Assert.True(context.constants[0].exported); Assert.AreEqual(0, context.constantsWithReferences.Count, "There should be no unresolved const left."); }
public void HandleDragEnterChild(UIElement el, int index) { if (ignoreEnter) { return; } dragList.Add("enter:child" + index); }
public LightList <string> Init() { LightList <string> list = new LightList <string>(); list.Add("Pasha"); list.Add("Valera"); list.Add("Tolik"); return(list); }
public void Insert() { LightList <int> ints = new LightList <int>(); ints.Add(0); ints.Add(1); ints.Add(3); ints.Add(4); ints.Insert(2, 2); Assert.AreEqual(5, ints.Count); for (int i = 0; i < ints.Count; i++) { Assert.AreEqual(i, ints[i]); } }
private bool ParseListExpressionStep(ref LightList <ASTNode> retn) { while (true) { int commaIndex = tokenStream.FindNextIndexAtSameLevel(ExpressionTokenType.Comma); if (commaIndex != -1) { ExpressionParser parser = CreateUndelimitedSubParser(commaIndex); tokenStream.Advance(); bool valid = parser.ParseListExpressionStep(ref retn); parser.Release(); if (!valid) { ReleaseList(retn); return(false); } } else { ASTNode node = ParseLoop(); if (node == null) { return(false); } retn.Add(node); return(true); } } }
// link every hole into the outer loop, producing a single-ring polygon without holes private static Node EliminateHoles(LightList <float> data, LightList <int> holeIndices, Node outerNode) { var len = holeIndices.Count; for (var i = 0; i < len; i++) { var start = holeIndices[i] * 2; var end = i < len - 1 ? holeIndices[i + 1] * 2 : data.Count; var list = LinkedList(data.Array, start, end, false); if (list == list.next) { list.steiner = true; } holeQueue.Add(GetLeftmost(list)); } holeQueue.Sort(nodeComparer); // process holes from left to right for (var i = 0; i < holeQueue.Count; i++) { EliminateHole(holeQueue[i], outerNode); outerNode = FilterPoints(outerNode, outerNode.next); } holeQueue.QuickClear(); return(outerNode); }
private static Node Get(int i, float x, float y) { Node retn = null; if (inactive.Count > 0) { retn = inactive.RemoveLast(); } else { retn = new Node(i, x, y); } retn.steiner = false; retn.next = default; retn.prev = default; retn.prevZ = default; retn.nextZ = default; retn.z = default; retn.i = i; retn.x = x; retn.y = y; active.Add(retn); return(retn); }
public void OnElementCreated(UIElement element) { m_ScratchAttrList.Clear(); element.GetAttributes(m_ScratchAttrList); if (m_ScratchAttrList.Count == 0) { return; } if (TryGetAttribute("router", m_ScratchAttrList, out ElementAttribute routerAttr)) { TryGetAttribute("defaultRoute", m_ScratchAttrList, out ElementAttribute defaultRouteAttr); Router router = new Router(element.id, routerAttr.value, defaultRouteAttr.value); for (int i = 0; i < m_Routers.Count; i++) { if (m_Routers[i].name == router.name) { throw new Exception("Duplicate router defined with the name: " + router.name); } } m_Routers.Add(router); } else if (TryGetAttribute("route", m_ScratchAttrList, out ElementAttribute routeAttr)) { string path = routeAttr.value; TryGetAttribute("defaultRoute", m_ScratchAttrList, out ElementAttribute defaultRouteAttr); Route route = new Route(path, element, defaultRouteAttr.value); // if (TryGetAttribute("onRouteEnter", m_ScratchAttrList, out ElementAttribute onRouteEnterAttr)) { } // // if (TryGetAttribute("onRouteEnter", m_ScratchAttrList, out ElementAttribute onRouteChangedAttr)) { } // // if (TryGetAttribute("onRouteEnter", m_ScratchAttrList, out ElementAttribute onRouteExitAttr)) { } Router router = FindRouterInHierarchy(element); if (router == null) { throw new Exception("Cannot resolve router in hierarchy"); } if (router.TryGetParentRouteFor(element, out Route parent)) { route.path = parent.path + route.path; parent.subRoutes.Add(route); } router.AddRoute(route); if (router.defaultRoute != path) { element.SetEnabled(false); } } }
public void PushAlias(string alias) { if (nameList == null) { nameList = new LightList <string>(4); } nameList.Add(alias); }
public Expression AddStatement(Expression statement) { if (compiler.addingStatements) { statements.Add(statement); } return(statement); }
public void LightListAddCapacity() { var list = new LightList <int>(src_.Length); for (int i = 0; i < src_.Length; i++) { list.Add(src_[i]); } }
public void Release(PooledMesh mesh) { if (mesh.isActive) { mesh.mesh.Clear(true); dynamicPool.Add(mesh); mesh.isActive = false; } }
public void AddChildRoute(RouteElement routeElement) { if (m_ChildRoutes.Contains(routeElement)) { return; } m_ChildRoutes.Add(routeElement); routeElement.SetEnabled(false); }
// todo -- support multiple indexer arguments public static IndexNode IndexExpressionNode(ASTNode expression, bool isElvisAccess) { IndexNode indexNode = s_IndexExpressionPool.Get(); LightList <ASTNode> list = LightList <ASTNode> .GetMinSize(4); list.Add(expression); indexNode.arguments = list; indexNode.isNullableAccess = isElvisAccess; return(indexNode); }
public MeasureLightListFor() { array_ = Enumerable.Range(0, 500000000).ToArray(); list_ = array_.ToList(); lightlist_ = new LightList <int>(array_.Length); for (int i = 0; i < array_.Length; i++) { lightlist_.Add(array_[i]); } }
public void InsertRange() { LightList <int> ints = new LightList <int>(); ints.Add(0); ints.Add(1); ints.Add(4); ints.Add(5); LightList <int> other = new LightList <int>(); other.Add(2); other.Add(3); ints.InsertRange(2, other); Assert.AreEqual(6, ints.Count); for (int i = 0; i < ints.Count; i++) { Assert.AreEqual(i, ints[i]); } }
public static void Release(ref UIForiaData data) { if (data == null || !data.isActive) { return; } data.isActive = false; data.Clear(); s_Pool.Add(data); data = null; }
public AnimationTask Animate(UIElement element, AnimationData styleAnimation) { switch (styleAnimation.animationType) { case AnimationType.KeyFrame: styleAnimation.options = EnsureDefaultAnimationOptionValues(styleAnimation); StyleKeyFrameAnimation animationTask = new StyleKeyFrameAnimation(element, styleAnimation); thisFrame.Add(animationTask); return(animationTask); case AnimationType.SpriteSheet: styleAnimation.options = EnsureDefaultSpriteAnimationOptionValues(styleAnimation); SpriteSheetAnimation spriteSheetTask = new SpriteSheetAnimation(element, styleAnimation); thisFrame.Add(spriteSheetTask); return(spriteSheetTask); default: throw new ArgumentOutOfRangeException(); } }
public void CreateContextWithMultipleConstants() { LightList <StyleASTNode> nodes = new LightList <StyleASTNode>(); nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("col0", StyleASTNodeFactory.ColorNode("red")))); nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("thing0", StyleASTNodeFactory.StringLiteralNode("someVal")))); nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("number", StyleASTNodeFactory.NumericLiteralNode("1")))); var context = new StyleSheetConstantImporter(new StyleSheetImporter(null, null)).CreateContext(nodes, default); Assert.AreEqual(3, context.constants.Count); Assert.AreEqual("col0", context.constants[0].name); Assert.True(context.constants[0].exported); Assert.AreEqual("thing0", context.constants[1].name); Assert.True(context.constants[1].exported); Assert.AreEqual("number", context.constants[2].name); Assert.True(context.constants[2].exported); }
public UITask AddTask(UITask task) { if (task.owner != null) { throw new Exception("Tasks can only be added to a task runner once."); } task.owner = this; task.state = UITaskState.Pending; thisFrame.Add(task); return(task); }
public void ImportAndUseConsts() { LightList <StyleASTNode> nodes = new LightList <StyleASTNode>(); nodes.Add(StyleASTNodeFactory.ImportNode("importedThing", "Data/Styles/ImportFromMe.style")); string basepath = Path.Combine(Application.dataPath, "..", "Packages", "UIForia", "Tests"); StyleCompileContext context = new StyleSheetConstantImporter(new StyleSheetImporter(basepath, null)).CreateContext(nodes, default); Assert.AreEqual(1, context.importedStyleConstants.Count); Assert.AreEqual(1, context.importedStyleConstants["importedThing"].Count); Assert.AreEqual("colorRed", context.importedStyleConstants["importedThing"][0].name); }
public void InsertRangeFromEndMinus1() { LightList <int> ints = new LightList <int>(); ints.Add(0); ints.Add(1); ints.Add(4); ints.Add(5); LightList <int> other = new LightList <int>(); other.Add(2); other.Add(3); ints.InsertRange(ints.Count - 1, other); Assert.AreEqual(6, ints.Count); Assert.AreEqual(0, ints[0]); Assert.AreEqual(1, ints[1]); Assert.AreEqual(4, ints[2]); Assert.AreEqual(2, ints[3]); Assert.AreEqual(3, ints[4]); Assert.AreEqual(5, ints[5]); }
public CompiledTemplate CreateTemplate(string filePath, string templateName) { CompiledTemplate compiledTemplate = new CompiledTemplate(); compiledTemplate.filePath = filePath; compiledTemplate.guid = Guid.NewGuid().ToString().Replace('-', '_'); compiledTemplate.templateId = compiledTemplates.size; compiledTemplates.Add(compiledTemplate); compiledTemplate.templateMetaData = new TemplateMetaData(compiledTemplate.templateId, filePath, null, null); compiledTemplate.templateName = templateName; return(compiledTemplate); }
public CompiledSlot CreateSlot(string filePath, string templateName, string slotName, SlotType slotType) { CompiledSlot compiledSlot = new CompiledSlot(); compiledSlot.filePath = filePath; compiledSlot.templateName = templateName; compiledSlot.slotName = slotName; compiledSlot.slotType = slotType; compiledSlot.guid = Guid.NewGuid().ToString().Replace('-', '_'); compiledSlot.slotId = compiledSlots.size; compiledSlots.Add(compiledSlot); return(compiledSlot); }
public override void Gather(UIElement origin, int templateId, LightList <UIElement> resultSet) { int depth = origin.hierarchyDepth; for (int i = 0; i < elements.size; i++) { UIElement element = elements.array[i]; if (element.hierarchyDepth < depth && element.templateMetaData.id == templateId) { resultSet.Add(element); } } }
public TemplateRootNode GetParsedTemplate(ProcessedType processedType) { TemplateAttribute templateAttr = processedType.templateAttr; templateAttr.filePath = ResolveTemplateFilePath(processedType); if (templateAttr.fullPathId == null) { templateAttr.fullPathId = templateAttr.templateId == null ? templateAttr.filePath : templateAttr.filePath + "#" + templateAttr.templateId; } Debug.Assert(templateAttr.fullPathId != null, "templateAttr.fullPathId != null"); if (templateMap.TryGetValue(templateAttr.fullPathId, out LightList <TemplateRootNode> list)) { for (int i = 0; i < list.size; i++) { if (list.array[i].processedType.rawType == processedType.rawType) { return(list.array[i]); } } TemplateRootNode retn = list[0].Clone(processedType); list.Add(retn); return(retn); } list = new LightList <TemplateRootNode>(2); templateMap[templateAttr.fullPathId] = list; TemplateDefinition templateDefinition = GetTemplateDefinition(processedType); templateAttr.source = templateDefinition.contents; TemplateShell shell = xmlTemplateParser.GetOuterTemplateShell(templateAttr); TemplateRootNode templateRootNode = new TemplateRootNode(templateAttr.templateId, shell, processedType, null, default) { tagName = processedType.tagName }; list.Add(templateRootNode); xmlTemplateParser.Parse(templateRootNode, processedType); return(templateRootNode); }
/// <summary> /// Populate a light list with an ordered set of the lights which are closest /// </summary> /// <remarks> /// <p> /// Note that since directional lights have no position, they are always considered /// closer than any point lights and as such will always take precedence. /// </p> /// <p> /// Subclasses of the default SceneManager may wish to take into account other issues /// such as possible visibility of the light if that information is included in their /// data structures. This basic scenemanager simply orders by distance, eliminating /// those lights which are out of range. /// </p> /// <p> /// The number of items in the list max exceed the maximum number of lights supported /// by the renderer, but the extraneous ones will never be used. In fact the limit will /// be imposed by Pass::getMaxSimultaneousLights. /// </p> /// </remarks> /// <param name="position">The position at which to evaluate the list of lights</param> /// <param name="radius">The bounding radius to test</param> /// <param name="destList">List to be populated with ordered set of lights; will be cleared by this method before population.</param> public virtual void PopulateLightList( Vector3 position, float radius, LightList destList ) { // Really basic trawl of the lights, then sort // Subclasses could do something smarter destList.Clear(); float squaredRadius = radius * radius; MovableObjectCollection lightList = this.GetMovableObjectCollection( LightFactory.TypeName ); // loop through the scene lights an add ones in range foreach ( Light light in lightList.Values ) { if ( light.IsVisible ) { if ( light.Type == LightType.Directional ) { // no distance light.tempSquaredDist = 0.0f; destList.Add( light ); } else { light.tempSquaredDist = ( light.DerivedPosition - position ).LengthSquared; light.tempSquaredDist -= squaredRadius; // only add in-range lights float range = light.AttenuationRange; if ( light.tempSquaredDist <= ( range * range ) ) { destList.Add( light ); } } } // if } // for // Sort Destination light list. // TODO: Not needed yet since the current LightList is a sorted list under the hood already //destList.Sort(); }
/// <summary> /// Render a group with the added complexity of additive texture shadows. /// </summary> /// <param name="group">Render queue group.</param> private void RenderAdditiveTextureShadowedQueueGroupObjects( RenderQueueGroup group ) { LightList tempLightList = new LightList(); foreach ( RenderPriorityGroup priorityGroup in group.PriorityGroups.Values ) { // Sort the queue first priorityGroup.Sort( this.cameraInProgress ); // Clear light list tempLightList.Clear(); // Render all the ambient passes first, no light iteration, no lights this.RenderSolidObjects( priorityGroup.solidPasses, false, tempLightList ); // Also render any objects which have receive shadows disabled this.renderingNoShadowQueue = true; this.RenderSolidObjects( priorityGroup.solidPassesNoShadow, true ); this.renderingNoShadowQueue = false; // only perform this next part if we're in the 'normal' render stage, to avoid // doing it during the render to texture if ( this.illuminationStage == IlluminationRenderStage.None ) { // Iterate over lights, render masked int sti = 0; foreach ( Light light in this.lightsAffectingFrustum ) { // Set light state if ( light.CastShadows && sti < this.shadowTextures.Count ) { Texture shadowTex = this.shadowTextures[ sti ]; // Get camera for current shadow texture Camera camera = shadowTex.GetBuffer().GetRenderTarget().GetViewport( 0 ).Camera; // Hook up receiver texture Pass targetPass = this.shadowTextureCustomReceiverPass != null ? this.shadowTextureCustomReceiverPass : this.shadowReceiverPass; targetPass.GetTextureUnitState( 0 ).SetTextureName( shadowTex.Name ); // Hook up projection frustum targetPass.GetTextureUnitState( 0 ).SetProjectiveTexturing( true, camera ); this.autoParamDataSource.TextureProjector = camera; // Remove any spot fader layer if ( targetPass.TextureUnitStageCount > 1 && targetPass.GetTextureUnitState( 1 ).TextureName == "spot_shadow_fade.png" ) { // remove spot fader layer (should only be there if // we previously used modulative shadows) targetPass.RemoveTextureUnitState( 1 ); } // Set lighting / blending modes targetPass.SetSceneBlending( SceneBlendFactor.One, SceneBlendFactor.One ); targetPass.LightingEnabled = true; targetPass.Load(); // increment shadow texture since used ++sti; this.illuminationStage = IlluminationRenderStage.RenderReceiverPass; } else { this.illuminationStage = IlluminationRenderStage.None; } // render lighting passes for this light tempLightList.Clear(); tempLightList.Add( light ); this.RenderSolidObjects( priorityGroup.solidPassesDiffuseSpecular, false, tempLightList ); } // for each light this.illuminationStage = IlluminationRenderStage.None; // Now render decal passes, no need to set lights as lighting will be disabled this.RenderSolidObjects( priorityGroup.solidPassesDecal, false ); } } // for each priority foreach ( RenderPriorityGroup priorityGroup in group.PriorityGroups.Values ) { // Do transparents this.RenderTransparentObjects( priorityGroup.transparentPasses, true ); } // for each priority }
/// <summary> /// Render a group with the added complexity of additive stencil shadows. /// </summary> /// <param name="group">Render queue group.</param> protected virtual void RenderAdditiveStencilShadowedQueueGroupObjects( RenderQueueGroup group ) { LightList tempLightList = new LightList(); foreach ( RenderPriorityGroup priorityGroup in group.PriorityGroups.Values ) { // sort the group first priorityGroup.Sort( this.cameraInProgress ); // Clear light list tempLightList.Clear(); // Render all the ambient passes first, no light iteration, no lights this.illuminationStage = IlluminationRenderStage.Ambient; this.RenderSolidObjects( priorityGroup.solidPasses, false, tempLightList ); // Also render any objects which have receive shadows disabled this.renderingNoShadowQueue = true; this.RenderSolidObjects( priorityGroup.solidPassesNoShadow, true ); this.renderingNoShadowQueue = false; // Now iterate per light this.illuminationStage = IlluminationRenderStage.PerLight; foreach ( Light light in lightsAffectingFrustum ) { // Set light state if ( light.CastShadows ) { // Clear stencil this.targetRenderSystem.ClearFrameBuffer( FrameBufferType.Stencil ); this.RenderShadowVolumesToStencil( light, this.cameraInProgress ); // turn stencil check on this.targetRenderSystem.StencilCheckEnabled = true; // NB we render where the stencil is equal to zero to render lit areas this.targetRenderSystem.SetStencilBufferParams( CompareFunction.Equal, 0 ); } // render lighting passes for this light tempLightList.Clear(); tempLightList.Add( light ); this.RenderSolidObjects( priorityGroup.solidPassesDiffuseSpecular, false, tempLightList ); // Reset stencil params this.targetRenderSystem.SetStencilBufferParams(); this.targetRenderSystem.StencilCheckEnabled = false; this.targetRenderSystem.SetDepthBufferParams(); } // for each light // Now render decal passes, no need to set lights as lighting will be disabled this.illuminationStage = IlluminationRenderStage.Decal; this.RenderSolidObjects( priorityGroup.solidPassesDecal, false ); } // for each priority // reset lighting stage this.illuminationStage = IlluminationRenderStage.None; // Iterate again foreach ( RenderPriorityGroup priorityGroup in group.PriorityGroups.Values ) { // Do transparents this.RenderTransparentObjects( priorityGroup.transparentPasses, true ); } // for each priority }
/// <summary> /// Overriden from SceneManager. /// </summary> /// <param name="position">The position at which to evaluate the list of lights</param> /// <param name="radius">The bounding radius to test</param> /// <param name="destList">List to be populated with ordered set of lights; will be cleared by this method before population.</param> protected override void PopulateLightList(Vector3 position, float radius, LightList destList) { BspNode positionNode = level.FindLeaf(position); BspNode[] lightNodes = new BspNode[lightList.Count]; for (int i = 0; i < lightList.Count; i++) { Light light = lightList[i]; lightNodes[i] = (BspNode) level.objectToNodeMap.FindFirst(light); } // Trawl of the lights that are visible from position, then sort destList.Clear(); float squaredRadius = radius * radius; // loop through the scene lights an add ones in range and visible from positionNode for(int i = 0; i < lightList.Count; i++) { TextureLight light = (TextureLight) lightList[i]; if(light.IsVisible && level.IsLeafVisible(positionNode, lightNodes[i])) { if(light.Type == LightType.Directional) { // no distance light.TempSquaredDist = 0.0f; destList.Add(light); } else { light.TempSquaredDist = (light.DerivedPosition - position).LengthSquared; light.TempSquaredDist -= squaredRadius; // only add in-range lights float range = light.AttenuationRange; if(light.TempSquaredDist <= (range * range)) { destList.Add(light); } } } // if } // for // Sort Destination light list. // TODO: Not needed yet since the current LightList is a sorted list under the hood already //destList.Sort(); }