示例#1
0
        protected bool RemoveItem(int itemInstanceId, int physicsInstanceId, bool sync)
        {
            Debug.Assert(sync == false || Sync.IsServer, "Synchronizing env. item removal from the client is forbidden!");
            Debug.Assert(m_physicsShapeInstanceIdToLocalId.ContainsKey(physicsInstanceId), "Could not find env. item shape!");
            Debug.Assert(m_localIdToPhysicsShapeInstanceId.ContainsKey(itemInstanceId), "Could not find env. item instance!");

            m_physicsShapeInstanceIdToLocalId.Remove(physicsInstanceId);
            m_localIdToPhysicsShapeInstanceId.Remove(itemInstanceId);

            MyEnvironmentItemData itemData = m_itemsData[itemInstanceId];

            itemData.Enabled            = false;
            m_itemsData[itemInstanceId] = itemData;

            HkStaticCompoundShape shape = (HkStaticCompoundShape)Physics.RigidBody.GetShape();
            var shapeKey = shape.ComposeShapeKey(physicsInstanceId, 0);

            shape.EnableShapeKey(shapeKey, false);

            Matrix matrix   = itemData.Transform.TransformMatrix;
            var    sectorId = MyEnvironmentSector.GetSectorId(matrix.Translation - m_cellsOffset, Definition.SectorSize);
            var    disabled = Sectors[sectorId].DisableInstance(itemData.SectorInstanceId, itemData.ModelId);

            Debug.Assert(disabled, "Env. item instance render not disabled");
            Sectors[sectorId].UpdateRenderInstanceData();

            OnRemoveItem(itemInstanceId, ref matrix, itemData.SubtypeId);

            if (sync)
            {
                MySyncEnvironmentItems.RemoveEnvironmentItem(EntityId, itemInstanceId);
            }
            return(true);
        }
示例#2
0
        protected bool RemoveNonPhysicalItem(int itemInstanceId, bool sync)
        {
            Debug.Assert(sync == false || Sync.IsServer, "Synchronizing env. item removal from the client is forbidden!");
            Debug.Assert(m_itemsData.ContainsKey(itemInstanceId), "Could not find env. item shape!");

            MyEnvironmentItemData itemData = m_itemsData[itemInstanceId];

            itemData.Enabled            = false;
            m_itemsData[itemInstanceId] = itemData;

            Matrix matrix   = itemData.Transform.TransformMatrix;
            var    sectorId = MyEnvironmentSector.GetSectorId(matrix.Translation, Definition.SectorSize);
            var    disabled = Sectors[sectorId].DisableInstance(itemData.SectorInstanceId, itemData.ModelId);

            Debug.Assert(disabled, "Env. item instance render not disabled");
            Sectors[sectorId].UpdateRenderInstanceData();

            OnRemoveItem(itemInstanceId, ref matrix, itemData.SubtypeId);

            if (sync)
            {
                MySyncEnvironmentItems.RemoveEnvironmentItem(EntityId, itemInstanceId);
            }

            return(true);
        }
示例#3
0
 public void BeginBatch(bool sync)
 {
     Debug.Assert(!IsBatching);
     m_batchTime = BATCH_DEFAULT_TIME;
     if (sync)
     {
         MySyncEnvironmentItems.SendBeginBatchAddMessage(EntityId);
     }
 }
示例#4
0
        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);
        }
示例#5
0
        public void EndBatch(bool sync)
        {
            m_batchTime = 0;

            if (m_batchedAddItems.Count > 0 || m_batchedModifyItems.Count > 0)
            {
                ProcessBatch();
            }

            m_batchedAddItems.Clear();
            m_batchedModifyItems.Clear();

            if (sync)
            {
                MySyncEnvironmentItems.SendEndBatchAddMessage(EntityId);
            }
        }
示例#6
0
        public void BatchModifyItem(int localId, int localModelId, bool sync)
        {
            Debug.Assert(IsBatching);
            Debug.Assert(m_itemsData.ContainsKey(localId));
            if (!m_itemsData.ContainsKey(localId))
            {
                return;
            }

            m_batchedModifyItems.Add(new ModifyItemData()
            {
                LocalId = localId, LocalModelId = localModelId
            });

            if (sync)
            {
                MySyncEnvironmentItems.SendBatchModifyItemMessage(EntityId, localId, localModelId);
            }
        }
示例#7
0
        public void BatchAddItem(Vector3D position, MyStringHash subtypeId, int localModelId, bool sync)
        {
            Debug.Assert(IsBatching);
            Debug.Assert(m_definition.ContainsItemDefinition(subtypeId));
            if (!m_definition.ContainsItemDefinition(subtypeId))
            {
                return;
            }

            m_batchedAddItems.Add(new AddItemData()
            {
                Position = position, SubtypeId = subtypeId, LocalModelId = localModelId
            });

            if (sync)
            {
                MySyncEnvironmentItems.SendBatchAddItemMessage(EntityId, position, subtypeId, localModelId);
            }
        }