Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
teknocide
Beginner


Joined: 15 Jul 2003
Posts: 25
Location: Sweden

PostPosted: Fri Jul 25, 2003 8:12 pm   

CPU-problems
 
I use a complex script with triggers and aliases. My problem is that when fully active, it takes up about 25% of my CPU resources, and this is highly noticable in gameplay! zMUD stutters and the usually smooth text flow jumps. This of course delays my player input, further reducing the purpose of the script.

Are these levels of CPU usage normal? I am using zMUD 6.40 on an Athlon XP 1700+, with 512MB RAM

I am utilizing Reg Exp to the full extent, since I haven't been able to figure out a way to make normal zMUD patterns do what I need to do. Could this be a reason for the heavy CPU-usage? I also have a trigger that checks my MUD-prompt and changes two variables based on the result, though I doubt that one is the problem, even though the trigger is called frequently.
I am also using about 10 triggers which fires on Expressions of variables. Are these triggers much slower than ordinary triggers?

Since I assume that normal zMUD patterns are faster than Rex Exp, I'll explain why I have used Reg Exp and also encourage you to come up with a faster solution to my problem if you can:

The problem is that I need to make sure that a pattern is EITHER at the start of the line, or directly after my prompt:

You get hit by a rock.
500hp/500mana >You get hit by a rock.


I do this because in some cases, the information from the MUD is received in such a way that the CR is lost, and the text appended right after the prompt. It can even happen that the prompt itself ends up on the same line as a previous prompt, and that the new prompt is followed by a pattern, like:

500hp/500mana >500hp/500mana >You get hit by a rock.

I am sure you all have experienced this at one time or another.
Anyhow, I figured out that if I used a Rex Exp like:

^(<prompt pattern>)*You get hit by a rock.

that would allow me to do just this.

Now, is there some way to do the same with normal zMUD patterns?



If you have any tips or ideas about about what I am doing wrong, how I might improve the script's performance or anything at all, please let me know.

Cheers!
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jul 25, 2003 10:03 pm   
 
This is fairly simple with normal zMUD patterns. All it requires is that you get rid of the misconception that everything has to be squeezed into ONE pattern.
#TR {^You get hit by a rock.}
#TR {%dhp/%dmana ~>You get hit by a rock.}
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Fri Jul 25, 2003 10:07 pm   
 
Rules of thumb are:
a) more defined the trigger the better, avoid wildcards, help the non-match test as much asd possible
b) less amount of enabled things at one time the better
c) watch out of long processing of complicated #LOOPs

You could try do something like like push the tail end command to the next line:
500hp/500mana >500hp/500mana >You get hit by a rock.
#TRIGGER {^(%d)hp~/(%d)mana ~>(%d)hp~/(%d)mana ~>(*)$} {#VAR Hp %1;#VAR Mana %2;#VAR MaxHp %3;#VAR MaxMana %4;#SH %cr%5}
Reply with quote
teknocide
Beginner


Joined: 15 Jul 2003
Posts: 25
Location: Sweden

PostPosted: Sat Jul 26, 2003 12:06 am   
 
LightBulb: the lower one will be insecure though, as to people being able to type:

say 1/2hp 3/4mana >You get hit by a rock.

I know I am being paranoid about this, but then again, why script non-bullet proof scripts if you can avoid it?

Also, there is no misconception; I was simply looking for the best possible solution, which I thought would be one trigger with a well functioning pattern.
However, if you are sure that two zMUD triggers are faster than one Reg Exp trigger, I will take your advice.

TonDiening: I was thinking of your idea about adding a CR to the end of the prompt, but thought it would space up the text too much. I'll try it though!

Thanks to you both for the feedback.
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Sat Jul 26, 2003 12:49 am   
 
Am not near zMud so I chose the over safe: #SH %cr%5
Might be able to use something like: #SH %5
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Jul 26, 2003 1:28 am   
 
Fine. You can add an anchor.
#TR {^%dhp/%dmana ~>You get hit by a rock.}
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Jul 26, 2003 2:32 am   
 
My solution has always been to forcibly put a newline at the end of my prompt. I simply don't play on muds that don't provide this capability in a custom prompt.

If you wish to create a securing system while allowing your mud coders to slack off you can make a way.

First step is the securing alias:
#AL TestSecure {SecuredLine=%remove(%copy(%line,%1,%2),%line);#IF (@SecuredLine) {#IF (@SecuredLine=~ "(%dhp/%dmana ~>)") {#IF (%begins(@SecuredLine,%%1)) {SecuredLine=%remove(%%1,@SecuredLine)}};#IF (@SecuredLine) {#IF (@SecuredLine=~ "(%dhp/%dmana ~>)") {#IF (%begins(@SecuredLine,%%1)) {SecuredLine=%remove(%%1,@SecuredLine)}};#IF (@SecuredLine) {#IF (@SecuredLine=~ "(%dhp/%dmana ~>)") {#IF (%begins(@SecuredLine,%%1)) {SecuredLine=%remove(%%1,@SecuredLine)}}}}

Finally we create the secure trigger:
#TR {(You get hit by a rock.)$} {TestSecure %x1;#IF (@SecuredLine="") {#NOOP Line was secured up to 3 prompts;#NOOP I can now turn into the Incredible Hulk}}

Note the trigger captures everything into a single %## parameter, then passes the positional information to the securing alias. In order to do this with a trigger that requires you have many parameters just capture the first and last characters as well and use %word(%x1,1) %word(%x##,2) where ## is the last number.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Jul 26, 2003 4:33 am   
 
Now that I got some of my Friday business out of the way...on to your CPU issues and speed problems.

RegEx is handled by a 3rd party library. I believe in Zugg's testing of it he found that it is slower then all other trigger types, but he can do nothing to accelerate it.

Expression triggers are not slower then regular triggers. They are checked every time a variable changes. Consider this simple example:
test=1
#TR {@test=1} {#ECHO @a} "" {exp}
a=0
#WHILE (@a<1000) {#ADD a 1;#ECHO preempted}

As you can see the expression trigger tests and, in this case, fires with every change in a. This pauses the activity of the loop to process the script for the trigger. Obviously slowing things down. If possible you should get rid of the expression triggers, or at the least disable (#T-) and enable (#T+) them when they really don't need to be active.

General programming rules regarding speed apply to zScript as well. Whenever you call into an alias from your script you make that script slightly slower then if you had placed all the alias's script inline. Creating a new variable takes longer then updating an existing one, loops eat time, if you can think of a way to do it without a loop (even if it uses 3 times as many variables) it will be faster.
Reply with quote
teknocide
Beginner


Joined: 15 Jul 2003
Posts: 25
Location: Sweden

PostPosted: Sat Jul 26, 2003 3:40 pm   
 
Thanks for your great feedback! I'll go into optimization now!
Reply with quote
teknocide
Beginner


Joined: 15 Jul 2003
Posts: 25
Location: Sweden

PostPosted: Sun Jul 27, 2003 1:35 am   
 
Though.. what is #SH %5 supposed to do? I don't catch any %5 parameter..
Reply with quote
teknocide
Beginner


Joined: 15 Jul 2003
Posts: 25
Location: Sweden

PostPosted: Sun Jul 27, 2003 3:28 am   
 
Just thought I'd show you my solution to the problem!

pattern:
^%dhp~/%dmana ~>(?)

command (part of it):
#IF (!%null( %2)) {#PSUB {%concat( %cr, %2)} %x2}


I will try it out now to see if it works!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net