Exemplo n.º 1
0
        static void RayTest_PostProcess(Physics2DRayTestItem item, List <Physics2DRayTestItem.ResultItem> resultList)
        {
            if (resultList.Count == 0)
            {
                item.Result = Array.Empty <Physics2DRayTestItem.ResultItem>();
                return;
            }

            if (item.Mode == Physics2DRayTestItem.ModeEnum.OneClosest || item.Mode == Physics2DRayTestItem.ModeEnum.One)
            {
                item.Result = new Physics2DRayTestItem.ResultItem[] { resultList[0] };
                return;
            }

            if (item.Mode == Physics2DRayTestItem.ModeEnum.OneForEach)
            {
                item.Result = GetResultsOnePerShape(resultList);
                return;
            }

            //sort by distance in any other case
            CollectionUtility.SelectionSort(resultList, Compare);

            if (item.Mode == Physics2DRayTestItem.ModeEnum.All)
            {
                item.Result = resultList.ToArray();
                return;
            }

            //item.Mode == PhysicsRayTestItem.ModeEnum.OneClosestForEach
            item.Result = GetResultsOnePerShape(resultList);
        }
Exemplo n.º 2
0
        public static SharpBgfx.VertexLayout CreateVertexDeclaration(this VertexElement[] elements, int forSource)
        {
            GetInfo(elements, out var vertexSize, out var holes);

            //!!!!
            if (holes)
            {
                Log.Fatal("VertexElement: CreateVertexDeclaration: holes. impl.");
            }

            //!!!!
            if (forSource != 0)
            {
                Log.Fatal("VertexElement: CreateVertexDeclaration: forSource != 0. impl.");
            }
            //if( element.Source == forSource )
            //{
            //}


            var result = new SharpBgfx.VertexLayout();

            result.Begin();

            var sorted = (VertexElement[])elements.Clone();

            CollectionUtility.SelectionSort(sorted, delegate(VertexElement element1, VertexElement element2)
            {
                if (element1.Offset < element2.Offset)
                {
                    return(-1);
                }
                if (element1.Offset > element2.Offset)
                {
                    return(1);
                }
                return(0);
            });

            foreach (var element in sorted)
            {
                element.GetBfgx(out var attribute, out var count, out var type, out var asInt);
                result.Add(attribute, count, type, false, asInt);
            }

            result.End();

            if (vertexSize != result.Stride)
            {
                Log.Fatal("VertexElement: CreateVertexDeclaration: vertexSize != result.Stride.");
            }

            return(result);
        }
Exemplo n.º 3
0
        SourceData GetSourceData()
        {
            var sourceData = new SourceData();

            sourceData.curveTypePosition          = CurveTypePosition;
            sourceData.roundedLineCurvatureRadius = RoundedLineCurvatureRadius;
            sourceData.curveTypeRotation          = CurveTypeRotation;
            sourceData.curveTypeScale             = CurveTypeScale;
            sourceData.timeScale = TimeScale;

            var points = GetComponents <Component_CurveInSpacePoint>(onlyEnabledInHierarchy: true);

            sourceData.points    = new SourceData.Point[1 + points.Length];
            sourceData.points[0] = new SourceData.Point()
            {
                transform = Transform, time = Time
            };
            for (int n = 0; n < points.Length; n++)
            {
                sourceData.points[n + 1] = new SourceData.Point()
                {
                    transform = points[n].Transform, time = points[n].Time
                }
            }
            ;

            //sort by time
            bool allPointsZeroTime = sourceData.points.All(p => p.time == 0);

            if (!allPointsZeroTime)
            {
                CollectionUtility.MergeSort(sourceData.points, delegate(SourceData.Point a, SourceData.Point b)
                {
                    if (a.time < b.time)
                    {
                        return(-1);
                    }
                    if (a.time > b.time)
                    {
                        return(1);
                    }
                    return(0);
                });
            }

            return(sourceData);
        }
