public override void Init(MyObjectBuilder_EntityBase builder, Sandbox.Engine.Voxels.IMyStorage storage)
        {
            ProfilerShort.Begin("MyPlanet::Init()");
            if (MyFakes.ENABLE_PLANETS == false)
            {
                throw new PlanetsNotEnabledException();
            }

            ProfilerShort.Begin("MyVoxelBase Init");

            SyncFlag = true;

            base.Init(builder);

            ProfilerShort.BeginNextBlock("Load Saved Data");

            var ob = (MyObjectBuilder_Planet)builder;

            if (ob == null)
            {
                return;
            }

            MyLog.Default.WriteLine("Planet init info - MutableStorage:" + ob.MutableStorage + " StorageName:" + ob.StorageName + " storage?:" + (storage != null).ToString());

            if (ob.MutableStorage)
            {
                StorageName = ob.StorageName;
            }
            else
            {
                StorageName = string.Format("{0}", ob.StorageName);
            }

            m_planetInitValues.StorageName           = StorageName;
            m_planetInitValues.PositionMinCorner     = ob.PositionAndOrientation.Value.Position;
            m_planetInitValues.HasAtmosphere         = ob.HasAtmosphere;
            m_planetInitValues.AtmosphereRadius      = ob.AtmosphereRadius;
            m_planetInitValues.AtmosphereWavelengths = ob.AtmosphereWavelengths;
            m_planetInitValues.GravityFalloff        = ob.GravityFalloff;
            m_planetInitValues.MarkAreaEmpty         = ob.MarkAreaEmpty;
            m_planetInitValues.SurfaceGravity        = ob.SurfaceGravity;
            m_planetInitValues.AddGps = ob.ShowGPS;
            m_planetInitValues.SpherizeWithDistance = ob.SpherizeWithDistance;
            m_planetInitValues.Generator            = ob.PlanetGenerator == ""
                ? null
                : MyDefinitionManager.Static.GetDefinition <MyPlanetGeneratorDefinition>(
                MyStringHash.GetOrCompute(ob.PlanetGenerator));
            if (m_planetInitValues.Generator == null)
            {
                string message = string.Format("No definition found for planet generator {0}.", ob.PlanetGenerator);
                MyLog.Default.WriteLine(message);
                throw new MyIncompatibleDataException(message);
            }

            m_planetInitValues.AtmosphereSettings = m_planetInitValues.Generator.AtmosphereSettings.HasValue
                ? m_planetInitValues.Generator.AtmosphereSettings.Value
                : MyAtmosphereSettings.Defaults();
            m_planetInitValues.UserCreated = false;

            ProfilerShort.BeginNextBlock("Load Storage");
            if (storage != null)
            {
                m_planetInitValues.Storage = storage;
            }
            else
            {
                m_planetInitValues.Storage = MyStorageBase.Load(ob.StorageName);

                if (m_planetInitValues.Storage == null)
                {
                    string message = string.Format("No storage loaded for planet {0}.", ob.StorageName);
                    MyLog.Default.WriteLine(message);
                    throw new MyIncompatibleDataException(message);
                }
            }

            m_planetInitValues.InitializeComponents = false;

            ProfilerShort.BeginNextBlock("Init Internal");

            // MZ: if any crashes are related to MP planet init in the future, i added logging of MyPlanetInitArguments and other sanity checks.
            //     we are currently having crashes without this additional info and it is likely that even after my hotfixes it is going to crash again
            //     ...but we can check the logs and know the setup of the player :)
            MyLog.Default.Log(MyLogSeverity.Info, "Planet generator name: {0}", ob.PlanetGenerator ?? "<null>");

            // Initialize!
            Init(m_planetInitValues);

            ProfilerShort.End();

            ProfilerShort.End();
        }
