private void LoadBalancer() { var shieldsWaking = 0; var entsUpdated = 0; var entsremoved = 0; var entsLostShield = 0; if (++RefreshCycle >= EntSlotScaler) { RefreshCycle = 0; } MyEntity ent; while (_entRefreshQueue.TryDequeue(out ent)) { MyProtectors myProtector; if (!GlobalProtect.TryGetValue(ent, out myProtector)) { continue; } var entShields = myProtector.Shields; var refreshCount = 0; DefenseShields iShield = null; var removeIShield = false; foreach (var s in entShields) { if (s.WasPaused) { continue; } lock (s.SubLock) { if (s.DsState.State.ReInforce && s.ShieldComp.SubGrids.Contains(ent)) { iShield = s; refreshCount++; } else if (!ent.InScene || !s.ResetEnts(ent, Tick)) { myProtector.Shields.Remove(s); entsLostShield++; } else { refreshCount++; } } if (iShield == null && myProtector.IntegrityShield == s) { removeIShield = true; myProtector.IntegrityShield = null; } var detectedStates = s.PlayerByShield || s.MoverByShield || Tick <= s.LastWokenTick + 580 || iShield != null || removeIShield; if (ScalerChanged || detectedStates) { s.Asleep = false; shieldsWaking++; } } if (iShield != null) { myProtector.Shields.Remove(iShield); myProtector.IntegrityShield = iShield; } myProtector.Shields.ApplyChanges(); if (refreshCount == 0) { GlobalProtect.Remove(ent); ProtSets.Return(myProtector); entsremoved++; } else { entsUpdated++; } } if (Tick1800 && Enforced.Debug >= 3) { for (int i = 0; i < SlotCnt.Length; i++) { SlotCnt[i] = 0; } foreach (var pair in GlobalProtect) { SlotCnt[pair.Value.RefreshSlot]++; } Log.Line($"[NewRefresh] SlotScaler:{EntSlotScaler} - EntsUpdated:{entsUpdated} - ShieldsWaking:{shieldsWaking} - EntsRemoved: {entsremoved} - EntsLostShield:{entsLostShield} - EntInRefreshSlots:({SlotCnt[0]} - {SlotCnt[1]} - {SlotCnt[2]} - {SlotCnt[3]} - {SlotCnt[4]} - {SlotCnt[5]} - {SlotCnt[6]} - {SlotCnt[7]} - {SlotCnt[8]}) \n" + $" ProtectedEnts:{GlobalProtect.Count} - FunctionalShields:{FunctionalShields.Count} - AllControllerBlocks:{Controllers.Count}"); } }
private void Scale() { if (Tick < 600) { return; } var oldScaler = EntSlotScaler; var globalProtCnt = GlobalProtect.Count; if (globalProtCnt <= 25) { EntSlotScaler = 1; } else if (globalProtCnt <= 50) { EntSlotScaler = 2; } else if (globalProtCnt <= 75) { EntSlotScaler = 3; } else if (globalProtCnt <= 100) { EntSlotScaler = 4; } else if (globalProtCnt <= 150) { EntSlotScaler = 5; } else if (globalProtCnt <= 200) { EntSlotScaler = 6; } else { EntSlotScaler = 9; } if (EntSlotScaler < MinScaler) { EntSlotScaler = MinScaler; } if (oldScaler != EntSlotScaler) { GlobalProtect.Clear(); ProtSets.Clean(); foreach (var s in FunctionalShields.Keys) { s.AssignSlots(); s.Asleep = false; } foreach (var c in Controllers) { if (FunctionalShields.ContainsKey(c)) { continue; } c.AssignSlots(); c.Asleep = false; } ScalerChanged = true; } else { ScalerChanged = false; } }