From aad7eb3a3d6a8881ffbafcfbf88827baff4c5bfc Mon Sep 17 00:00:00 2001 From: Yifan Sun Date: Wed, 22 May 2024 21:33:59 -0400 Subject: [PATCH 1/2] engine in simulation --- sim/simulation.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sim/simulation.go b/sim/simulation.go index 5e1ac8b..27b9006 100644 --- a/sim/simulation.go +++ b/sim/simulation.go @@ -2,6 +2,7 @@ package sim // A Simulation provides the service requires to define a simulation. type Simulation struct { + engine Engine components []Component compNameIndex map[string]int ports []Port @@ -16,6 +17,16 @@ func NewSimulation() *Simulation { } } +// RegisterEngine registers the engine used in the simulation. +func (s *Simulation) RegisterEngine(e Engine) { + s.engine = e +} + +// GetEngine returns the engine used in the simulation. +func (s *Simulation) GetEngine() Engine { + return s.engine +} + // RegisterComponent registers a component with the simulation. func (s *Simulation) RegisterComponent(c Component) { compName := c.Name() From 8e3b648d22a72e4b178e9d331dd71f8f7f5afd92 Mon Sep 17 00:00:00 2001 From: Yifan Sun Date: Wed, 22 May 2024 22:15:12 -0400 Subject: [PATCH 2/2] Update tick scheduling to allow ticking event at 0 --- sim/ticker.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sim/ticker.go b/sim/ticker.go index 3595472..b2e7334 100644 --- a/sim/ticker.go +++ b/sim/ticker.go @@ -47,6 +47,7 @@ func NewTickScheduler( ticker.handler = handler ticker.Engine = engine ticker.Freq = freq + ticker.nextTickTime = -1 // This will make sure the first tick is scheduled return ticker } @@ -64,6 +65,7 @@ func NewSecondaryTickScheduler( ticker.Engine = engine ticker.Freq = freq ticker.secondary = true + ticker.nextTickTime = -1 // This will make sure the first tick is scheduled return ticker }