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 ¶
- type Event
- type Observer
- type Scheduler
- type Ticker
- func (tck Ticker) Observe(label string) (*Event, bool)
- func (tck *Ticker) Schedule(delay int, payload func(), label string) *Event
- func (tck *Ticker) ScheduleWithArg(delay int, payload func(interface{}), arg interface{}, label string) *Event
- func (tck Ticker) String() string
- func (tck *Ticker) Tick() bool
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 ¶
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 ¶
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) RemainingCycles ¶
RemainingCycles reports the number of cycles remaining before payload function is ran
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 (Ticker) Observe ¶
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