future

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: GPL-3.0, GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Pacakge future conceptualises event delays inside the VCS. An event, in this context means, something that occurs as a response to a stimulus generated by the CPU. For example, when a program causes the CPU to strobe the RESP0 address, the act of resetting the player's horizontal position does not happen immediately. Instead there is a short delay, measured in cycles, before the effect of the memory write occurs.

The emulation code is full of events, like RESP0, that from the viewpoint of the event itself, occurs in the future. In the future package we use the Event type to represent this. The Event type is not instantiated directly. Instead, events are scheduled via an instance of the Ticker type.

The Ticker type coordinates scheduled events for those parts of the VCS that experience stimulus delays. For instance each player sprite has an instance of Ticker. Events are created and registered with Schedule function. The function takes the delay period, a label (useful identifying the event for debuggers) and a callback function as arguments. The callback is called once the delay period has expired.

The Tick() function of the Ticker type is used to indicate that time has passed. The RemainingCycles() function indicates how much more time (or to put another way, how many more calls to Tick()) is required before the payload is executed. It is up to the users of the package to govern how often and when Tick() is called. The other Ticker functions help the governor to fine tune the ticks.

To help keep code clean, two other interfaces to the Ticker type are provided, the Scheduler and Observer. The Scheduler is used in those places where an event is only ever scheduled. The Observer interface meanwhile is useful for debuggers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

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

Event represents a single occurance of a payload sometime in the future

func (*Event) AboutToEnd

func (ev *Event) AboutToEnd() bool

AboutToEnd is true if event resolves on next Tick()

func (*Event) Drop

func (ev *Event) Drop()

Drop is be used to remove the event from the ticker queue without executing the payload. Because the payload is not run then you should be careful to handle any cleanup that might otherwise occur (in the payload).

It is very important that any references to the event be forgotten once Drop() has been called

func (*Event) Force

func (ev *Event) Force()

Force can be used to immediately run the event's payload

It is very important that any references to the event be forgotten once Force() has been called

func (Event) JustStarted

func (ev Event) JustStarted() bool

JustStarted is true if the Tick() function for the event has not yet been called

func (*Event) Pause

func (ev *Event) Pause()

Pause prevents future calls to Tick() having any effect (until Resume() is called)

func (*Event) Push

func (ev *Event) Push()

Push back event completion by restarting the event

func (Event) RemainingCycles

func (ev Event) RemainingCycles() int

RemainingCycles reports the number of cycles remaining before payload function is ran

func (Event) String

func (ev Event) String() string

type Observer

type Observer interface {
	Observe(label string) (*Event, bool)
}

Observer exposes only the function relating to the observing of events

type Scheduler

type Scheduler interface {
	Schedule(delay int, payload func(), label string) *Event
	ScheduleWithArg(delay int, payload func(arg interface{}), arg interface{}, label string) *Event
}

Scheduler exposes only the functions relating to scheduling of events

type Ticker

type Ticker struct {
	Label string
	// contains filtered or unexported fields
}

Ticker is used to group payloads for future triggering.

func NewTicker

func NewTicker(label string) *Ticker

NewTicker is the only method of initialisation for the Ticker type

func (Ticker) Observe

func (tck Ticker) Observe(label string) (*Event, bool)

Observe looks for the most recent event with the specified label. if it is found then it is returned along with the value true to indicate a match. if it is not found, then the most recent event (with whatever label) is returned along with false to indicate no match

func (*Ticker) Schedule

func (tck *Ticker) Schedule(delay int, payload func(), label string) *Event

Schedule the pending future action

func (*Ticker) ScheduleWithArg

func (tck *Ticker) ScheduleWithArg(delay int, payload func(interface{}), arg interface{}, label string) *Event

ScheduleWithArg schedules the pending future action with an argument to the payload function

func (Ticker) String

func (tck Ticker) String() string

func (*Ticker) Tick

func (tck *Ticker) Tick() bool

Tick moves the pending action counter on one step

Jump to

Keyboard shortcuts

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