Terrarium.PeerToPeer.NetworkEngine.TeleportCallback C# (CSharp) Method

TeleportCallback() private method

private TeleportCallback ( IAsyncResult ar ) : void
ar IAsyncResult
return void
        internal void TeleportCallback(IAsyncResult ar)
        {
            // Extract the delegate from the AsyncResult
            var teleportDelegate = (TeleportDelegate) ((AsyncResult) ar).AsyncDelegate;

            // Obtain the result
            var unteleportedObject = teleportDelegate.EndInvoke(ar);
            if (unteleportedObject != null)
            {
                // Something failed, so we need to teleport locally
                var engine = GameEngine.Current;

                // The engine may be gone now since we're on a different thread.
                // If so, the organism is lost
                if (engine != null)
                {
                    engine.ReceiveTeleportation(unteleportedObject, true);
                    CountLocalTeleportation();
                }
            }
            else
            {
                CountRemoteTeleportation();
            }
        }