public SnackSimThreadPool() { jobList = new List <SimSnacks>(); mutex = new Mutex(); snackThreads = new List <SnackSimThread>(); vesselResourceDurations = new Dictionary <Vessel, Dictionary <string, double> >(); convertersAssumedActive = new Dictionary <Vessel, bool>(); maxThreads = SnacksScenario.Instance.maxThreads; SnackSimThread snackThread;; for (int index = 0; index < maxThreads; index++) { snackThread = new SnackSimThread(mutex, jobList); snackThread.OnSimulationComplete = OnThreadSimulationComplete; snackThread.OnSimulatorCycleComplete = OnThreadSimulatorCycleComplete; snackThread.Start(); } }
public override void SetVisible(bool newValue) { base.SetVisible(newValue); if (newValue) { partCount = 0; crewCapacity = 0; previousCrewCount = 0; currentCrewCount = -1; selectedBody = -1; if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedScene == GameScenes.SPACECENTER) { SnacksScenario.Instance.UpdateSnapshots(); SnacksScenario.onSnackTime.Add(onSnackTime); } else if (HighLogic.LoadedSceneIsEditor) { snackshots = new List <Snackshot>(); GameEvents.onEditorPartEvent.Add(onEditorPartEvent); GameEvents.onPartResourceListChange.Add(onPartResourceListChange); GameEvents.onEditorShipModified.Add(onEditorShipModified); snackThread = new SnackSimThread(new Mutex(), new List <SimSnacks>()); snackThread.OnSimulationComplete = OnSimulationComplete; snackThread.Start(); } exemptKerbals = SnacksScenario.Instance.exemptKerbals; SnacksScenario.Instance.SetExemptCrew(exemptKerbals); } else { if (snackThread != null) { snackThread.Stop(); } if (SnacksScenario.Instance == null) { return; } SnacksScenario.Instance.exemptKerbals = exemptKerbals; if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedScene == GameScenes.SPACECENTER) { SnacksScenario.onSnackTime.Remove(onSnackTime); if (SnacksScenario.Instance != null && SnacksScenario.Instance.threadPool != null) { SnacksScenario.Instance.threadPool.StopAllJobs(); } } else if (HighLogic.LoadedSceneIsEditor) { GameEvents.onEditorPartEvent.Remove(onEditorPartEvent); GameEvents.onPartResourceListChange.Remove(onPartResourceListChange); GameEvents.onEditorShipModified.Remove(onEditorShipModified); } } }