/// <summary>
        /// Marks replicable as successfully created, ready to receive events and state groups data.
        /// </summary>
        void SetReplicableReady(NetworkId networkId, IMyReplicable replicable)
        {
            MyPendingReplicable pendingReplicable;
            if (m_pendingReplicables.TryGetValue(networkId, out pendingReplicable))
            {
                var ids = pendingReplicable.StateGroupIds;

                AddNetworkObjectClient(networkId, replicable);

                using (m_tmpGroups)
                {
                    replicable.GetStateGroups(m_tmpGroups);
                    Debug.Assert(ids.Count == m_tmpGroups.Count, "Number of state groups on client and server for replicable does not match");
                    for (int i = 0; i < m_tmpGroups.Count; i++)
                    {
                        if (m_tmpGroups[i] != replicable)
                            AddNetworkObjectClient(ids[i], m_tmpGroups[i]);
                    }
                }

                m_pendingReplicables.Remove(networkId);
                m_eventBuffer.ProcessEvents(networkId, m_eventHandler);

                m_sendStream.ResetWrite();
                m_sendStream.WriteNetworkId(networkId);
                m_callback.SendReplicableReady(m_sendStream);
            }
            else
            {
                // Replicable was already destroyed on server, during it's load on client
                m_eventBuffer.RemoveEvents(networkId);
                replicable.OnDestroy();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Finds state group of specified type.
        /// Returns null when group of specified type not found.
        /// </summary>
        public static T FindStateGroup <T>(this IMyReplicable obj)
            where T : class, IMyStateGroup
        {
            try
            {
                if (obj == null)
                {
                    return(null);
                }

                obj.GetStateGroups(m_tmpStateGroups);
                foreach (var item in m_tmpStateGroups)
                {
                    var group = item as T;
                    if (group != null)
                    {
                        return(group);
                    }
                }
                return(null);
            }
            finally
            {
                m_tmpStateGroups.Clear();
            }
        }
Beispiel #3
0
        public void ProcessReplicationDestroy(MyPacket packet)
        {
            m_receiveStream.ResetRead(packet);
            NetworkId networkID = m_receiveStream.ReadNetworkId();

            MyPendingReplicable pendingReplicable;

            if (!m_pendingReplicables.TryGetValue(networkID, out pendingReplicable)) // When it wasn't in pending replicables, it's already active and in scene, destroy it
            {
                IMyReplicable replicable = (IMyReplicable)GetObjectByNetworkId(networkID);
                // Debug.Assert(replicable != null, "Client received ReplicationDestroy, but object no longer exists (removed locally?)");
                if (replicable != null)
                {
                    using (m_tmpGroups)
                    {
                        var streamable = replicable as IMyStreamableReplicable;
                        if (streamable != null && streamable.NeedsToBeStreamed)
                        {
                            m_tmpGroups.Add(streamable.GetStreamingStateGroup());
                        }

                        replicable.GetStateGroups(m_tmpGroups);

                        foreach (var g in m_tmpGroups)
                        {
                            if (g == null)
                            {
                                continue;
                            }

                            if (g != replicable)
                            {
                                RemoveNetworkedObject(g);
                            }
                            g.Destroy();
                        }
                    }

                    RemoveNetworkedObject(replicable);
                    replicable.OnDestroy();
                }
            }
            else
            {
                m_pendingReplicables.Remove(networkID);
                if (pendingReplicable.IsStreaming)
                {
                    IMyStateGroup group = (IMyStateGroup)GetObjectByNetworkId(pendingReplicable.StreamingGroupId);
                    if (group != null)
                    {
                        RemoveNetworkedObject(group);
                        group.Destroy();
                    }
                }
                m_eventBuffer.RemoveEvents(networkID);
            }
        }
 public void AddStateGroups(IMyReplicable replicable)
 {
     using (m_tmpGroups)
     {
         replicable.GetStateGroups(m_tmpGroups);
         foreach (var group in m_tmpGroups)
         {
             if (group != replicable)
             {
                 AddNetworkObjectServer(group);
             }
         }
         m_replicableGroups.Add(replicable, new List <IMyStateGroup>(m_tmpGroups));
     }
 }
        /// <summary>
        /// Marks replicable as successfully created, ready to receive events and state groups data.
        /// </summary>
        void SetReplicableReady(NetworkId networkId, IMyReplicable replicable)
        {
            MyPendingReplicable pendingReplicable;

            if (m_pendingReplicables.TryGetValue(networkId, out pendingReplicable))
            {
                var ids = pendingReplicable.StateGroupIds;

                AddNetworkObjectClient(networkId, replicable);

                using (m_tmpGroups)
                {
                    replicable.GetStateGroups(m_tmpGroups);
                    Debug.Assert(ids.Count == m_tmpGroups.Count, "Number of state groups on client and server for replicable does not match");
                    for (int i = 0; i < m_tmpGroups.Count; i++)
                    {
                        if (m_tmpGroups[i] != replicable)
                        {
                            AddNetworkObjectClient(ids[i], m_tmpGroups[i]);
                        }
                    }
                }

                m_pendingReplicables.Remove(networkId);
                m_eventBuffer.ProcessEvents(networkId, m_eventHandler);

                m_sendStream.ResetWrite();
                m_sendStream.WriteNetworkId(networkId);
                m_callback.SendReplicableReady(m_sendStream);
            }
            else
            {
                // Replicable was already destroyed on server, during it's load on client
                m_eventBuffer.RemoveEvents(networkId);
                replicable.OnDestroy();
            }
        }
        public void ProcessReplicationDestroy(MyPacket packet)
        {
            m_receiveStream.ResetRead(packet);
            NetworkId networkID = m_receiveStream.ReadNetworkId();

            if (!m_pendingReplicables.Remove(networkID)) // When it wasn't in pending replicables, it's already active and in scene, destroy it
            {
                IMyReplicable replicable = (IMyReplicable)GetObjectByNetworkId(networkID);
                using (m_tmpGroups)
                {
                    replicable.GetStateGroups(m_tmpGroups);
                    foreach (var g in m_tmpGroups)
                    {
                        if (g != replicable)
                        {
                            RemoveNetworkedObject(g);
                        }
                    }
                }

                RemoveNetworkedObject(replicable);
                replicable.OnDestroy();
            }
        }
        /// <summary>
        /// Marks replicable as successfully created, ready to receive events and state groups data.
        /// </summary>
        void SetReplicableReady(NetworkId networkId, IMyReplicable replicable, bool loaded)
        {
            MyPendingReplicable pendingReplicable;
            if (m_pendingReplicables.TryGetValue(networkId, out pendingReplicable))
            {
                m_pendingReplicables.Remove(networkId);

                if (loaded)
                {
                    var ids = pendingReplicable.StateGroupIds;

                    AddNetworkObjectClient(networkId, replicable);

                    using (m_tmpGroups)
                    {
                        
                        IMyStreamableReplicable streamable = replicable as IMyStreamableReplicable;
                        if (streamable != null && pendingReplicable.IsStreaming)
                        {
                            var group = streamable.GetStreamingStateGroup();
                            m_tmpGroups.Add(group);
                        }

                        replicable.GetStateGroups(m_tmpGroups);
                        Debug.Assert(ids.Count == m_tmpGroups.Count, "Number of state groups on client and server for replicable does not match");
                        for (int i = 0; i < m_tmpGroups.Count; i++)
                        {
                            if (m_tmpGroups[i] != replicable && m_tmpGroups[i].GroupType != StateGroupEnum.Streamining)
                            {
                                AddNetworkObjectClient(ids[i], m_tmpGroups[i]);
                            }
                        }
                    }
                    m_eventBuffer.ProcessEvents(networkId, m_eventHandler, m_isBlockedHandler, NetworkId.Invalid);
                }
                else
                {
                    MyLog.Default.WriteLine("Failed to create replicable ! Type : " + replicable.ToString());
                    m_eventBuffer.RemoveEvents(networkId);

                    IMyStreamableReplicable streamable = replicable as IMyStreamableReplicable;
                    if (streamable != null && pendingReplicable.IsStreaming)
                    {
                        var group = streamable.GetStreamingStateGroup();
                        group.Destroy();
                        NetworkId streaingGroupId;
                        if (TryGetNetworkIdByObject(group, out streaingGroupId))
                        {
                            RemoveNetworkedObject(group);
                        }
                        MyLog.Default.WriteLine("removing streaming group for not loaded replicable !");
                    }
                }

                m_sendStream.ResetWrite();
                m_sendStream.WriteNetworkId(networkId);
                m_sendStream.WriteBool(loaded);
                m_callback.SendReplicableReady(m_sendStream);
            }
            else
            {
                m_pendingReplicables.Remove(networkId);
                using (m_tmpGroups)
                {
                    IMyStreamableReplicable streamable = replicable as IMyStreamableReplicable;
                    if (streamable != null && streamable.NeedsToBeStreamed)
                    {
                        var group = streamable.GetStreamingStateGroup();
                        m_tmpGroups.Add(group);
                        MyLog.Default.WriteLine("removing streaming group for not loaded replicable !" );
                    }

                    replicable.GetStateGroups(m_tmpGroups);
                    foreach (var g in m_tmpGroups)
                    {
                        if (g != null) // when terminal repblicable fails to attach to block its state group is null becouase its created inside hook method.
                        {
                            g.Destroy();
                        }
                    }
                }      
                replicable.OnDestroy();
            }
        }
Beispiel #8
0
        /// <summary>
        /// Marks replicable as successfully created, ready to receive events and state groups data.
        /// </summary>
        void SetReplicableReady(NetworkId networkId, IMyReplicable replicable, bool loaded)
        {
            MyPendingReplicable pendingReplicable;

            if (m_pendingReplicables.TryGetValue(networkId, out pendingReplicable))
            {
                m_pendingReplicables.Remove(networkId);

                if (loaded)
                {
                    var ids = pendingReplicable.StateGroupIds;

                    AddNetworkObjectClient(networkId, replicable);

                    using (m_tmpGroups)
                    {
                        IMyStreamableReplicable streamable = replicable as IMyStreamableReplicable;
                        if (streamable != null && pendingReplicable.IsStreaming)
                        {
                            var group = streamable.GetStreamingStateGroup();
                            m_tmpGroups.Add(group);
                        }

                        replicable.GetStateGroups(m_tmpGroups);
                        Debug.Assert(ids.Count == m_tmpGroups.Count, "Number of state groups on client and server for replicable does not match");
                        for (int i = 0; i < m_tmpGroups.Count; i++)
                        {
                            if (m_tmpGroups[i] != replicable && m_tmpGroups[i].GroupType != StateGroupEnum.Streamining)
                            {
                                AddNetworkObjectClient(ids[i], m_tmpGroups[i]);
                            }
                        }
                    }
                    m_eventBuffer.ProcessEvents(networkId, m_eventHandler, m_isBlockedHandler, NetworkId.Invalid);
                }
                else
                {
                    MyLog.Default.WriteLine("Failed to create replicable ! Type : " + replicable.ToString());
                    m_eventBuffer.RemoveEvents(networkId);

                    IMyStreamableReplicable streamable = replicable as IMyStreamableReplicable;
                    if (streamable != null && pendingReplicable.IsStreaming)
                    {
                        var group = streamable.GetStreamingStateGroup();
                        group.Destroy();
                        NetworkId streaingGroupId;
                        if (TryGetNetworkIdByObject(group, out streaingGroupId))
                        {
                            RemoveNetworkedObject(group);
                        }
                        MyLog.Default.WriteLine("removing streaming group for not loaded replicable !");
                    }
                }

                m_sendStream.ResetWrite();
                m_sendStream.WriteNetworkId(networkId);
                m_sendStream.WriteBool(loaded);
                m_callback.SendReplicableReady(m_sendStream);
            }
            else
            {
                m_pendingReplicables.Remove(networkId);
                using (m_tmpGroups)
                {
                    IMyStreamableReplicable streamable = replicable as IMyStreamableReplicable;
                    if (streamable != null && streamable.NeedsToBeStreamed)
                    {
                        var group = streamable.GetStreamingStateGroup();
                        m_tmpGroups.Add(group);
                        MyLog.Default.WriteLine("removing streaming group for not loaded replicable !");
                    }

                    replicable.GetStateGroups(m_tmpGroups);
                    foreach (var g in m_tmpGroups)
                    {
                        if (g != null) // when terminal repblicable fails to attach to block its state group is null becouase its created inside hook method.
                        {
                            g.Destroy();
                        }
                    }
                }
                replicable.OnDestroy();
            }
        }
 public void AddStateGroups(IMyReplicable replicable)
 {
     using (m_tmpGroups)
     {
         replicable.GetStateGroups(m_tmpGroups);
         foreach (var group in m_tmpGroups)
         {
             if (group != replicable)
                 AddNetworkObjectServer(group);
         }
         m_replicableGroups.Add(replicable, new List<IMyStateGroup>(m_tmpGroups));
     }
 }
        public void AddStateGroups(IMyReplicable replicable)
        {
            using (m_tmpGroups)
            {
                IMyStreamableReplicable streamable = replicable as IMyStreamableReplicable;
                if (streamable != null)
                {
                    var group = streamable.GetStreamingStateGroup();
                    m_tmpGroups.Add(group);
                }

                replicable.GetStateGroups(m_tmpGroups);
                foreach (var group in m_tmpGroups)
                {
                    if (group != replicable)
                        AddNetworkObjectServer(group);
                }
         
                m_replicableGroups.Add(replicable, new List<IMyStateGroup>(m_tmpGroups));
            }
        }