private void TryAddBlockerForClient(ClientData clientData, IMyReplicable targetReplicable, IMyReplicable blockingReplicable) { // Register networkId as blocked and streaming has to finish for it. if (!clientData.IsReplicableReady(targetReplicable) || !clientData.IsReplicableReady(blockingReplicable) || clientData.BlockedReplicables.ContainsKey(targetReplicable) || clientData.BlockedReplicables.ContainsKey(blockingReplicable)) { // target to blocker MyDestroyBlocker destroyBlocker; if(!clientData.BlockedReplicables.TryGetValue(targetReplicable, out destroyBlocker)) { destroyBlocker = new MyDestroyBlocker(); clientData.BlockedReplicables.Add(targetReplicable, destroyBlocker); } destroyBlocker.Blockers.Add(blockingReplicable); // blocker to target MyDestroyBlocker destroyBlocker2; if (!clientData.BlockedReplicables.TryGetValue(blockingReplicable, out destroyBlocker2)) { destroyBlocker2 = new MyDestroyBlocker(); clientData.BlockedReplicables.Add(blockingReplicable, destroyBlocker2); } destroyBlocker2.Blockers.Add(targetReplicable); } }
private bool ProcessBlocker(IMyReplicable replicable, EndpointId endpoint, ClientData client, IMyReplicable parent) { if (client.BlockedReplicables.ContainsKey(replicable)) { MyDestroyBlocker destroyBlocker = client.BlockedReplicables[replicable]; if (destroyBlocker.IsProcessing) return true; destroyBlocker.IsProcessing = true; foreach(IMyReplicable childRepl in destroyBlocker.Blockers) { // Check if can remove if (!client.IsReplicableReady(replicable) || !client.IsReplicableReady(childRepl)) { destroyBlocker.IsProcessing = false; return false; } bool childSuccess = true; if (childRepl != parent) { childSuccess = this.ProcessBlocker(childRepl, endpoint, client, replicable); } if(!childSuccess) { destroyBlocker.IsProcessing = false; return false; } } // We can clean replicables only if all destory blockers are removed. client.BlockedReplicables.Remove(replicable); if (destroyBlocker.Remove) this.RemoveForClient(replicable, endpoint, client, true); destroyBlocker.IsProcessing = false; } return true; }