system

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2024 License: MIT Imports: 5 Imported by: 5

Documentation

Overview

Package system provides general-purpose [model.System] implementations.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackTermination added in v0.0.2

type CallbackTermination struct {
	Callback func(t int64) bool // The callback. ends the simulation when it returns true.
	// contains filtered or unexported fields
}

CallbackTermination system.

Terminates a model run according to the return value of a callback function.

Expects a resource of type [model.Termination].

Example
package main

import (
	"github.com/mlange-42/arche-model/model"
	"github.com/mlange-42/arche-model/system"
)

func main() {
	m := model.New()

	m.AddSystem(&system.CallbackTermination{
		Callback: func(t int64) bool {
			return t >= 99
		}},
	)

	m.Run()
}
Output:

func (*CallbackTermination) Finalize added in v0.0.2

func (s *CallbackTermination) Finalize(w *ecs.World)

Finalize the system

func (*CallbackTermination) Initialize added in v0.0.2

func (s *CallbackTermination) Initialize(w *ecs.World)

Initialize the system

func (*CallbackTermination) Update added in v0.0.2

func (s *CallbackTermination) Update(w *ecs.World)

Update the system

type FixedTermination

type FixedTermination struct {
	Steps int64 // Number of simulation ticks to run.
	// contains filtered or unexported fields
}

FixedTermination system.

Terminates a model run after a fixed number of ticks.

Expects a resource of type [model.Termination].

Example
package main

import (
	"github.com/mlange-42/arche-model/model"
	"github.com/mlange-42/arche-model/system"
)

func main() {
	m := model.New()

	m.AddSystem(&system.FixedTermination{Steps: 100})

	m.Run()
}
Output:

func (*FixedTermination) Finalize

func (s *FixedTermination) Finalize(w *ecs.World)

Finalize the system

func (*FixedTermination) Initialize

func (s *FixedTermination) Initialize(w *ecs.World)

Initialize the system

func (*FixedTermination) Update

func (s *FixedTermination) Update(w *ecs.World)

Update the system

type PerfTimer

type PerfTimer struct {
	UpdateInterval int  // Update/print interval in model ticks.
	Stats          bool // Whether to print world stats.
	// contains filtered or unexported fields
}

PerfTimer system for printing elapsed time per model step, and optional world statistics.

Example
package main

import (
	"github.com/mlange-42/arche-model/model"
	"github.com/mlange-42/arche-model/system"
)

func main() {
	m := model.New()

	m.AddSystem(&system.PerfTimer{UpdateInterval: 10})
	m.AddSystem(&system.FixedTermination{Steps: 30})

	// Uncomment the next line.

	// m.Run()
	
Output:

func (*PerfTimer) Finalize

func (s *PerfTimer) Finalize(w *ecs.World)

Finalize the system

func (*PerfTimer) Initialize

func (s *PerfTimer) Initialize(w *ecs.World)

Initialize the system

func (*PerfTimer) Update

func (s *PerfTimer) Update(w *ecs.World)

Update the system

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL