Exemple #1
0
    public static FloorCells LoadCellFile(string name)
    {
        FloorCells floorCells = new FloorCells();

        var path = Path.Combine(name + ms_fileExtension + ms_byteExtension);

        using (BinaryReader br = new BinaryReader(File.OpenRead(path)))
        {
            floorCells.config.fCellSize = br.ReadSingle();
            floorCells.config.fMinX     = br.ReadSingle();
            floorCells.config.fMinZ     = br.ReadSingle();
            floorCells.config.fBoundMin = br.ReadSingle();
            floorCells.config.fBoundMax = br.ReadSingle();
            floorCells.config.nWidth    = br.ReadInt32();
            floorCells.config.nHeight   = br.ReadInt32();

            FLOOR_CELL cell = new global::FLOOR_CELL();
            floorCells.cellsDictionary = new Dictionary <int, FLOOR_CELL>();
            floorCells.cellsHashTable  = new Hashtable();

            var cellCount = br.ReadInt32();
            for (int i = 0; i < cellCount; ++i)
            {
                var key = br.ReadInt32();
                cell.cellInfo = br.ReadInt32();

                floorCells.cellsDictionary.Add(key, cell);
                floorCells.cellsHashTable.Add(key, cell);
            }

            var heightCount = br.ReadInt32();
            floorCells.heightsArray = new float[heightCount];
            for (int i = 0; i < heightCount; ++i)
            {
                floorCells.heightsArray[i] = ToFloatHeight(br.ReadUInt16(), floorCells.Config.fBoundMin, floorCells.Config.fBoundMax);
            }
        }

        return(floorCells);
    }
Exemple #2
0
    public static void Main()
    {
        float[] elapsed = { .0f, 0.0f };

        FloorCells cells = LoadCellFile("DXC_HomeTown");
        const int  N     = 9000000;

        Random    rand       = new Random();
        float     height     = .0f;
        int       groundType = 0;
        Vector3   pos        = new Vector3();
        Stopwatch sw         = Stopwatch.StartNew();

        sw.Start();
        cells.useHashTable = true;
        for (int i = 0; i < N; ++i)
        {
            pos.x = (float)rand.NextDouble() * cells.Config.nWidth * cells.Config.fCellSize + cells.Config.fMinX;
            pos.z = (float)rand.NextDouble() * cells.Config.nHeight * cells.Config.fCellSize + cells.Config.fMinZ;
            cells.GetFloor(pos, ref height, ref groundType);
        }
        sw.Stop();
        elapsed[0] = sw.ElapsedMilliseconds;

        sw.Reset();
        sw.Start();
        cells.useHashTable = false;
        for (int i = 0; i < N; ++i)
        {
            pos.x = (float)rand.NextDouble() * cells.Config.nWidth * cells.Config.fCellSize + cells.Config.fMinX;
            pos.z = (float)rand.NextDouble() * cells.Config.nHeight * cells.Config.fCellSize + cells.Config.fMinZ;
            cells.GetFloor(pos, ref height, ref groundType);
        }
        sw.Stop();
        elapsed[1] = sw.ElapsedMilliseconds;

        Console.WriteLine("Hash:{0}, Dict:{1}", elapsed[0], elapsed[1]);
    }