Skip to content

Commit 773ce72

Browse files
committed
prepare Simulator for distributed simulation
1 parent c14f2f7 commit 773ce72

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

O2DESNet/Simulator.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,22 @@ public Simulator(State state)
1919
#endregion
2020

2121
State = state;
22-
if (State.InitEvents.Count == 0) throw new InitEventsNotFound();
22+
//if (State.InitEvents.Count == 0) throw new InitEventsNotFound();
2323
foreach (var evnt in State.InitEvents) Schedule(evnt, ClockTime);
24-
}
24+
}
25+
public bool HasFutureEvents { get { return FutureEventList.Count > 0; } }
26+
public DateTime HeadEventTime { get { return FutureEventList.Count > 0 ? FutureEventList.First().ScheduledTime : DateTime.MaxValue; } }
27+
/// <summary>
28+
/// Reset simulation clock time, used for HLA federate initialization.
29+
/// </summary>
30+
public void ResetClockTime(DateTime clockTime)
31+
{
32+
while (ClockTime < clockTime)
33+
{
34+
FutureEventList.Remove(FutureEventList.First());
35+
ClockTime = FutureEventList.Count > 0 ? FutureEventList.First().ScheduledTime : clockTime;
36+
}
37+
}
2538
internal protected void Schedule(Event evnt, DateTime time)
2639
{
2740
if (evnt.Simulator == null) evnt.Simulator = this;
@@ -46,6 +59,13 @@ protected bool ExecuteHeadEvent()
4659
head.Invoke();
4760
return true;
4861
}
62+
public virtual bool Run(Event evnt)
63+
{
64+
if (evnt.Simulator != null && !evnt.Simulator.Equals(this))
65+
return false;
66+
Execute(evnt);
67+
return true;
68+
}
4969
public virtual bool Run(TimeSpan duration) { return Run(ClockTime.Add(duration)); }
5070
public virtual bool Run(DateTime terminate)
5171
{

0 commit comments

Comments
 (0)