Class to mimick Java's ByteBuffer which is used heavily in Flatbuffers
Пример #1
0
        private void SendTestMsg()
        {
            var builder  = IMsgDispatcher.instance.flatBufferBuilder;
            var account  = builder.CreateString("春眠不觉晓,处处闻啼鸟。夜来风雨声,花落知多少。");
            var password = builder.CreateString("床前明月光,疑是地上霜,举头望明月,低头思故乡");

            fbs.ReqLogin.StartReqLogin(builder);
            fbs.ReqLogin.AddAccount(builder, account);
            fbs.ReqLogin.AddPassword(builder, password);
            var orc = fbs.ReqLogin.EndReqLogin(builder);

            builder.Finish(orc.Value);

            byte[] bytearray = builder.DataBuffer.ToFullArray();

            string strbyte = "";

            for (int i = 0; i < bytearray.Length; i++)
            {
                strbyte += bytearray[i].ToString() + " ";
            }
            ILogSystem.instance.Log(LogCategory.GameLogic, strbyte);

            FlatBuffers.ByteBuffer newbuf = new FlatBuffers.ByteBuffer(bytearray);

            var reqlogin = fbs.ReqLogin.GetRootAsReqLogin(builder.DataBuffer);

            ILogSystem.instance.Log(LogCategory.GameLogic, reqlogin.Account);
            ILogSystem.instance.Log(LogCategory.GameLogic, reqlogin.Password);
        }
Пример #2
0
        static void LocalPerformanceTest()
        {
            byte[] data = System.IO.File.ReadAllBytes ("/Users/mzaks/Downloads/flatbuffers-master/samples/doge/gen/player_state.mon");
            int length1 = data.Length, length2 = 0;
            var byteBuffer = new FlatBuffers.ByteBuffer (data);
            var gamestate = GameStateRoot.GetRootAsGameStateRoot (byteBuffer);
            Stopwatch watch = new Stopwatch ();
            int numberOfRuns = 100;
            double[] m = new double[numberOfRuns];
            for (int i = 0; i < numberOfRuns; i++) {
                watch.Start ();
                FBDeserializationService.singleton.Deserialize (gamestate);
                createSomeGroups ();

                FBSerialisationService.singleton.corePool = FBDeserializationService.singleton.corePool;
                FBSerialisationService.singleton.metaPool = FBDeserializationService.singleton.metaPool;

                data = FBSerialisationService.singleton.GenerateGameState ();
                length2 = data.Length;
                byteBuffer = new FlatBuffers.ByteBuffer (data);
                gamestate = GameStateRoot.GetRootAsGameStateRoot (byteBuffer);
                watch.Stop ();
                m [i] = watch.Elapsed.TotalMilliseconds;
            }
            Console.WriteLine ("Hello World! " + gamestate.GameData1.PlayerName);
            for (int i = 0; i < numberOfRuns; i++) {
                Console.WriteLine ("Elapsed " + ((i == 0) ? m [i] : m [i] - m [i - 1]));
            }
            Console.WriteLine ("Elapsed AVG " + ((m [numberOfRuns - 1] - m [0]) / (numberOfRuns - 1)));
            Console.WriteLine ("Number of core pool entities " + FBDeserializationService.singleton.corePool.Count);
            Console.WriteLine ("Number of meta pool entities " + FBDeserializationService.singleton.metaPool.Count);
            Console.WriteLine ("Length before: " + length1 + " after: " + length2);
            System.IO.File.WriteAllBytes (@"/Users/mzaks/Downloads/flatbuffers-master/samples/doge/gen/player_state2.mon", data);
        }
Пример #3
0
    private int GetMsgID(FlatBuffers.ByteBuffer bb)
    {
        int bb_pos = bb.GetInt(0);
        int vtable = bb_pos - bb.GetInt(bb_pos);
        var o      = 4 < bb.GetShort(vtable) ? (int)bb.GetShort(vtable + 4) : 0;

        return(bb.GetInt(o + bb_pos));
    }