Exemple #2
0
        public override void Init(MyObjectBuilder_EntityBase builder, Sandbox.Engine.Voxels.IMyStorage storage)
        {
            ProfilerShort.Begin("MyPlanet::Init()");
            if (MyFakes.ENABLE_PLANETS == false)
            {
                throw new PlanetsNotEnabledException();
            }

            ProfilerShort.Begin("MyVoxelBase Init");

            SyncFlag = true;

            base.Init(builder);

            ProfilerShort.BeginNextBlock("Load Saved Data");

            var ob = (MyObjectBuilder_Planet)builder;

            if (ob == null)
            {
                return;
            }

            if (ob.MutableStorage)
            {
                StorageName = ob.StorageName;
            }
            else
            {
                StorageName = string.Format("{0}", ob.StorageName);
            }

            m_planetInitValues.StorageName           = StorageName;
            m_planetInitValues.PositionMinCorner     = ob.PositionAndOrientation.Value.Position;
            m_planetInitValues.HasAtmosphere         = ob.HasAtmosphere;
            m_planetInitValues.AtmosphereRadius      = ob.AtmosphereRadius;
            m_planetInitValues.AtmosphereWavelengths = ob.AtmosphereWavelengths;
            m_planetInitValues.GravityFalloff        = ob.GravityFalloff;
            m_planetInitValues.MarkAreaEmpty         = ob.MarkAreaEmpty;
            m_planetInitValues.SurfaceGravity        = ob.SurfaceGravity;
            m_planetInitValues.AddGps = ob.ShowGPS;
            m_planetInitValues.SpherizeWithDistance = ob.SpherizeWithDistance;
            m_planetInitValues.Generator            = ob.PlanetGenerator == "" ? null : MyDefinitionManager.Static.GetDefinition <MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(ob.PlanetGenerator));
            if (m_planetInitValues.Generator == null)
            {
                string message = string.Format("No definition found for planet generator {0}.", ob.PlanetGenerator);
                MyLog.Default.WriteLine(message);
                throw new Exception(message);
            }

            m_planetInitValues.AtmosphereSettings = m_planetInitValues.Generator.AtmosphereSettings.HasValue ? m_planetInitValues.Generator.AtmosphereSettings.Value : MyAtmosphereSettings.Defaults();
            m_planetInitValues.UserCreated        = false;

            ProfilerShort.BeginNextBlock("Load Storage");
            if (storage != null)
            {
                m_planetInitValues.Storage = storage;
            }
            else
            {
                m_planetInitValues.Storage = MyStorageBase.Load(ob.StorageName);
            }

            ProfilerShort.BeginNextBlock("Init Internal");
            Init(m_planetInitValues);
            ProfilerShort.End();

            ProfilerShort.End();
        }
