Inheritance: IVoxelChannel
Exemple #1
0
        public IVoxelChannel MakeCopy()
        {
            VoxelChannel vc = new VoxelChannel(XScale, YScale, ZScale);

            vc.Voxels = Voxels;
            return(vc);
        }
Exemple #2
0
        static public VoxelChannel AND(VoxelChannel a, VoxelChannel b, ReplaceMode rep)
        {
            int x, y, z;

            for (z = 0; z < a.ZScale; z++)
            {
                for (y = 0; y < a.YScale; y++)
                {
                    for (x = 0; x < a.XScale; x++)
                    {
                        bool As = a.IsSolid(x, y, z);
                        bool Bs = b.IsSolid(x, y, z);
                        if (As && Bs)
                        {
                            a.SetVoxel(x, y, z, b.GetVoxel(x, y, z));
                        }
                    }
                }
            }
            return(a);
        }
Exemple #3
0
        /// <summary>
        /// Loads the World heightmap
        /// </summary>
        public override void LoadWorldMap()
        {
			uint sz=Constants.RegionSize;
			Voxels=new VoxelChannel(sz,sz,256);
            try
            {
                Voxels.Load(RegionInfo.RegionID.ToString());  	
            }
            catch (IOException)
            {
				m_log.Info("[TERRAIN]: No default terrain. Generating a new terrain.");
                Voxels = new VoxelChannel(sz, sz, 256);
                Voxels.Generate("default", GenerationSeed, (long)RegionInfo.RegionLocX, (long)RegionInfo.RegionLocY);
                Voxels.Save(RegionInfo.RegionID.ToString());
				
                // Non standard region size.    If there's an old terrain in the database, it might read past the buffer
                #pragma warning disable 0162
                if ((int)Constants.RegionSize != 256)
                {
                    Voxels = new VoxelChannel(sz,sz,sz);

                    Voxels.Save(RegionInfo.RegionID.ToString());
                }
            }
            catch (Exception e)
            {
                m_log.Warn("[TERRAIN]: Scene.cs: LoadWorldMap() - Failed with exception " + e.ToString());
            }
        }
Exemple #4
0
        /// <summary>
        /// Loads a terrain file from a stream and installs it in the scene.
        /// </summary>
        /// <param name="filename">Filename to terrain file. Type is determined by extension.</param>
        /// <param name="stream"></param>
        public void LoadFromStream(string filename, Stream stream)
        {
            foreach (KeyValuePair<string, IVoxelFileHandler> loader in m_loaders)
            {
                if (filename.EndsWith(loader.Key))
                {
                    lock (m_scene)
                    {
                        try
                        {
                            IVoxelChannel channel = loader.Value.LoadStream(stream);
                            m_scene.Voxels = channel;
                            m_channel = (VoxelChannel)channel;
                            UpdateRevertMap();
                        }
                        catch (NotImplementedException)
                        {
                            m_log.Error("[TERRAIN]: Unable to load voxelmap, the " + loader.Value +
                                        " parser does not support file loading. (May be save only)");
                            throw new Exception(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value));
                        }
                    }

                    CheckForTerrainUpdates();
                    m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully");
                    return;
                }
            }
            m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader available for that format.");
            throw new Exception(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename));
        }
Exemple #5
0
        //#region ITerrainModule Members

        public void UndoTerrain(IVoxelChannel channel)
        {
            m_channel = (VoxelChannel)channel;
        }
Exemple #6
0
        public void AddRegion(Scene scene)
        {
            m_scene = scene;

            // Install terrain module in the simulator
            lock (m_scene)
            {
                if (m_scene.Voxels == null)
                {
                    m_channel = new VoxelChannel(Constants.RegionSize,Constants.RegionSize,256);
                    m_revert = new VoxelChannel(Constants.RegionSize,Constants.RegionSize,256);
                    m_scene.Voxels = m_channel;
                    UpdateRevertMap();
                }
                else
                {
                    m_channel = (VoxelChannel)m_scene.Voxels;
                    m_revert = new VoxelChannel(Constants.RegionSize,Constants.RegionSize,256);
                    UpdateRevertMap();
                }

				
                m_scene.RegisterModuleInterface<VoxelModule>(this);
                m_scene.EventManager.OnNewClient += EventManager_OnNewClient;
                m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
                m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick;
				m_scene.EventManager.OnRegisterCaps += HandleM_sceneEventManagerOnRegisterCaps;
                InstallInterfaces();
            }

            //InstallDefaultEffects();
            //LoadPlugins();
        }
Exemple #7
0
		static public VoxelChannel AND(VoxelChannel a,VoxelChannel b,ReplaceMode rep)
		{
			int x,y,z;
			for(z=0;z<a.ZScale;z++)
			{
				for(y=0;y<a.YScale;y++)
				{
					for(x=0;x<a.XScale;x++)
					{
						bool As=a.IsSolid(x,y,z);
						bool Bs=b.IsSolid(x,y,z);
						if(As && Bs)
						{
							a.SetVoxel(x,y,z,b.GetVoxel(x,y,z));
						}
					}
				}
			}
			return a;
		}
Exemple #8
0
		public IVoxelChannel MakeCopy()
		{
			VoxelChannel vc = new VoxelChannel(XScale,YScale,ZScale);
			vc.Voxels=Voxels;
			return vc;
		}
