public override void OnCreated(IThreading threading) { Logger.Message("==============================="); Logger.Message("Initializing auto color monitor"); Logger.Message("Initializing colors"); GenericNames.Initialize(); Logger.Message("Loading current config"); _config = Configuration.Instance; _colorStrategy = SetColorStrategy(_config.ColorStrategy); _namingStrategy = SetNamingStrategy(_config.NamingStrategy); _usedColors = new NullUsedColors(); Logger.Message("Found color strategy of " + _config.ColorStrategy); Logger.Message("Found naming strategy of " + _config.NamingStrategy); _initialized = true; Instance = this; Logger.Message("done creating"); base.OnCreated(threading); }
// TODO: make this whole thing a coroutine? public override void OnUpdate(float realTimeDelta, float simulationTimeDelta) { TransportManager theTransportManager; SimulationManager theSimulationManager; TransportLine[] lines; try { //Digest changes if (_config.UndigestedChanges) { Logger.Message("Applying undigested changes"); _colorStrategy = SetColorStrategy(_config.ColorStrategy); _namingStrategy = SetNamingStrategy(_config.NamingStrategy); _config.UndigestedChanges = false; } if (_initialized == false) { return; } // try and limit how often we are scanning for lines. this ain't that important if (_nextUpdateTime >= DateTimeOffset.Now) { return; } if (!Singleton <TransportManager> .exists || !Singleton <SimulationManager> .exists) { return; } theTransportManager = Singleton <TransportManager> .instance; theSimulationManager = Singleton <SimulationManager> .instance; lines = theTransportManager.m_lines.m_buffer; } catch (Exception ex) { Logger.Error(ex.ToString()); return; } if (theSimulationManager.SimulationPaused) { return; } var locked = false; try { _nextUpdateTime = DateTimeOffset.Now.AddSeconds(Constants.UpdateIntervalSeconds); locked = Monitor.TryEnter(lines, SimulationManager.SYNCHRONIZE_TIMEOUT); if (!locked) { return; } _usedColors = UsedColors.FromLines(lines); for (ushort i = 0; i < lines.Length - 1; i++) { ProcessLine(i, lines[i], false, theSimulationManager, theTransportManager); } } catch (Exception ex) { Logger.Error(ex.ToString()); } finally { if (locked) { Monitor.Exit(lines); } } }