Exemple #3
0
        private static MyPlanet CreatePlanet(string storageName, string planetName, ref Vector3D positionMinCorner, int seed, float size, long entityId, ref MyPlanetGeneratorDefinition generatorDef, bool addGPS, bool userCreated = false)
        {
            if (MyFakes.ENABLE_PLANETS == false)
            {
                return(null);
            }

            var random = MyRandom.Instance;

            using (MyRandom.Instance.PushSeed(seed))
            {
                MyPlanetStorageProvider provider = new MyPlanetStorageProvider();
                provider.Init(seed, generatorDef, size / 2f);

                IMyStorage storage = new MyOctreeStorage(provider, provider.StorageSize);

                float minHillSize = provider.Radius * generatorDef.HillParams.Min;
                float maxHillSize = provider.Radius * generatorDef.HillParams.Max;

                float averagePlanetRadius = provider.Radius;

                float outerRadius = averagePlanetRadius + maxHillSize;
                float innerRadius = averagePlanetRadius + minHillSize;

                float atmosphereRadius = generatorDef.AtmosphereSettings.HasValue && generatorDef.AtmosphereSettings.Value.Scale > 1f ? 1 + generatorDef.AtmosphereSettings.Value.Scale : 1.75f;
                atmosphereRadius *= provider.Radius;

                float redAtmosphereShift   = random.NextFloat(generatorDef.HostileAtmosphereColorShift.R.Min, generatorDef.HostileAtmosphereColorShift.R.Max);
                float greenAtmosphereShift = random.NextFloat(generatorDef.HostileAtmosphereColorShift.G.Min, generatorDef.HostileAtmosphereColorShift.G.Max);
                float blueAtmosphereShift  = random.NextFloat(generatorDef.HostileAtmosphereColorShift.B.Min, generatorDef.HostileAtmosphereColorShift.B.Max);

                Vector3 atmosphereWavelengths = new Vector3(0.650f + redAtmosphereShift, 0.570f + greenAtmosphereShift, 0.475f + blueAtmosphereShift);

                atmosphereWavelengths.X = MathHelper.Clamp(atmosphereWavelengths.X, 0.1f, 1.0f);
                atmosphereWavelengths.Y = MathHelper.Clamp(atmosphereWavelengths.Y, 0.1f, 1.0f);
                atmosphereWavelengths.Z = MathHelper.Clamp(atmosphereWavelengths.Z, 0.1f, 1.0f);

                var planet = new MyPlanet();
                planet.EntityId = entityId;

                MyPlanetInitArguments planetInitArguments;
                planetInitArguments.StorageName           = storageName;
                planetInitArguments.Storage               = storage;
                planetInitArguments.PositionMinCorner     = positionMinCorner;
                planetInitArguments.Radius                = provider.Radius;
                planetInitArguments.AtmosphereRadius      = atmosphereRadius;
                planetInitArguments.MaxRadius             = outerRadius;
                planetInitArguments.MinRadius             = innerRadius;
                planetInitArguments.HasAtmosphere         = generatorDef.HasAtmosphere;
                planetInitArguments.AtmosphereWavelengths = atmosphereWavelengths;
                planetInitArguments.GravityFalloff        = generatorDef.GravityFalloffPower;
                planetInitArguments.MarkAreaEmpty         = true;
                planetInitArguments.AtmosphereSettings    = generatorDef.AtmosphereSettings.HasValue ? generatorDef.AtmosphereSettings.Value : MyAtmosphereSettings.Defaults();
                planetInitArguments.SurfaceGravity        = generatorDef.SurfaceGravity;
                planetInitArguments.AddGps                = addGPS;
                planetInitArguments.SpherizeWithDistance  = true;
                planetInitArguments.Generator             = generatorDef;
                planetInitArguments.UserCreated           = userCreated;

                planet.Init(planetInitArguments);

                MyEntities.Add(planet);
                MyEntities.RaiseEntityCreated(planet);

                return(planet);
            }
            return(null);
        }
