当前位置: 首页>>代码示例>>C#>>正文


C# BitStream.SetBitPositionWrite方法代码示例

本文整理汇总了C#中VRage.Library.Collections.BitStream.SetBitPositionWrite方法的典型用法代码示例。如果您正苦于以下问题:C# BitStream.SetBitPositionWrite方法的具体用法?C# BitStream.SetBitPositionWrite怎么用?C# BitStream.SetBitPositionWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VRage.Library.Collections.BitStream的用法示例。


在下文中一共展示了BitStream.SetBitPositionWrite方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Write

        public void Write(BitStream stream)
        {
            // TODO: this is suboptimal
            if (stream == null || m_writeData == null)
            {
                if (stream == null)
                    Debug.Fail("BitReaderWriter - Write - stream is null");
                if ( m_writeData == null)
                    Debug.Fail("BitReaderWriter - Write - m_writeData is null");
                return;
            }

            // Store old bit position
            int pos = stream.BitPosition;

            // Write data
            m_writeData.Serialize(stream, false);

            // Measure data len
            int len = stream.BitPosition - pos;

            // Restore old position
            stream.SetBitPositionWrite(pos);

            // Write data len
            stream.WriteVariant((uint)len);

            // Write data again
            m_writeData.Serialize(stream, false);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:30,代码来源:BitReaderWriter.cs

示例2: Write

        public void Write(BitStream stream)
        {
            // TODO: this is suboptimal

            // Store old bit position
            int pos = stream.BitPosition;

            // Write data
            m_writeData.Serialize(stream, false);

            // Measure data len
            int len = stream.BitPosition - pos;

            // Restore old position
            stream.SetBitPositionWrite(pos);

            // Write data len
            stream.WriteVariant((uint)len);

            // Write data again
            m_writeData.Serialize(stream, false);
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:22,代码来源:BitReaderWriter.cs

示例3: Serialize

        public override bool Serialize(BitStream stream, EndpointId forClient,uint timestamp, byte packetId, int maxBitPosition)
        {
            // Client does not care about slave grids, he always synced group through controlled object
            Debug.Assert(stream.Reading || !Sync.IsServer || Entity == GetMasterGrid(Entity), "Writing data from SlaveGrid!");

            bool apply = !IsControlledLocally;

            bool moving = false;
            if (stream.Writing)
            {
                moving = IsMoving(Entity);
                stream.WriteBool(moving);
            }
            else
            {
                moving = stream.ReadBool();
            }


            // Serialize this grid
            apply = SerializeTransform(stream, Entity, null, m_lowPrecisionOrientation, apply,moving, timestamp, m_positionValidation, MoveHandler);
            SerializeVelocities(stream, Entity, EffectiveSimulationRatio, apply, moving,VelocityHandler);

     
            // Serialize other grids in group
            Vector3D basePos = Entity.WorldMatrix.Translation;
            if (stream.Writing)
            {
                bool fullyWritten = true;
                UpdateGridMaxSpeed(Entity, Sync.IsServer);
                var g = MyCubeGridGroups.Static.PhysicalDynamic.GetGroup(Entity);
                if (g == null)
                {
                    stream.WriteBool(false);
                }
                else
                {
                    m_groups.Clear();
                    int i = 0;
                    foreach (var node in g.Nodes)
                    {                        
                        i++;
                        if (ResponsibleForUpdate(node.NodeData, forClient))
                        {
                            continue;
                        } 

                        if(i < m_currentSentPosition)
                        {
                            continue;
                        }


                        var target = MyMultiplayer.Static.ReplicationLayer.GetProxyTarget((IMyEventProxy)node.NodeData);
                        
                        int pos = stream.BitPosition;

                        if (node.NodeData != Entity && !node.NodeData.IsStatic && target != null)
                        {                 
                            stream.WriteBool(true);
                            // ~26.5 bytes per grid, not bad
                            NetworkId networkId = MyMultiplayer.Static.ReplicationLayer.GetNetworkIdByObject(target);
                            stream.WriteNetworkId(networkId); // ~2 bytes
             
                            moving = IsMoving(node.NodeData);
                            stream.WriteBool(moving);

                            SerializeTransform(stream, node.NodeData, basePos, m_lowPrecisionOrientation, apply, moving, timestamp, null, null); // 12.5 bytes
                            SerializeVelocities(stream, node.NodeData, EffectiveSimulationRatio, apply, moving); // 12 byte
                            UpdateGridMaxSpeed(node.NodeData, Sync.IsServer);
                            m_groups.Add(node.NodeData);

                            m_currentSentPosition++;
                        }

                        if (stream.BitPosition > maxBitPosition)
                        {
                            stream.SetBitPositionWrite(pos);
                            fullyWritten = false;
                            m_currentSentPosition--;
                            break;
                        }

                        if (i == g.Nodes.Count)
                        {
                            m_currentSentPosition = 0;
                        }
                    }

                    stream.WriteBool(false);
                }

                stream.WriteBool(fullyWritten);

                if (fullyWritten)
                {
                    SerializeRopeData(stream, apply, gridsGroup: m_groups);
                }
                return fullyWritten;

//.........这里部分代码省略.........
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGridPhysicsStateGroup.cs

示例4: WriteSubgrids

        public static  bool WriteSubgrids(MyCubeGrid masterGrid, BitStream stream, ref EndpointId forClient, uint timestamp, int maxBitPosition, bool lowPrecisionOrientation,ref Vector3D basePos, ref int currentSentPosition)
        {
            bool fullyWritten = true;
            var g = MyCubeGridGroups.Static.PhysicalDynamic.GetGroup(masterGrid);
            if (g == null)
            {
                stream.WriteBool(false);
            }
            else
            {
                m_groups.Clear();
                int i = 0;
                foreach (var node in g.Nodes)
                {
                    i++;

                    if (i < currentSentPosition)
                    {
                        continue;
                    }


                    var target = MyMultiplayer.Static.ReplicationLayer.GetProxyTarget((IMyEventProxy)node.NodeData);

                    int pos = stream.BitPosition;

                    if (node.NodeData != masterGrid && node.NodeData.Physics != null && !node.NodeData.Physics.IsStatic && target != null)
                    {
                        stream.WriteBool(true);
                        // ~26.5 bytes per grid, not bad
                        NetworkId networkId = MyMultiplayer.Static.ReplicationLayer.GetNetworkIdByObject(target);
                        stream.WriteNetworkId(networkId); // ~2 bytes

                        bool moving = IsMovingSubGrid(node.NodeData);
                        stream.WriteBool(moving);

                        SerializeTransform(stream, node.NodeData, basePos, lowPrecisionOrientation, false, moving, timestamp, null, null); // 12.5 bytes
                        SerializeVelocities(stream, node.NodeData, EffectiveSimulationRatio, false, moving); // 12 byte
                        UpdateGridMaxSpeed(node.NodeData, Sync.IsServer);
                        m_groups.Add(node.NodeData);

                        currentSentPosition++;
                    }

                    if (stream.BitPosition > maxBitPosition)
                    {
                        stream.SetBitPositionWrite(pos);
                        fullyWritten = false;
                        currentSentPosition--;
                        break;
                    }

                    if (i == g.Nodes.Count)
                    {
                        currentSentPosition = 0;
                    }
                }

                stream.WriteBool(false);
            }
            return fullyWritten;
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:62,代码来源:MyGridPhysicsStateGroup.cs

示例5: PrepareSendData


//.........这里部分代码省略.........
                            sentData.HasChanges = true;
                        }
                        else
                        {
                            needsSplit = true;
                        }
                    }
                }
            }

            stream.WriteBool(packetInfo.RemovedItems != null);
            if (packetInfo.RemovedItems != null)
            {
                stream.WriteInt32(packetInfo.RemovedItems.Count);
                if (stream.BitPosition > maxBitPosition)
                {
                    needsSplit = true;
                }
                else
                {
                    sentData.RemovedItems = new List<uint>();
                    foreach (var item in packetInfo.RemovedItems)
                    {
                        stream.WriteUInt32(item);

                        if (stream.BitPosition <= maxBitPosition)
                        {
                            sentData.RemovedItems.Add(item);
                            sentData.HasChanges = true;
                        }
                        else
                        {
                            needsSplit = true;
                        }
                    }
                }
            }

            stream.WriteBool(packetInfo.NewItems != null);
            if (packetInfo.NewItems != null)
            {
                stream.WriteInt32(packetInfo.NewItems.Count);
                if (stream.BitPosition > maxBitPosition)
                {
                    needsSplit = true;
                }
                else
                {
                    sentData.NewItems = new SortedDictionary<int, MyPhysicalInventoryItem>();

                    foreach (var item in  packetInfo.NewItems)
                    {
                        MyPhysicalInventoryItem inventoryItem = item.Value;
                        VRage.Serialization.MySerializer.Write(stream, ref inventoryItem, MyObjectBuilderSerializer.Dynamic);

                        if (stream.BitPosition <= maxBitPosition)
                        {
                            sentData.NewItems[item.Key] = inventoryItem;
                            sentData.HasChanges = true;
                        }
                        else
                        {
                            needsSplit = true;
                        }
                    }
                }
            }

            stream.WriteBool(packetInfo.SwappedItems != null);
            if (packetInfo.SwappedItems != null)
            {
                stream.WriteInt32(packetInfo.SwappedItems.Count);
                if (stream.BitPosition > maxBitPosition)
                {
                    needsSplit = true;
                }
                else
                {
                    sentData.SwappedItems = new Dictionary<int, int>();

                    foreach (var item in packetInfo.SwappedItems)
                    {
                        stream.WriteInt32(item.Key);
                        stream.WriteInt32(item.Value);

                        if (stream.BitPosition <= maxBitPosition)
                        {
                            sentData.SwappedItems[item.Key] = item.Value;
                            sentData.HasChanges = true;
                        }
                        else
                        {
                            needsSplit = true;
                        }
                    }
                }
            }
            stream.SetBitPositionWrite(startStreamPosition);
            return sentData;
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:101,代码来源:MyEntityInventoryStateGroup.cs

示例6: WriteInventory

        private InventoryPartInfo WriteInventory(ref InventoryPartInfo packetInfo, BitStream stream, byte packetId, int maxBitPosition, bool resend = false)
        {
            if (m_items == null)
            {
                m_items = new List<MyPhysicalInventoryItem>();
            }

            Console.WriteLine(String.Format("sending: {0}, {1}", packetId, Inventory.Owner.ToString()));
            InventoryPartInfo sendPacketInfo = new InventoryPartInfo();
            sendPacketInfo.AllItemsSend = true;

            List<MyPhysicalInventoryItem> items = Inventory.GetItems();
            int numItems = items.Count;

            int sentItems = packetInfo.StartItemIndex + (resend ? 0 : packetInfo.NumItems);
            sendPacketInfo.StartItemIndex = sentItems;

            bool startNewTransfer = (resend == false) && sentItems == 0;
            VRage.Serialization.MySerializer.Write(stream, ref startNewTransfer);
            int startStreamPosition = stream.BitPosition;
            VRage.Serialization.MySerializer.Write(stream, ref numItems);

            int maxNumItems = (resend ? packetInfo.NumItems : numItems);
            for (; sentItems < numItems; ++sentItems)
            {
                MyPhysicalInventoryItem item = items[sentItems];
                m_items.Add(item);
                VRage.Serialization.MySerializer.Write(stream, ref item, MyObjectBuilderSerializer.Dynamic);
                if (stream.BitPosition > maxBitPosition)
                {
                    m_items.RemoveAt(m_items.Count - 1);
                    break;
                }
                else if (sentItems >= maxNumItems)
                {
                    break;
                }

            }

            if (m_items.Count < numItems)
            {
                sendPacketInfo.AllItemsSend = false;
                stream.SetBitPositionWrite(startStreamPosition);
                numItems = m_items.Count;
                VRage.Serialization.MySerializer.Write(stream, ref numItems);

                for (int i = 0; i < m_items.Count; ++i)
                {
                    MyPhysicalInventoryItem item = m_items[i];
                    VRage.Serialization.MySerializer.Write(stream, ref item, MyObjectBuilderSerializer.Dynamic);
                }
            }

            VRage.Serialization.MySerializer.Write(stream, ref sendPacketInfo.StartItemIndex);
            sendPacketInfo.NumItems = m_items.Count;
            m_items.Clear();
            return sendPacketInfo;
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:59,代码来源:MyEntityInventoryStateGroup.cs


注:本文中的VRage.Library.Collections.BitStream.SetBitPositionWrite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。