private void BehaviorChanged(Behavior behavior) { ServerPlayer[] playerInRange = SpatialPartitioning.GetEntitiesInRadius <ServerPlayer>(transform.position); SendDirtyMemoryVar(playerInRange); SendChangeBehavior(playerInRange, behavior); }
public override void Tick() { transform.position = Position; transform.rotation = Quaternion.Euler(Rotation); SpatialPartitioning.Update(this); }
private void OnSendingInitData() { if (previousState != null) { ServerPlayer[] playerInRange = SpatialPartitioning.GetEntitiesInRadius <ServerPlayer>(transform.position); Server.Send(previousState, playerInRange.Select(e => e.EntityId)); } }
void SaveStatePacket(PlayerSaveStatePacket packet) { Debug.Log("RECEIVED!"); trackedEntityIds = new HashSet <int>(); AccountId = packet.state.accountId; this.saveState = packet.state; SpatialPartitioning.Register(this); }
protected override void Start() { base.Start(); OnInitData += OnSendingInitData; Position = transform.position; Rotation = transform.rotation.eulerAngles; RegisterNPC(); SpatialPartitioning.Register(this); }
public void SpatialPartitioningCheckIf00Reachable() { GameObject Floor = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Prefabs/Floor (With Collision boxes)")); var Testing = Floor.transform.Find("CollisionBox(0,0)"); SpatialPartitioning NeighCollider = Testing.GetComponent <SpatialPartitioning>(); Assert.True(NeighCollider.height == 0); Assert.True(NeighCollider.width == 0); // Use the Assert class to test conditions }
//TODO: Split this up, as it is doing 2 things: //Updating nearby entities //Updating the position public void UpdateNearbyEntities() { // TODO: Hysteresis // We'll need to have a way to look up an entity by its id nearbyEntitiesCount = SpatialPartitioning.GetEntitiesInRadius(ref nearbyEntities, Position); for (int i = 0; i < nearbyEntitiesCount; i++) { var entity = nearbyEntities[i]; if (entity == this || entity == null) { continue; } // Assume we haven't seen this entity before int frameIdLastUpdated = NetworkConstants.BeforeStartOfGameFrameId; // If we have seen this entity before... if (trackedEntityIds.Contains(entity.EntityId)) { // TODO : Store the actual last frame we updated them, but for the moment // we update them every frame, so we saw them last frame frameIdLastUpdated = Server.FrameID - 1; } entity.SendState(this, frameIdLastUpdated); trackedEntityIds.Remove(entity.EntityId); } // These have all now disappered foreach (var entityId in trackedEntityIds) { // Tell the client to remove that entity EntityDestroyPacket destroyPacket = (EntityDestroyPacket)IntrepidSerialize.TakeFromPool(PacketType.EntityDestroy); destroyPacket.entityId = entityId; Server.Send(destroyPacket, EntityId.SingleItemAsEnumerable()); } // Create the new list of tracked entities trackedEntityIds.Clear(); for (int i = 0; i < nearbyEntitiesCount; i++) { var entity = nearbyEntities[i]; if (entity == this || entity == null) { continue; } trackedEntityIds.Add(entity.EntityId); } }
private void SetNeighbors() { int[,] cords = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 }, { 1, 1 }, { 1, -1 }, { -1, 1 }, { -1, -1 } }; for (int i = 0; i < cords.GetLength(0); i++) { GameObject NeigGameObject = GameObject.Find($"CollisionBox({height + cords[i,0]},{width + cords[i, 1]})"); if (NeigGameObject != null) { SpatialPartitioning NeighCollider = NeigGameObject.GetComponent <SpatialPartitioning>(); Neighbors.Add(NeighCollider); } } }
private void AttackRequestPacket(Combat_AttackRequest packet) { // TODO: Validate attack. Combat_AttackOriginate ao = (Combat_AttackOriginate)IntrepidSerialize.TakeFromPool(PacketType.Combat_AttackOriginate); ao.attackerId = EntityId; ao.frameId = Server.FrameID; ao.abilityId = packet.abilityId; ao.targetId = packet.targetId; ao.position = packet.position; // keep in mind threading things /*int nearbyPlayersCount = */ SpatialPartitioning.GetEntitiesInRadius(ref nearbyPlayers, Position); Server.Send(ao, nearbyPlayers.Select(e => e.EntityId)); }
public void SpatialPartitioningCheckIfCanSelect2EntitiesSelfAndNeigbors() { GameObject Floor = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Prefabs/Floor (With Collision boxes)")); var GoFrom = Floor.transform.Find("CollisionBox(3,3)"); var GoTo = Floor.transform.Find("CollisionBox(3,5)"); SpatialPartitioning GoFromSelected = GoFrom.GetComponent <SpatialPartitioning>(); SpatialPartitioning GoToSelected = GoTo.GetComponent <SpatialPartitioning>(); GoFromSelected.Entities.Add(new GameObject()); GoToSelected.Entities.Add(new GameObject()); List <GameObject> Entities; Entities = GoFromSelected.GetEntitiesWithExtraNeighbors(1); Assert.True(Entities.Count == 1); Entities = GoFromSelected.GetEntitiesWithExtraNeighbors(2); Assert.True(Entities.Count == 2); }
public List <GameObject> GetEntitiesWithExtraNeighbors(int steps) { List <GameObject> EntitiesWithExtraNeighbors; for (int i = -steps; i <= steps; i++) { for (int j = -steps; j <= steps; j++) { var Testing = transform.parent.Find($"CollisionBox({ height + i},{ width + j})"); if (Testing != null && Testing.name != this.name) { SpatialPartitioning NeigGameObject = Testing.GetComponent <SpatialPartitioning>(); ExtraNeighbors.Add(NeigGameObject); } } } EntitiesWithExtraNeighbors = GetEntitiesWithNeigbors(); ExtraNeighbors.Clear(); return(EntitiesWithExtraNeighbors); }
public override void Tick() { Position = transform.position; Rotation = transform.rotation.eulerAngles; SpatialPartitioning.Update(this); }
private void OnDrawGizmos() { SpatialPartitioning.DrawOctree(); }