Exemplo n.º 1
0
        private void GetPacket()
        {
            packet = GamestatePacketManager.GetPacket();

            for (int i = 0; i < GamestatePacket.maxBools; i++)
            {
                setBools[i] = false;
            }
        }
Exemplo n.º 2
0
        internal void Increment(EntryErrorCallback callback)
        {
            PreparePacketForIncrement();

            errorCallbacks.Add(callback);
            commitHandler.CommitPacket(packet);

            GamestatePacketManager.ReleasePacket(packet);
            packet = null;

            Release();
        }
Exemplo n.º 3
0
        void Awake()
        {
            GamestatePacketManager.RegisterPacket();

            DontDestroyOnLoad(gameObject);
            UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoaded;
            view = GetComponent <PhotonView>();

            _globals = new GlobalsEntry(this);
            _players = new GamestateTable <PlayerEntry>(this, Table.Players);
            _teams   = new GamestateTable <TeamEntry>(this, Table.Teams);
        }
Exemplo n.º 4
0
        public void Increment()
        {
            PreparePacketForIncrement();

            if (errorCallbacks.Count == 0)
            {
                errorCallbacks.Add(null);
            }
            commitHandler.CommitPacket(packet);

            GamestatePacketManager.ReleasePacket(packet);
            packet = null;

            Release();
        }
Exemplo n.º 5
0
        internal void Commit(EntryErrorCallback callback)
        {
            PreparePacketForCommit();

            errorCallbacks.Add(callback);
            if (errorCallbacks.Count == 1)
            {
                commitHandler.CommitPacket(packet);
            }

            GamestatePacketManager.ReleasePacket(packet);
            packet = null;

            Release();
        }
Exemplo n.º 6
0
        public void Delete()
        {
            if (packet == null)
            {
                GetPacket();
            }

            packet.id         = id;
            packet.packetType = GamestatePacket.PacketType.Delete;

            commitHandler.CommitPacket(packet);

            GamestatePacketManager.ReleasePacket(packet);
            packet = null;

            Release();
        }
Exemplo n.º 7
0
        public static object Deserialize(byte[] data)
        {
            GamestatePacket packet = GamestatePacketManager.GetPacket();

            int index = 0;

            //  Deserialize metadata
            packet.packetType = (PacketType)(data[index] & 0x03);
            packet.table      = (GamestateTracker.Table)((data[index] & 0x7C) >> 2);
            packet.hasName    = (data[index] & 0x80) == 0x80;
            index++;

            //  Deserialize id
            short idA = (short)(((uint)data[index] << 8) & 0x0000FF00);
            short idB = (short)((uint)data[index + 1] & 0x000000FF);

            packet.id = (short)(idA | idB);
            index    += 2;

            if (packet.packetType != PacketType.Delete)
            {
                if (packet.packetType != PacketType.Increment)
                {
                    //  Deserialize revision number
                    uint revisionNumberA = ((uint)data[index] << 24) & 0xFF000000;
                    uint revisionNumberB = ((uint)data[index + 1] << 16) & 0x00FF0000;
                    uint revisionNumberC = ((uint)data[index + 2] << 8) & 0x0000FF00;
                    uint revisionNumberD = (uint)data[index + 3] & 0x000000FF;
                    packet.revisionNumber = revisionNumberA | revisionNumberB | revisionNumberC | revisionNumberD;
                    index += 4;
                }

                //  Deserialize revision actor
                packet.revisionActor = data[index];
                index++;

                //  Deserialize short metadata
                int shortCount = 0;
                for (int i = 0; i < 8; i++)
                {
                    if (((data[index] >> i) & 0x01) == 0x01)
                    {
                        packet.hasShortValues[i + 8] = true;
                        shortCount++;
                    }
                    else
                    {
                        packet.hasShortValues[i + 8] = false;
                    }

                    if (((data[index + 1] >> i) & 0x01) == 0x01)
                    {
                        packet.hasShortValues[i] = true;
                        shortCount++;
                    }
                    else
                    {
                        packet.hasShortValues[i] = false;
                    }
                }
                index += 2;

                //  Deserialize bool values
                for (int i = 0; i < 8; i++)
                {
                    if (((data[index] >> i) & 0x01) == 0x01)
                    {
                        packet.boolValues[i + 8] = true;
                    }
                    else
                    {
                        packet.boolValues[i + 8] = false;
                    }

                    if (((data[index + 1] >> i) & 0x01) == 0x01)
                    {
                        packet.boolValues[i] = true;
                    }
                    else
                    {
                        packet.boolValues[i] = false;
                    }
                }
                index += 2;

                if (packet.packetType != PacketType.Increment)
                {
                    //  Deserialise name
                    if (packet.hasName)
                    {
                        int nameLength = data[index];
                        packet.name = stringEncoder.GetString(data, index + 1, nameLength);
                        index      += nameLength + 1;
                    }
                }

                //  Deserialize short values
                for (int i = 0; i < shortCount; i++)
                {
                    short valueA = (short)(((uint)data[index] << 8) & 0x0000FF00);
                    short valueB = (short)((uint)data[index + 1] & 0x000000FF);
                    packet.shortValues.Add((short)(valueA | valueB));
                    index += 2;
                }
            }

            return(packet);
        }