コード例 #1
0
ファイル: Packet.cs プロジェクト: Norne9/NecroServer
 public static void Register(NetSerializer netSerializer)
 {
     netSerializer.RegisterCustomType <ObstacleInfo>();
     netSerializer.RegisterCustomType <PlayerInfo>();
     netSerializer.RegisterCustomType <PlayerCameraInfo>();
     netSerializer.RegisterCustomType <UnitInfo>();
     netSerializer.RegisterCustomType <RuneInfo>();
 }
コード例 #2
0
ファイル: SerializerTest.cs プロジェクト: zhennTil/LiteNetLib
            public ServerListener()
            {
                _netSerializer = new NetSerializer();
                _netSerializer.RegisterCustomType(SomeVector2.Serialize, SomeVector2.Deserialize);
                _netSerializer.RegisterCustomType <SampleNetSerializable>();

                //user data support
                _netSerializer.SubscribeReusable <SamplePacket, NetPeer>(OnSamplePacketReceived);
            }
コード例 #3
0
    void Init()
    {
        serializer = new NetSerializer();
        serializer.RegisterCustomType(SerializedLobbyPlayer.Serialize, SerializedLobbyPlayer.Deserialize);

        serializer.SubscribeReusable <PClientHandshake, NetPeer>(OnReceiveHandshake);

        isInit = true;
    }
コード例 #4
0
        public void Init()
        {
            _samplePacket = new SamplePacket
            {
                SomeFloat    = 3.42f,
                SomeIntArray = new[] { 6, 5, 4 },
                SomeString   = "Test String",
                SomeVector2  = new SomeVector2(4, 5),
                SomeVectors  = new[] { new SomeVector2(1, 2), new SomeVector2(3, 4) },
                SomeEnum     = TestEnum.B,
                TestObj      = new SampleNetSerializable {
                    Value = 5
                }
            };

            _serializer = new NetSerializer();
            _serializer.RegisterCustomType <SampleNetSerializable>();
            _serializer.RegisterCustomType(SomeVector2.Serialize, SomeVector2.Deserialize);
        }
コード例 #5
0
ファイル: NetworkClient.cs プロジェクト: Fyffe/LiteNetLobby
    void Init()
    {
        serializer = new NetSerializer();
        serializer.RegisterCustomType(SerializedLobbyPlayer.Serialize, SerializedLobbyPlayer.Deserialize);

        serializer.SubscribeReusable <PLobby, NetPeer>(OnReceiveLobby);
        serializer.SubscribeReusable <PLobbyPlayer>(OnClientLobbyAction);

        isInit = true;
    }
コード例 #6
0
ファイル: SerializerTest.cs プロジェクト: zhennTil/LiteNetLib
        private void TestPerformance()
        {
            const int LoopLength = 100000;
            //Test serializer performance
            Stopwatch       stopwatch       = new Stopwatch();
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            MemoryStream    memoryStream    = new MemoryStream();
            NetDataWriter   netDataWriter   = new NetDataWriter();

            SamplePacket samplePacket = new SamplePacket
            {
                SomeFloat    = 0.3f,
                SomeString   = "TEST",
                SomeIntArray = new [] { 1, 2, 3 },
                SomeVector2  = new SomeVector2(1, 2),
                SomeVectors  = new [] { new SomeVector2(3, 4), new SomeVector2(5, 6) }
            };

            NetSerializer netSerializer = new NetSerializer();

            netSerializer.RegisterCustomType <SampleNetSerializable>();
            netSerializer.RegisterCustomType(SomeVector2.Serialize, SomeVector2.Deserialize);

            //Prewarm cpu
            for (int i = 0; i < 10000000; i++)
            {
                double c = Math.Sin(i);
            }

            //Test binary formatter
            stopwatch.Start();
            for (int i = 0; i < LoopLength; i++)
            {
                binaryFormatter.Serialize(memoryStream, samplePacket);
            }
            stopwatch.Stop();
            Console.WriteLine("BinaryFormatter time: " + stopwatch.ElapsedMilliseconds + " ms");

            //Test NetSerializer
            stopwatch.Restart();
            for (int i = 0; i < LoopLength; i++)
            {
                netSerializer.Serialize(netDataWriter, samplePacket);
            }
            stopwatch.Stop();
            Console.WriteLine("NetSerializer first run time: " + stopwatch.ElapsedMilliseconds + " ms");

            //Test NetSerializer
            netDataWriter.Reset();
            stopwatch.Restart();
            for (int i = 0; i < LoopLength; i++)
            {
                netSerializer.Serialize(netDataWriter, samplePacket);
            }
            stopwatch.Stop();
            Console.WriteLine("NetSerializer second run time: " + stopwatch.ElapsedMilliseconds + " ms");

            //Test RAW
            netDataWriter.Reset();
            stopwatch.Restart();
            for (int i = 0; i < LoopLength; i++)
            {
                netDataWriter.Put(samplePacket.SomeFloat);
                netDataWriter.Put(samplePacket.SomeString);
                netDataWriter.PutArray(samplePacket.SomeIntArray);
                netDataWriter.Put(samplePacket.SomeVector2.X);
                netDataWriter.Put(samplePacket.SomeVector2.Y);
                netDataWriter.Put(samplePacket.SomeVectors.Length);
                for (int j = 0; j < samplePacket.SomeVectors.Length; j++)
                {
                    netDataWriter.Put(samplePacket.SomeVectors[j].X);
                    netDataWriter.Put(samplePacket.SomeVectors[j].Y);
                }
                netDataWriter.Put(samplePacket.EmptyString);
                netDataWriter.Put(samplePacket.TestObj.Value);
            }
            stopwatch.Stop();
            Console.WriteLine("DataWriter (raw put method calls) time: " + stopwatch.ElapsedMilliseconds + " ms");
        }
コード例 #7
0
ファイル: SerializerTest.cs プロジェクト: zhennTil/LiteNetLib
 public ClientListener()
 {
     _serializer = new NetSerializer();
     _serializer.RegisterCustomType <SampleNetSerializable>();
     _serializer.RegisterCustomType(SomeVector2.Serialize, SomeVector2.Deserialize);
 }
コード例 #8
0
 public ServerListener()
 {
     _netSerializer = new NetSerializer();
     _netSerializer.RegisterCustomType(SomeVector2.Serialize, SomeVector2.Deserialize);
     _netSerializer.Subscribe <SamplePacket>(OnSamplePacketReceived);
 }