[MUD-Dev] Programming Languages and I/O Algorithms

Kwon Ekstrom justice at softhome.net
Sun Jan 26 11:40:50 New Zealand Daylight Time 2003

From: "Ben Chambers" <bjchamb at bellsouth.net>

> Which language is prefferred for mud design?  C/C++ provides speed
> but Java adds a lot of flexibility.  Furthermore how do most muds
> handle incoming commands in order to minimize lag?  I was thinking
> some sort of queue sorted by criticality of the type of event, but
> then you have to pre-process all the events and sort the queue
> which then creates lag in the process.  What are some common
> solutions?

My preference is java, but I'm writing a hobbyist mud not a full
blown commercial project.  If you're expecting alot of players
and/or alot of active NPC's then you probably want to take c/c++.
There's alot of other considerations to take into account when
comparing java and c++ of course, but if performance "might" become
an issue then it's best to stick with the better performer.

I'd say that the majority of muds out there are written in c/c++ for
various reasons.  Although I'd say java is more than adequate.

As for incoming commands, I wouldn't worry about that being a major
performance issue.  There's alot of optimization techniques you can
use on your command.  You can index your commands by first letter at
load time and then use a priority queue (alphabetical isn't the best
way to store commands since a command that's lower alphabetically
might be used more often).  For IO, I simply buffer all incoming
data into a char array and manually parse it into lines which get
sent out to the rest of my code.  I'm using java and have
contemplated not using strings (Strings are immutable and therefore
can't be changes and input commands are transient by nature).  I put
each line into a list and have an access method to get the next line
(or null if the list is empty).

Also figure that players send command infrequently... maybe 2 a
second at most.. and you only have to handle 1 command per game loop
per player.  It's not going to be a major performance issue.  The
biggest issues I'd say are trigger (event) handling and game world

Another thing you might want to optimize is keyword resolution
(mobs/objects), I personally use a bitvector system to flag what
first and second letters are available in the list.  You can quickly
(by checking the first 2 letters determine whether to actually check
the rest of the list, acts like a hash).

I tried sorting the tables and doing an optimized search, but found
that the overhead was more than the gains after the bitvector
flagging mentioned above.

-- Kwon J. Ekstrom

MUD-Dev mailing list
MUD-Dev at kanga.nu

More information about the MUD-Dev mailing list