Exemple #4
0
        public static void AddPlanetPrefab(string planetName, string definitionName, Vector3D position, bool addGPS)
        {
            DictionaryValuesReader <MyDefinitionId, MyPlanetPrefabDefinition> planetPrefabDefinitions = MyDefinitionManager.Static.GetPlanetsPrefabsDefinitions();

            foreach (var planetPrefabDefinition in planetPrefabDefinitions)
            {
                if (planetPrefabDefinition.Id.SubtypeName == planetName)
                {
                    MyPlanetGeneratorDefinition planetDefinition = MyDefinitionManager.Static.GetDefinition <MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(definitionName));

                    var planet = new MyPlanet();
                    var ob     = planetPrefabDefinition.PlanetBuilder;

                    string storageName = MyFileSystem.ContentPath + "\\VoxelMaps\\" + ob.StorageName + MyVoxelConstants.FILE_EXTENSION;
                    planet.EntityId = ob.EntityId;

                    MyPlanetInitArguments planetInitArguments;
                    planetInitArguments.StorageName           = ob.StorageName;
                    planetInitArguments.Storage               = MyStorageBase.LoadFromFile(storageName);
                    planetInitArguments.PositionMinCorner     = position;
                    planetInitArguments.Radius                = ob.Radius;
                    planetInitArguments.AtmosphereRadius      = ob.AtmosphereRadius;
                    planetInitArguments.MaxRadius             = ob.MaximumHillRadius;
                    planetInitArguments.MinRadius             = ob.MinimumSurfaceRadius;
                    planetInitArguments.HasAtmosphere         = planetDefinition.HasAtmosphere;
                    planetInitArguments.AtmosphereWavelengths = ob.AtmosphereWavelengths;
                    planetInitArguments.GravityFalloff        = planetDefinition.GravityFalloffPower;
                    planetInitArguments.MarkAreaEmpty         = true;
                    planetInitArguments.AtmosphereSettings    = ob.AtmosphereSettings.HasValue ? ob.AtmosphereSettings.Value : MyAtmosphereSettings.Defaults();
                    planetInitArguments.SurfaceGravity        = planetDefinition.SurfaceGravity;
                    planetInitArguments.AddGps                = addGPS;
                    planetInitArguments.SpherizeWithDistance  = true;
                    planetInitArguments.Generator             = planetDefinition;
                    planetInitArguments.UserCreated           = false;

                    planet.Init(planetInitArguments);
                    MyEntities.Add(planet);
                    MyEntities.RaiseEntityCreated(planet);
                }
            }
        }
        private void CreatePlanet(int seed, float size)
        {
            Vector3D pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * size * 3 - new Vector3D(size);

            MyPlanetGeneratorDefinition planetDefinition = MyDefinitionManager.Static.GetDefinition <MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(m_selectedPlanetName));
            MyPlanetStorageProvider     provider         = new MyPlanetStorageProvider();

            provider.Init(seed, planetDefinition, size / 2f);

            IMyStorage storage = new MyOctreeStorage(provider, provider.StorageSize);

            float minHillSize = provider.Radius * planetDefinition.HillParams.Min;
            float maxHillSize = provider.Radius * planetDefinition.HillParams.Max;

            float averagePlanetRadius = provider.Radius;

            float outerRadius = averagePlanetRadius + maxHillSize;
            float innerRadius = averagePlanetRadius + minHillSize;

            float atmosphereRadius = planetDefinition.AtmosphereSettings.HasValue && planetDefinition.AtmosphereSettings.Value.Scale > 1f ? 1 + planetDefinition.AtmosphereSettings.Value.Scale : 1.75f;

            atmosphereRadius *= provider.Radius;

            var planet = new MyPlanet();

            planet.EntityId = MyRandom.Instance.NextLong();

            MyPlanetInitArguments planetInitArguments;

            planetInitArguments.StorageName           = "test";
            planetInitArguments.Storage               = storage;
            planetInitArguments.PositionMinCorner     = pos;
            planetInitArguments.Radius                = provider.Radius;
            planetInitArguments.AtmosphereRadius      = atmosphereRadius;
            planetInitArguments.MaxRadius             = outerRadius;
            planetInitArguments.MinRadius             = innerRadius;
            planetInitArguments.HasAtmosphere         = planetDefinition.HasAtmosphere;
            planetInitArguments.AtmosphereWavelengths = Vector3.Zero;
            planetInitArguments.GravityFalloff        = planetDefinition.GravityFalloffPower;
            planetInitArguments.MarkAreaEmpty         = true;
            planetInitArguments.AtmosphereSettings    = planetDefinition.AtmosphereSettings.HasValue ? planetDefinition.AtmosphereSettings.Value : MyAtmosphereSettings.Defaults();
            planetInitArguments.SurfaceGravity        = planetDefinition.SurfaceGravity;
            planetInitArguments.AddGps                = false;
            planetInitArguments.SpherizeWithDistance  = true;
            planetInitArguments.Generator             = planetDefinition;
            planetInitArguments.UserCreated           = true;

            planet.Init(planetInitArguments);

            m_lastAsteroidInfo = new SpawnAsteroidInfo()
            {
                Asteroid         = null,
                RandomSeed       = seed,
                Position         = Vector3D.Zero,
                IsProcedural     = true,
                ProceduralRadius = size,
            };

            MyCubeBuilder.Static.ActivateVoxelClipboard(planet.GetObjectBuilder(), storage, MySector.MainCamera.ForwardVector, (storage.Size * 0.5f).Length());
        }
 void OnResetButtonClicked(MyGuiControlButton button)
 {
     m_atmosphereSettings = MyAtmosphereSettings.Defaults();
     RecreateControls(false);
     UpdateAtmosphere();
 }