/* * Handles removal of buildings and status changes * * Note: Just because a building has been removed visually, it does not mean * it is removed as far as the game is concerned. The building is only truly removed * when the frame covers the building's id, and that's when we will remove the * building from our records. */ public override void OnUpdate(float realTimeDelta, float simulationTimeDelta) { if (_terminated) { return; } if (!_helper.BuildingMonitorSpinnable) { return; } if (!_settings.Enable._BuildingMonitor) { return; } try { if (!_initialized) { _data = Data.Instance; _mapping = new BuildingPrefabMapping(); _paused = false; _instance = Singleton <BuildingManager> .instance; _capacity = _instance.m_buildings.m_buffer.Length; _id = (ushort)_capacity; for (ushort i = 0; i < _capacity; i++) { if (ProcessBuilding(i)) { UpdateBuilding(); } } _lastProcessedFrame = GetFrame(); _initialized = true; _helper.BuildingMonitorSpun = true; _helper.BuildingMonitor = this; _helper.Log("Building monitor initialized"); } else if (!SimulationManager.instance.SimulationPaused) { _data._BuildingsUpdated.Clear(); _data._BuildingsRemoved.Clear(); int end = GetFrame(); while (_lastProcessedFrame != end) { _lastProcessedFrame = GetFrame(_lastProcessedFrame + 1); int[] boundaries = GetFrameBoundaries(_lastProcessedFrame); ushort id; for (int i = boundaries[0]; i <= boundaries[1]; i++) { id = (ushort)i; if (UpdateBuilding(id)) { _data._BuildingsUpdated.Add(id); } else if (_data._Buildings.Contains(id)) { _data._BuildingsRemoved.Add(id); RemoveBuilding(id); } } } } OutputDebugLog(); } catch (Exception e) { string error = "Building monitor failed to initialize\r\n"; error += String.Format("Error: {0}\r\n", e.Message); error += "\r\n"; error += "==== STACK TRACE ====\r\n"; error += e.StackTrace; _helper.Log(error); _terminated = true; } base.OnUpdate(realTimeDelta, simulationTimeDelta); }
/* * Handles removal of buildings and status changes * * Note: Just because a building has been removed visually, it does not mean * it is removed as far as the game is concerned. The building is only truly removed * when the frame covers the building's id, and that's when we will remove the * building from our records. */ public override void OnUpdate(float realTimeDelta, float simulationTimeDelta) { if (_terminated) return; if (!_helper.BuildingMonitorSpinnable) return; if (!_settings.Enable._BuildingMonitor) return; try { if (!_initialized) { _data = Data.Instance; _mapping = new BuildingPrefabMapping(); _paused = false; _instance = Singleton<BuildingManager>.instance; _capacity = _instance.m_buildings.m_buffer.Length; _id = (ushort)_capacity; _added.Clear(); _removed.Clear(); for (ushort i = 0; i < _capacity; i++) { if (ProcessBuilding(i)) UpdateBuilding(); } _lastProcessedFrame = GetFrame(); _initialized = true; _helper.BuildingMonitorSpun = true; _helper.BuildingMonitor = this; _helper.NotifyPlayer("Building monitor initialized"); } else if (!SimulationManager.instance.SimulationPaused) { _data._BuildingsAdded.Clear(); _data._BuildingsUpdated.Clear(); _data._BuildingsRemoved.Clear(); foreach (ushort i in _added) _data._BuildingsAdded.Add(i); _added.Clear(); foreach (ushort i in _removed) _data._BuildingsRemoved.Add(i); _removed.Clear(); int end = GetFrame(); while (_lastProcessedFrame != end) { _lastProcessedFrame = GetFrame(_lastProcessedFrame + 1); int[] boundaries = GetFrameBoundaries(_lastProcessedFrame); ushort id; for (int i = boundaries[0]; i <= boundaries[1]; i++) { id = (ushort)i; if (UpdateBuilding(id)) _data._BuildingsUpdated.Add(id); else if (_data._Buildings.Contains(id)) { _data._BuildingsRemoved.Add(id); RemoveBuilding(id); } } } } OutputDebugLog(); } catch (Exception e) { string error = "Building monitor failed to initialize\r\n"; error += String.Format("Error: {0}\r\n", e.Message); error += "\r\n"; error += "==== STACK TRACE ====\r\n"; error += e.StackTrace; _helper.Log(error); _terminated = true; } base.OnUpdate(realTimeDelta, simulationTimeDelta); }