Up to Main Index                         Up to Journal for September, 2021

                   JOURNAL FOR SUNDAY 26TH SEPTEMBER, 2021
______________________________________________________________________________

SUBJECT: Improved message text update
   DATE: Sun 26 Sep 18:09:56 BST 2021

In real life, work has been busier than usual this week — a lot of heavy going
technical development on a very tight schedule. However, I’ve still been busy
with WolfMUD and just pushed out another, somewhat smaller, update. Before I
go into the details, I need to revisit the issue of snapshots. I’ve been asked
if I can at least add player accounts to the experiment before I merge the Git
branches and start releasing snapshots. I can do that, but it is a whole bunch
of work. I’ll need to implement a Thing.Marshal, so players can be saved, as
well as a new frontend for login and account creation. It’ll delay my plans,
but I can see how it would make the snapshots more useful. That’s what I’m
working on next…

Getting back to the update. Messages sent to players have been improved. They
now have better formatting and flow better:


  [Trading post]
  You are standing in a large trading post. The only exit is west into the
  street.

  You see Hewman the trader here.
  You see an iron bound chest here.
  You see a small sack here.
  You see a small bag here.

  You see exits: south
  >
  Hewman the trader sneezes.
  >exam chest
  You examine the iron bound chest.
  This is a very stout wooden chest about 2 feet wide and 1 foot deep. Thick
  metal bands bind it. It contains a small leather pouch.
  >take pouch chest
  You take the small leather pouch out of the iron bound chest.
  >exam pouch
  You examine the small leather pouch.
  This is a small pouch made of soft dark leather. It contains a small red
  ball.
  >
  Hewman the trader coughs.
  >get chest
  You get the iron bound chest.
  >junk chest
  You junk the iron bound chest.
  >take ball pouch
  You take the small red ball out of the small leather pouch.
  >put ball bag
  You put the small red ball into the small bag.
  >exam bag
  You examine the small bag.
  This is a small bag, handy for carrying things in. It contains a small red
  ball.
  >
  The small leather pouch moves.
  >junk pouch
  You junk the small leather pouch.
  >
  You notice an iron bound chest you didn't see before.
  >


In these messages we are flipping between “an iron bound chest” and “the iron
bound chest” as well as “a small leather pouch” and “the small leather pouch”.

A minor change and a small detail, but I think the text looks a lot nicer now.

The implementation for this was a typical CPU usage vs memory trade-off. I’ve
opted to calculate everything up front and store the results. This means that
a Thing now has four name values for use in messages: Name, UName, TheName and
UTheName. Taking the pouch as an example it will have:


      Name: a small leather pouch
   TheName: the small leather pouch
     UName: A small leather pouch
  UTheName: The small leather pouch


These are all Thing.As values. Picking an appropriate variant and dropping it
into a message is as easy as:


  s.Msg(s.actor, text.Good, "You junk ", what.As[TheName], ".")


The values have duplicated data — in this case “small leather pouch”. If this
becomes a problem the current implementation can be replaced. We could store
the prefix separate from the name and then drop both of them into the message:


  s.Msg(s.actor, text.Good, "You junk ", what.As[Prefix], what.As[Name], ".")


I’ve used “Prefix” in the example. There would need to be four values. Maybe
Prefix, UPrefix, ThePrefix and UThePrefix. Note, we can’t just hard-code “the”
into some messages as “the” is only used as a replacement when the name starts
with ‘a’, ‘an’ or ‘some’. Take for example our friend Merkle, we wouldn’t want
to refer to him as “The Merkle”. However, for now I like this simple approach.

The only other change is to do with the default buffer size used for the read
buffer player’s have. A bufio.Reader has a default buffer of 4096 bytes. For
players that is quite large. I’ve reduced it to 80 bytes will no ill effects.
When running 64,000 bots it reduces overall memory usage from 1.7Gb to 1.2Gb.

For most users the reduced memory probably won’t be noticed — they will have
far fewer players. The memory saved should cover the extra memory required to
store the additional name variants ;)

--
Diddymus


  Up to Main Index                         Up to Journal for September, 2021