message

package
v0.0.0-...-5996917 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReleaseBuffer

func ReleaseBuffer(b *Buffer)

ReleaseBuffer puts a *Buffer back into a pool of *Buffer for reuse.

Types

type Buffer

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

Buffer provides temporary storage for messages to players. The Buffer accumulates messages which can then be sent as single network writes to the players. A Buffer can handle insertion of line feeds into messages automatically when required.

While a *Buffer can be created using &Buffer{} it is a better to use calls to AcquireBuffer and ReleaseBuffer which will supply a *Buffer from a reusable pool of *Buffer and return the *Buffer to the pool for reuse.

NOTE: omitLF indicates whether an empty Buffer should start with a line feed or not. This should be true for an actor's Buffer as they would have moved to a new line when pressing enter to issue a command. For all other Buffers it should be false as we need to move them off their prompt line manually.

func AcquireBuffer

func AcquireBuffer() (b *Buffer)

AcquireBuffer returns a *Buffer from a pool of *Buffer. A *Buffer should be returned to the pool by calling ReleaseBuffer. It is not essential that ReleaseBuffer is called as the pool will replenish itself, however a *Buffer that is simply discarded cannot be reused - which avoids allocations and generating garbage.

func (*Buffer) Append

func (b *Buffer) Append(s ...string)

Append takes a number of strings and writes them into the Buffer appending to a previous message. The message is appended to the current Buffer with a leading single space. Append is useful when a message needs to be composed in several stages. Append does not normally increase the message count returned by Len, but see special cases below.

If the Buffer is in silent mode the Buffer will not be modified and the passed strings will be discarded.

Special cases:

If Append is called without an initial Send then Append will behave like a Send and also increase the message count by one.

If Append is called without an initial Send or after a Send with an empty string the leading space will be omitted. This is so that Send can cause the start a new message but text is only appended by calling Append.

func (*Buffer) Deliver

func (b *Buffer) Deliver(w ...io.Writer)

Deliver writes the messages in the Buffer to the passed Writers.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of messages in a Buffer.

func (*Buffer) OmitLF

func (b *Buffer) OmitLF(new bool) (old bool)

OmitLF sets a Buffer omitLF flag to true or false and returns the old omitLF setting. For details of the omitLF flag see the Buffer type.

func (*Buffer) Send

func (b *Buffer) Send(s ...string)

Send takes a number of strings and writes them into the Buffer as a single message. The message will automatically be prefixed with a line feed if required so that the message starts on its own new line when displayed to the player. Each time Send is called the message count returned by Len is increased by one.

If the Buffer is in silent mode the Buffer and message count will not be modified and the passed strings will be discarded.

func (*Buffer) SendBad

func (b *Buffer) SendBad(s ...string)

SendBad is convenient for sending a message using text.Bad as the color.

func (*Buffer) SendGood

func (b *Buffer) SendGood(s ...string)

SendGood is convenient for sending a message using text.Good as the color.

func (*Buffer) SendInfo

func (b *Buffer) SendInfo(s ...string)

SendInfo is convenient for sending a message using text.Info as the color.

func (*Buffer) Silent

func (b *Buffer) Silent(new bool) (old bool)

Silent sets a Buffer silent mode to true or false and returning the old silent mode. When a Buffer is in silent mode it will ignore calls to Send and Append.

type Msg

type Msg struct {
	Actor              *Buffer
	GM                 *Buffer
	ActorVerbose       *Buffer
	Participant        *Buffer
	ParticipantVerbose *Buffer
	Observer           *Buffer
	ObserverVerbose    *Buffer
	Observers          buffers
	ObserversVerbose   buffers
}

Msg is a collection of buffers for gathering messages to send back as a result of processing a command.

func (*Msg) Allocate

func (m *Msg) Allocate(obsRooms []int)

Allocate sets up the message buffers for the actor, participant and observers.

func (*Msg) Deallocate

func (m *Msg) Deallocate()

Deallocate releases the references to message buffers for the actor, participant and observers. Specific deallocation can help with garbage collection.

Jump to

Keyboard shortcuts

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