Exemplo n.º 1
0
    public virtual void SendDestroyMessage(ServerPlayer destPlayer)
    {
        var packet = new EntityDestroyPacket();

        packet.entityId = EntityId;

        Server.Send(packet, destPlayer.EntityId.SingleItemAsEnumerable());
    }
Exemplo n.º 2
0
    private void OnEntityDestroy(EntityDestroyPacket packet)
    {
        var entity = RemoveEntity(packet.entityId);

        if (entity != null)
        {
            client.RemoveListenersForEntity(packet.entityId);
            GameObject.Destroy(entity.gameObject);
        }
    }
Exemplo n.º 3
0
    //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);
        }
    }
Exemplo n.º 4
0
 private void OnEntityDestroyPacket(EntityDestroyPacket obj)
 {
     // Signal the main thread to destroy this entity
     shouldDestroy = true;
 }