Example #1
0
        public unsafe                                  CubeGrid32x32x32UnsafePtr this[int x, int y, int z]
        {
            get
            {
                var i3    = new int3(x, y, z) + 1;
                var yspan = this.wholeGridLength.x * this.wholeGridLength.z;
                var zspan = this.wholeGridLength.x;
                var i     = i3.y * yspan + i3.z * zspan + i3.x;

                var grid = this.grids[i];

                if (!grid.p->IsFullOrEmpty)
                {
                    return(grid);
                }

                if (grid.p == this.defaultFilledCubePtr.p | grid.p == this.defaultBlankCubePtr.p)
                {
                    var newGrid = new CubeGrid32x32x32Unsafe(isFillAll: grid.p->IsFull);
                    this.gridStock.AddNoResize(newGrid);  // アドレスを変化させてはいけないので、拡張してはいけない。

                    return(this.grids[i] = new CubeGrid32x32x32UnsafePtr
                    {
                        p = (CubeGrid32x32x32Unsafe *)this.gridStock.GetUnsafePtr() + (this.gridStock.Length - 1)
                    });
                }

                return(grid);
            }
        }
Example #2
0
        static public CubeGrid32x32x32Unsafe GetDefault(bool isFillAll)
        {
            //var align = UnsafeUtility.AlignOf<uint4>();
            const int align = 16;
            //const int size = sizeof( uint ) * 4;
            const int size = sizeof(uint) * 1 * 32 * 32;

            var grid = new CubeGrid32x32x32Unsafe();

            grid.alloc_(size, align, isFillAll);

            return(grid);
        }
Example #3
0
        public CubeGridArrayUnsafe(int x, int y, int z) : this()
        {
            this.GridLength      = new int3(x, y, z);
            this.wholeGridLength = new int3(x, y, z) + 2;

            this.gridStock = allocGridStock_(this.GridLength);
            this.grids     = allocGrids_(this.wholeGridLength);

            makeDefaultGrids_(ref this);

            var startGrid = new int3(-1, -1, -1);
            var endGrid   = wholeGridLength;

            this.FillCubes(startGrid, endGrid, isFillAll: false);

            return;


            NativeArray <CubeGrid32x32x32UnsafePtr> allocGrids_(int3 wholeGridLength)
            {
                var totalLength = wholeGridLength.x * wholeGridLength.y * wholeGridLength.z;

                return(new NativeArray <CubeGrid32x32x32UnsafePtr>(totalLength, Allocator.Persistent));
            }

            NativeList <CubeGrid32x32x32Unsafe> allocGridStock_(int3 gridLength)
            {
                var capacity = gridLength.x * gridLength.y * gridLength.z + 2;// +2 はデフォルト分

                return(new NativeList <CubeGrid32x32x32Unsafe>(capacity, Allocator.Persistent));
            }

            void makeDefaultGrids_(ref CubeGridArrayUnsafe ga)
            {
                ga.gridStock.AddNoResize(CubeGrid32x32x32Unsafe.GetDefault(isFillAll: false));
                ga.defaultBlankCubePtr = new CubeGrid32x32x32UnsafePtr
                {
                    p = (CubeGrid32x32x32Unsafe *)ga.gridStock.GetUnsafePtr() + 0
                };

                ga.gridStock.AddNoResize(CubeGrid32x32x32Unsafe.GetDefault(isFillAll: true));
                ga.defaultFilledCubePtr = new CubeGrid32x32x32UnsafePtr
                {
                    p = (CubeGrid32x32x32Unsafe *)ga.gridStock.GetUnsafePtr() + 1
                };
            }
        }