public override void Serialize(NetBuffer buffer)
        {
            if (this.stateFlag != null)
            {
                ByteFlag stateFlag = new ByteFlag();
                stateFlag.Set(0, IsFlashlightOn);
                stateFlag.Set(1, IsReloading);

                this.stateFlag.Value = stateFlag;
            }

            if (this.movementFlag != null)
            {
                ByteFlag movementFlag = new ByteFlag();

                movementFlag.Set(0, IsCrouching);
                movementFlag.Set(1, IsSprinting);
                movementFlag.Set(2, IsMoving);
                movementFlag.Set(3, IsAiming);
                movementFlag.Set(4, IsGrounded);
                movementFlag.Set(5, IsJumping);

                this.movementFlag.Value = movementFlag;
            }

            base.Serialize(buffer);
        }
Exemplo n.º 2
0
        public static bool Matches(IEntityOld entity, ByteFlag components, EntityMatchesOld match = EntityMatchesOld.All)
        {
            bool matches = false;

            switch (match)
            {
            case EntityMatchesOld.All:
                matches = MatchesAll(entity, components);
                break;

            case EntityMatchesOld.Any:
                matches = MatchesAny(entity, components);
                break;

            case EntityMatchesOld.None:
                matches = !MatchesAny(entity, components);
                break;

            case EntityMatchesOld.Exact:
                matches = MatchesExact(entity, components);
                break;
            }

            return(matches);
        }
Exemplo n.º 3
0
        public override void Serialize(NetBuffer buffer)
        {
            ByteFlag actionFlag = new ByteFlag();

            actionFlag.Set(0, IsFlashlightVisible);
            actionFlag.Set(1, Reload);
            actionFlag.Set(2, DropIntel);

            this.actionFlag.Value = actionFlag;

            ByteFlag movementFlag = new ByteFlag();

            movementFlag.Set(0, IsCrouching);
            movementFlag.Set(1, IsSprinting);
            movementFlag.Set(2, IsMoving);
            movementFlag.Set(3, IsAiming);
            movementFlag.Set(4, IsGrounded);
            movementFlag.Set(5, Jump);

            this.movementFlag.Value = movementFlag;

            Reload    = false;
            DropIntel = false;
            Jump      = false;

            base.Serialize(buffer);
        }
        public override void Deserialize(NetBuffer buffer)
        {
            base.Deserialize(buffer);

            if (this.stateFlag != null)
            {
                ByteFlag stateFlag = (ByteFlag)this.stateFlag.Value;
                IsFlashlightOn = stateFlag.Get(0);
                IsReloading    = stateFlag.Get(1);
            }

            if (this.movementFlag != null)
            {
                ByteFlag movementFlag = (ByteFlag)this.movementFlag.Value;

                IsCrouching = movementFlag.Get(0);
                IsSprinting = movementFlag.Get(1);
                IsMoving    = movementFlag.Get(2);
                IsAiming    = movementFlag.Get(3);
                IsGrounded  = movementFlag.Get(4);
                IsJumping   = movementFlag.Get(5);
            }

            if (NetId != initId)
            {
                throw new Exception(string.Format(
                                        "PlayerSnapshot id mismatch! Server had different id than client! (NetId, initId) {0} != {1}", NetId, initId));
            }
        }
Exemplo n.º 5
0
        public static ByteFlag GetComponentFlags(Type componentType)
        {
            var flag = new ByteFlag();
            flag[GetOrAddComponentId(componentType)] = true;

            return flag;
        }
Exemplo n.º 6
0
        public static bool Matches(ByteFlag groups1, ByteFlag groups2, EntityMatchesOld match = EntityMatchesOld.All)
        {
            bool matches = false;

            switch (match)
            {
            case EntityMatchesOld.All:
                matches = MatchesAll(groups1, groups2);
                break;

            case EntityMatchesOld.Any:
                matches = MatchesAny(groups1, groups2);
                break;

            case EntityMatchesOld.None:
                matches = !MatchesAny(groups1, groups2);
                break;

            case EntityMatchesOld.Exact:
                matches = MatchesExact(groups1, groups2);
                break;
            }

            return(matches);
        }
