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);
        }
Пример #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);
        }
Пример #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));
            }
        }
Пример #5
0
        public static ByteFlag GetComponentFlags(Type componentType)
        {
            var flag = new ByteFlag();
            flag[GetOrAddComponentId(componentType)] = true;

            return flag;
        }
Пример #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);
        }
Пример #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));
        }
Пример #8
0
        public static ByteFlag GetComponentFlags(Type componentType)
        {
            var flag = new ByteFlag();

            flag[GetOrAddComponentId(componentType)] = true;

            return(flag);
        }
Пример #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));
        }
Пример #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]);
        }
Пример #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]);
        }
Пример #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;
        }
Пример #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]);
        }
Пример #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);
        }
Пример #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;
        }
Пример #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);
        }
Пример #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;
 }
Пример #18
0
        public EntityGroupOld GetGroupByComponentGroup(ByteFlag components)
        {
            EntityGroupOld entityGroup;

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

            return(entityGroup);
        }
Пример #19
0
        public EntityGroupOld GetGroupByEntityGroup(ByteFlag groups)
        {
            EntityGroupOld entityGroup;

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

            return(entityGroup);
        }
Пример #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);
        }
Пример #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));
        }
Пример #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));
        }
Пример #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);
        }
Пример #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;
            }
Пример #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);
        }
Пример #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);
            }
        }
Пример #28
0
 static bool MatchesAny(ByteFlag groups1, ByteFlag groups2)
 {
     return (groups1 & ~groups2) != groups1;
 }
Пример #29
0
 static bool MatchesAll(ByteFlag groups1, ByteFlag groups2)
 {
     return (~groups1 & groups2) == ByteFlag.Nothing;
 }
Пример #30
0
 public static IEntityGroupOld GetEntityGroup(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All)
 {
     return(masterGroup.Filter(groups, match));
 }
Пример #31
0
 public IEntityGroupOld Filter(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All)
 {
     return(GetMatchGroup(match).GetGroupByEntityGroup(groups));
 }
Пример #32
0
        public EntityGroupOld GetGroupByComponentGroup(ByteFlag components)
        {
            EntityGroupOld entityGroup;

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

            return entityGroup;
        }
Пример #33
0
 static bool MatchesExact(ByteFlag groups1, ByteFlag groups2)
 {
     return(groups1 == groups2);
 }
Пример #34
0
 public EntityMatchOld(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All)
 {
     this.groups = groups;
     this.match = match;
 }
Пример #35
0
 static bool MatchesAny(ByteFlag groups1, ByteFlag groups2)
 {
     return((groups1 & ~groups2) != groups1);
 }
Пример #36
0
 public bool IsEntityGroupValid(IEntityOld entity, ByteFlag groups)
 {
     return EntityMatchOld.Matches(entity.Groups, groups, match);
 }
Пример #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;
        }
Пример #38
0
 public bool IsEntityGroupValid(IEntityOld entity, ByteFlag groups)
 {
     return(EntityMatchOld.Matches(entity.Groups, groups, match));
 }
Пример #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]);
        }
Пример #40
0
 static bool MatchesExact(ByteFlag groups1, ByteFlag groups2)
 {
     return groups1 == groups2;
 }
Пример #41
0
 public bool IsComponentGroupValid(IEntityOld entity, ByteFlag components)
 {
     return EntityMatchOld.Matches(entity, components, match);
 }
Пример #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;
        }
Пример #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);
        }
Пример #44
0
 public bool IsComponentGroupValid(IEntityOld entity, ByteFlag components)
 {
     return(EntityMatchOld.Matches(entity, components, match));
 }
Пример #45
0
 public EntityMatchOld(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All)
 {
     this.groups = groups;
     this.match  = match;
 }
Пример #46
0
 public GroupData(string ownerName, string groupName, ByteFlag group)
 {
     OwnerName = ownerName;
     GroupName = groupName;
     Group = group;
 }
Пример #47
0
 public GroupData(string ownerName, string groupName, ByteFlag group)
 {
     OwnerName = ownerName;
     GroupName = groupName;
     Group     = group;
 }
Пример #48
0
        public EntityGroupOld GetGroupByEntityGroup(ByteFlag groups)
        {
            EntityGroupOld entityGroup;

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

            return entityGroup;
        }
Пример #49
0
 static bool MatchesAll(ByteFlag groups1, ByteFlag groups2)
 {
     return((~groups1 & groups2) == ByteFlag.Nothing);
 }