Пример #4
0
 static byte[] runTest(byte[] data)
 {
     var byteBuffer = new FlatBuffers.ByteBuffer (data);
     var gamestate = GameStateRoot.GetRootAsGameStateRoot (byteBuffer);
     FBDeserializationService.singleton.Deserialize (gamestate);
     createSomeGroups ();
     //
     FBSerialisationService.singleton.corePool = FBDeserializationService.singleton.corePool;
     FBSerialisationService.singleton.metaPool = FBDeserializationService.singleton.metaPool;
     //
     FBSerialisationService.singleton.GenerateGameState ();
     //
     return data;
 }
Пример #5
0
    public void DispatchMessage(FlatBuffers.ByteBuffer buffer)
    {
        var             type = CMessageID.GetMsgType(GetMsgID(buffer));
        List <Callback> calls;

        if (msgRegister.TryGetValue(type, out calls))
        {
            int len = calls.Count;
            for (int i = 0; i < len; i++)
            {
                calls[i].method.Invoke(calls[i].instance, new object[] { buffer });
            }
        }
    }
Пример #6
0
        public override void Invoke(byte[] bytearray)
        {
            FlatBuffers.ByteBuffer buf = new FlatBuffers.ByteBuffer(bytearray);
            m_obj.__init(buf.GetInt(buf.Position) + buf.Position, buf);

            try
            {
                m_dlg(m_obj);
            }
            catch (Exception e)
            {
                LogSystem.instance.LogError(LogCategory.GameEngine, "process msg error!" + typeof(T).FullName);
                LogSystem.instance.LogError(LogCategory.GameEngine, e.ToString());
            }
        }