Exemplo n.º 7
0
        public void AndFlags()
        {
            var flagsA = new ByteFlag(1, 2, 3);
            var flagsB = flagsA & new ByteFlag(3, 4);

            Assert.That(flagsA, !Is.EqualTo(flagsB));
            Assert.That(flagsB == new ByteFlag(3));
        }
Exemplo n.º 8
0
        public static ByteFlag GetComponentFlags(Type componentType)
        {
            var flag = new ByteFlag();

            flag[GetOrAddComponentId(componentType)] = true;

            return(flag);
        }
Exemplo n.º 9
0
        public void XorFlags()
        {
            var flagsA = new ByteFlag(1, 2, 3);
            var flagsB = flagsA ^ new ByteFlag(3, 4);

            Assert.That(flagsA, !Is.EqualTo(flagsB));
            Assert.That(flagsB == new ByteFlag(1, 2, 4));
        }
Exemplo n.º 10
0
        public void SubtractFlags()
        {
            var flagsA = new ByteFlag(1, 2, 3);
            var flagsB = flagsA - new ByteFlag(4, 3);

            Assert.That(flagsA, !Is.EqualTo(flagsB));
            Assert.IsTrue(flagsA[3]);
            Assert.IsFalse(flagsB[3]);
        }
Exemplo n.º 11
0
        public void AddFlags()
        {
            var flagsA = new ByteFlag(1, 2, 3);
            var flagsB = flagsA + new ByteFlag(3, 4);

            Assert.That(flagsA, !Is.EqualTo(flagsB));
            Assert.IsFalse(flagsA[4]);
            Assert.IsTrue(flagsB[4]);
        }
Exemplo n.º 12
0
        public static ByteFlag GetComponentFlags(Type[] componentTypes)
        {
            var flag = new ByteFlag();

            for (int i = 0; i < componentTypes.Length; i++)
                flag[GetOrAddComponentId(componentTypes[i])] = true;

            return flag;
        }
Exemplo n.º 13
0
        public void AddFlags()
        {
            var flagsA = new ByteFlag(1, 2, 3);
            var flagsB = flagsA + new ByteFlag(3, 4);

            Assert.That(flagsA, !Is.EqualTo(flagsB));
            Assert.IsFalse(flagsA[4]);
            Assert.IsTrue(flagsB[4]);
        }
Exemplo n.º 14
0
        public static ByteFlag GetComponentFlags(Type[] componentTypes)
        {
            var flag = new ByteFlag();

            for (int i = 0; i < componentTypes.Length; i++)
            {
                flag[GetOrAddComponentId(componentTypes[i])] = true;
            }

            return(flag);
        }
Exemplo n.º 15
0
        public EntityGroupOld CreateEntityGroup(ByteFlag groups)
        {
            var entityGroup = new EntityGroupOld();

            for (int i = 0; i < parent.Entities.Count; i++)
            {
                var entity = parent.Entities[i];
                entityGroup.UpdateEntity(entity, IsEntityGroupValid(entity, groups));
            }

            return entityGroup;
        }
