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 ¶
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 ¶ added in v0.0.5
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) Deliver ¶
Deliver writes all of the messages in the Buffer to the passed Writers. After the messages have been delivered the messages and message count will be cleared.
func (*Buffer) OmitLF ¶ added in v0.0.5
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) SendBad ¶ added in v0.0.5
SendBad is convenient for sending a message using text.Bad as the color.
func (*Buffer) SendGood ¶ added in v0.0.5
SendGood is convenient for sending a message using text.Good as the color.
func (*Buffer) SendInfo ¶ added in v0.0.5
SendInfo is convenient for sending a message using text.Info as the color.
type Msg ¶
Msg is a collection of buffers for gathering messages to send back as a result of processing a command. Before use a Msg should have Allocate called on it to allocate and setup the buffers internally. After use Deallocate should be called to free up the buffers. The Allocate and Deallocate methods are kept separate so that a Msg can be reused by repeated calls to Allocate/Deallocate.
NOTE: Observer is setup as an 'alias' for Observers[s.where] - Observer and Observers[s.where] point to the same Buffer. See the Allocate method for more details.
func (*Msg) Allocate ¶
Allocate sets up the message buffers for the actor, participant and observers. The 'where' passed in should be the current location so that Observer can be linked to the correct Observers element. The locks passed in are used to setup a Buffer for observers in each of the locations being locked.
The actor's Buffer is initially set to half a page (half of 80 columns by 24 lines) as it is common to be sending location descriptions back to the actor. Half a page is arbitrary but seems to be reasonable.
NOTE: For crowded locations buffers of observers are automatically put in silent mode.