private static Vector3D?FindFreePlaceImproved(Vector3D pos, Quaternion orientation, Vector3 halfExtents, Vector3 gravity) { if (IsFreePlace(pos, orientation, halfExtents)) { return(pos); } var distanceStepSize = halfExtents.Length() / 10f; for (var distanceStep = 1; distanceStep <= 20; distanceStep++) { var distance = distanceStep * distanceStepSize; for (var attempt = 0; attempt < 50; attempt++) { var dir = MyUtils.GetRandomVector3HemisphereNormalized(-gravity); var testPos = pos + dir * distance; if (IsFreePlace(testPos, orientation, halfExtents)) { var planet = MyPlanets.GetPlanets()[0]; var centerVoxData = planet.WorldPositionToStorage(testPos); VoxelData.Resize(new Vector3I(1)); planet.Storage.ReadRange(VoxelData, MyStorageDataTypeFlags.Content, 0, centerVoxData, centerVoxData); return(testPos); } } } return(null); }
private void RefreshSectors() { foreach (var planet in MyPlanets.GetPlanets()) { var component = planet.Components.Get <MyPlanetEnvironmentComponent>(); component.CloseAll(); } }
public override void OnRemovedFromScene(object source) { base.OnRemovedFromScene(source); MyPlanets.UnRegister(this); MyGravityProviderSystem.RemoveNaturalGravityProvider(Components.Get <MyGravityProviderComponent>()); MyOxygenProviderSystem.RemoveOxygenGenerator(this); }
public override void OnAddedToScene(object source) { base.OnAddedToScene(source); MyPlanets.Register(this); MyGravityProviderSystem.AddNaturalGravityProvider(Components.Get <MyGravityProviderComponent>()); MyOxygenProviderSystem.AddOxygenGenerator(this); }
public override void OnRemovedFromScene(object source) { base.OnRemovedFromScene(source); MyPlanets.UnRegister(this); MyGravityProviderSystem.RemovePlanet(this); MyOxygenProviderSystem.RemoveOxygenGenerator(this); }
public override void OnAddedToScene(object source) { base.OnAddedToScene(source); MyPlanets.Register(this); MyGravityProviderSystem.AddPlanet(this); MyOxygenProviderSystem.AddOxygenGenerator(this); }
protected void WritePlanetSectors(BitStream stream) { stream.WriteInt32(PlanetMagic); var planets = MyPlanets.GetPlanets(); // Planets are not enabled if session component is not loaded. if (planets == null) { stream.WriteInt32(0); return; } stream.WriteInt32(planets.Count); foreach (var planet in planets) { stream.WriteInt64(planet.EntityId); MyPlanetEnvironmentComponent env = planet.Components.Get <MyPlanetEnvironmentComponent>(); var syncLod = env.EnvironmentDefinition.SyncLod; foreach (var provider in env.Providers) { foreach (var sector in provider.LogicalSectors) { if (sector.MinLod <= syncLod) { stream.WriteInt64(sector.Id); } } } // don't know how many in advance so I will use ~0 termination instead of count. stream.WriteInt64(~0); } }
private void WritePlanetSectors(BitStream stream) { stream.WriteInt32(0x42424242); var planets = MyPlanets.GetPlanets(); stream.WriteInt32(planets.Count); foreach (var planet in planets) { stream.WriteInt64(planet.EntityId); foreach (var sector in planet.EnvironmentSectors.Values) { if (sector.HasPhysics || sector.ServerOwned) { stream.WriteInt64(sector.SectorId.Pack64()); } } // don't know how many in advance so I will use -1 termination instead of count. stream.WriteInt64(-1); } }
private void UpdateViewRange(MyPlanet planet) { var pos = MySector.MainCamera.Position; double dist = double.MaxValue; foreach (var p in MyPlanets.GetPlanets()) { double dsq = Vector3D.DistanceSquared(pos, p.WorldMatrix.Translation); if (dsq < dist) { planet = p; dist = dsq; } } var radius = planet.MinimumRadius; double altitude; m_height = planet.MaximumRadius - radius; var center = planet.WorldMatrix.Translation; m_radius = HyperSphereHelpers.DistanceToTangentProjected(ref center, ref pos, radius, out altitude); var up = center - pos; up.Normalize(); m_center = pos + up * altitude; var forward = Vector3D.CalculatePerpendicularVector(up); m_orientation = QuaternionD.CreateFromForwardUp(forward, up); }
public SpaceEngineersCore() { var contentPath = ToolboxUpdater.GetApplicationContentPath(); string userDataPath = SpaceEngineersConsts.BaseLocalPath.DataPath; MyFileSystem.ExePath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(FastResourceLock)).Location); MyLog.Default = MySandboxGame.Log; SpaceEngineersGame.SetupBasicGameInfo(); _startup = new MyCommonProgramStartup(new string[] { }); //var appDataPath = _startup.GetAppDataPath(); //MyInitializer.InvokeBeforeRun(AppId, MyPerGameSettings.BasicGameInfo.ApplicationName + "SEToolbox", appDataPath); //MyInitializer.InitCheckSum(); MyFileSystem.Reset(); MyFileSystem.Init(contentPath, userDataPath); // This will start the Steam Service, and Steam will think SE is running. // TODO: we don't want to be doing this all the while SEToolbox is running, // perhaps a once off during load to fetch of mods then disconnect/Dispose. _steamService = MySteamGameService.Create(MySandboxGame.IsDedicated, AppId); MyServiceManager.Instance.AddService(_steamService); IMyUGCService ugc = MySteamUgcService.Create(AppId, _steamService); //MyServiceManager.Instance.AddService(ugc); MyGameService.WorkshopService.AddAggregate(ugc); MyFileSystem.InitUserSpecific(_steamService.UserId.ToString()); // This sets the save file/path to load games from. //MyFileSystem.InitUserSpecific(null); //SpaceEngineersWorkshop.MySteam.Dispose(); MySandboxGame.Config = new MyConfig("SpaceEngineers.cfg"); // TODO: Is specific to SE, not configurable to ME. MySandboxGame.Config.Load(); SpaceEngineersGame.SetupPerGameSettings(); VRage.MyVRage.Init(new ToolboxPlatform()); VRage.MyVRage.Platform.Init(); MySandboxGame.InitMultithreading(); VRageRender.MyRenderProxy.Initialize(new MyNullRender()); // We create a whole instance of MySandboxGame! // If this is causing an exception, then there is a missing dependency. MySandboxGame gameTemp = new DerivedGame(new string[] { "-skipintro" }); // creating MySandboxGame will reset the CurrentUICulture, so I have to reapply it. Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode); SpaceEngineersApi.LoadLocalization(); MyStorageBase.UseStorageCache = false; // Create an empty instance of MySession for use by low level code. var mySession = (Sandbox.Game.World.MySession)FormatterServices.GetUninitializedObject(typeof(Sandbox.Game.World.MySession)); // Required as the above code doesn't populate it during ctor of MySession. ReflectionUtil.ConstructField(mySession, "CreativeTools"); ReflectionUtil.ConstructField(mySession, "m_sessionComponents"); ReflectionUtil.ConstructField(mySession, "m_sessionComponentsForUpdate"); mySession.Settings = new MyObjectBuilder_SessionSettings { EnableVoxelDestruction = true }; // change for the Clone() method to use XML cloning instead of Protobuf because of issues with MyObjectBuilder_CubeGrid.Clone() ReflectionUtil.SetFieldValue(typeof(VRage.ObjectBuilders.MyObjectBuilderSerializer), "ENABLE_PROTOBUFFERS_CLONING", false); // Assign the instance back to the static. Sandbox.Game.World.MySession.Static = mySession; var heightMapLoadingSystem = new MyHeightMapLoadingSystem(); mySession.RegisterComponent(heightMapLoadingSystem, heightMapLoadingSystem.UpdateOrder, heightMapLoadingSystem.Priority); heightMapLoadingSystem.LoadData(); var planets = new MyPlanets(); mySession.RegisterComponent(planets, heightMapLoadingSystem.UpdateOrder, heightMapLoadingSystem.Priority); planets.LoadData(); _stockDefinitions = new SpaceEngineersResources(); _stockDefinitions.LoadDefinitions(); _manageDeleteVoxelList = new List <string>(); }