public Entity GetEntityByGuid(EntityGuid guid) { var entity = GetEntityFromGuidCache(guid); if (entity != Entity.Null) { return(entity); } var query = new EntityQueryDesc() { All = new ComponentType[] { typeof(EntityGuid) }, Options = EntityQueryOptions.IncludeDisabled }; using (var group = EntityManager.CreateEntityQuery(query)) using (var entities = group.ToEntityArray(Allocator.TempJob)) using (var guids = group.ToComponentDataArray <EntityGuid>(Allocator.TempJob)) { for (var i = 0; i < group.CalculateEntityCount(); ++i) { if (guids[i] == guid) { entity = entities[i]; AddEntityToGuidCache(entity, guid); return(entity); } } } return(Entity.Null); }
public void TestDefaultValueString() { EntityGuid guid = new EntityGuid(); string stringGuid = guid; Assert.AreEqual(null, stringGuid); }
/// <inheritdoc /> protected override async Task HandleSubMessage(IPeerMessageContext <PSOBBGamePacketPayloadClient> context, Sub60FinishedWarpingBurstingCommand command) { if (Logger.IsInfoEnabled) { Logger.Info($"Recieved finished warp from Client: {command.Identifier} SameZone: {command}"); } //TODO: Can we always assume we have a world object when we recieved this?? if (!LocalPlayerData.isWorldObjectSpawned) { throw new InvalidOperationException($"Recieved {nameof(Sub60FinishedWarpingBurstingCommand)} before local player exists."); } Vector3 <float> scaledPosition = ScalingService.UnScale(LocalPlayerData.WorldObject.transform.position).ToNetworkVector3(); float scaledRotation = ScalingService.UnScaleYRotation(LocalPlayerData.WorldObject.transform.rotation.y); //If have to send this message otherwise other client's won't know we're also in the same zone //It's odd, but it's something we have to do. await context.PayloadSendService.SendMessage(new Sub60FinishedWarpAckCommand(LocalPlayerData.SlotIndex, ZoneId, scaledPosition, scaledRotation).ToPayload()); //Other clients send photon char information but I don't know what is in it yet or if it's required await context.PayloadSendService.SendMessage(new Sub62PhotonChairCommand().ToPayload()); int entityGuid = EntityGuid.ComputeEntityGuid(EntityType.Player, command.Identifier); //TODO: Is it really safe to assume that they have zone data?? If they never sent it then this will throw here. Or it'll be stale. //TODO: Should we broadcast this event before or after the warp ack is sent? OnRemotePlayedFinishedWarpToZone?.Invoke(this, new PlayerWarpedToZoneEventArgs(entityGuid, PlayerZoneDataMappable[entityGuid].ZoneId)); }
/// <inheritdoc /> protected override Task HandleSubMessage(IPeerMessageContext <PSOBBGamePacketPayloadClient> context, TPositionChangeCommandType command) { int entityGuid = EntityGuid.ComputeEntityGuid(EntityType.Player, command.Identifier); //TODO: is this the best approach, just ignoring/ditching the position of players //if they aren't in our zone? if (!MovementManagerMappable.ContainsKey(entityGuid)) { return(Task.CompletedTask); } //We can safely assume they have a known world transform or they can't have been spawned. Vector2 position = Scaler.ScaleYasZ(command.Position); MovementManagerMappable[entityGuid].RegisterState(CreateMovementGenerator(position, command)); //New position commands should be direcly updating the entity's position. Even though "MovementGenerators" handle true movement by learping them. //They aren't the source of Truth since they aren't deterministic/authorative like is REAL MMOs. So, the true source of truth is the WorldTransform. Vector3 positionIn3dSpace = new Vector3(position.x, WorldTransformMappable[entityGuid].Position.y, position.y); WorldTransformMappable[entityGuid] = new WorldTransform(positionIn3dSpace, WorldTransformMappable[entityGuid].Rotation); return(Task.CompletedTask); }
/// <summary> /// Outputs server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter" /> object and stores tracing information about the control if tracing is enabled. /// </summary> /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter" /> object that receives the control content.</param> public override void RenderControl(HtmlTextWriter writer) { var rockPage = this.Page as RockPage; if (rockPage != null) { writer.AddAttribute("class", "tag-wrap"); writer.RenderBeginTag(HtmlTextWriterTag.Div); base.RenderControl(writer); writer.RenderEndTag(); var script = string.Format(@" Rock.controls.tagList.initialize({{ controlId: '{0}', entityTypeId: '{1}', currentPersonId: '{2}', entityGuid: '{3}', entityQualifierColumn: '{4}', entityQualifierValue: '{5}', preventTagCreation: {6}, delaySave: {7} }});", this.ClientID, EntityTypeId, rockPage.CurrentPersonId, EntityGuid.ToString(), string.IsNullOrWhiteSpace(EntityQualifierColumn) ? string.Empty : EntityQualifierColumn, string.IsNullOrWhiteSpace(EntityQualifierValue) ? string.Empty : EntityQualifierValue, (!AllowNewTags).ToString().ToLower(), DelaySave.ToString().ToLower()); ScriptManager.RegisterStartupScript(this, this.GetType(), "tag_picker_" + this.ID, script, true); } }
/// <inheritdoc /> protected override Task HandleSubMessage(IPeerMessageContext <PSOBBGamePacketPayloadClient> context, Sub60FinishedWarpAckCommand command) { int entityGuid = EntityGuid.ComputeEntityGuid(EntityType.Player, command.Identifier); if (Logger.IsInfoEnabled) { Logger.Info($"Client broadcasted existence Id: {command.Identifier} ZoneId: {command.ZoneId}"); } //The reason we have to do this is because remote players, that we already known about, //could be broadcasting out a warp ack to alert other players that they exist //but not intend for it to reach us really. In this case, we already have the player existing //so if we don't do it this way then we will end up with duplicate spawns if (WorldTransformMappable.ContainsKey(entityGuid) && ZoneDataMappable.ContainsKey(entityGuid)) { //TODO: Should we ever assume they will ack a new zone??? Probably never legit in the lobby but might happen in games? Unsure. InitializeAckDataToEntityMappables(command, entityGuid); } else { HandleUnknownEntityWarpAck(command, entityGuid); } return(Task.CompletedTask); }
public static unsafe EntityGuid ToEntityGuid(this Guid guid) { if (guid == Guid.Empty) { return(EntityGuid.Null); } var bytes = stackalloc byte[16]; { var pGuid = (long *)&guid; var pDest = (long *)(bytes); pDest[0] = pGuid[0]; pDest[1] = pGuid[1]; } var entityGuid = new EntityGuid { a = ((ulong)bytes[0]) << 32 | ((ulong)bytes[1]) << 40 | ((ulong)bytes[2]) << 48 | ((ulong)bytes[3]) << 56 | ((ulong)bytes[4]) << 16 | ((ulong)bytes[5]) << 24 | ((ulong)bytes[6]) << 0 | ((ulong)bytes[7]) << 8, b = ((ulong)bytes[8]) << 56 | ((ulong)bytes[9]) << 48 | ((ulong)bytes[10]) << 40 | ((ulong)bytes[11]) << 32 | ((ulong)bytes[12]) << 24 | ((ulong)bytes[13]) << 16 | ((ulong)bytes[14]) << 8 | ((ulong)bytes[15]) << 0 }; return(entityGuid); }
public void TestDefaultValueNullableGuid() { EntityGuid guid = new EntityGuid(); Guid? realGuid = guid; Assert.AreEqual(null, realGuid); }
/// <inheritdoc /> public void Tick() { //Don't need to do this if we aren't moving if (isMoving) { using (SyncObj.Lock()) { //Double check locking if (!isMoving) { return; } GameObject worldObject = WorldObjectMap[EntityGuid.ComputeEntityGuid(EntityType.Player, SlotModel.SlotSelected)]; //From old movement //Vector3.Magnitude(lastPosition - transform.position) > Vector3.kEpsilon if (Vector3.Magnitude(LastPosition - worldObject.transform.position) > Vector3.kEpsilon) { LocalPlayerNetworkController.UpdatedMovementLocation(worldObject.transform.position, worldObject.transform.rotation); //TODO: This design is such that the above statement will be true the first time around. This could be bad for the first time the player moves LastPosition = worldObject.transform.position; } } } }
public void TestNullableGuid() { EntityGuid guid = null; Guid? realGuid = guid; Assert.AreEqual(null, realGuid); }
public void TestFromStringToString() { EntityGuid guid = "0001"; string stringGuid = guid; Assert.AreEqual("0001", stringGuid); }
public void ToString_ExtractsPackedValues() { var g0 = new EntityGuid(1, 2, 3); var g1 = new EntityGuid(-1, 0xF0, 0x89ABCDEF); Assert.That(g0.ToString(), Is.EqualTo("1:02:00000003")); Assert.That(g1.ToString(), Is.EqualTo("-1:f0:89abcdef")); }
public void ToGuid() { var entityGuid = new EntityGuid { a = 81985529216486895, b = 81985529216486895 }; Assert.AreEqual(entityGuid.ToString(), entityGuid.ToGuid().ToString("N")); }
public void TestFromGuidToString() { Guid value = Guid.NewGuid(); EntityGuid guid = value; string stringGuid = guid; Assert.AreEqual(value.ToString(), stringGuid); }
public void TestFromStringToNullableGuid() { Guid value = Guid.NewGuid(); EntityGuid guid = value.ToString(); Guid? realGuid = guid; Assert.AreEqual(value, realGuid); }
public void TestFromNullableGuidToString() { Guid?value = null; EntityGuid guid = value; string stringGuid = guid; Assert.AreEqual(null, stringGuid); }
/// <inheritdoc /> protected override Task HandleSubMessage(IPeerMessageContext <PSOBBGamePacketPayloadClient> context, Sub60WarpToNewAreaCommand command) { //All we need to do is set the new zone for lobby. //We should not assume that they are ever going to leave in the lobby //so don't remove them even if it appears they're going to a different map/area //that the local player is not in. ZoneDataMappable[EntityGuid.ComputeEntityGuid(EntityType.Player, command.Identifier)] = new PlayerZoneData(command.Zone); return(Task.CompletedTask); }
public LocalPlayerWorldRepresentationCreationContext(int entityId, Transform transform) { if (EntityGuid.GetEntityType(entityId) != EntityType.Player) { throw new ArgumentException($"Cannot create: {nameof(LocalPlayerWorldRepresentationCreationContext)} with guid with {nameof(EntityType)}: {EntityGuid.GetEntityType(entityId)}", nameof(entityId)); } SpawnData = new EntityAssoicatedObject <WorldTransform>(entityId, new WorldTransform(transform.position, transform.rotation)); }
public void TestFromGuidToGuid() { Guid value = Guid.NewGuid(); EntityGuid guid = value; Guid realGuid = guid; Assert.AreEqual(value, realGuid); }
protected void EnableNodes(EntityGuid entityID, bool enabled) { var rootItem = GetRootItem(this); var nodesWithConnection = GetNodesWithConnection(rootItem, entityID); foreach (var node in nodesWithConnection) { node.IsEnabled = enabled; } }
public override int GetHashCode() { unchecked { var hashCode = EntityGuid.GetHashCode(); hashCode = (hashCode * 397) ^ AttributeGuid.GetHashCode(); hashCode = (hashCode * 397) ^ (TagName != null ? TagName.GetHashCode() : 0); return(hashCode); } }
/// <inheritdoc /> protected override Task HandleSubMessage(IPeerMessageContext <PSOBBGamePacketPayloadClient> context, Sub60WarpToNewAreaCommand command) { //For games, we only set zone data in this handler if they are bursting right now. if (BurstingService.isBurstingInProgress && BurstingService.BurstingEntityGuid.Value == EntityGuid.ComputeEntityGuid(EntityType.Player, command.Identifier)) { ZoneDataMappable[EntityGuid.ComputeEntityGuid(EntityType.Player, command.Identifier)] = new PlayerZoneData(command.Zone); } return(Task.CompletedTask); }
protected override void Execute(CodeActivityContext activityContext) { QueryPartitionBase queryPartition = QueryPartition.Get(activityContext); switch (queryPartition.Query.ExecutionMode) { case ExecutionMode.SingleServer: queryPartition.InitializeQueryObject(null, null, true); break; case ExecutionMode.Graywulf: using (var context = ContextManager.Instance.CreateContext(this, activityContext, ConnectionMode.AutoOpen, TransactionMode.AutoCommit)) { var scheduler = activityContext.GetExtension <IScheduler>(); //queryPartition.DatabaseVersionName = queryPartition.Query.SourceDatabaseVersionName; TODO: delete queryPartition.InitializeQueryObject(context, scheduler, false); var dss = queryPartition.FindRequiredDatasets(); // Check if there are any Graywulf datasets referenced in the query var assignmydb = (dss.Values.FirstOrDefault(ds => !ds.IsSpecificInstanceRequired) == null); // *** TODO: replace this whole thing to use JOIN graphs // If no graywulf datasets are used, use the server containing myDB, // otherwise ask the scheduler for an appropriate server if (dss.Count == 0 || assignmydb) { // use MyDB's server var ef = new EntityFactory(context); var federation = queryPartition.FederationReference.Value; var user = ef.LoadEntity <User>(context.UserGuid); var di = federation.MyDBDatabaseVersion.GetUserDatabaseInstance(user); queryPartition.AssignedServerInstance = di.ServerInstance; } else { // Assign new server instance var si = new ServerInstance(context); si.Guid = scheduler.GetNextServerInstance( dss.Values.Where(x => !x.IsSpecificInstanceRequired).Select(x => x.DatabaseDefinition.Guid).ToArray(), queryPartition.Query.SourceDatabaseVersionName, null); si.Load(); queryPartition.AssignedServerInstance = si; } queryPartition.InitializeQueryObject(context, scheduler, true); EntityGuid.Set(activityContext, queryPartition.AssignedServerInstance.Guid); } break; } }
/// <inheritdoc /> public override async Task HandleMessage(IPeerMessageContext <PSOBBGamePacketPayloadClient> context, BlockGamePlayerJoinedEventPayload payload) { //When this join is recieved, then we have to set the bursting state so it can be remembered, referenced or cleaned up. if (BurstingService.SetBurstingEntity(EntityGuid.ComputeEntityGuid(EntityType.Player, payload.Identifier))) { //TODO: We are creating a fake 0x6D 0x70 here. Do we ever need a real one?? await context.PayloadSendService.SendMessage(new BlockNetworkCommand6DEventClientPayload(payload.Identifier, new Sub6DFakePlayerJoinDataNeededCommand(SlotModel.SlotSelected))); } //TODO: What do we do if this fails? }
public bool Equals(EntityAttributeModel other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(EntityGuid.Equals(other.EntityGuid) && AttributeGuid.Equals(other.AttributeGuid) && string.Equals(TagName, other.TagName)); }
/// <inheritdoc /> public LocalPlayerWorldRepresentationCreationContext([NotNull] EntityAssoicatedObject <WorldTransform> data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (EntityGuid.GetEntityType(data.EntityGuid) != EntityType.Player) { throw new ArgumentException($"Cannot create: {nameof(LocalPlayerWorldRepresentationCreationContext)} with guid with {nameof(EntityType)}: {EntityGuid.GetEntityType(data.EntityGuid)}", nameof(data)); } SpawnData = data; }
/// <summary> /// 添加用户 /// </summary> /// <param name="sysUserInfo"></param> /// <returns></returns> public bool AddSysUser(SysUserInfo sysUserInfo) { sysUserInfo.SysNo = EntityGuid.NewComb(); //获取混淆码 string passwordSalt = SecurityHelper.GenerateSalt(); //获取混淆码加密过的密码 string passwordHash = SecurityHelper.EncodePassword(sysUserInfo.PasswordHash, passwordSalt); sysUserInfo.PasswordHash = passwordHash; sysUserInfo.PasswordSalt = passwordSalt; return(_sysUserRepository.Insert(sysUserInfo) > 0); }
public void Ctor_StoresValuesPacked() { var g0 = new EntityGuid(1, 2, 3); var g1 = new EntityGuid(-1, 0xF0, 0x89ABCDEF); Assert.That(g0.OriginatingId, Is.EqualTo(1)); Assert.That(g0.NamespaceId, Is.EqualTo(2)); Assert.That(g0.Serial, Is.EqualTo((uint)3)); Assert.That(g1.OriginatingId, Is.EqualTo(-1)); Assert.That(g1.NamespaceId, Is.EqualTo(0xF0)); Assert.That(g1.Serial, Is.EqualTo(0x89ABCDEF)); }
public override bool Equals(object otherObject) { if (otherObject is AttributeUpdate) { var otherUpdate = otherObject as AttributeUpdate; return(EntityGuid.Equals(otherUpdate.EntityGuid) && ComponentName.Equals(otherUpdate.ComponentName) && AttributeName.Equals(otherUpdate.AttributeName) && NewValue.Equals(otherUpdate.NewValue)); } return(false); }
protected static Entity GetEntity(EntityManager entityManager, EntityGuid entityGuid) { var entities = entityManager.GetAllEntities(); foreach (var entity in entities) { if (entityManager.GetComponentData <EntityGuid>(entity).Equals(entityGuid)) { return(entity); } } return(Entity.Null); }
/// <summary> /// Gets an entity based on GUID in this map. /// </summary> /// <param name="guid">EntityGuid of unit to look for</param> /// <returns>IWorldEntity object</returns> public IWorldEntity GetEntityInMap(EntityGuid guid) { Contract.Requires(guid != EntityGuid.Zero); return _entityLookup.TryGet(guid); }
public static void WriteSmartGuid(this BinaryWriter writer, EntityGuid guid) { Contract.Requires(writer != null); WritePackedUInt64(writer, guid.Full); }
public void TestDefaultValueGuid() { EntityGuid guid = new EntityGuid(); Guid stringGuid = guid; }