public void MarkCellsDirty(BoundingSphereD toMark, BoundingSphereD?toExclude = null, bool scale = true) { BoundingSphereD toMarkScaled = new BoundingSphereD(toMark.Center, toMark.Radius * (scale ? SCALE : 1)); BoundingSphereD toExcludeScaled = new BoundingSphereD(); if (toExclude.HasValue) { toExcludeScaled = toExclude.Value; if (scale) { toExcludeScaled.Radius *= SCALE; } } ProfilerShort.Begin("Mark dirty cells"); Vector3I cellId = Vector3I.Floor((toMarkScaled.Center - toMarkScaled.Radius) / CELL_SIZE); for (var iter = GetCellsIterator(toMarkScaled); iter.IsValid(); iter.GetNext(out cellId)) { MyProceduralCell cell; if (m_cells.TryGetValue(cellId, out cell)) { if (!toExclude.HasValue || toExcludeScaled.Contains(cell.BoundingVolume) == ContainmentType.Disjoint) { m_dirtyCells.Add(cell); } } } ProfilerShort.End(); }
public static void StartDebugWave(Vector3 pos) { m_currentTarget = new BoundingSphereD(pos, 100); m_meteorcount = (int)(Math.Pow(m_currentTarget.Value.Radius, 2) * Math.PI / 3000); m_meteorcount /= (MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.CATACLYSM || MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.CATACLYSM_UNREAL) ? 1 : 8; m_meteorcount = MathHelper.Clamp(m_meteorcount, 1, 40); StartWave(); }
static void UpdateShowerTarget([Serialize(MyObjectFlags.Nullable)] BoundingSphereD?target) { if (target.HasValue) { MyMeteorShower.CurrentTarget = new BoundingSphereD(target.Value.Center, target.Value.Radius); } else { MyMeteorShower.CurrentTarget = null; } }
protected override void UnloadData() { foreach (var meteor in m_meteorList) { if (!meteor.MarkedForClose) meteor.Close(); } m_meteorList.Clear(); m_currentTarget = null; m_targetList.Clear(); base.UnloadData(); }
protected override void UnloadData() { foreach (var meteor in m_meteorList) { if (!meteor.MarkedForClose) { meteor.Close(); } } m_meteorList.Clear(); m_currentTarget = null; m_targetList.Clear(); base.UnloadData(); }
private static void RescheduleEvent(object senderEvent) { if (m_waveCounter > WAVES_IN_SHOWER) { TimeSpan time = CalculateShowerTime(MySession.Static.EnvironmentHostility); MyGlobalEvents.RescheduleEvent((MyGlobalEventBase)senderEvent, time); m_waveCounter = -1; m_currentTarget = null; MySyncMeteorShower.UpdateShowerTarget(m_currentTarget); } else { TimeSpan nextWave = TimeSpan.FromSeconds(m_meteorcount / 5f + MyUtils.GetRandomFloat(2, 5)); MyGlobalEvents.RescheduleEvent((MyGlobalEventBase)senderEvent, nextWave); } }
/// <summary> /// Marks all cells inside of the toUnload bounding sphere to be unloaded, except all Objects inside toExclude. /// </summary> /// <param name="toUnload">Unload sphere</param> /// <param name="toExclude">Exclude sphere</param> public void MarkToUnloadCells(BoundingSphereD toUnload, BoundingSphereD?toExclude = null) { Vector3I cellId = Vector3I.Floor((toUnload.Center - toUnload.Radius) / CELL_SIZE); for (var iter = GetCellsIterator(toUnload); iter.IsValid(); iter.GetNext(out cellId)) { MyProceduralCell cell; if (m_cells.TryGetValue(cellId, out cell)) { if (toExclude == null || !toExclude.HasValue || toExclude.Value.Contains(cell.BoundingVolume) == ContainmentType.Disjoint) { m_toUnloadCells.Add(cell); } } } }
private static void MeteorWaveInternal(object senderEvent) { if (MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.SAFE) { Debug.Assert(false, "Meteor shower shouldnt be enabled in safe enviroment"); ((MyGlobalEventBase)senderEvent).Enabled = false; return; } if (Sync.IsServer == false) { return; } m_waveCounter++; SetupDirVectors(); if (m_waveCounter == 0) { ClearMeteorList(); if (m_targetList.Count == 0) { GetTargets(); if (m_targetList.Count == 0) { m_waveCounter = WAVES_IN_SHOWER + 1; RescheduleEvent(senderEvent); return; } } m_currentTarget = m_targetList.ElementAt(MyUtils.GetRandomInt(m_targetList.Count - 1)); MyMultiplayer.RaiseStaticEvent(x => UpdateShowerTarget, m_currentTarget); m_targetList.Remove(m_currentTarget.Value); m_meteorcount = (int)(Math.Pow(m_currentTarget.Value.Radius, 2) * Math.PI / 3000); m_meteorcount /= (MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.CATACLYSM || MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.CATACLYSM_UNREAL) ? 1 : 10; m_meteorcount = MathHelper.Clamp(m_meteorcount, 1, 60); } RescheduleEvent(senderEvent); CheckTargetValid(); if (m_waveCounter < 0) { return; } StartWave(); }
public override IEnumerable <ProceduralObject> Generate(BoundingSphereD include, BoundingSphereD?exclude) { var mult = _config.ViewDistance / include.Radius; include.Radius *= mult; if (exclude.HasValue) { exclude = new BoundingSphereD(exclude.Value.Center, exclude.Value.Radius * mult); } var min = Vector3D.Floor((include.Center - include.Radius) / _config.SystemSpacing); var max = Vector3D.Floor(((include.Center + include.Radius) / _config.SystemSpacing) + 1.0D); for (var x = min.X; x < max.X; x++) { for (var y = min.Y; y < max.Y; y++) { for (var z = min.Z; z < max.Z; z++) { var seedVec = new Vector3I(x, y, z); var seed = seedVec.GetHashCode(); var rand = new Random(seed); if (rand.NextDouble() >= _config.SystemProbability) { continue; } if (_systems.ContainsKey(seedVec)) { continue; } var world = (new Vector3D(x, y, z) + 0.5) * _config.SystemSpacing + rand.NextVector3D() * (_config.SystemSpacing / 8); if (include.Contains(world) == ContainmentType.Disjoint || (exclude.HasValue && exclude.Value.Contains(world) != ContainmentType.Disjoint)) { continue; } var list = _config.Systems.Where(s => s.MinDistanceFromOrigin <= world.Length()).ToList(); var ttl = list.Sum(s => s.Probability); foreach (var s in list) { if (ttl <= s.Probability) { var position = MatrixD.CreateFromQuaternion(rand.NextQuaternion()); position.Translation = world; var result = new ProceduralSystem(this, s, rand.NextLong(), position); _systems.Add(seedVec, result); foreach (var b in result.Bodies) { _addQueue.Enqueue(b); } yield return(result); break; } ttl -= s.Probability; } } } } }
private static void RescheduleEvent(object senderEvent) { if (m_waveCounter > WAVES_IN_SHOWER) { TimeSpan time = CalculateShowerTime(MySession.Static.EnvironmentHostility); MyGlobalEvents.RescheduleEvent((MyGlobalEventBase)senderEvent, time); m_waveCounter = -1; m_currentTarget = null; MyMultiplayer.RaiseStaticEvent(x => UpdateShowerTarget,m_currentTarget); } else { TimeSpan nextWave = TimeSpan.FromSeconds(m_meteorcount / 5f + MyUtils.GetRandomFloat(2, 5)); MyGlobalEvents.RescheduleEvent((MyGlobalEventBase)senderEvent, nextWave); } }
private static void MeteorWaveInternal(object senderEvent) { if (MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.SAFE) { Debug.Assert(false,"Meteor shower shouldnt be enabled in safe enviroment"); ((MyGlobalEventBase)senderEvent).Enabled = false; return; } if(Sync.IsServer == false) { return; } m_waveCounter++; if (m_waveCounter == 0) { ClearMeteorList(); if (m_targetList.Count == 0) { GetTargets(); if (m_targetList.Count == 0) { m_waveCounter = WAVES_IN_SHOWER + 1; RescheduleEvent(senderEvent); return; } } m_currentTarget = m_targetList.ElementAt(MyUtils.GetRandomInt(m_targetList.Count - 1)); MyMultiplayer.RaiseStaticEvent(x => UpdateShowerTarget, m_currentTarget); m_targetList.Remove(m_currentTarget.Value); m_meteorcount = (int)(Math.Pow(m_currentTarget.Value.Radius, 2) * Math.PI / 6000); m_meteorcount /= (MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.CATACLYSM || MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.CATACLYSM_UNREAL) ? 1 : 8; m_meteorcount = MathHelper.Clamp(m_meteorcount, 1, 30); } RescheduleEvent(senderEvent); CheckTargetValid(); if ( m_waveCounter < 0 ) return; StartWave(); }
public override IEnumerable <ProceduralObject> Generate(BoundingSphereD include, BoundingSphereD?exclude) { var aabb = new BoundingBoxD(include.Center - include.Radius, include.Center + include.Radius); foreach (var cell in StationNoise.TryGetSpawnIn(aabb, (x) => include.Intersects(x) && (!exclude.HasValue || exclude.Value.Contains(x) != ContainmentType.Contains))) { LoadingConstruction instance; if (!m_instances.TryGetValue(cell.Item1, out instance)) { var numSeed = cell.Item1.GetHashCode(); Ob_ProceduralConstructionSeed dbSeed; Ob_ProceduralConstruction dbBlueprint; Ob_ProceduralFaction dbFaction; ProceduralConstructionSeed seed; if (m_database.TryGetBuildingBlueprint(numSeed, out dbSeed, out dbBlueprint) && dbSeed != null && m_database.TryGetFaction(dbSeed.FactionSeed, out dbFaction) && dbFaction != null) { seed = new ProceduralConstructionSeed(new ProceduralFactionSeed(dbFaction), cell.Item2.XYZ(), dbSeed); } else { seed = new ProceduralConstructionSeed(Factions.SeedAt(cell.Item2.XYZ()), cell.Item2, null, numSeed); } instance = m_instances[cell.Item1] = new LoadingConstruction(this, cell.Item1, seed); } else if (!instance.IsMarkedForRemoval) { continue; // Already loaded + not marked for removal -- already in the tree. } instance.EnsureGenerationStarted(); yield return(instance); } }
public override IEnumerable <ProceduralObject> Generate(BoundingSphereD include, BoundingSphereD?exclude) { var root = Vector3D.Transform(include.Center, m_invTransform); var excludeRoot = exclude.HasValue ? Vector3D.Transform(exclude.Value.Center, m_invTransform) : default(Vector3D); var minLocal = root - include.Radius; var maxLocal = root + include.Radius; minLocal = Vector3D.Max(minLocal, Shape.RelevantArea.Min); maxLocal = Vector3D.Min(maxLocal, Shape.RelevantArea.Max); for (var i = 0; i < m_layers.Length; i++) { var layer = m_layers[i]; var includePaddedSquared = include.Radius + layer.AsteroidSpacing * 2; includePaddedSquared *= includePaddedSquared; var excludePaddedSquared = exclude.HasValue ? exclude.Value.Radius - layer.AsteroidSpacing * 2 : 0; excludePaddedSquared *= excludePaddedSquared; var minPos = Vector3I.Floor(minLocal / layer.AsteroidSpacing); var maxPos = Vector3I.Ceiling(maxLocal / layer.AsteroidSpacing); for (var itr = new Vector3I_RangeIterator(ref minPos, ref maxPos); itr.IsValid(); itr.MoveNext()) { var seed = new Vector4I(itr.Current.X, itr.Current.Y, itr.Current.Z, i); var localPos = ((Vector3D)itr.Current + 0.5) * layer.AsteroidSpacing; // Very quick, include/exclude. if (Vector3D.DistanceSquared(root, localPos) > includePaddedSquared) { continue; } if (exclude.HasValue && Vector3D.DistanceSquared(excludeRoot, localPos) < excludePaddedSquared) { continue; } var localWeight = Shape.Weight(localPos) + layer.UsableRegion - 1; if (1 - layer.AsteroidDensity > localWeight) { continue; } var densityNoise = Math.Abs(m_noise.GetValue(localPos + Math.PI)) * localWeight; if (1 - layer.AsteroidDensity > densityNoise) { continue; } localPos.X += 0.45 * m_noise.GetValue(localPos) * layer.AsteroidSpacing; localPos.Y += 0.45 * m_noise.GetValue(localPos) * layer.AsteroidSpacing; localPos.Z += 0.45 * m_noise.GetValue(localPos) * layer.AsteroidSpacing; localPos.X += 0.35 * Shape.WarpSize.X * m_noiseWarp.GetValue(localPos); localPos.Y += 0.35 * Shape.WarpSize.Y * m_noiseWarp.GetValue(localPos); localPos.Z += 0.05 * Shape.WarpSize.Z * m_noiseWarp.GetValue(localPos); var worldPos = Vector3D.Transform(localPos, m_transform); ProceduralAsteroid procAst; if (!m_asteroids.TryGetValue(seed, out procAst)) { var size = m_noise.GetValue(worldPos) * (layer.AsteroidMaxSize - layer.AsteroidMinSize) + layer.AsteroidMinSize; m_asteroids[seed] = procAst = new ProceduralAsteroid(this, seed, worldPos, size, m_layers[i]); } procAst.SpawnIfNeeded((procAst.m_boundingBox.Center - include.Center).LengthSquared()); yield return(procAst); } } }
public abstract IEnumerable <ProceduralObject> Generate(BoundingSphereD include, BoundingSphereD?exclude);