Example #1
0
 public FlowField FindPath(DijkstraNodeGrid dijkstraNodeNetwork, IPathRequest pathRequest, out bool succes)
 {
     if (_flowFieldCache == null || !_flowFieldCache.TryGetValue(pathRequest, out var flowField))
     {
         var potentialField = _potentialFieldAlgorithm.FindPath(dijkstraNodeNetwork, pathRequest, out succes);
         flowField = new FlowField(potentialField);
         _flowFieldCache?.Add(pathRequest, flowField);
     }
     succes = flowField[pathRequest.PathStart].Length > 0;
     return(flowField);
 }
Example #2
0
        public PotentialField FindPath(DijkstraNodeGrid dijkstraNodeNetwork, IPathRequest pathRequest, out bool succes)
        {
            if (_potentialFieldCache == null || !_potentialFieldCache.TryGetValue(pathRequest, out var potentialField))
            {
                var pathfindingNetwork = dijkstraNodeNetwork.GetCollisionLayerNetwork(pathRequest.CollisionCategory);

                _dijkstraAlgorithm.StartFindPath(pathfindingNetwork, dijkstraNodeNetwork.DefinitionNodeGrid.NodeArray, pathRequest.PathEnd);
                _dijkstraAlgorithm.FindPath(pathfindingNetwork, dijkstraNodeNetwork.DefinitionNodeGrid.NodeGrid.Array, pathRequest.PathStart, pathRequest.AgentSize, pathRequest.CollisionCategory);
                potentialField = FindPath(dijkstraNodeNetwork, pathfindingNetwork, pathRequest.PathEnd, pathRequest);
                _potentialFieldCache?.Add(pathRequest, potentialField);
            }
            ref var startDefinitionNode = ref dijkstraNodeNetwork.DefinitionNodeGrid.NodeArray[pathRequest.PathStart];
Example #3
0
        private static List <PropertyInfo> GetPropertyInfos(object obj)
        {
            if (obj == null)
            {
                return(new List <PropertyInfo>());
            }

            if (_paramCache.TryGetValue(obj.GetType(), out var properties))
            {
                return(properties.ToList());
            }
            properties = obj.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public).ToList();
            _paramCache[obj.GetType()] = properties;
            return(properties);
        }
        internal InMethodBinder GetRecordConstructorInMethodBinder(SynthesizedRecordConstructor constructor)
        {
            RecordDeclarationSyntax typeDecl = constructor.GetSyntax();

            var extraInfo = NodeUsage.ConstructorBodyOrInitializer;
            var key       = BinderFactoryVisitor.CreateBinderCacheKey(typeDecl, extraInfo);

            if (!_binderCache.TryGetValue(key, out Binder resultBinder))
            {
                // Ctors cannot be generic
                Debug.Assert(constructor.Arity == 0, "Generic Ctor, What to do?");
                resultBinder = new InMethodBinder(constructor, GetInRecordBodyBinder(typeDecl));

                _binderCache.TryAdd(key, resultBinder);
            }

            return((InMethodBinder)resultBinder);
        }
Example #5
0
        internal string NormalizeDebugDocumentPath(string path, string basePath)
        {
            if (_resolverOpt == null)
            {
                return(path);
            }

            var    key = ValueTuple.Create(path, basePath);
            string normalizedPath;

            if (!_normalizedPathsCache.TryGetValue(key, out normalizedPath))
            {
                normalizedPath = _resolverOpt.NormalizePath(path, basePath) ?? path;
                _normalizedPathsCache.TryAdd(key, normalizedPath);
            }

            return(normalizedPath);
        }
Example #6
0
        internal string NormalizeDebugDocumentPath(string path, string basePath)
        {
            var resolver = _compilation.Options.SourceReferenceResolver;

            if (resolver == null)
            {
                return(path);
            }

            var    key = ValueTuple.Create(path, basePath);
            string normalizedPath;

            if (!_normalizedPathsCache.TryGetValue(key, out normalizedPath))
            {
                normalizedPath = resolver.NormalizePath(path, basePath) ?? path;
                _normalizedPathsCache.TryAdd(key, normalizedPath);
            }

            return(normalizedPath);
        }
        private static Type GetMapperType <T>()
        {
            Type type = typeof(T);

#if NETSTANDARD1_3 || NETSTANDARD2_0
            if (!type.GetTypeInfo().IsInterface)
#else
            if (!type.IsInterface)
#endif
            {
                throw new ArgumentException($"The mapper only supports interface type defined that inherited ISqlOperationMapper");
            }

            if (mapperTypeCache.TryGetValue(type.TypeHandle, out Type mapperType))
            {
                return(mapperType);
            }

            var assemblyBuilder = GetAssemblyBuilder();
            var moduleBuilder   = GetModuleBuilder(assemblyBuilder);
            var typeBuilder     = GetTypeBuilder(type, moduleBuilder);

            var fieldBuilder = DefineFieldConnection(typeBuilder);
            DefineConstructor(typeBuilder, fieldBuilder);

            var methods = type.GetMethods();
            foreach (MethodInfo methodInfo in methods)
            {
                DefineMethod(typeBuilder, fieldBuilder, methodInfo);
            }

#if NETSTANDARD1_3 || NETSTANDARD2_0
            mapperType = typeBuilder.CreateTypeInfo().AsType();
#else
            mapperType = typeBuilder.CreateType();
#endif
            mapperTypeCache[type.TypeHandle] = mapperType;
            return(mapperType);
        }
