Ejemplo n.º 1
0
        /// <summary>
        /// Find replicable and write data into m_sender
        /// </summary>
        private MyExternalReplicable PrepareSend <TMsg>(ref TMsg msg, MyTransportMessageEnum messageType)
            where TMsg : struct, IEntityMessage
        {
            long entityId = msg.GetEntityId();
            var  entity   = MyEntities.GetEntityById(entityId);

            Debug.Assert(entity is IMyEventProxy, "To use SendAsRpc, entity must be IMyEventProxy and must have replicable in replication layer");

            var id       = TransportLayer.GetId <TMsg>(messageType);
            var callback = TransportLayer.GetCallback <TMsg>(messageType);

            m_sender.SendStream.Position = 0;
            m_sender.SendStream.WriteUShort(id.Item1);
            callback.Write(m_sender.SendStream, ref msg);
            var replicable = MyMultiplayer.Static.ReplicationLayer.GetProxyTarget((IMyEventProxy)entity) as MyExternalReplicable;

            Debug.Assert(replicable != null, "No replicable found for entity");
            Debug.Assert(replicable is IMyProxyTarget, "Replicable must be proxy target");
            return(replicable);
        }