void Update() { // tick game timer float gameSeconds = Time.deltaTime / realSecondsPerGameSecond; DateTime newTime = CurrentTime.AddSeconds(gameSeconds); if (newTime.Year - CurrentTime.Year > 0) { OnYearPassed(newTime); } if (newTime.Month - CurrentTime.Month > 0) { OnMonthPassed(newTime); } if (newTime.Day - CurrentTime.Day > 0) { OnDayPassed(newTime); } if (newTime.Hour - CurrentTime.Hour > 0) { OnHourPassed(newTime); } if (newTime.Minute - CurrentTime.Minute > 0) { OnMinutePassed(newTime); } if (gameSeconds >= 0) { OnSecondPassed(newTime); } CurrentTime = newTime; }
public virtual void Set <T>(string key, T value, int expiredSeconds) { if (expiredSeconds <= 0) { expiredSeconds = _expiredSeconds; } SetInner(key, value, CurrentTime.AddSeconds(expiredSeconds)); }
public virtual void SetBatch <T>(IEnumerable <CacheItem <T> > items, int expiredSeconds) { if (expiredSeconds <= 0) { expiredSeconds = _expiredSeconds; } DateTime expriedTime = CurrentTime.AddSeconds(expiredSeconds); SetBatch(items, expriedTime); }
public bool Next(long seconds) { var currentTimeUx = CUtility.UnixTime.GetFromDateTime(CurrentTime); var nextTime = CurrentTime.AddSeconds(seconds); if (nextTime > this.EndTime) { return(false); } var nextTimeUx = CUtility.UnixTime.GetFromDateTime(nextTime); var error = false; try { var dt = _db.GetDataTable( string.Format( "select date,price from trades where currency='{0}' and {1} < date and date <= {2} and real=1 order by tid desc limit 1", this.Currency, currentTimeUx, nextTimeUx)); var dateUx = (long)dt.Rows[0].ItemArray[0]; var date = CUtility.UnixTime.ConvertToDateTime((uint)dateUx); this.MarketTime = date; var ask = (double)dt.Rows[0].ItemArray[1]; this.Ask = (decimal)ask; this.Bid = this.Ask; } catch (Exception ex) { error = true; } finally { using (var sw = new StreamWriter(@"data\output\raw.csv", true)) { sw.WriteLine(string.Format("{0}, {1}, {2}, {3}", this.MarketTime.ToString("s"), this.Ask.ToString(CultureInfo.InvariantCulture), this.Ask.ToString(CultureInfo.InvariantCulture), error ? 1 : 0)); sw.Flush(); } CurrentTime = nextTime; } return(true); }
public DeviceReading GetReading() { var rand = new Random(); CurrentTime = CurrentTime.AddSeconds(Interval); Reading += Range * (rand.NextDouble() - .5); return(new DeviceReading { DeviceID = this.DeviceName, Reading = Reading, Time = CurrentTime, ReadingID = (DateTime.MaxValue - CurrentTime).Ticks }); }
protected override object GetInner(Type type, string key) { object value = firstCache.Get(type, key); if (value != null) { return(value); } value = secondCache.Get(type, key); if (value != null) { OnSetFirstCache(key, value, CurrentTime.AddSeconds(ExpiredSeconds)); } return(value); }
public void start() { thread = new Thread(() => { while (threadenable) { Tick(this, new AlarmEventArgs(CurrentTime)); TimeSpan diff = CurrentTime - AlarmTime; if (diff < new TimeSpan(0, 0, 15) && diff >= new TimeSpan(0, 0, 0)) { Alarm(this, new AlarmEventArgs(CurrentTime)); } Thread.Sleep(1000); CurrentTime = CurrentTime.AddSeconds(1); } }); thread.Start(); }
//Updates statistics public override async void Update() { CurrentTime = CurrentTime.AddSeconds(1); var distancesTravelled = DroneController.DistanceTravelled.Values.ToList(); var speeds = DroneController.Speeds.Values.ToList(); await Task.Run(() => { Statistic.RunTimeSeconds = (int)CurrentTime.Subtract(Statistic.StartRunTime).TotalSeconds; Statistic.DroneCount = !DroneController.Drones.IsNullOrEmpty() ? DroneController.Drones.Count : 0; Statistic.AverageDistanceTravelled = distancesTravelled.IsNullOrEmpty() ? 0 : distancesTravelled.Average(); Statistic.AverageDroneSpeed = speeds.IsNullOrEmpty() ? 0 : speeds.Average(); }); if (!CurrentTime.Equals(Statistic.CurrentTimeInRun.AddMinutes(5))) { return; } Statistic.CurrentTimeInRun = CurrentTime; RecordStatistics(false); }
private static async Task <double> CalculateScore(AStarCity start, AStarCity end) { var startLocation = GetLocation(start); var endLocation = GetLocation(end); await GetTravelInfo(startLocation, endLocation); while (Result == null) { await Task.Delay(25); } double distanceScore = 1 / (double)Result.distance.value; CurrentTime = CurrentTime.AddSeconds(Result.duration.value); if (CurrentTime > end.City.ArrivingTime) { return(0); } double timeScore = (1 / (end.City.ArrivingTime.Subtract(CurrentTime).TotalSeconds)) * _timeImportanceCoeficient; Result = null; return(distanceScore + timeScore); }
public void StartSimulation() { listIndex = 0; activityList = dbHandler.GetActivityData(DataSetIndex); SetInitialPosition(activityList[listIndex].Activity); CurrentTime = activityList[listIndex].StartTime.AddSeconds(-1); Room = activityList[listIndex].Room; Activity = activityList[listIndex].Activity; configPositionList = dbHandler.GetConfigPositions(1); ShowNextActivity(); //Simulation loop while (listIndex <= activityList.Count - 1) { Room = activityList[listIndex].Room; Activity = activityList[listIndex].Activity; if (fastMode && fastmodeThreadFinished) { fastmodeCaller = new Thread(new ThreadStart(ActivateFastMode)); fastmodeCaller.Start(); } for (int i = 0; i < configPositionList.Count; i++) { if (configPositionList[i].Activity == Activity) { if (PersonPositionX != configPositionList[i].XPos && PersonPositionY != configPositionList[i].YPos && listIndex != 0 && animationThreadFinished) { animationThreadFinished = false; animationCaller = new Thread(new ThreadStart(AnimateMovement)); animationCaller.Start(); } } } CurrentTime = CurrentTime.AddSeconds(1); if (CurrentTime < activityList[listIndex + 1].StartTime) { if (nextActivity == true) { SkipToNextActivity(); } } else { Room = activityList[listIndex].Room; Activity = activityList[listIndex].Activity; if (animationThreadFinished) { animationThreadFinished = false; animationCaller = new Thread(new ThreadStart(AnimateMovement)); animationCaller.Start(); } ShowNextActivity(); listIndex++; } if (SimulationSuspended == true) { try { Thread.Sleep(Timeout.Infinite); } catch (ThreadInterruptedException) { Thread.Sleep((int)(Math.Round(1000 / SimulationSpeed))); } } else { try { Thread.Sleep((int)(Math.Round(1000 / SimulationSpeed))); } catch (ThreadInterruptedException) { Thread.Sleep((int)(Math.Round(1000 / SimulationSpeed))); } } } simulationThreadFinished = true; }
//Checks if the Normally Distributed spawn times contain the current time public bool CheckTimeToSpawn() { CurrentTime = CurrentTime.AddSeconds(1); return(SpawnTimes.Contains(CurrentTime)); }
public void NextFrame() { DateTime newTime = CurrentTime.AddSeconds(this.timeResolution); SetFrameByTime(newTime); }