Documentation
¶
Index ¶
- func ReleaseBuffer(b *Buffer)
- type Buffer
- func (b *Buffer) Append(s ...string)
- func (b *Buffer) Deliver(w ...io.Writer)
- func (b *Buffer) Len() int
- func (b *Buffer) OmitLF(new bool) (old bool)
- func (b *Buffer) Send(s ...string)
- func (b *Buffer) SendBad(s ...string)
- func (b *Buffer) SendGood(s ...string)
- func (b *Buffer) SendInfo(s ...string)
- func (b *Buffer) Silent(new bool) (old bool)
- type Msg
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 ¶
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) OmitLF ¶
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 ¶
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) SendGood ¶
SendGood is convenient for sending a message using text.Good as the color.
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 ¶
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.