예제 #1
0
        private static Vector3Short[] Get1E7ShortArray(bool positive)
        {
            Vector3Short[] vectors = new Vector3Short[10000000];

            short xmin = positive == true ? (short)0 : (short)-1000;
            short xmax = positive == true ? (short)1000 : (short)0;
            short zmin = positive == true ? (short)0 : (short)-10;
            short zmax = positive == true ? (short)10 : (short)0;

            int    index = 0;
            Random r     = new Random();

            // Populate array
            for (short x = xmin; x < xmax; x++)
            {
                for (short y = xmin; y < xmax; y++)
                {
                    for (short z = zmin; z < zmax; z++)
                    {
                        vectors[index] = new Vector3Short(x, y, z);
                        index++;
                    }
                }
            }

            return(vectors);
        }
예제 #2
0
 public void Enqueue(Vector3Short v, int priority)
 {
     if (!elements.ContainsKey(v))
     {
         elements.Add(v, priority);
         count++;
     }
 }
예제 #3
0
        private static Vector3Short[] GetShortArray(int elementsToHash, bool positive)
        {
            Vector3Short[] vectors = new Vector3Short[elementsToHash];

            int    min = positive == true ? 0 : -511;
            int    max = positive == true ? 511 : 0;
            Random r   = new Random();

            // Populate array
            for (int i = 0; i < elementsToHash; i++)
            {
                vectors[i] = new Vector3Short((short)r.Next(min, max), (short)r.Next(min, max), (short)r.Next(min, max));
            }

            return(vectors);
        }
예제 #4
0
        public static long BenchmarkEquality64Short(int elementsToHash, bool positive)
        {
            Vector3Short[] vectors = Get1E7ShortArray(positive);

            Vector3Short v = new Vector3Short(13, -7, 19);
            bool         result;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            for (int i = 0; i < elementsToHash; i++)
            {
                result = vectors[i].Equals64(v);
            }

            stopwatch.Stop();
            return(stopwatch.ElapsedMilliseconds);
        }
예제 #5
0
    public Vector3Short Dequeue()
    {
        int          bestValue = 999;
        Vector3Short bestKey   = Vector3Short.zero;

        Dictionary <Vector3Short, int> .Enumerator enumerator = elements.GetEnumerator();
        KeyValuePair <Vector3Short, int>           keyValue;

        while (enumerator.MoveNext())
        {
            keyValue = enumerator.Current;
            if (keyValue.Value < bestValue)
            {
                bestValue = keyValue.Value;
                bestKey   = keyValue.Key;
            }
        }

        elements.Remove(bestKey);
        count--;
        return(bestKey);
    }
예제 #6
0
 public ChunkPosition(long bytePosition, Vector3Short position)
 {
     this.bytePosition = bytePosition;
     this.position     = position;
 }
예제 #7
0
    private bool ReadChunkInformation(Vector3Short position)
    {
        Debug.Log("Read " + position.x);
        long bytePosition = -1;

        try
        {
            Debug.Log("Read try " + position.x);
            using (var fileStreamChunk = new FileStream(fileWorld + ".bm", FileMode.Open))
            {
                Debug.Log("Read try FileStream " + position.x);
                int  chunkByteSize = chunkSize * chunkSize * chunkSize;
                long fileSize      = fileStreamChunk.Length;
                for (long i = 0; i < fileSize; i += 6 + chunkByteSize)
                {
                    Debug.Log("Read try FileStream for " + i);
                    Debug.Log("Read try FileStream for Seek " + SeekOrigin.Begin);
                    fileStreamChunk.Seek(i, SeekOrigin.Begin);
                    var positionX = new byte[2];
                    positionX[0] = (byte)fileStreamChunk.ReadByte();
                    positionX[1] = (byte)fileStreamChunk.ReadByte();
                    var positionY = new byte[2];
                    positionY[0] = (byte)fileStreamChunk.ReadByte();
                    positionY[1] = (byte)fileStreamChunk.ReadByte();
                    var positionZ = new byte[2];
                    positionZ[0] = (byte)fileStreamChunk.ReadByte();
                    positionZ[1] = (byte)fileStreamChunk.ReadByte();
                    Debug.Log("Read try FileStream for read " + BitConverter.ToInt16(positionX, 0) + " " + BitConverter.ToInt16(positionY, 0) + " " + BitConverter.ToInt16(positionZ, 0));
                    if (position.x == BitConverter.ToInt16(positionX, 0) && position.y == BitConverter.ToInt16(positionY, 0) && position.z == BitConverter.ToInt16(positionZ, 0))
                    {
                        Debug.Log("Read try FileStream for find " + i);
                        var bytesChunk = new byte[chunkSize, chunkSize, chunkSize];
                        bytePosition = fileStreamChunk.Position;
                        int chunkSize2D = chunkSize * chunkSize;
                        int x           = 0;
                        int y           = 0;
                        int z           = 0;
                        bytesChunk[0, 0, 0] = (byte)fileStreamChunk.ReadByte();
                        for (int j = 1; j < chunkByteSize; j++)
                        {
                            if (j % chunkSize == 0)
                            {
                                y++;
                                z = 0;
                            }
                            if (j % chunkSize2D == 0)
                            {
                                x++;
                                y = 0;
                                z = 0;
                            }
                            bytesChunk[x, y, z] = (byte)fileStreamChunk.ReadByte();
                            z++;
                        }
                        dictChunks[position] = bytesChunk;
                        goto FindIt;
                    }
                }
            }
        }
        catch
        {
            Debug.Log("Exception caught in process reading chunk information");
            return(false);
        }
        if (bytePosition == -1)
        {
            Debug.Log("Read false");
            return(false);
        }
FindIt:
        Debug.Log("Read true " + bytePosition);
        processedChunks.Enqueue(new QueueActionCube(true, new ChunkPosition(bytePosition, position)));
        return(true);
    }
예제 #8
0
 public bool Contains(Vector3Short v)
 {
     return(elements.ContainsKey(v));
 }
예제 #9
0
 public Vector3Short Divide(Vector3Short other) => new Vector3Short((short)(X / other.X), (short)(Y / other.Y), (short)(Z / other.Z));
예제 #10
0
 public Vector3Short Multiply(Vector3Short other) => new Vector3Short((short)(X * other.X), (short)(Y * other.Y), (short)(Z * other.Z));
예제 #11
0
 public Vector3Short Subtract(Vector3Short other) => new Vector3Short((short)(X - other.X), (short)(Y - other.Y), (short)(Z - other.Z));
예제 #12
0
 public Vector3Short Add(Vector3Short other) => new Vector3Short((short)(X + other.X), (short)(Y + other.Y), (short)(Z + other.Z));
예제 #13
0
 public Vector2Short(Vector3Short vector3)
 {
     x = vector3.x;
     y = vector3.y;
 }