private void AddTransferData(MyEnvironmentItems from, MyEnvironmentItems to, int localId, MyStringHash subtypeId) { m_transferList.Add(new TransferData() { From = from, To = to, LocalId = localId, SubtypeId = subtypeId, }); }
public bool ModifyItemModel(int itemInstanceId, int localModelId, bool updateSector, bool sync) { MyEnvironmentItemData data; if (!m_itemsData.TryGetValue(itemInstanceId, out data)) { Debug.Assert(false, "Item instance not found."); return(false); } int modelId = MyEnvironmentItems.GetModelId(data.SubtypeId, localModelId); if (data.Enabled && data.ModelId != modelId) { Matrix matrix = data.Transform.TransformMatrix; var sectorId = MyEnvironmentSector.GetSectorId(matrix.Translation - CellsOffset, Definition.SectorSize); MyModel modelData = MyModels.GetModelOnlyData(MyModel.GetById(modelId)); var sector = Sectors[sectorId]; Matrix invOffset = Matrix.Invert(sector.SectorMatrix); matrix = matrix * invOffset; sector.DisableInstance(data.SectorInstanceId, data.ModelId); int newSectorInstanceId = sector.AddInstance(data.SubtypeId, modelId, itemInstanceId, ref matrix, modelData.BoundingBox, m_instanceFlags, m_definition.MaxViewDistance); data.ModelId = modelId; data.SectorInstanceId = newSectorInstanceId; m_itemsData[itemInstanceId] = data; if (updateSector) { sector.UpdateRenderInstanceData(); sector.UpdateRenderEntitiesData(WorldMatrix); } if (ItemModified != null) { ItemModified(this, new ItemInfo() { LocalId = data.Id, SubtypeId = data.SubtypeId, Transform = data.Transform }); } if (sync) { MySyncEnvironmentItems.SendModifyModelMessage(EntityId, itemInstanceId, localModelId); } } return(true); }
private void AddTransferData(MyEnvironmentItems from, MyEnvironmentItems to, int localId, MyStringHash subtypeId) { TransferData item = new TransferData { From = from, To = to, LocalId = localId, SubtypeId = subtypeId }; this.m_transferList.Add(item); }
public static void TransferItems(MyEnvironmentItems from, MyEnvironmentItems to, int localId, MyStringHash subtypeId, int timeS = 10) { Static.AddTransferData(from, to, localId, subtypeId); Static.StartTimer(timeS); }
public MyEnviromentItemsDebugDraw(MyEnvironmentItems items) { m_items = items; }
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; } }
/// <summary> /// Adds environment item to internal collections. Creates render and physics data. /// </summary> /// <returns>True if successfully added, otherwise false.</returns> private bool AddItem( MyEnvironmentItemDefinition itemDefinition, ref MatrixD worldMatrix, ref BoundingBoxD aabbWorld, HkStaticCompoundShape sectorRootShape, Dictionary <MyStringHash, HkShape> subtypeIdToShape, int localModelId = MAIN_MODEL_LOCAL_ID) { if (!MyFakes.ENABLE_ENVIRONMENT_ITEMS) { return(true); } Debug.Assert(m_definition.ContainsItemDefinition(itemDefinition), String.Format("Environment item with definition '{0}' not found in class '{1}'", itemDefinition.Id, m_definition.Id)); if (!m_definition.ContainsItemDefinition(itemDefinition)) { return(false); } if (itemDefinition.Model == null) { return(false); } //MyDefinitionId defId = new MyDefinitionId(envItemObjectBuilderType, subtypeId.ToString()); int modelId = MyEnvironmentItems.GetModelId(itemDefinition.Id.SubtypeId, localModelId); string modelName = MyModel.GetById(modelId); MyModel model = MyModels.GetModelOnlyData(modelName); if (model == null) { //Debug.Fail(String.Format("Environment item model of '{0}' not found, skipping the item...", itemDefinition.Id)); return(false); } CheckModelConsistency(itemDefinition); int localId = worldMatrix.Translation.GetHashCode(); MyEnvironmentItemData data = new MyEnvironmentItemData() { Id = localId, SubtypeId = itemDefinition.Id.SubtypeId, Transform = new MyTransformD(ref worldMatrix), Enabled = true, SectorInstanceId = -1, ModelId = modelId, }; //Preload split planes //VRageRender.MyRenderProxy.PreloadMaterials(model.AssetName); aabbWorld.Include(model.BoundingBox.Transform(worldMatrix)); MatrixD transform = data.Transform.TransformMatrix; Vector3I sectorId = MyEnvironmentSector.GetSectorId(transform.Translation - CellsOffset, m_definition.SectorSize); MyEnvironmentSector sector; if (!m_sectors.TryGetValue(sectorId, out sector)) { sector = new MyEnvironmentSector(sectorId, sectorId * m_definition.SectorSize + CellsOffset); m_sectors.Add(sectorId, sector); } // Adds instance of the given model. Local matrix specified might be changed internally in renderer. MatrixD sectorOffset = MatrixD.CreateTranslation(-sectorId * m_definition.SectorSize - CellsOffset); Matrix transformL = (Matrix)(transform * sectorOffset); data.SectorInstanceId = sector.AddInstance(itemDefinition.Id.SubtypeId, data.ModelId, localId, ref transformL, model.BoundingBox, m_instanceFlags, m_definition.MaxViewDistance); int physicsShapeInstanceId; if (AddPhysicsShape(data.SubtypeId, model, ref transform, sectorRootShape, subtypeIdToShape, out physicsShapeInstanceId)) { // Map to data index - note that itemData is added after this to its list! m_physicsShapeInstanceIdToLocalId[physicsShapeInstanceId] = localId; m_localIdToPhysicsShapeInstanceId[localId] = physicsShapeInstanceId; } data.Transform = new MyTransformD(transform); if (m_itemsData.ContainsKey(localId)) { //Debug.Fail("More items on same place! " + transform.Translation.ToString()); } else { m_itemsData.Add(localId, data); } if (ItemAdded != null) { ItemAdded(this, new ItemInfo() { LocalId = localId, SubtypeId = data.SubtypeId, Transform = data.Transform, }); } return(true); }
private void item_ItemRemoved(MyEnvironmentItems item, ItemInfo itemInfo) { var entityId = item.EntityId; int i = 0; while (i < m_forestAreas.Count) { var area = m_forestAreas[i]; if (area.IsValid && area.ItemIds.ContainsKey(entityId) && area.ItemIds[entityId].Contains(itemInfo.LocalId)) { area.ItemIds[entityId].Remove(itemInfo.LocalId); if (area.IsValid) { InvalidateArea(area); i++; } else { RemoveArea(m_forestAreas, i); } } else { i++; } } }
private void DistributeItems(MyEnvironmentItems envItem, ref Vector3D sectorPosition) { envItem.GetItemsInSector(ref sectorPosition, m_tmpItemInfos); var envItemId = envItem.EntityId; foreach (var itemInfo in m_tmpItemInfos) { bool included = false; var worldBox = GetWorldBox(itemInfo.SubtypeId, itemInfo.Transform.TransformMatrix); var extended = worldBox.GetInflated(DEFAULT_INFLATE_VALUE); m_aabbTree.OverlapAllBoundingBox(ref extended, m_tmpAreas); for (int i = 0; i < m_tmpAreas.Count; i++) { var forestBox = m_tmpAreas[i].ForestBox; if ((forestBox.Center - worldBox.Center).LengthSquared() <= BOX_INCLUDE_DIST_SQ) { forestBox.Include(ref worldBox); m_tmpAreas[i].ForestBox = forestBox; m_tmpAreas[i].AddItem(envItemId, itemInfo.LocalId); included = true; m_aabbTree.MoveProxy(m_tmpAreas[i].ProxyId, ref worldBox, Vector3D.Zero); } } m_tmpAreas.Clear(); if (!included) { var newForestBox = new Area(); newForestBox.ForestBox = worldBox; newForestBox.AddItem(envItemId, itemInfo.LocalId); newForestBox.ProxyId = m_aabbTree.AddProxy(ref worldBox, newForestBox, 0); m_forestAreas.Add(newForestBox); } } m_tmpItemInfos.Clear(); }
private void RemoveEnvironmentItem(MyEnvironmentItems item) { if (!m_envItems.ContainsKey(item.EntityId)) return; m_envItems.Remove(item.EntityId); item.OnMarkForClose -= item_OnMarkForClose; item.ItemAdded -= item_ItemAdded; item.ItemRemoved -= item_ItemRemoved; foreach (var area in m_forestAreas) { if (area.IsValid) area.ItemIds.Remove(item.EntityId); } m_immediateInvalidate = true; }
private void item_ItemAdded(MyEnvironmentItems envItems, ItemInfo itemInfo) { m_checkedSectors.Add(envItems.GetSectorId(ref itemInfo.Transform.Position)); var itemBox = GetWorldBox(itemInfo.SubtypeId, itemInfo.Transform.TransformMatrix); var checkBox = itemBox.GetInflated(DEFAULT_INFLATE_VALUE); m_aabbTree.OverlapAllBoundingBox(ref checkBox, m_tmpAreas); var newForestBox = new Area(); newForestBox.ForestBox = itemBox; newForestBox.AddItem(envItems.EntityId, itemInfo.LocalId); newForestBox.ProxyId = m_aabbTree.AddProxy(ref itemBox, newForestBox, 0); m_tmpAreas.Add(newForestBox); MergeAreas(m_tmpAreas); if (newForestBox.IsValid) m_forestAreas.Add(newForestBox); m_tmpAreas.Clear(); }
public void AddEnvironmentItem(MyEnvironmentItems item) { item.OnMarkForClose += item_OnMarkForClose; m_envItems.Add(item.EntityId, item); m_checkQueue.Enqueue(item.EntityId); item.ItemRemoved += item_ItemRemoved; item.ItemAdded += item_ItemAdded; m_loadPhase = true; }
public static bool HasBelongingItems(int areaId, MyEnvironmentItems items) { return Static.HasBelongingItemsInternal(areaId, items); }
private bool HasBelongingItemsInternal(int areaId, MyEnvironmentItems items) { var area = m_aabbTree.GetUserData<Area>(areaId); if (!area.ItemIds.ContainsKey(items.EntityId)) return false; return area.ItemIds[items.EntityId].Count > 0; }
internal MyRenderComponentEnvironmentItems(MyEnvironmentItems environmentItems) { EnvironmentItems = environmentItems; }