resource

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 2 Imported by: 7

Documentation

Overview

Package resource provides commonly used resources (in the ECS sense).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rand

type Rand struct {
	rand.Source `json:"-"` // Source to use for PRNGs in [System] implementations.
}

Rand is a PRNG resource to be used in [System] implementations.

This resource is provided by github.com/mlange-42/ark-tools/app.App per default.

Example
app := app.New(1024)

src := ecs.GetResource[resource.Rand](app.World)
rng := rand.New(src.Source)
_ = rng.NormFloat64()

type SelectedEntity

type SelectedEntity struct {
	Selected ecs.Entity
}

SelectedEntity is a resource holding the currently selected entity.

The primarily purpose is communication between UI systems, e.g. for entity inspection or manipulation by the user.

Example
package main

import (
	"fmt"

	"github.com/mlange-42/ark-tools/app"
	"github.com/mlange-42/ark-tools/resource"
	"github.com/mlange-42/ark/ecs"
)

func main() {
	app := app.New(1024)
	ecs.AddResource(app.World, &resource.SelectedEntity{})

	sel := ecs.GetResource[resource.SelectedEntity](app.World)

	fmt.Println(sel.Selected.IsZero())
}
Output:

true

type Termination

type Termination struct {
	Terminate bool // Whether the simulation run is finished. Can be set by systems.
}

Termination is a resource holding whether the simulation should terminate after the current step.

This resource is provided by github.com/mlange-42/ark-tools/app.App per default.

Example
package main

import (
	"fmt"

	"github.com/mlange-42/ark-tools/app"
	"github.com/mlange-42/ark-tools/resource"
	"github.com/mlange-42/ark/ecs"
)

func main() {
	app := app.New(1024)

	term := ecs.GetResource[resource.Termination](app.World)

	fmt.Println(term.Terminate)
}
Output:

false

type Tick

type Tick struct {
	Tick int64 // The current tick.
}

Tick is a resource holding the app's time step. The tick value should not be modified by user code, as it is managed by the scheduler.

This resource is provided by github.com/mlange-42/ark-tools/app.App per default.

Example
package main

import (
	"fmt"

	"github.com/mlange-42/ark-tools/app"
	"github.com/mlange-42/ark-tools/resource"
	"github.com/mlange-42/ark/ecs"
)

func main() {
	app := app.New(1024)

	tick := ecs.GetResource[resource.Tick](app.World)

	fmt.Println(tick.Tick)
}
Output:

0

Jump to

Keyboard shortcuts

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