piroutine

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package piroutine provides functionality similar to coroutines found in other languages (e.g., Lua). It allows you to create Routines, which are programs composed of a sequence of steps, typically executed over many game frames.

This package helps you write more readable code, but at the cost of more difficult debugging and higher resource usage. Recommended for cases where your logic can be expressed as a sequence of steps, such as creating animations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Routine

type Routine struct {
	// contains filtered or unexported fields
}

Routine is a program composed of a sequence of steps, typically executed over multiple game frames.

func New

func New(steps ...Step) *Routine

New creates a new Routine composed of the provided steps.

func (*Routine) Resume

func (r *Routine) Resume() bool

Resume resumes the execution of the Routine.

It returns true if the Routine has not yet finished and can be continued by calling Resume again.

func (*Routine) ScheduleOn

func (r *Routine) ScheduleOn(event piloop.Event) pievent.Handler

ScheduleOn schedules the Routine to resume on the given event.

Each publication of the event will call Resume.

Returns a handler that can be unregistered from piloop.Target to stop further resuming.

func (*Routine) SetName

func (r *Routine) SetName(name string)

SetName sets the name of the Routine.

Used for tracing.

func (*Routine) SetTracing

func (r *Routine) SetTracing(tracing bool)

SetTracing enables or disables logging of each step execution.

Very useful for debugging a Routine.

func (*Routine) Stop

func (r *Routine) Stop()

Stop terminates the execution of the Routine.

func (*Routine) Stopped

func (r *Routine) Stopped() bool

type Step

type Step func() bool

Step is a single step in a Routine.

It returns true when the step has finished and the next step in the Routine can be executed

func Call

func Call(f func()) Step

Call creates a Routine step that executes the given function and immediately advances to the next step

func Printf

func Printf(format string, v ...any) Step

Printf logs the text and immediately advances to the next Routine step.

func SlowDown

func SlowDown(n int, f func() bool) Step

SlowDown returns a Routine step that executes f every n updates.

func Wait

func Wait(n int) Step

Wait creates a Routine step that waits for n resumes before advancing to the next step.

Jump to

Keyboard shortcuts

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