Exemple #9
0
		public IVoxelChannel Load (string file)
		{
			VoxelChannel vc = new VoxelChannel(Constants.RegionSize,Constants.RegionSize,256);
            vc.LoadFromFile(file);
			return vc;
		}
Exemple #10
0
        /// <summary>
        /// From the VoxelSim project
        /// http://github.com/N3X15/VoxelSim
        /// </summary>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        /// <param name="chunksize"></param>
        /// <returns></returns>
        public void Generate(ref IVoxelChannel _mh, long X, long Y)
        {
            VoxelChannel mh = (VoxelChannel)_mh;

            m_log.InfoFormat("Generating terrain for a <{0},{1},{2}>m area.", mh.XScale, mh.YScale, mh.ZScale);

            bool PlaceGravel = ((GravelNoise.GetValue((X * mh.XScale), (Y * mh.YScale), 0) + 1) / 2.0) > 0.90d;

            int ZH = (int)mh.ZScale;

            byte[, ,] b = new byte[mh.XScale, mh.YScale, mh.ZScale];
            m_log.Debug("Stand by, generating terrain...");
            Console.WriteLine();
            for (int x = 0; x < mh.XScale; x++)
            {
                Console.CursorLeft = 0;
                Console.Write(" * Generating slice {0}/{1}... ({2}% complete)", x, mh.XScale, (int)System.Math.Round(((double)x / (double)mh.XScale) * 100d));
                for (int y = 0; y < mh.YScale; y++)
                {
                    for (int z = 0; z < ZH; z++)
                    {
                        int    intensity    = z * (255 / ZH);
                        double heightoffset = (ContinentNoise.GetValue(x + (X * mh.XScale), y + (Y * mh.YScale), 0) + 1d) / 2.0;
                        //Console.WriteLine("HeightOffset {0}",heightoffset);
                        //if (z == 0)
                        //    b[x, y, z] = 7;
                        ////else if (x == 0 && y == 0)
                        ////    b[x, y, z] = 1;
                        //else
                        //{
                        bool   d1  = ((TerrainNoise.GetValue(x + (X * mh.XScale), y + (Y * mh.YScale), z * TerrainDivisor) + 1) / 2.0) > System.Math.Pow((((double)z * (HeightDivisor + (heightoffset))) / (double)ZH), 3d);  // 3d
                        double _do = ((CaveNoise.GetValue(x + (X * mh.XScale), y + (Y * mh.YScale), z * CaveDivisor) + 1) / 2.0);
                        bool   d3  = _do > CaveThreshold;
                        // XOR?
                        if (d1)    //if (!(!d1 || !d2))
                        {
                            //Console.Write("#");
                            b[x, y, z] = (d3) ? b[x, y, z] : mMap.Rock.ID;
                            //if (x == 0|| y == 0)
                            //    b[x, y, z] = 41;
                        }
                        else if (z == 1)
                        {
                            b[x, y, z] = 11;
                        }
                        //}
                    }
                }
            }
            Console.WriteLine();
            //Console.WriteLine("Done generating chunk.  [{0},{1}]",min,max);
            for (int x = 0; x < mh.XScale; x++)
            {
                Console.CursorLeft = 0;
                Console.Write(" * Applying sediment to slice {0}/{1}... ({2}% complete)", x, mh.XScale, (int)System.Math.Round(((double)x / (double)mh.XScale) * 100d));
                //Console.WriteLine();
                for (int y = 0; y < mh.YScale; y++)
                {
                    bool HavePloppedGrass = false;
                    bool HaveTouchedSoil  = false;
                    for (int z = (int)mh.ZScale - 1; z > 0; z--)
                    {
                        if (b[x, y, z] == mMap.Rock.ID)
                        {
                            HaveTouchedSoil = true;
                            if (z + DERT_DEPTH >= ZH)
                            {
                                continue;
                            }
                            byte ddt = b[x, y, z + DERT_DEPTH];
                            if (ddt == mMap.Air.ID || ddt == mMap.Water.ID)
                            {
                                if (z - DERT_DEPTH <= WaterHeight && GenerateWater)
                                {
                                    b[x, y, z] = mMap.Sand.ID; // (!PlaceGravel) ? ...
                                }
                                else
                                {
                                    b[x, y, z] = (HavePloppedGrass) ? mMap.Soil.ID : mMap.Grass.ID;
                                }
                                if (!HavePloppedGrass)
                                {
                                    HavePloppedGrass = true;
                                }
                            }
                            else
                            {
                                z = 0;
                            }
                        }
                        else if (b[x, y, z] == 0 && z <= WaterHeight && !HaveTouchedSoil && GenerateWater)
                        {
                            b[x, y, z] = mMap.Water.ID;
                        }
                    }
                }
            }
            Console.WriteLine();

            /*
             * for (int x = 0; x < mh.XScale; x++)
             * {
             *  for (int y = 0; y < mh.YScale; y++)
             *  {
             *      int z = 1;
             *      // TODO Yell at Notch for not making Lava occlude. :|
             *      if (b[x, y, z] == 0)
             *          b[x, y, z] = mMap.Lava.ID; // Lava for air.
             *      else if (b[x, y, z] == mMap.Water.ID)
             *          b[x, y, z] = mMap.Obsidian.ID; // Obsidian for underwater shit.
             *  }
             * }
             */
            mh.SetTo(b);
        }