View Single Post
Old 06-26-2004, 06:19 AM   #4
scandum
Senior Member
 
Join Date: Jun 2004
Posts: 315
scandum will become famous soon enough
It's mostly refered to as tokenized scripts. The mob prog engine my merc mud uses works pretty much as you described, in short:

unsigned char: type - social, command, if, else, endif, switch, break, etc.

char *: string - the argument to the command, if check, etc. If checks are spaced out upon bootup, this way they can get hashed (got roughly 100K lines of mprog total, so that saves quite some memory), and read with sscanf easily.

short: index - index of the command/social table (saves 2 bytes compared to a pointer) usage:

(*cmd_table[token->value].do_fun) (mob, token->string);

unsigned char: level - the functional if level, goes up after an if, goes down after an endif, etc. It's the corner stone for a solid and efficient parser. Each prog is parsed on boot, setting the level of each line.

The main issue when it comes to performance are the progs that trigger at (random) time intervals. 60% of my muds cpu usage was spend on that before I had a look at it, 20% currently.

I got it down mainly by adding a command to add a mob to the time interval trigger list when it should start doing stuff at random, and removing it from that list when it's finished. Sort of looks like:

token -> seconds per trigger -> pointer to the script

Another advantage is that it spreads cpu usage, instead of all random progs being executed every 4 seconds, the progs are triggered in time slices of 0.5 seconds.

In a very bad scenario that would mean that instead of 1 second to execute all progs every 4 seconds during which players are lagged, there are only 0.125 seconds of additional lag every 0.5 seconds.
scandum is offline   Reply With Quote