Skip to content

Commit e41adf7

Browse files
committed
Decrease the citizen processing cycle to 8h instead of 24h
- aging is 3x faster now, 1 game day = 1 citizen year
1 parent d60aa5d commit e41adf7

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

src/RealTime/CustomAI/RealTimeResidentAI.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,26 @@ public void RegisterCitizenArrival(uint citizenId)
137137
schedule.DepartureToWorkTime = default;
138138
}
139139

140-
/// <summary>Performs simulation for starting a new day. Enables the logic to perform the 'new day processing' for the citizens.</summary>
141-
public void BeginNewDayProcessing()
140+
/// <summary>Performs simulation for starting a day cycle beginning with specified hour.
141+
/// Enables the logic to perform the 'new cycle processing' for the citizens.</summary>
142+
/// <param name="hour">The hour of the cycle.</param>
143+
public void BeginNewHourCycleProcessing(int hour)
142144
{
143-
Log.Debug(LogCategory.Generic, TimeInfo.Now, "Starting of the 'new day' processing for each citizen...");
144-
workBehavior.BeginNewDay();
145-
todayWakeUp = TimeInfo.Now.Date.AddHours(Config.WakeUpHour);
145+
Log.Debug(LogCategory.Generic, TimeInfo.Now, "Starting of the 'new cycle' processing for each citizen...");
146+
if (hour == 0)
147+
{
148+
workBehavior.BeginNewDay();
149+
todayWakeUp = TimeInfo.Now.Date.AddHours(Config.WakeUpHour);
150+
}
151+
146152
CanCitizensGrowUp = true;
147153
}
148154

149-
/// <summary>Disables the 'new day processing' for the citizens.</summary>
150-
public void EndNewDayProcessing()
155+
/// <summary>Disables the 'new cycle processing' for the citizens.</summary>
156+
public void EndHourCycleProcessing()
151157
{
152158
CanCitizensGrowUp = false;
153-
Log.Debug(LogCategory.Generic, TimeInfo.Now, "The 'new day' processing for the citizens is now completed.");
159+
Log.Debug(LogCategory.Generic, TimeInfo.Now, "The 'new cycle' processing for the citizens is now completed.");
154160
}
155161

156162
/// <summary>Performs simulation for starting a new day for a citizen with specified ID.</summary>

src/RealTime/Simulation/CitizenProcessor.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ internal sealed class CitizenProcessor<TAI, TCitizen>
2222
private readonly RealTimeResidentAI<TAI, TCitizen> residentAI;
2323
private readonly SpareTimeBehavior spareTimeBehavior;
2424
private readonly ITimeInfo timeInfo;
25-
private int dayStartFrame;
25+
private int cycleStartFrame;
26+
private int cycleHour;
2627

2728
/// <summary>Initializes a new instance of the <see cref="CitizenProcessor{TAI, TCitizen}"/> class.</summary>
2829
/// <param name="residentAI">The custom resident AI implementation.</param>
@@ -34,13 +35,18 @@ public CitizenProcessor(RealTimeResidentAI<TAI, TCitizen> residentAI, SpareTimeB
3435
this.residentAI = residentAI ?? throw new ArgumentNullException(nameof(residentAI));
3536
this.spareTimeBehavior = spareTimeBehavior ?? throw new ArgumentNullException(nameof(spareTimeBehavior));
3637
this.timeInfo = timeInfo ?? throw new ArgumentNullException(nameof(timeInfo));
37-
dayStartFrame = int.MinValue;
38+
cycleStartFrame = int.MinValue;
3839
}
3940

40-
/// <summary>Notifies this simulation object that a new game day begins.</summary>
41-
public void StartNewDay()
41+
/// <summary>Notifies this simulation object that a particular day hour begins.</summary>
42+
/// <param name="hour">The day time hour.</param>
43+
public void TriggerHour(int hour)
4244
{
43-
dayStartFrame = int.MinValue;
45+
if (hour % 8 == 0)
46+
{
47+
cycleHour = hour;
48+
cycleStartFrame = int.MinValue;
49+
}
4450
}
4551

4652
/// <summary>Re-calculates the duration of a simulation frame.</summary>
@@ -61,21 +67,21 @@ public void ProcessTick()
6167
/// <param name="frameIndex">The index of the simulation frame to process.</param>
6268
public void ProcessFrame(uint frameIndex)
6369
{
64-
if (dayStartFrame == -1)
70+
if (cycleStartFrame == -1)
6571
{
6672
return;
6773
}
6874

6975
uint step = frameIndex & StepMask;
70-
if (dayStartFrame == int.MinValue)
76+
if (cycleStartFrame == int.MinValue)
7177
{
72-
residentAI.BeginNewDayProcessing();
73-
dayStartFrame = (int)step;
78+
residentAI.BeginNewHourCycleProcessing(cycleHour);
79+
cycleStartFrame = (int)step;
7480
}
75-
else if (step == dayStartFrame)
81+
else if (step == cycleStartFrame)
7682
{
77-
residentAI.EndNewDayProcessing();
78-
dayStartFrame = -1;
83+
residentAI.EndHourCycleProcessing();
84+
cycleStartFrame = -1;
7985
return;
8086
}
8187

src/RealTime/Simulation/SimulationHandler.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,20 @@ public override void OnBeforeSimulationTick()
8282
return;
8383
}
8484

85-
DateTime currentDate = SimulationManager.instance.m_currentGameTime.Date;
86-
if (currentDate != lastHandledDate)
85+
DateTime currentDateTime = SimulationManager.instance.m_currentGameTime;
86+
if (currentDateTime.Hour != lastHandledDate.Hour || lastHandledDate == default)
8787
{
88-
lastHandledDate = currentDate;
89-
DayTimeSimulation.Process(currentDate);
90-
CitizenProcessor.StartNewDay();
91-
OnNewDay(this);
88+
int triggerHour = lastHandledDate == default
89+
? 0
90+
: currentDateTime.Hour;
91+
92+
lastHandledDate = currentDateTime;
93+
CitizenProcessor.TriggerHour(triggerHour);
94+
if (triggerHour == 0)
95+
{
96+
DayTimeSimulation.Process(currentDateTime);
97+
OnNewDay(this);
98+
}
9299
}
93100
}
94101

0 commit comments

Comments
 (0)