private PointcutSelector CreateAdviceSelector(ReflectionNode node, WeavingContext context) { var adviceSelector = new PointcutSelector(); var excludeAdviceAttributes = node.CustomAttributes.Where(ca => ca.AttributeType.SafeEquivalent(context.ExcludeAdviceAttributeType)); foreach (var excludeAdviceAttribute in excludeAdviceAttributes) { var rule = new PointcutSelectorRule(); // full names wildcards if (excludeAdviceAttribute.ConstructorArguments.Count == 1) { rule.Names.AddRange(GetStrings(excludeAdviceAttribute.ConstructorArguments[0].Value)); } // then named properties foreach (var namedArgument in excludeAdviceAttribute.NamedArguments) { // names (which should usually not happen) if (namedArgument.Name == nameof(ExcludeAdvicesAttribute.AdvicesTypes)) { rule.Names.AddRange(GetStrings(namedArgument.Value)); } } adviceSelector.ExcludeRules.Add(rule); } if (node.Parent != null) { adviceSelector = GetAdviceSelector(node.Parent, context) + adviceSelector; } return(adviceSelector); }
private PointcutSelector GetAdviceSelector(ReflectionNode node, WeavingContext context) { if (node.AdviceSelector != null) { return(node.AdviceSelector); } return(node.AdviceSelector = CreateAdviceSelector(node, context)); }
/// <summary> /// Gets the marked methods. /// </summary> /// <param name="reflectionNode">The reflection node.</param> /// <param name="markerInterface">The marker interface.</param> /// <param name="types">The types.</param> /// <returns></returns> private IEnumerable <MarkedNode> GetMarkedMethods(ReflectionNode reflectionNode, TypeDefinition markerInterface, Types types) { return(reflectionNode.GetAncestorsToChildren().AsParallel() .Where(n => n.Method != null) .Select(n => new MarkedNode { Node = n, Definitions = GetAllMarkers(n, markerInterface, types).ToArray() }) .Where(m => m.Definitions.Length > 0)); }
/// <summary> /// Determines whether the specified <see cref="ReflectionNode"/> allows the given <see cref="MarkerDefinition"/>. /// </summary> /// <param name="markerDefinition">The marker definition.</param> /// <param name="node">The node.</param> /// <param name="context">The context.</param> /// <returns> /// <c>true</c> if [is included by node] [the specified node]; otherwise, <c>false</c>. /// </returns> private bool IsIncludedByNode(MarkerDefinition markerDefinition, ReflectionNode node, WeavingContext context) { var adviceSelector = GetAdviceSelector(node, context); var isIncluded = adviceSelector.Select(markerDefinition.Type); if (!isIncluded) { Logging.WriteDebug("Method '{0}' excluded advice '{1}'", node.Method.FullName, markerDefinition.Type.FullName); } return(isIncluded); }
/// <summary> /// Indicates whether the node belongs to a strut /// </summary> /// <param name="node"></param> /// <returns></returns> private bool IsDeclaredByValue(ReflectionNode node) { var ownerType = node.GetSelfAndAncestors().OfType <TypeReflectionNode>().First(); // this should not happen if (ownerType is null) { return(false); } return(!ownerType.TypeDefinition.IsClass); }
private void GenerateTerrainGeometries() { SettingsContainer Settings = FileManager.MasteryFile.Settings; List <WorldFile> ActiveWorldFiles = FileManager.MasteryFile.ActiveWorldFiles; for (int i = 0; i < ActiveWorldFiles.Count; i++) { bool HasGeometry = false; for (int j = 0; j < TerrainGeometries.Count; j++) { if (ActiveWorldFiles[i] == TerrainGeometries[j].WorldFile) { HasGeometry = true; } } if (!HasGeometry) { Node3D Node = null; for (int j = 0; j < RenderNodeLayers.Count; j++) { if (RenderNodeLayers[j].Name.Replace("Layer:", "") == ActiveWorldFiles[i].LODID + "") { Node = RenderNodeLayers[j]; } } if (Node != null) { TerrainGeometryContainer NewContainer = new TerrainGeometryContainer(Render, Settings, ActiveWorldFiles[i]); //TerrainDeformableCoverContainer NewDeformedCover = new TerrainDeformableCoverContainer(Render,ActiveWorldFiles[i],NewContainer, Settings,FromBelowDepthTarget); TerrainWaterContainer WaterContainer = new TerrainWaterContainer( Render, NewContainer, ReflectionNode, RefractionNode, PropNode, ActiveWorldFiles[i], Settings, ActiveWorldFiles[i].GetPosition(), ReflectionRenderTarget, RefractionRenderTarget, DepthMapRenderTarget, FromBelowDepthTarget); DepthMapRenderTarget.DebugTextureName = "SceneWaterDepthDebug"; TerrainGeometries.Add(NewContainer); //DeformedTerrainGeometries.Add(NewDeformedCover); WaterGeometries.Add(WaterContainer); ReflectionNode.Attach(NewContainer.TerrainGeometry); RefractionNode.Attach(NewContainer.TerrainGeometry); Node.Attach(WaterContainer.Geom); //Node.Attach(NewDeformedCover.Geom); Node.Attach(NewContainer.TerrainGeometry); } } } }
/// <summary> /// Gets the marked methods. /// </summary> /// <param name="reflectionNode">The reflection node.</param> /// <param name="markerInterface">The marker interface.</param> /// <param name="context">The context.</param> /// <returns></returns> private IEnumerable <MarkedNode> GetMarkedMethods(ReflectionNode reflectionNode, ITypeDefOrRef markerInterface, WeavingContext context) { var ancestorsToChildren = reflectionNode.GetAncestorsToDescendants().ToArray(); return(from node in ancestorsToChildren where node.Method is not null let allMakersNode = new MarkedNode(node, GetAllMarkers(node, markerInterface, context).Select(t => t.Item2)) where allMakersNode.Definitions.Any() && IsIncludedByPointcut(allMakersNode, context) //&& !IsDeclaredByValue(node) let includedMarkersNode = new MarkedNode(node, allMakersNode.Definitions.Where(d => IsIncludedByNode(d, node, context))) where includedMarkersNode.Definitions.Any() select includedMarkersNode); }
/// <summary> /// Gets all attributes that implement the given advice interface /// </summary> /// <param name="reflectionNode">The reflection node.</param> /// <param name="markerInterface">The advice interface.</param> /// <param name="context">The context.</param> /// <returns></returns> private IEnumerable <MarkerDefinition> GetAllMarkers(ReflectionNode reflectionNode, ITypeDefOrRef markerInterface, WeavingContext context) { var markers = reflectionNode.GetAncestorsToChildren() .SelectMany(n => n.CustomAttributes .Where(a => !a.AttributeType.DefinitionAssembly.IsSystem()) .SelectMany(a => TypeResolver.Resolve(a.AttributeType).GetSelfAndParents()) .Where(t => IsMarker(t, markerInterface))) .Distinct() .Select(t => GetMarkerDefinition(t, context)); return(markers); }
/// <summary> /// Gets all attributes that implement the given advice interface /// </summary> /// <param name="reflectionNode">The reflection node.</param> /// <param name="markerInterface">The advice interface.</param> /// <param name="types">The types.</param> /// <returns></returns> private IEnumerable <MarkerDefinition> GetAllMarkers(ReflectionNode reflectionNode, TypeDefinition markerInterface, Types types) { var markers = reflectionNode.GetAncestorsToChildren() .SelectMany(n => n.CustomAttributes.SelectMany(a => a.AttributeType.Resolve().GetSelfAndParents()) .Where(t => IsMarker(t, markerInterface))) .Distinct() .Select(t => GetMarkerDefinition(t, types)); #if DEBUG // Logger.WriteDebug(string.Format("{0} --> {1}", reflectionNode.ToString(), markers.Count())); #endif return(markers); }
private PointcutSelector CreateAdviceSelector(ReflectionNode node, WeavingContext context) { var adviceSelector = new PointcutSelector(); // Advices should not advise themselves var typeReflectionNode = node as TypeReflectionNode; if (typeReflectionNode != null && IsMarker(typeReflectionNode.TypeDefinition, context.AdviceInterfaceType)) { Logging.WriteDebug("Excluding {0} from itself", typeReflectionNode.TypeDefinition.FullName); adviceSelector.ExcludeRules.Add(new PointcutSelectorRule(typeReflectionNode.TypeDefinition.FullName)); } if (context.ExcludeAdviceAttributeType != null) { var excludeAdviceAttributes = node.CustomAttributes.Where(ca => ca.AttributeType.SafeEquivalent(context.ExcludeAdviceAttributeType)); foreach (var excludeAdviceAttribute in excludeAdviceAttributes) { var rule = new PointcutSelectorRule(); // full names wildcards if (excludeAdviceAttribute.ConstructorArguments.Count == 1) { rule.Names.AddRange(GetStrings(excludeAdviceAttribute.ConstructorArguments[0].Value)); } // then named properties foreach (var namedArgument in excludeAdviceAttribute.NamedArguments) { // names (which should usually not happen) if (namedArgument.Name == nameof(ExcludeAdvicesAttribute.AdvicesTypes)) { rule.Names.AddRange(GetStrings(namedArgument.Value)); } } adviceSelector.ExcludeRules.Add(rule); } } if (node.Parent != null) { adviceSelector = GetAdviceSelector(node.Parent, context) + adviceSelector; } return(adviceSelector); }
public void UpdateRenderTargets() { List <Geometry3D> ReflectionUpdateList = new List <Geometry3D>(); List <Geometry3D> RefractionUpdateList = new List <Geometry3D>(); List <Geometry3D> DepthUpdateList = new List <Geometry3D>(); if (ReflectionRenderTarget != null) { ReflectionUpdateList.AddRange(ReflectionRenderTarget.GeometryUpdateList); Render.DetachRenderTarget(ReflectionRenderTarget); //ReflectionRenderTarget.Dispose(); } if (RefractionRenderTarget != null) { RefractionUpdateList.AddRange(RefractionRenderTarget.GeometryUpdateList); Render.DetachRenderTarget(RefractionRenderTarget); //RefractionRenderTarget.Dispose(); } if (DepthMapRenderTarget != null) { DepthUpdateList.AddRange(DepthMapRenderTarget.GeometryUpdateList); Render.DetachRenderTarget(DepthMapRenderTarget); //DepthMapRenderTarget.Dispose(); } Settings = FileManager.MasteryFile.Settings; PropStructureContainer = new WorldPropStructureContainer(Render); List <Geometry3D> PropBatches = PropStructureContainer.GetGeometries(-1); RenderNode.AttachRange(PropBatches); ReflectionNode.AttachRange(PropBatches); RefractionNode.AttachRange(PropBatches); PropNode.AttachRange(PropBatches); ReflectionRenderTarget = new SceneRenderTarget("ReflectionMap", ReflectionNode, Render.Graphics, Render.Camera.Position, Settings.CameraClosePlane, Settings.CameraFarPlane, Settings.WaterReflectionPlaneDirection, Settings.WaterReflectionResolutionX, Settings.WaterReflectionResolutionY, SceneRenderTarget.RenderType.SingleColor); RefractionRenderTarget = new SceneRenderTarget("RefractionMap", RefractionNode, Render.Graphics, Render.Camera.Position, Settings.CameraClosePlane, Settings.CameraFarPlane, Settings.WaterRefractionPlaneDirection, Settings.WaterReflectionResolutionX, Settings.WaterReflectionResolutionY, SceneRenderTarget.RenderType.SingleColor); DepthMapRenderTarget = new SceneRenderTarget("DepthMap", RefractionNode, Render.Graphics, Render.Camera.Position, Settings.CameraClosePlane, Settings.CameraFarPlane, Settings.WaterRefractionPlaneDirection, Settings.WaterReflectionResolutionX, Settings.WaterReflectionResolutionY, SceneRenderTarget.RenderType.SingleDepth); FromBelowDepthTarget = new SceneRenderTarget("DepthMap", RefractionNode, Render.Graphics, new Vector3(), Settings.FromBelowClosePlane, Settings.FromBelowFarPlane, 0, Settings.FromBelowResolutionX, Settings.FromBelowResolutionY, SceneRenderTarget.RenderType.SingleDepth, Settings.ChunkSize, Settings.ChunkSize); ReflectionRenderTarget.ClipOffset = Settings.ClipOffset; RefractionRenderTarget.ClipOffset = Settings.ClipOffset; DepthMapRenderTarget.ClipOffset = Settings.ClipOffset; FromBelowDepthTarget.DebugTextureName = "SceneColorDebug"; //DepthMapRenderTarget.DebugTextureName = "SceneDepthDebug"; Render.AddRenderTarget(ReflectionRenderTarget); Render.AddRenderTarget(RefractionRenderTarget); Render.AddRenderTarget(DepthMapRenderTarget); Render.AddRenderTarget(FromBelowDepthTarget); ReflectionRenderTarget.AttachRange(ReflectionUpdateList); RefractionRenderTarget.AttachRange(RefractionUpdateList); DepthMapRenderTarget.AttachRange(DepthUpdateList); }
/// <summary> /// Gets the marked methods. /// </summary> /// <param name="reflectionNode">The reflection node.</param> /// <param name="markerInterface">The marker interface.</param> /// <returns></returns> private IEnumerable<MethodDefinition> GetMarkedMethods(ReflectionNode reflectionNode, TypeDefinition markerInterface) { return reflectionNode.GetAncestorsToChildren().AsParallel() .Where(n => n.Method != null && GetAllMarkers(n, markerInterface).Any()) .Select(n => n.Method); }
/// <summary> /// Gets all attributes that implement the given advice interface /// </summary> /// <param name="reflectionNode">The reflection node.</param> /// <param name="markerInterface">The advice interface.</param> /// <returns></returns> private IEnumerable<TypeReference> GetAllMarkers(ReflectionNode reflectionNode, TypeDefinition markerInterface) { var markers = reflectionNode.GetAncestorsToChildren() .SelectMany(n => n.CustomAttributes.SelectMany(a => a.AttributeType.Resolve().GetSelfAndParents()).Where(t => IsMarker(t, markerInterface))) .Distinct(); #if DEBUG // Logger.WriteDebug(string.Format("{0} --> {1}", reflectionNode.ToString(), markers.Count())); #endif return markers; }
/// <summary> /// Gets all attributes that implement the given advice interface /// </summary> /// <param name="reflectionNode">The reflection node.</param> /// <param name="markerInterface">The advice interface.</param> /// <param name="context">The context.</param> /// <returns></returns> private IEnumerable <Tuple <ReflectionNode, MarkerDefinition> > GetAllMarkers(ReflectionNode reflectionNode, ITypeDefOrRef markerInterface, WeavingContext context) { var markers = reflectionNode.GetAncestorsToDescendants() .Select(n => new { Node = n, Attributes = n.CustomAttributes }) .SelectMany(n => n.Attributes.Select(a => new { Node = n.Node, Attribute = a }) .Where(a => !a.Attribute.AttributeType.DefinitionAssembly.IsSystem()) .Select(a => new { Node = a.Node, Type = ResolveTypeOrGenericDefinition(a.Attribute.AttributeType) }) .Where(t => IsMarker(t.Type, markerInterface))) .Select(t => Tuple.Create(t.Node, GetMarkerDefinition(t.Type, context))); return(markers); }
public MarkedNode(ReflectionNode node, IEnumerable <MarkerDefinition> definitions) { Node = node; Definitions = definitions.ToList(); }