Exemplo n.º 16
0
        static bool MatchesExact(IEntityOld entity, ByteFlag components)
        {
            for (byte i = 0; i < EntityUtility.IdCount; i++)
            {
                if (components[i] != entity.HasComponent(EntityUtility.GetComponentType(i)))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 17
0
 public void FromByteFlag(ByteFlag movementFlag, bool isAiming)
 {
     Sprint       = movementFlag.Get(0);
     Crouch       = movementFlag.Get(1);
     Jump         = movementFlag.Get(2);
     MoveForward  = movementFlag.Get(3);
     MoveBackward = movementFlag.Get(4);
     MoveLeft     = movementFlag.Get(5);
     MoveRight    = movementFlag.Get(6);
     Walk         = movementFlag.Get(7);
     Aiming       = isAiming;
 }
Exemplo n.º 18
0
        public EntityGroupOld GetGroupByComponentGroup(ByteFlag components)
        {
            EntityGroupOld entityGroup;

            if (!componentGroups.TryGetValue(components, out entityGroup))
            {
                entityGroup = CreateComponentGroup(components);
                componentGroups[components] = entityGroup;
            }

            return(entityGroup);
        }
Exemplo n.º 19
0
        public EntityGroupOld GetGroupByEntityGroup(ByteFlag groups)
        {
            EntityGroupOld entityGroup;

            if (!entityGroups.TryGetValue(groups, out entityGroup))
            {
                entityGroup          = CreateEntityGroup(groups);
                entityGroups[groups] = entityGroup;
            }

            return(entityGroup);
        }
Exemplo n.º 20
0
        public EntityGroupOld CreateComponentGroup(ByteFlag components)
        {
            var entityGroup = new EntityGroupOld();

            for (int i = 0; i < parent.Entities.Count; i++)
            {
                var entity = parent.Entities[i];
                entityGroup.UpdateEntity(entity, IsComponentGroupValid(entity, components));
            }

            return(entityGroup);
        }
Exemplo n.º 21
0
        public void HasAll()
        {
            var flags = new ByteFlag(1, 2, 3);

            Assert.IsTrue(flags.HasAll(new ByteFlag(1, 2, 3)));
            Assert.IsTrue(flags.HasAll(new ByteFlag(1)));
            Assert.IsTrue(flags.HasAll(ByteFlag.Nothing));
            Assert.IsTrue(ByteFlag.Everything.HasAll(flags));
            Assert.IsFalse(flags.HasAll(new ByteFlag(1, 2, 4)));
            Assert.IsFalse(flags.HasAll(new ByteFlag(4, 5, 6)));
            Assert.IsFalse(flags.HasAll(ByteFlag.Everything));
            Assert.IsFalse(ByteFlag.Nothing.HasAll(flags));
        }
Exemplo n.º 22
0
        public void HasNone()
        {
            var flags = new ByteFlag(1, 2, 3);

            Assert.IsTrue(flags.HasNone(new ByteFlag(4, 5, 6)));
            Assert.IsTrue(flags.HasNone(ByteFlag.Nothing));
            Assert.IsTrue(ByteFlag.Nothing.HasNone(flags));
            Assert.IsFalse(flags.HasNone(new ByteFlag(1, 2, 3)));
            Assert.IsFalse(flags.HasNone(new ByteFlag(1)));
            Assert.IsFalse(flags.HasNone(new ByteFlag(1, 2, 4)));
            Assert.IsFalse(flags.HasNone(ByteFlag.Everything));
            Assert.IsFalse(ByteFlag.Everything.HasNone(flags));
        }
Exemplo n.º 23
0
        public override void Deserialize(NetBuffer packet)
        {
            base.Deserialize(packet);

            ByteFlag actionFlag = (ByteFlag)this.actionFlag.Value;

            IsFlashlightVisible = actionFlag.Get(0);
            Reload    = actionFlag.Get(1);
            DropIntel = actionFlag.Get(2);

            ByteFlag movementFlag = (ByteFlag)this.movementFlag.Value;

            IsCrouching = movementFlag.Get(0);
            IsSprinting = movementFlag.Get(1);
            IsMoving    = movementFlag.Get(2);
            IsAiming    = movementFlag.Get(3);
            IsGrounded  = movementFlag.Get(4);
            Jump        = movementFlag.Get(5);
        }
Exemplo n.º 24
0
            public void SetNeighbors(bool above, bool below, bool left, bool right, bool forward, bool backward)
            {
                ByteFlag newFlag = new ByteFlag();

                newFlag.Set(0, left);
                newFlag.Set(1, right);
                newFlag.Set(2, above);
                newFlag.Set(3, below);
                newFlag.Set(4, forward);
                newFlag.Set(5, backward);

                byte nCount = 0;

                if (above)
                {
                    nCount++;
                }
                if (below)
                {
                    nCount++;
                }
                if (left)
                {
                    nCount++;
                }
                if (right)
                {
                    nCount++;
                }
                if (forward)
                {
                    nCount++;
                }
                if (backward)
                {
                    nCount++;
                }

                neighborFlags = newFlag;
                NeighborCount = nCount;
            }
Exemplo n.º 25
0
        void OnByteFlagSelected(FlagsOption option, SerializedProperty property)
        {
            var byteFlag = property.GetValue <ByteFlag>();

            switch (option.Type)
            {
            case FlagsOption.OptionTypes.Everything:
                byteFlag = new ByteFlag(enumValues.Convert((object v) => Convert.ToByte(v)));
                break;

            case FlagsOption.OptionTypes.Nothing:
                byteFlag = ByteFlag.Nothing;
                break;

            case FlagsOption.OptionTypes.Custom:
                byte value = (byte)option.Value;
                byteFlag = byteFlag[value] ? byteFlag - value : byteFlag + value;
                break;
            }

            property.SetValue(byteFlag);
        }
Exemplo n.º 26
0
        public static bool Matches(ByteFlag groups1, ByteFlag groups2, EntityMatchesOld match = EntityMatchesOld.All)
        {
            bool matches = false;

            switch (match)
            {
                case EntityMatchesOld.All:
                    matches = MatchesAll(groups1, groups2);
                    break;
                case EntityMatchesOld.Any:
                    matches = MatchesAny(groups1, groups2);
                    break;
                case EntityMatchesOld.None:
                    matches = !MatchesAny(groups1, groups2);
                    break;
                case EntityMatchesOld.Exact:
                    matches = MatchesExact(groups1, groups2);
                    break;
            }

            return matches;
        }
        internal bool ReadHeader()
        {
            Position = 0;
            char prefix = ReadChar();

            if (prefix != PACKET_PREFIX)
            {
                return(false);
            }
            else
            {
                Type = (NetPacketType)ReadByte();
                Id   = ReadUInt16();

                ByteFlag flags = ReadByteFlag();
                isReliable   = flags.Get(0);
                isChunked    = flags.Get(1);
                isCompressed = flags.Get(2);
                isEncrypted  = flags.Get(3);
                isPartial    = flags.Get(4);

                return(true);
            }
        }
Exemplo n.º 28
0
 static bool MatchesAny(ByteFlag groups1, ByteFlag groups2)
 {
     return (groups1 & ~groups2) != groups1;
 }
Exemplo n.º 29
0
 static bool MatchesAll(ByteFlag groups1, ByteFlag groups2)
 {
     return (~groups1 & groups2) == ByteFlag.Nothing;
 }
Exemplo n.º 30
0
 public static IEntityGroupOld GetEntityGroup(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All)
 {
     return(masterGroup.Filter(groups, match));
 }
Exemplo n.º 31
0
 public IEntityGroupOld Filter(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All)
 {
     return(GetMatchGroup(match).GetGroupByEntityGroup(groups));
 }
Exemplo n.º 32
0
        public EntityGroupOld GetGroupByComponentGroup(ByteFlag components)
        {
            EntityGroupOld entityGroup;

            if (!componentGroups.TryGetValue(components, out entityGroup))
            {
                entityGroup = CreateComponentGroup(components);
                componentGroups[components] = entityGroup;
            }

            return entityGroup;
        }
Exemplo n.º 33
0
 static bool MatchesExact(ByteFlag groups1, ByteFlag groups2)
 {
     return(groups1 == groups2);
 }
Exemplo n.º 34
0
 public EntityMatchOld(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All)
 {
     this.groups = groups;
     this.match = match;
 }
Exemplo n.º 35
0
 static bool MatchesAny(ByteFlag groups1, ByteFlag groups2)
 {
     return((groups1 & ~groups2) != groups1);
 }
Exemplo n.º 36
0
 public bool IsEntityGroupValid(IEntityOld entity, ByteFlag groups)
 {
     return EntityMatchOld.Matches(entity.Groups, groups, match);
 }
Exemplo n.º 37
0
        public static bool Matches(IEntityOld entity, ByteFlag components, EntityMatchesOld match = EntityMatchesOld.All)
        {
            bool matches = false;

            switch (match)
            {
                case EntityMatchesOld.All:
                    matches = MatchesAll(entity, components);
                    break;
                case EntityMatchesOld.Any:
                    matches = MatchesAny(entity, components);
                    break;
                case EntityMatchesOld.None:
                    matches = !MatchesAny(entity, components);
                    break;
                case EntityMatchesOld.Exact:
                    matches = MatchesExact(entity, components);
                    break;
            }

            return matches;
        }
Exemplo n.º 38
0
 public bool IsEntityGroupValid(IEntityOld entity, ByteFlag groups)
 {
     return(EntityMatchOld.Matches(entity.Groups, groups, match));
 }
Exemplo n.º 39
0
        public void SubtractFlags()
        {
            var flagsA = new ByteFlag(1, 2, 3);
            var flagsB = flagsA - new ByteFlag(4, 3);

            Assert.That(flagsA, !Is.EqualTo(flagsB));
            Assert.IsTrue(flagsA[3]);
            Assert.IsFalse(flagsB[3]);
        }
Exemplo n.º 40
0
 static bool MatchesExact(ByteFlag groups1, ByteFlag groups2)
 {
     return groups1 == groups2;
 }
Exemplo n.º 41
0
 public bool IsComponentGroupValid(IEntityOld entity, ByteFlag components)
 {
     return EntityMatchOld.Matches(entity, components, match);
 }
Exemplo n.º 42
0
        static bool MatchesExact(IEntityOld entity, ByteFlag components)
        {
            for (byte i = 0; i < EntityUtility.IdCount; i++)
            {
                if (components[i] != entity.HasComponent(EntityUtility.GetComponentType(i)))
                    return false;
            }

            return true;
        }
Exemplo n.º 43
0
        void OnByteFlagSelected(FlagsOption option, SerializedProperty property)
        {
            var byteFlag = property.GetValue<ByteFlag>();

            switch (option.Type)
            {
                case FlagsOption.OptionTypes.Everything:
                    byteFlag = new ByteFlag(enumValues.Convert((object v) => Convert.ToByte(v)));
                    break;
                case FlagsOption.OptionTypes.Nothing:
                    byteFlag = ByteFlag.Nothing;
                    break;
                case FlagsOption.OptionTypes.Custom:
                    byte value = (byte)option.Value;
                    byteFlag = byteFlag[value] ? byteFlag - value : byteFlag + value;
                    break;
            }

            property.SetValue(byteFlag);
        }
Exemplo n.º 44
0
 public bool IsComponentGroupValid(IEntityOld entity, ByteFlag components)
 {
     return(EntityMatchOld.Matches(entity, components, match));
 }
Exemplo n.º 45
0
 public EntityMatchOld(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All)
 {
     this.groups = groups;
     this.match  = match;
 }
Exemplo n.º 46
0
 public GroupData(string ownerName, string groupName, ByteFlag group)
 {
     OwnerName = ownerName;
     GroupName = groupName;
     Group = group;
 }
Exemplo n.º 47
0
 public GroupData(string ownerName, string groupName, ByteFlag group)
 {
     OwnerName = ownerName;
     GroupName = groupName;
     Group     = group;
 }
Exemplo n.º 48
0
        public EntityGroupOld GetGroupByEntityGroup(ByteFlag groups)
        {
            EntityGroupOld entityGroup;

            if (!entityGroups.TryGetValue(groups, out entityGroup))
            {
                entityGroup = CreateEntityGroup(groups);
                entityGroups[groups] = entityGroup;
            }

            return entityGroup;
        }
Exemplo n.º 49
0
 static bool MatchesAll(ByteFlag groups1, ByteFlag groups2)
 {
     return((~groups1 & groups2) == ByteFlag.Nothing);
 }