Drawing a weapon efficiently
|
Lazarus Wake
Registered User
Join date: 9 Jan 2006
Posts: 33
|
10-24-2006 13:53
So I've been experimenting around with a couple of ideas for some weapons similar to the Combat: Samurai Island swords, but without any scripts to handle combat. Like the C  I swords I was going to have two objects, one for the sheathed sword and one for the drawn sword. Originally I had planned on putting scripts into every section of the hilt of the sheathed sword. When the weapon was drawn a message would be broadcast and each script would set the alpha of its prim to 0. However, after Fushichou Mfume post today talking about inefficient codes I realized that even though each listening script is very small and not doing anything 99.999% of the time all those scripts will contribute more to server load than I would like. So the question is, does anyone have any ideas for how just certain prims can have their alpha set to 0 rapidly and efficiently? If SL actually had a hierarchical linking system I know I could do it through the setLinkAlpha function on one branch but it appears that instead SL just links every prim in the set to a single parent, meaning sword and scabbard would vanish. Using a loop with a single script will result in the parts of the hilt vanishing in sequence rather than just vanishing cleanly. Making the hilt extremely simple is another solution, but I'd like to avoid that since I would like to make a nice, detailed sword (and because that won't translate very well to gun, something else I'd like to do). So any other ideas?
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
10-24-2006 14:05
llSetLinkAlpha() is your friend here. One idea: On script init, loop through all linked prims, adding to a list of integers the index of each prim that is to have the alpha toggle used. You can use llGetLinkName() to determine the name of a linked prim, and may use a name like "handle" to indicate (on a sheathed sword for instance) that a prim will be turned invisible when the sword is "drawn". Then, you can iterate that list of indexes calling llSetLinkAlpha() for each. I will fire you off one of my swords as an example in-game. Edit: Oh, I see you contemplated that.... Well, while it's true that they vanish 'in-sequence', unless you have a high number of prims it's often sufficiently fast (as you *should* see on my example sword). An overly simplified method: setHandleAlpha( float alpha ) {
integer prims_total = llGetNumberOfPrims(); integer i; for( i = 1; i <= prims_total; ++i ) { if( llGetLinkName(i) == "Handle" ) { llSetLinkAlpha( i, alpha, ALL_SIDES ); } } }
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
10-24-2006 14:11
From: someone Using a loop with a single script will result in the parts of the hilt vanishing in sequence rather than just vanishing cleanly. Try it and see if that's visible, it might not be. I've made objects where I want them to visibly disappear in sequence, and I've had to insert sleeps between the calls to llSetLinkAlpha so the user sees them disappear one at a time. Regardless, there is a way to make this closer to simultaneous. Use one listener, have it send a link message to LINK_SET, and put receiver scripts in the prims that need to hide that trigger off the link message. You'll still get the same number of active scripts, but you'll use only one listener instead of dozens (or whatever), and that will help script performance a lot. It's rare that a linked object needs more than one listener on the same channel. And the script is as easy to write - replace listen(...) with link_message(...), and the rest of the code in the function can be identical. Also, you can make the link message version go faster - instead of sending strings like "show" and "hide", use numbers like 1 and 0. An integer comparison is a lot faster than a string comparison.
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
10-24-2006 14:13
From: Ziggy Puff Try it and see if that's visible, it might not be. I've made objects where I want them to visibly disappear in sequence, and I've had to insert sleeps between the calls to llSetLinkAlpha so the user sees them disappear one at a time.
Regardless, there is a way to make this closer to simultaneous. Use one listener, have it send a link message to LINK_SET, and put receiver scripts in the prims that need to hide that trigger off the link message. You'll still get the same number of active scripts, but you'll use only one listener instead of dozens (or whatever), and that will help script performance a lot.
It's rare that a linked object needs more than one listener on the same channel. And the script is as easy to write - replace listen(...) with link_message(...), and the rest of the code in the function can be identical. Also, you can make the link message version go faster - instead of sending strings like "show" and "hide", use numbers like 1 and 0. An integer comparison is a lot faster than a string comparison. Quite right. Same number of largely inactive scripts, but good perf and only one listen. Good advice all around.
|
Lazarus Wake
Registered User
Join date: 9 Jan 2006
Posts: 33
|
10-24-2006 14:13
Generating the list beforehand would make the loop more efficient but it still seems that you would likely see the drawn item 'disassemble' if it's composed of a respectable number of prims, wouldn't you?
Edit: Wrote that while you were editting your own post.
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
10-24-2006 14:18
From: Lazarus Wake Generating the list beforehand would make the loop more efficient but it still seems that you would likely see the drawn item 'disassemble' if it's composed of a respectable number of prims, wouldn't you? Yes, if it's a large number of prims, that is correct. But the handle should really not be that many prims, correct? I forgot to mention that you can use llSetLinkAlpha( LINK_SET, 1.0, ALL_SIDES ); to set the alpha of an object with a large number of prims (such as the sword in hand) quite quickly.
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
10-24-2006 14:22
One final thought, obvious though it is: Due to arbitrary issues like sim lag, you will never be able to get it to operate perfectly in all cases  Even the very best swords I've seen in SL show some issues with the draw/sheath process sometimes.
|
Lazarus Wake
Registered User
Join date: 9 Jan 2006
Posts: 33
|
10-24-2006 14:30
From: Ziggy Puff ... Regardless, there is a way to make this closer to simultaneous. Use one listener, have it send a link message to LINK_SET, and put receiver scripts in the prims that need to hide that trigger off the link message. You'll still get the same number of active scripts, but you'll use only one listener instead of dozens (or whatever), and that will help script performance a lot. ... The impression I had from Fushichou Mfume's post was that even if the script wasn't running a listener and was largely inactive it counted into that total for active scripts running on a sim, not just for the purposes of stats but for actually degrading performance (though I have to admit it seems odd that it would do so).
|
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
|
10-24-2006 14:39
From: Lazarus Wake The impression I had from Fushichou Mfume's post was that even if the script wasn't running a listener and was largely inactive it counted into that total for active scripts running on a sim, not just for the purposes of stats but for actually degrading performance (though I have to admit it seems odd that it would do so). Each script, whether doing anything or not, contributes some cycles. However, and active listener will contribute far more cycles than an otherwise inactive script waiting for a link message. I guess the best thing to do is play with the various methods and get a feel for the best. If you are referring to the thread that I am thinking of, there are ways given to get some idea of the relative impact of each method. I would be quite curious what your results are 
|
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
|
10-24-2006 14:58
From: Lazarus Wake Using a loop with a single script will result in the parts of the hilt vanishing in sequence rather than just vanishing cleanly. Yes, but frankly i don't think the desire to have item as trivial as weapon handle vanish 'in one pop' is just enough to warrant 100+ scripts running in the parts, at the expense of everyone in the sim when it could be otherwise avoided. Not to mention, when everything around you gets streamed down the 'net pipes appearing and rezzing around you in random manner and order, why does that sword piece has to act different? ^^;;
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
10-24-2006 15:05
From: Lazarus Wake The impression I had from Fushichou Mfume's post was that even if the script wasn't running a listener and was largely inactive it counted into that total for active scripts running on a sim, not just for the purposes of stats but for actually degrading performance (though I have to admit it seems odd that it would do so). I believe that is correct. That's why I said "You'll still get the same number of active scripts". However, I also believe that not all active scripts are equal, and in this case, a script with a link message handler is easier on the sim than a script with a listen handler. It comes down to what you want to do as a designer/scripter. If you absolutely want the prims to disappear as close to simultaneously as you want, use the link message technique. If nothing else, it'll be better than using listeners. If you're willing to sacrifice some visual effect for more efficient performance, use the "loop through the prim numbers" technique.
|
Lazarus Wake
Registered User
Join date: 9 Jan 2006
Posts: 33
|
10-24-2006 15:22
From: Joannah Cramer Yes, but frankly i don't think the desire to have item as trivial as weapon handle vanish 'in one pop' is just enough to warrant 100+ scripts running in the parts, at the expense of everyone in the sim... Quite right, which is why I'm looking for alternatives.
|
Lazarus Wake
Registered User
Join date: 9 Jan 2006
Posts: 33
|
10-24-2006 15:26
From: Ziggy Puff I believe that is correct. That's why I said "You'll still get the same number of active scripts". However, I also believe that not all active scripts are equal, and in this case, a script with a link message handler is easier on the sim than a script with a listen handler.
It comes down to what you want to do as a designer/scripter. If you absolutely want the prims to disappear as close to simultaneously as you want, use the link message technique. If nothing else, it'll be better than using listeners. If you're willing to sacrifice some visual effect for more efficient performance, use the "loop through the prim numbers" technique. I realize that all scripts are not created equal, but I though that less efficient scripts were handled by the Script Time stat that Fushichou Mfume assigned to the less efficient scripts. I guess that's really a question for that thread.
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
10-24-2006 15:36
From: Lazarus Wake I realize that all scripts are not created equal, but I though that less efficient scripts were handled by the Script Time stat that Fushichou Mfume assigned to the less efficient scripts. Yes they are. I'm not sure if we're disagreing on anything  We both seem to agree that using a single script to loop through the prims is best, followed by using multiple scripts with link message handlers (whcih will show up in the active list count but won't be doing much), and worst is multiple scripts with individual listeners, because listeners seem to require somewhat more processing than the link messages. That's from a sim load / performance POV. Whether the lowest load design is good enough for the effect you're trying to achieve, is something only yo ucan decide.
|
Angelique LaFollette
Registered User
Join date: 17 Jun 2004
Posts: 1,595
|
10-24-2006 19:30
Look for Swords made by Alex Fitzsimmons. The Draw, AND resheath animations are smooth, and very Graceful.
Ange.
|