Example #8
0
        public PotentialField FindPath(DijkstraNodeGrid dijkstraNodeNetwork, IPathRequest pathRequest, out bool succes)
        {
            try
            {
                if (pathRequest.AgentSize % 2 == 0)
                {
                    throw new InvalidAgentSizeException("Potential fields only support uneven agent sizes such as 1,3,5 etc.");
                }

                if (_potentialFieldCache == null || !_potentialFieldCache.TryGetValue(pathRequest, out var potentialField))
                {
                    var sw = Stopwatch.StartNew();
                    var pathfindingNetwork = dijkstraNodeNetwork.GetCollisionLayerNetwork(pathRequest.CollisionCategory);
                    var startNode          = NodePointer.Dereference(pathRequest.PathStart.Index, pathfindingNetwork);
                    var targetNode         = NodePointer.Dereference(pathRequest.PathEnd.Index, pathfindingNetwork);
                    if (_dijkstraAlgorithm.FindPath(pathfindingNetwork, targetNode, startNode, pathRequest))
                    {
                        potentialField = FindPath(dijkstraNodeNetwork, pathfindingNetwork, targetNode, pathRequest);
                    }
                    else
                    {
                        potentialField = new PotentialField(dijkstraNodeNetwork.DefinitionNodeGrid.Transformer, (Point2)targetNode.DefinitionNode.Position);
                    }
                    _potentialFieldCache?.Add(pathRequest, potentialField);
                    Debug.WriteLine($"Potentialfield created in {sw.ElapsedMilliseconds} ms.");
                }
                var nodeWorldPosition = potentialField.GridTransformer.ToWorld(pathRequest.PathStart.Position);
                var offset            = GridClearanceHelper.GridNodeOffset(pathRequest.AgentSize, dijkstraNodeNetwork.DefinitionNodeGrid.Transformer.Scale);
                succes = potentialField.GetHeading(nodeWorldPosition + offset).Length > 0;
                return(potentialField);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Debugger.Break();
                succes = false;
                return(null);
            }
        }
Example #9
0
 public FlowField FindPath(DijkstraNodeGrid dijkstraNodeNetwork, IPathRequest pathRequest, out bool succes)
 {
     try
     {
         if (_flowFieldCache == null || !_flowFieldCache.TryGetValue(pathRequest, out var flowField))
         {
             var potentialField = _potentialFieldAlgorithm.FindPath(dijkstraNodeNetwork, pathRequest, out succes);
             var sw             = Stopwatch.StartNew();
             flowField = new FlowField(potentialField);
             Debug.WriteLine($"Flowfield created in {sw.ElapsedMilliseconds} ms.");
             _flowFieldCache?.Add(pathRequest, flowField);
         }
         succes = flowField[pathRequest.PathStart.Index.Index].Length > 0;
         return(flowField);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex);
         Debugger.Break();
         succes = false;
         return(null);
     }
 }
Example #10
0
        public void Publish <TEvent>(TEvent @event) where TEvent : Event
        {
            if (@event == null)
            {
                return;
            }

            var eventQueue = eventQueueDict.GetOrAdd(@event.EventId, new ConcurrentQueue <Event>());

            eventQueue.Enqueue(@event);

            if (!taskDict.TryGetValue(@event.EventId, out Task task) || task.IsCompleted || task.IsCanceled || task.IsFaulted)
            {
                task?.Dispose();

                taskDict[@event.EventId] = Task.Run(() =>
                {
                    while (!eventQueue.IsEmpty && eventQueue.TryDequeue(out var evt))
                    {
                        messageProcessor.Send(evt);
                    }
                });
            }
        }
Example #11
0
        public override bool TryGetBinder(LanguageSyntaxNode node, object usage, out Binder binder)
        {
            var key = new BinderCacheKey(node, usage);

            return(_binderCache.TryGetValue(key, out binder));
        }