//First argument is simulatorID (int), all subsequent arguments follow the format in _parseSimulationDatum public static void Main(string[] simulationData) { try { ConsoleManager.WriteLine("Starting simulator instance...", ConsoleMessageType.Debug); Logger.Initialize(); TimeKeeper.Initialize(); _simulatorConfig = new SimulatorConfig(); _physicsConfig = new PhysicsConfig(); RedisServer redisServer = new RedisServer(Logger.LogRedisError, Logger.LogRedisInfo, new RedisConfig().Address); RedisNetworkingService redisNetworkingService = new RedisNetworkingService(_simulatorConfig, redisServer); int simulatorID = int.Parse(simulationData[0]); List <string> dataArray = new List <string>(); for (int i = 1; i < simulationData.Length; i++) { dataArray.Add(simulationData[i]); } _mainManager = new MainManager(simulatorID, redisNetworkingService, new SimulatorGameTimeService(), _simulatorConfig, _physicsConfig); //IDs are parsed, then each ID is used to subscribe to a redis channel, which the server uses to communicate data about each system foreach (string s in dataArray) { if (s == "") { continue; } var data = _parseSimulationDatum(s); _mainManager.StartSimulatingArea(data.Item2, data.Item1); } _mainManager.ConnectToServer(); Run(); } catch (Exception e) { ConsoleManager.WriteLine("Exception in simulator", ConsoleMessageType.Error); ConsoleManager.WriteLine(e.ToString(), ConsoleMessageType.Error); ConsoleManager.WriteLine(e.Message, ConsoleMessageType.Error); Run(); } }
public void Start() { Initialize(); _disableObjectUpdates = true;//Don't forget this, or you'll end up with null errors System.Timers.Timer objectUpdater = GetTimer(ServerConfig.ObjectUpdatePeriod, _updateManagers); System.Timers.Timer structureUpdater = GetTimer(ServerConfig.StructureUpdatePeriod, _updateStructures); System.Timers.Timer syncTimer = GetTimer(ServerConfig.DBSyncPeriod, dbSyncer.SyncAllToDB); System.Timers.Timer economyManagerTimer = GetTimer(ServerConfig.TradeSynchronizerUpdatePeriod, _economyManager.Update);; System.Timers.Timer masterServerTimer = GetTimer(ServerConfig.MasterServerManagerUpdatePeriod, _masterServerManager.Update);; masterServerTimer.Start();//Must start this to receive systems to simulate UpdateTimers.Add(objectUpdater); UpdateTimers.Add(structureUpdater); UpdateTimers.Add(syncTimer); UpdateTimers.Add(masterServerTimer); UpdateTimers.Add(economyManagerTimer); LidgrenMessagePollerThreaded mp = new LidgrenMessagePollerThreaded(_connectionManager.Server, this); Thread MessagePoller = new Thread(mp.Poll); MessagePoller.Start(); while (!_msMessageHandler.PSystemsLoaded) { //Spinwait while systems are loading Thread.Sleep(1); } _simulatorManager.Initialize(_galaxyManager.Systems); TimeKeeper.Initialize(); _disableObjectUpdates = false; foreach (var t in UpdateTimers) { t.Start(); } _cargoSynchronizer.Start(ServerConfig.CargoSynchronizerUpdatePeriod, ServerConfig.CargoSynchronizerNumThreads); }