Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Speed issues...

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sat Aug 09, 2003 1:21 pm    Post subject: Speed issues... Reply with quote

Does anyone have any good tips for speeding up scripts?

Does anyone know whether the increment()/ decrement() are any faster than writing
x := x + y
? Thinking about it, it seems logical that it would be faster, as the PS interpreter only does one command instead of 2. Though I don't think I've ever used a decrement or increment command in any of my scripts ever.... :S
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Blazes Battles Inc.
I'm a chimp, not a




Joined: 25 Jan 2003
Posts: 505

PostPosted: Sat Aug 09, 2003 4:46 pm    Post subject: Reply with quote

I doubt it's noticably faster. I have a script with about ten thousand of those set variable commands that barely takes an instant to finish. Is the script actually working slowly, or are you just planning ahead?
_________________
Preserve OHR history! Do it for the children!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Inferior Minion
Metric Ruler



Joined: 03 Jan 2003
Posts: 741
Location: Santa Barbara, CA

PostPosted: Sat Aug 09, 2003 9:40 pm    Post subject: Reply with quote

When it comes to analyzing scripts, it's standard practice to treat all assignment commands as taking the same time. The real meat of the runtime is caused by loops and whatnot.

I'm not sure if this will help at all...but it's the lecture notes from my Comp. Sci. class on Analyzing Algorithm Runtimes...Here's the lecture and here are the notes for filling in the blanks. The way the class was conducted, the teacher would use the first sheet and a projector for lecture. We could download/print the lecture before hand and fill in the blanks as he went along. He would then put the second page online a week or so later.

Hopefully it's useful to someone Raspberry!

_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sun Aug 10, 2003 3:31 am    Post subject: Reply with quote

Well, thanks, I'll have to read through all of that..

I'm planning in advance, I'm sure my script is going to run really slow, having alot of compund loops, recursing, and npc intructions..

Code:
it's standard practice to treat all assignment commands as taking the same time


I meant the difference in speed between interpreted Plotscripting instructions, and instructions coded into game.exe
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
planethunter
Lost In Emotion




Joined: 07 Jul 2003
Posts: 258
Location: Éire

PostPosted: Sun Aug 10, 2003 11:44 pm    Post subject: Reply with quote

the only "good" thing about using the increment and decrement commands
is that instead of the compiler assessing both variables and adding, it just
assesses one and adds...

But! doing so would probably just increase the "speed" by 0.0000000001%
It really makes no odds what you use. the X: x+y thing is only useful if
you use changing variables. ( I dislike saying variable variables)
That aside you should just keep it simple, and use de/increment commands.

phew!
_________________
~PH
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Mon Aug 11, 2003 10:23 pm    Post subject: Speed Reply with quote

Yes, theoretically, increment(V) ought to be just slightly faster than V:=V+1 , but the difference is so incredibly small that you should not care.

The slowest commands are the ones that affect NPC's, In particular, any command that uses an NPC ID is guaranteed to be slow. Use NPC references wherever possible. For example, suppose you want to write a script that checks every NPC to see whether or not it is standing within 4 blocks of the hero

Code:

variable(ID)
for(ID,0,35)
do,begin
   if(NPC X(ID) >= hero X (me) -- 4,and,NPC X(ID) <= hero X (me) + 4,and,NPC Y(ID) >= hero Y (me) -- 4,and,NPC Y(ID) <= hero Y (me) + 4)
   then,begin
       # do special stuff for close-by NPCs
   end
end


This example will be super slow, because for every NPC ID it runs four commands that use the NPC ID. (NPC X twice and NPC Y twice). You can cut the speed of this script to almost a quarter by using an NPC reference.

Code:

variable(ID,ref)
for(ID,0,35)
do,begin
   ref:=NPC reference(ID)
   if(NPC X(ref) >= hero X (me) -- 4,and,NPC X(ref) <= hero X (me) + 4,and,NPC Y(ref) >= hero Y (me) -- 4,and,NPC Y(ref) <= hero Y (me) + 4)
   then,begin
       # do special stuff for close-by NPCs
   end
end


Now you only have to use the NPC ID in one single command (NPC reference) so the script will not have to re-look-up the NPC each time you use NPC X and NPC Y.

This applies also to Walk NPC, NPC Direction, set NPC direction, Create NPC Destroy NPC, and almost anything else that can use an NPC ID number ("Alter NPC" being the exception, It goes about the same speed whether you use an ID or a reference)

Another way to keep scripts fast is to only loop as much as you really need to. Take the previous example again. Suppose you want to check for NPCs within 4 spaces of the hero, and do something special for them, but you know that you have only actually created twelve NPCs on this particular map.

Code:

variable(ID,ref)
for(ID,0,11)
do,begin
   ref:=NPC reference(ID)
   if(NPC X(ref) >= hero X (me) -- 4,and,NPC X(ref) <= hero X (me) + 4,and,NPC Y(ref) >= hero Y (me) -- 4,and,NPC Y(ref) <= hero Y (me) + 4)
   then,begin
       # do special stuff for close-by NPCs
   end
end


just change the "for" so you only loop as much as you need to.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Thu Aug 14, 2003 1:24 pm    Post subject: Reply with quote

Even create NPC? I never knew that... but I did know to avoid npc functions..

well, thanks for the help!
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can 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


Powered by phpBB © 2001, 2005 phpBB Group