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); }
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); }
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)); } }
public static ByteFlag GetComponentFlags(Type componentType) { var flag = new ByteFlag(); flag[GetOrAddComponentId(componentType)] = true; return flag; }
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); }
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)); }
public static ByteFlag GetComponentFlags(Type componentType) { var flag = new ByteFlag(); flag[GetOrAddComponentId(componentType)] = true; return(flag); }
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)); }
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]); }
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]); }
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; }
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); }
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; }
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); }
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; }
public EntityGroupOld GetGroupByComponentGroup(ByteFlag components) { EntityGroupOld entityGroup; if (!componentGroups.TryGetValue(components, out entityGroup)) { entityGroup = CreateComponentGroup(components); componentGroups[components] = entityGroup; } return(entityGroup); }
public EntityGroupOld GetGroupByEntityGroup(ByteFlag groups) { EntityGroupOld entityGroup; if (!entityGroups.TryGetValue(groups, out entityGroup)) { entityGroup = CreateEntityGroup(groups); entityGroups[groups] = entityGroup; } return(entityGroup); }
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); }
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)); }
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)); }
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); }
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; }
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); }
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); } }
static bool MatchesAny(ByteFlag groups1, ByteFlag groups2) { return (groups1 & ~groups2) != groups1; }
static bool MatchesAll(ByteFlag groups1, ByteFlag groups2) { return (~groups1 & groups2) == ByteFlag.Nothing; }
public static IEntityGroupOld GetEntityGroup(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All) { return(masterGroup.Filter(groups, match)); }
public IEntityGroupOld Filter(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All) { return(GetMatchGroup(match).GetGroupByEntityGroup(groups)); }
public EntityGroupOld GetGroupByComponentGroup(ByteFlag components) { EntityGroupOld entityGroup; if (!componentGroups.TryGetValue(components, out entityGroup)) { entityGroup = CreateComponentGroup(components); componentGroups[components] = entityGroup; } return entityGroup; }
static bool MatchesExact(ByteFlag groups1, ByteFlag groups2) { return(groups1 == groups2); }
public EntityMatchOld(ByteFlag groups, EntityMatchesOld match = EntityMatchesOld.All) { this.groups = groups; this.match = match; }
static bool MatchesAny(ByteFlag groups1, ByteFlag groups2) { return((groups1 & ~groups2) != groups1); }
public bool IsEntityGroupValid(IEntityOld entity, ByteFlag groups) { return EntityMatchOld.Matches(entity.Groups, groups, match); }
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; }
public bool IsEntityGroupValid(IEntityOld entity, ByteFlag groups) { return(EntityMatchOld.Matches(entity.Groups, groups, match)); }
static bool MatchesExact(ByteFlag groups1, ByteFlag groups2) { return groups1 == groups2; }
public bool IsComponentGroupValid(IEntityOld entity, ByteFlag components) { return EntityMatchOld.Matches(entity, components, match); }
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; }
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); }
public bool IsComponentGroupValid(IEntityOld entity, ByteFlag components) { return(EntityMatchOld.Matches(entity, components, match)); }
public GroupData(string ownerName, string groupName, ByteFlag group) { OwnerName = ownerName; GroupName = groupName; Group = group; }
public EntityGroupOld GetGroupByEntityGroup(ByteFlag groups) { EntityGroupOld entityGroup; if (!entityGroups.TryGetValue(groups, out entityGroup)) { entityGroup = CreateEntityGroup(groups); entityGroups[groups] = entityGroup; } return entityGroup; }
static bool MatchesAll(ByteFlag groups1, ByteFlag groups2) { return((~groups1 & groups2) == ByteFlag.Nothing); }