Another tinymudserver question.

Posted by Metsuro on Sun 17 Sep 2006 09:03 AM — 6 posts, 27,856 views.

USA #0
Alright, in tinymudserver look goes through all players connect to see if they are in same room then displays them, to me I kinda think this is a waste? I'd rather something more like smaug I guess, where rooms have a list of players in it or something and then goes through them? I'd rather have a form kinda like instead of going through all players connect, anyone interested in explaining how I could do this and maybe help start me off with it?
USA #1
Well, you could create a double linked list of the characters in the room, like smaug uses by copying what smaug has for that into your souc=rce code for tinymudserver, no?
USA #2
A waste? I don't think it would be that inefficient until you have 2000+ players you're looping through, I guess.
Australia Forum Administrator #3
That was really a simple example of writing a MUD server. Even now I would do things differently, like, rewrite it in Lua. ;)

I agree that it is slightly wasteful to scan all characters to see if they are in a particular room, but searching a list for a match on an integer is really quite a fast operation. Certainly with 2000 players you might want to do it more efficiently.

Remember that the code to do it efficiently, like a linked list per room has an overhead of its own. For example, leaving one room and going to another means removing from one list and adding to another. There would be a breakeven point where the separate lists are more efficient, however it might be 10+ players on the MUD. And even then the savings on a fast PC might be microseconds.
USA #4
Well I guess my biggest problem with it, is I want to add attacks and things that can be used room wide, some that work from the first person in the room down. And if It has to search the entire mud for whos in the room, it doesn't work so well right? Only problem is I'm not really sure what a linked list is or how to use a linked list.
Australia Forum Administrator #5
Searching "the entire MUD" isn't too bad, as you are only searching logged-in players. How many would that be? 50? 20? 10?

Linked lists and other things are easy to do in STL, which is used extensively in the tinymudserver anyway. Read my posts about STL for clues on how to use that. You won't get far modifying the server without understanding STL anyway.

See:

http://www.gammon.com.au/forum/?id=2899