Exemple #1
0
        public bool Get(int x, int y, int z, out IBiomeData chunk)
        {
            if (_allocSize == 0)
            {
                chunk = null;
                return(false);
            }

            var index = HashInt(x, y, z) & _allocSize;
            var entry = _data[index];

            while (entry != null)
            {
                var pos = entry.position;
                if (pos.x == x && pos.y == y && pos.z == z)
                {
                    chunk = entry.value;
                    return(chunk != null);
                }

                index = (index + 1) & _allocSize;
                entry = _data[index];
            }

            chunk = null;
            return(false);
        }
        public IBiomeData BuildBiomeIfNotExist(int x, int y, int z)
        {
            Debug.Assert(model.settings.biomeNull != null);

            IBiomeData biomeData = null;

            if (this.Biomes.Get(x, y, z, out biomeData))
            {
                return(biomeData);
            }

            foreach (var it in _biomeGenerators)
            {
                biomeData = it.OnBuildBiome(x, y, z);
                if (biomeData != null)
                {
                    break;
                }
            }

            if (biomeData == null)
            {
                biomeData = model.settings.biomeNull;
            }

            model.settings.biomeManager.Set(x, y, z, biomeData);
            return(biomeData);
        }
Exemple #3
0
        public bool Set(int x, int y, int z, IBiomeData value)
        {
            lock (this)
            {
                if (_allocSize == 0)
                {
                    this.Create(0xFF);
                }

                var index = HashInt(x, y, z) & _allocSize;
                var entry = _data[index];

                while (entry != null)
                {
                    var pos = entry.position;
                    if (pos.x == x && pos.y == y && pos.z == z)
                    {
                        _data[index].value = value;
                        return(true);
                    }

                    index = (index + 1) & _allocSize;
                    entry = _data[index];
                }

                if (value != null)
                {
                    _data[index] = new BiomeDataNode <Vector3 <int>, IBiomeData>(new Vector3 <int>(x, y, z), value);
                    _count++;

                    if (_count >= _allocSize)
                    {
                        this.Grow();
                    }

                    return(true);
                }

                return(false);
            }
        }
        public void CreateChunk(IPlayer player, int x, int y, int z)
        {
            ChunkPrimer chunk = null;

            if (_callbacks.OnLoadChunkBefore != null)
            {
                _callbacks.OnLoadChunkBefore(x, y, z, ref chunk);
            }

            if (chunk == null)
            {
                IBiomeData biomeData = context.behaviour.biomeManager.BuildBiomeIfNotExist(x, y, z);
                if (biomeData != null)
                {
                    if (chunk == null)
                    {
                        chunk = biomeData.OnBuildChunk(this.context.behaviour, x, y, z);
                    }
                }
            }

            if (chunk == null)
            {
                chunk = new ChunkPrimer(model.settings.chunkSize, x, y, z);
            }

            if (_callbacks.OnLoadChunkAfter != null)
            {
                _callbacks.OnLoadChunkAfter(chunk);
            }

            this.manager.Set(x, y, z, chunk);

            if (chunk.voxels.Count > 0)
            {
                _deferredUpdater.Enqueue(chunk);
            }
        }
Exemple #5
0
 public bool Set(Vector3 <int> pos, IBiomeData value)
 {
     return(Set(pos.x, pos.y, pos.z, value));
 }
Exemple #6
0
        public bool Exists(int x, int y, int z)
        {
            IBiomeData instanceID = null;

            return(this.Get(x, y, z, out instanceID));
        }
Exemple #7
0
 public bool Get(Vector3 <int> pos, out IBiomeData instanceID)
 {
     return(this.Get(pos.x, pos.y, pos.z, out instanceID));
 }