Skip to content

Commit

Permalink
Add model initializer with custom systems (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored May 16, 2024
1 parent 7464453 commit 33f1f5c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions model/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,32 @@ func Default(p params.Params, m *model.Model) *model.Model {

return m
}

// Default sets up a beecs model with the given systems instead of the default ones.
//
// If the argument m is nil, a new model instance is created.
// If it is non-nil, the model is reset and re-used, saving some time for initialization and memory allocation.
func WithSystems(p params.Params, sys []model.System, m *model.Model) *model.Model {
if m == nil {
m = model.New()
} else {
m.Reset()
}

p.Apply(&m.World)

factory := globals.NewForagerFactory(&m.World)
ecs.AddResource(&m.World, &factory)

stats := globals.PopulationStats{}
ecs.AddResource(&m.World, &stats)

consumptionStats := globals.ConsumptionStats{}
ecs.AddResource(&m.World, &consumptionStats)

for _, s := range sys {
m.AddSystem(s)
}

return m
}

0 comments on commit 33f1f5c

Please sign in to comment.