Exemplo n.º 4
0
        static void GenerateVideoModes()
        {
            //generate list
            videoModes = PlatformFunctionality.Get().GetVideoModes();

            //safe list
            if (videoModes.Count == 0)
            {
                videoModes.Add(new Vector2I(640, 480));
                videoModes.Add(new Vector2I(800, 600));
                videoModes.Add(new Vector2I(1024, 768));
                videoModes.Add(new Vector2I(1152, 864));
                videoModes.Add(new Vector2I(1280, 1024));
                videoModes.Add(new Vector2I(1600, 1200));
            }

            //sort
            CollectionUtility.SelectionSort(videoModes, delegate(Vector2I mode1, Vector2I mode2)
            {
                if (mode1.X < mode2.X)
                {
                    return(-1);
                }
                if (mode1.X > mode2.X)
                {
                    return(1);
                }
                if (mode1.Y < mode2.Y)
                {
                    return(-1);
                }
                if (mode1.Y > mode2.Y)
                {
                    return(1);
                }
                return(0);
            });
        }
Exemplo n.º 5
0
            public static List <TemplateClass> GetTemplates()
            {
                //init templates
                if (templates.Count == 0)
                {
                    var templatesPath = VirtualPathUtility.GetRealPathByVirtual(@"Base\Tools\NewResourceTemplates\");
                    if (Directory.Exists(templatesPath))
                    {
                        string[] filePaths = Directory.GetFiles(templatesPath, "*.scene", SearchOption.AllDirectories);
                        CollectionUtility.InsertionSort(filePaths, string.Compare);

                        foreach (var path in filePaths)
                        {
                            var name        = Path.GetFileNameWithoutExtension(path);
                            var previewPath = Path.Combine(Path.GetDirectoryName(path), name + ".png");
                            var preview     = File.Exists(previewPath) ? Image.FromFile(previewPath) : null;
                            templates.Add(new TemplateClass(name, preview));
                        }
                    }
                }

                return(templates);
            }
Exemplo n.º 6
0
        /// <summary>
        /// Convex Hull Graham algorithm.
        /// </summary>
        /// <param name="points"></param>
        /// <param name="epsilon"></param>
        /// <returns></returns>
        public static int[] GetFromPoints(IList <Vector2> points, double epsilon)
        {
            List <PointItem> list = new List <PointItem>(points.Count);

            for (int nPoint = 0; nPoint < points.Count; nPoint++)
            {
                Vector2 point = points[nPoint];

                //const double epsilon = .001;

                bool skip = false;
                for (int nPointItem = 0; nPointItem < list.Count; nPointItem++)
                {
                    PointItem listItem = list[nPointItem];
                    if (listItem.point.Equals(ref point, epsilon))
                    {
                        skip = true;
                        break;
                    }
                }
                if (skip)
                {
                    continue;
                }

                PointItem pointItem = new PointItem();
                pointItem.sourceIndex = nPoint;
                pointItem.point       = points[nPoint];
                list.Add(pointItem);
            }

            if (list.Count < 3)
            {
                int[] array = new int[points.Count];
                for (int n = 0; n < array.Length; n++)
                {
                    array[n] = n;
                }
                return(array);
            }

            //!!!!merge sort
            CollectionUtility.SelectionSort(list, delegate(PointItem item1, PointItem item2)
            {
                Vector2 i1 = item1.point;
                Vector2 i2 = item2.point;

                if (i1.X < i2.X || i1.X == i2.X && i1.Y < i2.Y)
                {
                    return(1);
                }
                else
                {
                    return(-1);
                }
            });

            PointItem p1 = list[0];
            PointItem p2 = list[list.Count - 1];

            List <PointItem> up   = new List <PointItem>(points.Count);
            List <PointItem> down = new List <PointItem>(points.Count);

            up.Add(p1);
            down.Add(p1);

            for (int i = 1; i < list.Count; ++i)
            {
                if (i == list.Count - 1 || cw(p1.point, list[i].point, p2.point))
                {
                    while (up.Count >= 2 && !cw(up[up.Count - 2].point, up[up.Count - 1].point,
                                                list[i].point))
                    {
                        up.RemoveAt(up.Count - 1);
                    }
                    up.Add(list[i]);
                }
                if (i == list.Count - 1 || ccw(p1.point, list[i].point, p2.point))
                {
                    while (down.Count >= 2 && !ccw(down[down.Count - 2].point,
                                                   down[down.Count - 1].point, list[i].point))
                    {
                        down.RemoveAt(down.Count - 1);
                    }
                    down.Add(list[i]);
                }
            }

            List <int> result = new List <int>(points.Count);

            for (int i = 0; i < up.Count; i++)
            {
                result.Add(up[i].sourceIndex);
            }
            for (int i = down.Count - 2; i > 0; i--)
            {
                result.Add(down[i].sourceIndex);
            }

            return(result.ToArray());
        }
Exemplo n.º 7
0
        static void UpdateChannels(double delta, bool update3DChannels)
        {
            List <SoundVirtualChannel> activeVirtualChannels;
            List <SoundRealChannel>    realChannels;

            if (update3DChannels)
            {
                activeVirtualChannels = activeVirtual3DChannels;
                realChannels          = real3DChannels;
            }
            else
            {
                activeVirtualChannels = activeVirtual2DChannels;
                realChannels          = real2DChannels;
            }

            //update virtual channels time
            if (delta != 0)
            {
                for (int n = 0; n < activeVirtualChannels.Count; n++)
                {
                    var virtualChannel = activeVirtualChannels[n];
                    if (!virtualChannel.IsTotalPaused())
                    {
                        virtualChannel.time += delta * virtualChannel.pitch;

                        var sound = virtualChannel.sound;
                        if (virtualChannel.time >= sound.Length)
                        {
                            if ((sound.Mode & SoundModes.Loop) != 0)
                            {
                                virtualChannel.time -= sound.Length;
                            }
                            else
                            {
                                if (virtualChannel.currentRealChannel == null || virtualChannel.time >= sound.Length + .1f)
                                {
                                    virtualChannel.Stop();
                                    n--;
                                }
                            }
                        }
                    }
                }
            }

            //calculate priority

            //!!!!slowly. часто обновляется может

            for (int n = 0; n < activeVirtualChannels.Count; n++)
            {
                var virtualChannel = activeVirtualChannels[n];
                var sound          = virtualChannel.sound;

                double priority = 0;

                if (virtualChannel.AttachedToScene == null || virtualChannel.AttachedToScene == listenerCurrentScene)
                {
                    if (virtualChannel.GetTotalVolume() != 0 && !virtualChannel.IsTotalPaused())
                    {
                        if (update3DChannels)
                        {
                            double distanceSqr = (virtualChannel.position - listenerPosition).LengthSquared();
                            priority = (100000000.0 - distanceSqr) * (virtualChannel.Priority + .00001);
                            //priority += 1.0f / distanceSqr + virtualChannel.Priority * 10000;
                        }
                        else
                        {
                            //if( ( sound.Mode & SoundModes.Stream ) != 0 )
                            //	priority += 10;
                            priority = (virtualChannel.Priority + .00001) * 10000000000;

                            //fix sorting jerking problem
                            priority += (double)sound.createIndex;
                        }

                        //if( ( sound.Mode & SoundModes.Mode3D ) == 0 )
                        //{
                        //	priority += 100000000;
                        //	if( ( sound.Mode & SoundModes.Stream ) != 0 )
                        //		priority += 100000000;
                        //}
                        //else
                        //{
                        //	double distanceSqr = ( virtualChannel.position - listenerPosition ).LengthSquared();

                        //	priority += ( 1000000.0 - distanceSqr ) + virtualChannel.priority * 10000;
                        //	//priority += 1.0f / distanceSqr + virtualChannel.Priority * 10000;
                        //}

                        ////only for small fix sorting jerking problem at the DataBuffer and Streams
                        //if( sound.Name == null || ( sound.Mode & SoundModes.Stream ) != 0 )
                        //	priority += (double)sound.createIndex;
                    }
                }

                virtualChannel.tempPriority = priority;
            }

            //Sort by priority
            CollectionUtility.SelectionSort(activeVirtualChannels, virtualChannelsTempPriorityComparer);
            //ListUtils.MergeSort( activeVirtualChannels, virtualChannelsTempPriorityComparer );

            //remove virtual channels from real channels
            for (int n = 0; n < activeVirtualChannels.Count; n++)
            {
                var virtualChannel = activeVirtualChannels[n];
                var realChannel    = virtualChannel.currentRealChannel;

                if (realChannel != null)
                {
                    if (n >= realChannels.Count || virtualChannel.tempPriority == 0)
                    {
                        realChannel.PreDetachVirtualChannel();
                        realChannel.currentVirtualChannel = null;
                        virtualChannel.currentRealChannel = null;
                    }
                }
            }

            //bind virtual channels to real channels
            var freeRealChannels = new Queue <SoundRealChannel>(realChannels.Count);

            foreach (var c in realChannels)
            {
                if (c.CurrentVirtualChannel == null)
                {
                    freeRealChannels.Enqueue(c);
                }
            }

            for (int n = 0; n < activeVirtualChannels.Count; n++)
            {
                //no free real channels
                if (freeRealChannels.Count == 0)
                {
                    break;
                }

                var virtualChannel = activeVirtualChannels[n];
                if (virtualChannel.currentRealChannel == null && virtualChannel.tempPriority != 0)
                {
                    var realChannel = freeRealChannels.Dequeue();

                    realChannel.currentVirtualChannel = virtualChannel;
                    virtualChannel.currentRealChannel = realChannel;
                    realChannel.PostAttachVirtualChannel();
                }
            }

            ////add virtual channels to real channels
            //int currentRealChannelIndex = 0;

            //for( int n = 0; n < activeVirtualChannels.Count; n++ )
            //{
            //	VirtualChannel virtualChannel = activeVirtualChannels[ n ];

            //	if( currentRealChannelIndex >= realChannels.Count )
            //		break;
            //	if( virtualChannel.currentRealChannel != null )
            //		continue;
            //	if( virtualChannel.tempPriority == 0 )
            //		continue;

            //	if( virtualChannel.Time >= virtualChannel.Sound.Length )
            //	{
            //		if( ( virtualChannel.Sound.Mode & SoundModes.Loop ) == 0 )
            //			continue;
            //		else
            //			virtualChannel.time -= virtualChannel.Sound.Length;
            //	}

            //	RealChannel realChannel = null;
            //	{
            //		while( realChannels[ currentRealChannelIndex ].CurrentVirtualChannel != null )
            //		{
            //			currentRealChannelIndex++;
            //			if( currentRealChannelIndex >= realChannels.Count )
            //				break;
            //		}

            //		if( currentRealChannelIndex < realChannels.Count )
            //		{
            //			realChannel = realChannels[ currentRealChannelIndex ];
            //			currentRealChannelIndex++;
            //		}
            //	}

            //	if( realChannel == null )
            //		break;

            //	if( realChannel.currentVirtualChannel != null )
            //		Log.Fatal( "SoundWorld: UpdateChannels: realChannel.currentVirtualChannel != null." );

            //	realChannel.currentVirtualChannel = virtualChannel;
            //	virtualChannel.currentRealChannel = realChannel;
            //	realChannel.PostAttachVirtualChannel();
            //}

            //update gain for 3d sound (calculate attenuation)
            if (update3DChannels)
            {
                for (int n = 0; n < real3DChannels.Count; n++)
                {
                    SoundRealChannel realChannel = real3DChannels[n];
                    if (realChannel.currentVirtualChannel != null)
                    {
                        //!!!!slowly enter to critical section for each real channel?
                        realChannel.UpdateVolume();
                    }
                }
            }
        }
        //!!!!подобное для Brush режима
        //public delegate void CalculateCreateObjectPositionUnderCursorEventDelegate( Component_ObjectInSpace objectInSpace, ref bool found, ref Vector3 position );
        //public static event CalculateCreateObjectPositionUnderCursorEventDelegate CalculateCreateObjectPositionUnderCursorEvent;

        //public class CalculateCreateObjectPositionByRayResult
        //{
        //	public bool Found;
        //	public Vector3 Position;
        //	public Component_ObjectInSpace CollidedWith;
        //	public Vector3F Normal;
        //}

        public static (bool found, Vector3 position, Component_ObjectInSpace collidedWith) CalculateCreateObjectPositionByRay(Component_Scene scene, Component_ObjectInSpace objectInSpace, Ray ray, bool allowSnap)
        {
            //var viewport = ViewportControl.Viewport;

            //Vector2 mouse;
            //if( overrideMouse.HasValue )
            //	mouse = overrideMouse.Value;
            //else
            //{
            //	mouse = viewport.MousePosition;
            //	if( !new Rectangle( 0, 0, 1, 1 ).Contains( mouse ) )
            //		mouse = new Vector2( 0.5, 0.5 );
            //}

            //Ray ray;
            //if( overrideRay.HasValue )
            //	ray = overrideRay.Value;
            //else
            //	ray = viewport.CameraSettings.GetRayByScreenCoordinates( mouse );
            //!!!!? clamp max distance
            //ray.Direction = ray.Direction.GetNormalize() * 100;

            //!!!!можно конвекс форму делать вместо бокса
            Bounds localBounds = new Bounds();

            if (objectInSpace != null)
            {
                //particle system specific
                if (!(objectInSpace is Component_ParticleSystemInSpace))
                {
                    localBounds = objectInSpace.SpaceBounds.CalculatedBoundingBox - objectInSpace.Transform.Value.Position;
                }
            }
            if (localBounds.GetSize().X < 0.001)
            {
                localBounds.Expand(new Vector3(0.001, 0, 0));
            }
            if (localBounds.GetSize().Y < 0.001)
            {
                localBounds.Expand(new Vector3(0, 0.001, 0));
            }
            if (localBounds.GetSize().Z < 0.001)
            {
                localBounds.Expand(new Vector3(0, 0, 0.001));
            }

            double resultMinScale = 1.01;
            Component_ObjectInSpace resultMinScaleCollidedWith = null;

            if (objectInSpace != null)
            {
                //when objectInSpace != null

                Plane[] planes;
                {
                    var b1     = localBounds + ray.Origin;
                    var b2     = b1 + ray.Direction;
                    var points = CollectionUtility.Merge(b1.ToPoints(), b2.ToPoints());
                    ConvexHullAlgorithm.Create(points, out planes);
                }

                var item = new Component_Scene.GetObjectsInSpaceItem(Component_Scene.GetObjectsInSpaceItem.CastTypeEnum.All, null, true, planes);
                scene.GetObjectsInSpace(item);

                foreach (var resultItem in item.Result)
                {
                    if (objectInSpace != resultItem.Object && !resultItem.Object.GetAllParents(false).Contains(objectInSpace))
                    {
                        //mesh in space
                        if (resultItem.Object is Component_MeshInSpace meshInSpace)
                        {
                            Vector3[] verticesFull;
                            int[]     indices;
                            {
                                var b1     = localBounds + ray.Origin;
                                var b2     = b1 + ray.Direction;
                                var points = CollectionUtility.Merge(b1.ToPoints(), b2.ToPoints());
                                ConvexHullAlgorithm.Create(points, out verticesFull, out indices);
                            }

                            if (meshInSpace._Intersects(verticesFull, indices))
                            {
                                double minScale = 1.01;

                                double currentScale = 0.5;
                                //!!!!?
                                const double threshold = 0.00001;

                                double step = 0.25;
                                while (step > threshold)
                                {
                                    Vector3[] vertices = new Vector3[verticesFull.Length];
                                    for (int n = 0; n < vertices.Length; n++)
                                    {
                                        vertices[n] = verticesFull[n] - ray.Direction + ray.Direction * currentScale;
                                    }
                                    //Vector3[] vertices;
                                    //int[] indices;
                                    //{
                                    //	var b1 = localBounds + ray.Origin;
                                    //	var b2 = b1 + ray.Direction * currentScale;
                                    //	var points = CollectionUtility.Merge( b1.ToPoints(), b2.ToPoints() );
                                    //	ConvexHullAlgorithm.Create( points, out vertices, out indices );
                                    //}

                                    bool intersects = meshInSpace._Intersects(vertices, indices);

                                    if (!intersects)
                                    {
                                        minScale = currentScale;
                                    }

                                    if (intersects)
                                    {
                                        currentScale -= step;
                                    }
                                    else
                                    {
                                        currentScale += step;
                                    }
                                    step /= 2;
                                }

                                if (minScale <= 1 && minScale < resultMinScale)
                                {
                                    resultMinScale             = minScale;
                                    resultMinScaleCollidedWith = meshInSpace;
                                }
                            }
                        }

                        //!!!!какие еще
                    }
                }
            }
            else
            {
                //when objectInSpace == null

                var item = new Component_Scene.GetObjectsInSpaceItem(Component_Scene.GetObjectsInSpaceItem.CastTypeEnum.All, null, true, ray);
                scene.GetObjectsInSpace(item);

                foreach (var resultItem in item.Result)
                {
                    //mesh in space
                    if (resultItem.Object is Component_MeshInSpace meshInSpace)
                    {
                        if (meshInSpace.RayCast(ray, Component_Mesh.CompiledData.RayCastMode.Auto, out var scale, out var triangleIndex))
                        {
                            if (scale <= 1 && scale < resultMinScale)
                            {
                                resultMinScale             = scale;
                                resultMinScaleCollidedWith = meshInSpace;
                                //if( triangleIndex != -1 )
                                //{
                                //}
                            }
                        }
                    }

                    //!!!!какие еще
                }
            }

            bool    found;
            Vector3 pos;

            if (resultMinScale <= 1)
            {
                found = true;
                pos   = ray.GetPointOnRay(resultMinScale);
            }
            else
            {
                found = false;
                pos   = ray.Origin + ray.Direction.GetNormalize() * Math.Max(localBounds.GetBoundingSphere().Radius, 1) * 20;
            }

            //snap for 2D mode
            if (scene.Mode.Value == Component_Scene.ModeEnum._2D)
            {
                pos.Z = Math.Ceiling(pos.Z);
            }

            //snap
            if (allowSnap)
            {
                double snap;

                //if( Form.ModifierKeys.HasFlag( Keys.Control ) )
                snap = ProjectSettings.Get.SceneEditorStepMovement;
                //else
                //	snap = 0;
                if (snap != 0)
                {
                    Vector3 snapVec = new Vector3(snap, snap, snap);
                    pos += snapVec / 2;
                    pos /= snapVec;
                    pos  = new Vector3I((int)pos.X, (int)pos.Y, (int)pos.Z).ToVector3();
                    pos *= snapVec;
                }
            }

            //CalculateCreateObjectPositionUnderCursorEvent?.Invoke( objectInSpace, ref found, ref pos );

            return(found, pos, resultMinScaleCollidedWith);
            //objectToTransform.Transform = new Transform( pos, objectToTransform.Transform.Value.Rotation, objectToTransform.Transform.Value.Scale );
            //}
            //else
            //{
            //	var localBounds = objectInSpace.SpaceBounds.CalculatedBoundingBox - objectInSpace.Transform.Value.Position;

            //	//disable object to disable collisions
            //	var disable = ContainsPhysicsBodies( objectInSpace );
            //	if( disable )
            //		objectInSpace.Enabled = false;

            //	//!!!!contact group
            //	PhysicsConvexSweepTestItem castItem = new PhysicsConvexSweepTestItem( Matrix4.FromTranslate( ray.Origin ),
            //		Matrix4.FromTranslate( ray.Origin + ray.Direction ), 1, -1, PhysicsConvexSweepTestItem.ModeEnum.OneClosest, localBounds );
            //	Scene.PhysicsConvexSweepTest( new PhysicsConvexSweepTestItem[] { castItem } );

            //	//restore disabled object
            //	if( disable )
            //		objectInSpace.Enabled = true;

            //	Vector3 pos;
            //	if( castItem.Result.Length != 0 )
            //		pos = castItem.Result[ 0 ].Position;
            //	else
            //	{
            //		pos = ray.Origin + ray.Direction.GetNormalize() * Math.Max( localBounds.GetBoundingSphere().Radius, 1 ) * 20;
            //	}

            //	objectInSpace.Transform = new Transform( pos, objectInSpace.Transform.Value.Rotation, objectInSpace.Transform.Value.Scale );
            //}
        }
Exemplo n.º 9
0
        //!!!!
        //public static bool InsidePackage( string path )
        //{
        //	lock( VirtualFileSystem.lockObject )
        //	{
        //		if( !VirtualFileSystem.initialized )
        //			Log.Fatal( "VirtualFileSystem: File system is not initialized." );

        //		if( VirtualFileSystem.LoggingFileOperations )
        //			Log.Info( "Logging file operations: VirtualDirectory.IsInArchive( \"{0}\" )", path );

        //		string realPath = VirtualPathUtils.GetRealPathByVirtual( path );
        //		if( Directory.Exists( realPath ) )
        //			return false;

        //		return PackageManager.IsDirectoryExists( path );
        //	}
        //}

        /// <summary>
        /// Returns the names of files in the specified directory that match the specified
        /// search pattern, using a value to determine whether to search subdirectories.
        /// </summary>
        /// <param name="path">The directory from which to retrieve the files.</param>
        /// <param name="searchPattern">
        /// The search string to match against the names of files in path. The parameter
        /// cannot end in two periods ("..") or contain two periods ("..") followed by
        /// System.IO.Path.DirectorySeparatorChar or System.IO.Path.AltDirectorySeparatorChar,
        /// nor can it contain any of the characters in System.IO.Path.InvalidPathChars.
        ///
        /// </param>
        /// <param name="searchOption">
        /// One of the System.IO.SearchOption values that specifies whether the search
        /// operation should include all subdirectories or only the current directory.
        /// </param>
        /// <returns>
        /// A <b>String</b> array containing containing the names of files in the
        /// specified directory that match the specified search pattern.
        /// </returns>
        public static string[] GetFiles(string path, string searchPattern = "*", SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            if (!VirtualFileSystem.initialized)
            {
                Log.Fatal("VirtualFileSystem: File system is not initialized.");
            }

            if (VirtualFileSystem.LoggingFileOperations)
            {
                Log.Info("Logging file operations: VirtualDirectory.GetFiles( \"{0}\", \"{1}\", \"{2}\" )", path, searchPattern, searchOption);
            }

            if (searchPattern.IndexOfAny(new char[] { '\\', '/', '?' }) != -1)
            {
                throw new ArgumentException("searchPattern: following characters: \\, /, ? is not supported.");
            }
            if (path.Contains(".."))
            {
                throw new ArgumentException("path: \"..\" is not supported.");
            }
            if (searchPattern.Contains(".."))
            {
                throw new ArgumentException("searchPattern: \"..\" is not supported.");
            }

            string realPath = VirtualPathUtility.GetRealPathByVirtual(path);

            //!!!!redirections

            string[] files;
            if (Directory.Exists(realPath))
            {
                files = Directory.GetFiles(realPath, searchPattern, searchOption);
            }
            else
            {
                files = new string[0];
            }

            if (VirtualPathUtility.IsUserDirectoryPath(path))
            {
                int prefixLength = VirtualFileSystem.Directories.UserSettings.Length + 1;
                for (int n = 0; n < files.Length; n++)
                {
                    files[n] = "user:" + files[n].Substring(prefixLength);
                }

                CollectionUtility.MergeSort(files, StringComparer.Ordinal);

                return(files);
            }
            else
            {
                int prefixLength = VirtualFileSystem.Directories.Assets.Length + 1;
                for (int n = 0; n < files.Length; n++)
                {
                    files[n] = files[n].Substring(prefixLength);
                }

                //!!!!!
                //List<string> result = new List<string>( 64 );
                //PackageManager.GetFiles( path, searchPattern, searchOption, result );
                //if( result.Count != 0 )
                //{
                //	foreach( string name in files )
                //		result.Add( name );

                //	ListUtils.MergeSort( result, StringComparer.Ordinal );

                //	//remove replies
                //	for( int n = result.Count - 1; n >= 1; n-- )
                //	{
                //		if( string.Compare( result[ n ], result[ n - 1 ], true ) == 0 )
                //			result.RemoveAt( n );
                //	}

                //	files = result.ToArray();
                //}
                //else
                //{

                CollectionUtility.MergeSort(files, StringComparer.Ordinal);

                //}

                return(files);
            }
        }
Exemplo n.º 10
0
        public virtual void RenderUI(CanvasRenderer renderer, Component_RenderingPipeline.RenderSceneData.LightItem lightItem, Viewport viewport, double intensity)
        {
            var lightPosition = lightItem.Position;

            //!!!!override real position
            //{
            //	if( Sun.Instances.Count > 0 )
            //	{
            //		//get first sun entity on the map.
            //		Sun sun = Sun.Instances[ 0 ];

            //		Vec3 direction;
            //		if( sun.BillboardOverridePosition != Vec3.Zero )
            //			direction = sun.BillboardOverridePosition.GetNormalize();
            //		else
            //			direction = -sun.Rotation.GetForward();
            //		position = camera.Position + direction * 100000;

            //		return true;
            //	}

            //	position = Vec3.Zero;
            //	return false;
            //}

            if (viewport.CameraSettings.ProjectToScreenCoordinates(lightPosition, out var screenLightPosition))
            {
                //get enabled flares
                var flares = GetComponents <Component_LensFlare>(onlyEnabledInHierarchy: true);

                //sort by position
                CollectionUtility.SelectionSort(flares, delegate(Component_LensFlare f1, Component_LensFlare f2)
                {
                    if (f1.Position > f2.Position)
                    {
                        return(-1);
                    }
                    if (f1.Position < f2.Position)
                    {
                        return(1);
                    }
                    return(0);
                });

                //for( int n = 0; n < flares.Count; n++ )
                //	sortedFlares[ n ].tempSmoothIntensityFactor = cameraInfo.SmoothIntensityFactors[ n ];

                //render
                foreach (var flare in flares)
                {
                    var image = flare.Image.Value;

                    var flareVector   = screenLightPosition - new Vector2(0.5, 0.5);
                    var flarePosition = new Vector2(0.5, 0.5) + flareVector * flare.Position;
                    var size          = flare.Size.Value;
                    var flareSize     = new Vector2(size.X, size.Y * renderer.AspectRatio);
                    var rectangle     = new Rectangle(flarePosition - flareSize * 0.5, flarePosition + flareSize * 0.5);

                    var flareColor = Color.Value * flare.Color * new ColorValue(1, 1, 1, intensity);
                    // * new ColorValue( 1, 1, 1, item.tempSmoothIntensityFactor );

                    if (flareColor.Alpha > 0)
                    {
                        renderer.PushBlendingType(flare.Blending.Value);
                        renderer.AddQuad(rectangle, new RectangleF(0, 0, 1, 1), image, flareColor, true);
                        renderer.PopBlendingType();
                    }
                }
            }
        }