void OnSectorItemRemoved(MyEnvironmentItems item, MyEnvironmentItems.ItemInfo value) { foreach (var spawner in m_spawners) { spawner.Value.EnvironmentItems.Save = true; } if (m_saved == false) { m_planet.OnEnviromentSectorItemRemoved(m_pos); m_saved = true; } }
public void PlaceItems() { ProfilerShort.Begin("flora : spawn"); Vector3 direction = -m_planet.GetWorldGravity(m_sectorCenter); direction.Normalize(); var random = MyRandom.Instance; using (var stateToken = random.PushSeed(m_cellHashCode)) { for (int i = 0; i < NumItemsInSector; ++i) { Vector3D spawnPosition = GetRandomPosition(ref SectorBox); Vector3D localPosition; MyVoxelCoordSystems.WorldPositionToLocalPosition(m_planet.PositionLeftBottomCorner, ref spawnPosition, out localPosition); Vector3D gravity = m_planet.GetWorldGravityNormalized(ref spawnPosition); localPosition = m_planet.GetClosestSurfacePoint(ref localPosition, ref gravity, NUM_PLACE_ITERATION, 0); MyVoxelCoordSystems.LocalPositionToWorldPosition(m_planet.PositionLeftBottomCorner, ref localPosition, out spawnPosition); if (m_planet.Storage.DataProvider.IsMaterialAtPositionSpawningFlora(ref localPosition)) { m_spawnPositions.Add(spawnPosition); } } if (m_spawnPositions.Count > 0) { m_spawners = new Dictionary <MyStringHash, MyEnvironmentItems.MyEnvironmentItemsSpawnData>(); var itemClasses = MyDefinitionManager.Static.GetEnvironmentItemClassDefinitions(); ProfilerShort.Begin("flora : begin spawn"); foreach (var itemClass in itemClasses) { m_spawners[itemClass.Id.SubtypeId] = MyEnvironmentItems.BeginSpawn(itemClass); m_spawners[itemClass.Id.SubtypeId].EnvironmentItems.Save = false; m_spawners[itemClass.Id.SubtypeId].EnvironmentItems.CellsOffset = m_planet.PositionLeftBottomCorner; m_spawners[itemClass.Id.SubtypeId].EnvironmentItems.ItemRemoved += OnSectorItemRemoved; } ProfilerShort.End(); for (int i = 0; i < m_spawnPositions.Count; ++i) { int value = random.Next(1, 4); var cl = MyDefinitionManager.Static.GetRandomEnvironmentClass(value); if (cl != null) { var itemDef = cl.GetRandomItemDefinition(); if (itemDef != null) { var spawner = m_spawners[cl.Id.SubtypeId]; MyEnvironmentItems.SpawnItem(spawner, itemDef, m_spawnPositions[i], direction); m_numPlacedItems++; } } } ProfilerShort.Begin("flora : end spawn"); foreach (var spawner in m_spawners) { MyEnvironmentItems.EndSpawn(spawner.Value, false); } ProfilerShort.End(); m_spawnPositions.Clear(); } } ProfilerShort.End(); }
internal MyRenderComponentEnvironmentItems(MyEnvironmentItems environmentItems) { EnvironmentItems = environmentItems; }