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


C# BitStream.WriteCompressed方法代码示例

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


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

示例1: SendChatMessage

        public override void SendChatMessage(string message)
        {
            BitStream bs = new BitStream(null);

            bs.Write((byte)MessageIDEnum.CHAT_MESSAGE);
            bs.WriteCompressed(message);

            SendMessageToServer(bs, PacketPriorityEnum.IMMEDIATE_PRIORITY, PacketReliabilityEnum.RELIABLE_ORDERED);
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:9,代码来源:MyRakNetClient.cs

示例2: SendChatMessageInternal

        private void SendChatMessageInternal(ulong steamID, string message, RakNetGUID? exclude = null)
        {
            BitStream bs = new BitStream(null);

            bs.Write((byte)MessageIDEnum.CHAT_MESSAGE);
            bs.Write((long)steamID);
            bs.WriteCompressed(message);

            BroadcastMessage(bs, PacketPriorityEnum.IMMEDIATE_PRIORITY, PacketReliabilityEnum.RELIABLE_ORDERED, 0, exclude);
        }
开发者ID:caomw,项目名称:SpaceEngineers,代码行数:10,代码来源:MyRakNetServer.cs

示例3: Replicate

        public static void Replicate(object obj, ulong entityID)
        {
            Debug.Assert(Static != null);
            Debug.Assert(Static.m_peer is MyRakNetServer);
            Debug.Assert(!Static.m_stateData.ContainsKey(entityID));
            Debug.Assert(Static.m_idToType.Contains(obj.GetType()));

            int typeID = Static.m_typeToId[obj.GetType()];

            BitStream bs = new BitStream(null);
            bs.Write((byte)MessageIDEnum.REPLICATION_CREATE);
            bs.WriteCompressed(typeID); // TODO:SK better compression
            bs.Write((long)entityID);

            MySyncedClass syncedClass = GetSyncedClass(obj);
            syncedClass.TypeID = typeID;
            syncedClass.EntityId = entityID;
            syncedClass.Serialize(bs);

            RegisterSynced(syncedClass);

            ((MyRakNetServer)Static.m_peer).BroadcastMessage(bs, PacketPriorityEnum.LOW_PRIORITY, PacketReliabilityEnum.RELIABLE, 0, RakNetGUID.UNASSIGNED_RAKNET_GUID);
        }
开发者ID:caomw,项目名称:SpaceEngineers,代码行数:23,代码来源:MyRakNetSyncLayer.cs

示例4: SerializeStateData

 //TODO:SK: Split the message to allow clint to load the 
 internal void SerializeStateData(ulong steamID, BitStream bs)
 {
     bs.Write(m_stateData.Count);
     foreach (var syncedObject in m_stateData.Values)
     {
         bs.WriteCompressed(syncedObject.TypeID);
         bs.Write((long)syncedObject.EntityId);
         syncedObject.SerializeDefault(bs);
     }
 }
开发者ID:caomw,项目名称:SpaceEngineers,代码行数:11,代码来源:MyRakNetSyncLayer.cs

示例5: Main

        static void Main(string[] args)
        {
            RakPeerInterface rakClient = RakNetworkFactory.GetRakPeerInterface();
            RakPeerInterface rakServer = RakNetworkFactory.GetRakPeerInterface();

            quit = false;
            string text;

            rakClient.RegisterAsRemoteProcedureCall(typeof(Program).GetMethod("clientRPC"));

            SocketDescriptor socketDescriptor = new SocketDescriptor(2000, string.Empty);
            if (!rakServer.Startup(1, 30, new SocketDescriptor[] { socketDescriptor }, 1))
            {
                Console.Write("Start call failed!\n");
                return;
            }
            rakServer.SetMaximumIncomingConnections(1);
            socketDescriptor.port = 2100;
            rakClient.Startup(1, 30, new SocketDescriptor[] { socketDescriptor }, 1);
            if (!rakClient.Connect("127.0.0.1", 2000, string.Empty, 0))
            {
                Console.Write("Connect call failed\n");
                return;
            }

            BitStream outgoingBitstream = new BitStream();
            uint age;

            Console.Write("A sample on how to use RakNet's bitstream class\n");
            Console.Write("Difficulty: Beginner\n\n");

            Console.Write("Enter your name.\n");
            text = Console.ReadLine();
            if (text.Equals(string.Empty))
                text = "Unnamed!";
            outgoingBitstream.Write(text);

            Console.Write("Enter your age (numbers only).\n");
            text = Console.ReadLine();
            if (text.Equals(string.Empty))
                age = 0;
            else
                age = uint.Parse(text);

            outgoingBitstream.WriteCompressed(age);

            Console.Write("Are you employed (y/n)?\n");
            text = Console.ReadLine();
            if (text == "y")
            {
                outgoingBitstream.Write(true);

                // Read some data into a struct
                EmploymentStruct employmentStruct;
                Console.Write("What is your salary (enter a number only)?\n");
                text = Console.ReadLine();
                employmentStruct.salary = int.Parse(text);
                Console.Write("How many years have you been employed (enter a number only)?\n");
                text = Console.ReadLine();
                employmentStruct.yearsEmployed = byte.Parse(text);

                // We can write structs to a bitstream but this is not portable due to:
                //  1. Different-endian CPUs
                //  2. Different 'padding' of structs depending on compiler, etc
                // The only safe way to send a struct is by using the BitStream
                // to write out every single member which you want to send.
                outgoingBitstream.Write(employmentStruct.salary);
                outgoingBitstream.Write(employmentStruct.yearsEmployed);
                // We're done writing to the struct
            }
            else
            {
                //Console.Write("Number of bits before [false]: %d\n",
                //outgoingBitstream.GetNumberOfBitsUsed() );
                outgoingBitstream.Write(false); // Writing a bool takes 1 bit
                // We're done writing to the struct.  Compare this to the example above - we wrote quite a bit less.
            }

            bool success = rakServer.RPC(typeof(Program).GetMethod("clientRPC"), outgoingBitstream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE, 0, RakNetBindings.UNASSIGNED_SYSTEM_ADDRESS, true, 0, RakNetBindings.UNASSIGNED_NETWORK_ID, null);
            if (!success)
                Console.Write("RPC call failed\n");

            while (!quit)
            {
                rakClient.DeallocatePacket(rakClient.Receive());
                rakServer.DeallocatePacket(rakServer.Receive());

                System.Threading.Thread.Sleep(30);
            }

            Console.Write("Press enter to quit\n");
            Console.ReadLine();

            rakClient.Shutdown(100, 0);
            rakServer.Shutdown(100, 0);

            // This is not necessary since on shutdown everything is unregistered.  This is just here to show usage
            rakClient.UnregisterAsRemoteProcedureCall(typeof(Program).GetMethod("clientRPC"));

            RakNetworkFactory.DestroyRakPeerInterface(rakClient);
//.........这里部分代码省略.........
开发者ID:JetCrusherTorpedo,项目名称:raknetdotnet,代码行数:101,代码来源:Program.cs


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