Пример #7
0
 public static uvSwapItemMesh GetRootAsuvSwapItemMesh(ByteBuffer _bb, uvSwapItemMesh obj)
 {
     return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
Пример #8
0
 public animation __init(int _i, ByteBuffer _bb)
 {
     bb_pos = _i; bb = _bb; return this;
 }
Пример #9
0
 public static animation GetRootAsanimation(ByteBuffer _bb)
 {
     return GetRootAsanimation(_bb, new animation());
 }
Пример #10
0
 public static ListModulesResponse GetRootAsListModulesResponse(ByteBuffer _bb, ListModulesResponse obj)
 {
     return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
Пример #11
0
 public ListBreakpointsRequest __init(int _i, ByteBuffer _bb)
 {
     bb_pos = _i; bb = _bb; return this;
 }
Пример #12
0
 public static ListBreakpointsRequest GetRootAsListBreakpointsRequest(ByteBuffer _bb)
 {
     return GetRootAsListBreakpointsRequest(_bb, new ListBreakpointsRequest());
 }
Пример #13
0
 public static BreakpointEvent GetRootAsBreakpointEvent(ByteBuffer _bb, BreakpointEvent obj)
 {
     return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
Пример #14
0
    void Start()
    {
        oNetworkManager MainPlayer = NetworkObject.mainPlayer.GetComponent <oNetworkManager>();

        NetDataReader.GetInstace().Reder[Class.Player] = (data) => {
            var m_player = Player.GetRootAsPlayer(data.ByteBuffer);

            if (m_player.ID != MainPlayer.id)
            {
                if (!OPlayers.ContainsKey(m_player.ID))
                {
                    var obj = Instantiate(PlayerPrifab, Vector3.zero, Quaternion.identity);
                    obj.AddComponent <OtherPlayer>();
                    obj.AddComponent <oNetworkIdentity>().id   = m_player.ID;
                    obj.GetComponent <oNetworkIdentity>().type = oNetworkIdentity.ObjType.player;
                    OPlayers[m_player.ID] = obj.GetComponent <OtherPlayer>();
                    SendToMe_PlayerStat.Send(m_player.ID);
                }

                OPlayers[m_player.ID].UpdateOtherObj(m_player);
            }
            else if (m_player.ID == MainPlayer.id)
            {
                var pos = m_player.Pos.Value;
                MainPlayer.transform.position.Set(pos.X, pos.Y, pos.Z);
            }
        };



        NetDataReader.GetInstace().Reder[Class.FirstCharacterData] = (data) =>
        {
            var FirstPlayerData = FirstCharacterData.GetRootAsFirstCharacterData(data.ByteBuffer);


            var fbb = new FlatBuffers.FlatBufferBuilder(1);

            fbb.Finish(PlayerStat.CreatePlayerStat(
                           fbb,
                           Class.PlayerStat,
                           FirstPlayerData.HP,
                           FirstPlayerData.HPLim,
                           FirstPlayerData.MP,
                           FirstPlayerData.MPLim,
                           FirstPlayerData.EXP,
                           FirstPlayerData.Attack,
                           FirstPlayerData.LV,
                           FirstPlayerData.ID
                           ).Value);

            var buf = new FlatBuffers.ByteBuffer(fbb.SizedByteArray());

            var _PlayerStat = PlayerStat.GetRootAsPlayerStat(buf);

            var pos = FirstPlayerData.Pos.Value;
            MainPlayer.GetComponent <oCreature>().Data_Update(_PlayerStat);
            MainPlayer.GetComponent <oCreature>().Data_Update(pos);
            MainPlayer.GetComponent <NetworkObject>().m_CurrentHP.NoEventSet(_PlayerStat.HP);
            MainPlayer.GetComponent <NetworkObject>().m_CurrentMP.NoEventSet(_PlayerStat.MP);
            MainPlayer.GetComponent <NetworkObject>().m_CurrentHPLim.NoEventSet(_PlayerStat.HPLim);
            MainPlayer.GetComponent <NetworkObject>().m_CurrentMPLim.NoEventSet(_PlayerStat.MPLim);
            MainPlayer.GetComponent <NetworkObject>().m_CurrentLV.NoEventSet(_PlayerStat.LV);
            MainPlayer.GetComponent <NetworkObject>().m_CurrentEXP.NoEventSet(_PlayerStat.EXP);
            MainPlayer.GetComponent <NetworkObject>().m_CurrentATK.NoEventSet(_PlayerStat.Attack);

            MainPlayer.GetComponent <NetworkObject>().CharacterName.NoEventSet(FirstPlayerData.Name);
            Vector3 v3 = new Vector3();
            v3.Set(pos.X, pos.Y, pos.Z);
        };



        NetDataReader.GetInstace().Reder[Class.fEquipSome] = (data) =>
        {
            var equipSome = fEquipSome.GetRootAsfEquipSome(data.ByteBuffer);
            Debug.Log(MainPlayer.GetComponent <oNetworkIdentity>().id + ":" + equipSome.PID + ":" + equipSome.SlotNum + ":" + equipSome.ObjNum);
            if (MainPlayer.GetComponent <oNetworkIdentity>().id == equipSome.PID)
            {
                MainPlayer.GetComponent <EquipManager>().Equip(equipSome.ObjNum, equipSome.SlotNum);
            }
            else
            {
                OPlayers[equipSome.PID].GetComponent <EquipManager>().Equip(equipSome.ObjNum, -1);
            }
        };


        NetDataReader.GetInstace().Reder[Class.PlayerStat] = (data) => {
            var _PlayerStat = PlayerStat.GetRootAsPlayerStat(data.ByteBuffer);
            var player      = MainPlayer.GetComponent <NetworkObject>();

            if (_PlayerStat.ID == MainPlayer.id)
            {
                MainPlayer.GetComponent <oCreature>().Data_Update(_PlayerStat);
                player.m_CurrentHP.NoEventSet(_PlayerStat.HP);
                player.m_CurrentMP.NoEventSet(_PlayerStat.MP);
                player.m_CurrentHPLim.NoEventSet(_PlayerStat.HPLim);
                player.m_CurrentMPLim.NoEventSet(_PlayerStat.MPLim);
                player.m_CurrentEXP.NoEventSet(_PlayerStat.EXP);
                player.m_CurrentATK.NoEventSet(_PlayerStat.Attack);
                if (_PlayerStat.LV > player.m_CurrentLV.Value)
                {
                    IG_EffectManager.Show(player.gameObject.transform.position, "LVUP");
                }
                player.m_CurrentLV.NoEventSet(_PlayerStat.LV);
            }
            else if (OPlayers.ContainsKey(_PlayerStat.ID))
            {
                if (OPlayers[_PlayerStat.ID].GetComponent <oCreature>() == null)
                {
                    OPlayers[_PlayerStat.ID].gameObject.AddComponent <oCreature>();
                    OPlayers[_PlayerStat.ID].gameObject.AddComponent <SendStateManager>();
                    OPlayers[_PlayerStat.ID].gameObject.GetComponent <OtherPlayer>().SetStatEvent();
                    OPlayers[_PlayerStat.ID].gameObject.name = _PlayerStat.NikName;
                }

                OPlayers[_PlayerStat.ID].gameObject.GetComponent <oCreature>().Data_Update(_PlayerStat);
            }
        };
    }
Пример #15
0
    public override void Deserialize(FlatBuffers.ByteBuffer buf)
    {
        var fbSettlerDataComponent = Serial./*name|pre#FB:ComponentName*/ FBGenTemplateComponent /*endname*/./*name|pre#GetRootAsFB:ComponentName*/ GetRootAsFBGenTemplateComponent/*endname*/ (buf);

        Deserialize(fbSettlerDataComponent);
    }
Пример #16
0
 public static GameData GetRootAsGameData(ByteBuffer _bb)
 {
     return GetRootAsGameData(_bb, new GameData());
 }
Пример #17
0
 public GameData __init(int _i, ByteBuffer _bb)
 {
     bb_pos = _i; bb = _bb; return this;
 }
Пример #18
0
 public BreakpointEvent __init(int _i, ByteBuffer _bb)
 {
     bb_pos = _i; bb = _bb; return this;
 }
 public PulseKeyFrameData_Float __init(int _i, ByteBuffer _bb)
 {
     bb_pos = _i; bb = _bb; return this;
 }
Пример #20
0
 public static ActorData GetRootAsActorData(ByteBuffer _bb)
 {
     return GetRootAsActorData(_bb, new ActorData());
 }
Пример #21
0
 public static ListBreakpointsRequest GetRootAsListBreakpointsRequest(ByteBuffer _bb, ListBreakpointsRequest obj)
 {
     return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
 public static animationMeshTimeSample GetRootAsanimationMeshTimeSample(ByteBuffer _bb)
 {
     return GetRootAsanimationMeshTimeSample(_bb, new animationMeshTimeSample());
 }
Пример #23
0
 public static ListModulesResponse GetRootAsListModulesResponse(ByteBuffer _bb)
 {
     return GetRootAsListModulesResponse(_bb, new ListModulesResponse());
 }
 public static animationMeshTimeSample GetRootAsanimationMeshTimeSample(ByteBuffer _bb, animationMeshTimeSample obj)
 {
     return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
Пример #25
0
 public ListModulesResponse __init(int _i, ByteBuffer _bb)
 {
     bb_pos = _i; bb = _bb; return this;
 }
 public animationMeshTimeSample __init(int _i, ByteBuffer _bb)
 {
     bb_pos = _i; bb = _bb; return this;
 }
Пример #27
0
 public static animation GetRootAsanimation(ByteBuffer _bb, animation obj)
 {
     return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
Пример #28
0
 public static TypeAmount GetRootAsTypeAmount(ByteBuffer _bb)
 {
     return GetRootAsTypeAmount(_bb, new TypeAmount());
 }
Пример #29
0
 public static uvSwapItemMesh GetRootAsuvSwapItemMesh(ByteBuffer _bb)
 {
     return GetRootAsuvSwapItemMesh(_bb, new uvSwapItemMesh());
 }
Пример #30
0
 public static TypeAmount GetRootAsTypeAmount(ByteBuffer _bb, TypeAmount obj)
 {
     return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
Пример #31
0
 public uvSwapItemMesh __init(int _i, ByteBuffer _bb)
 {
     bb_pos = _i; bb = _bb; return this;
 }
Пример #32
0
 public TypeAmount __init(int _i, ByteBuffer _bb)
 {
     bb_pos = _i; bb = _bb; return this;
 }
Пример #33
0
 public static GameData GetRootAsGameData(ByteBuffer _bb, GameData obj)
 {
     return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
 public static PulseKeyFrameData_Float GetRootAsPulseKeyFrameData_Float(ByteBuffer _bb)
 {
     return GetRootAsPulseKeyFrameData_Float(_bb, new PulseKeyFrameData_Float());
 }
Пример #35
0
 public XObject __init(int _i, ByteBuffer _bb)
 {
     bb_pos = _i; bb = _bb; return this;
 }
 public static PulseKeyFrameData_Float GetRootAsPulseKeyFrameData_Float(ByteBuffer _bb, PulseKeyFrameData_Float obj)
 {
     return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }