2 // huffware script: FPS color changer, by fred huffhines
4 // a freebie script by eltee statosky supplied inspiration for this script.
5 // we have re-used his color scheme, but rewritten this for our needs.
7 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
8 // do not use it in objects without fully realizing you are implicitly accepting that license.
11 integer SHOW_TITLE = FALSE;
12 // if this is true, a title is set above the object.
14 //hmmm: this max fps value used to compute a percentage may be totally bogus.
15 // highest i've seen is 55 or so in opensim. used to be highest in second life
16 // was 45 or something. seems unknowable so far.
17 float MAX_SIM_FPS = 60.0;
20 // huffware script: auto-retire, by fred huffhines, version 2.5.
21 // distributed under BSD-like license.
22 // !! keep in mind that this code must be *copied* into another
23 // !! script that you wish to add auto-retirement capability to.
24 // when a script has auto_retire in it, it can be dropped into an
25 // object and the most recent version of the script will destroy
26 // all older versions.
28 // the version numbers are embedded into the script names themselves.
29 // the notation for versions uses a letter 'v', followed by two numbers
30 // in the form "major.minor".
31 // major and minor versions are implicitly considered as a floating point
32 // number that increases with each newer version of the script. thus,
33 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
34 // and "hazmap v3.2" is a more recent version.
36 // example usage of the auto-retirement script:
39 // auto_retire(); // make sure newest addition is only version of script.
42 // this script is partly based on the self-upgrading scripts from markov brodsky
43 // and jippen faddoul.
46 string self = llGetScriptName(); // the name of this script.
47 list split = compute_basename_and_version(self);
48 if (llGetListLength(split) != 2) return; // nothing to do for this script.
49 string basename = llList2String(split, 0); // script name with no version attached.
50 string version_string = llList2String(split, 1); // the version found.
52 // find any scripts that match the basename. they are variants of this script.
53 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
54 //log_it("invpo=" + (string)posn);
55 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
56 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
57 // found a basic match at least.
58 list inv_split = compute_basename_and_version(curr_script);
59 if (llGetListLength(inv_split) == 2) {
60 // see if this script is more ancient.
61 string inv_version_string = llList2String(inv_split, 1); // the version found.
62 // must make sure that the retiring script is completely the identical basename;
63 // just matching in the front doesn't make it a relative.
64 if ( (llList2String(inv_split, 0) == basename)
65 && ((float)inv_version_string < (float)version_string) ) {
66 // remove script with same name from inventory that has inferior version.
67 llRemoveInventory(curr_script);
74 // separates the base script name and version number. used by auto_retire.
75 list compute_basename_and_version(string to_chop_up)
77 // minimum script name is 2 characters plus a version.
79 // find the last useful space and 'v' combo.
80 for (space_v_posn = llStringLength(to_chop_up) - 3;
81 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
83 // look for space and v but do nothing else.
84 //log_it("pos=" + (string)space_v_posn);
86 if (space_v_posn < 2) return []; // no space found.
87 //log_it("space v@" + (string)space_v_posn);
88 // now we zoom through the stuff after our beloved v character and find any evil
89 // space characters, which are most likely from SL having found a duplicate item
90 // name and not so helpfully renamed it for us.
92 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
93 //log_it("indy=" + (string)space_v_posn);
94 if (llGetSubString(to_chop_up, indy, indy) == " ") {
95 // found one; zap it. since we're going backwards we don't need to
96 // adjust the loop at all.
97 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
98 //log_it("saw case of previously redundant item, aieee. flattened: " + to_chop_up);
101 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
102 // ditch the space character for our numerical check.
103 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
104 // strip out a 'v' if there is one.
105 if (llGetSubString(chop_suffix, 0, 0) == "v")
106 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
107 // if valid floating point number and greater than zero, that works for our version.
108 string basename = to_chop_up; // script name with no version attached.
109 if ((float)chop_suffix > 0.0) {
110 // this is a big success right here.
111 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
112 return [ basename, chop_suffix ];
114 // seems like we found nothing useful.
122 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
123 on_rez(integer parm) { state rerun; }
125 state rerun { state_entry() { state default; } }
130 auto_retire(); // make sure newest addition is only version of script.
131 llSetTimerEvent(4.0);
135 float fps = llGetRegionFPS();
137 if (fps > 50) sim_color = <0.5, 1.0, 0.5>;
138 else if (fps > 40) sim_color = <0.75, 0.75, 0>;
139 else if (fps > 30) sim_color = <1.0, 0.5, 0.5>;
140 else sim_color = <0.5, 0.0, 0.0>;
141 llSetColor(sim_color, ALL_SIDES);
143 integer left_part = (integer)fps; // left of decimal point.
144 integer right_part = (integer)(llRound((fps - (integer)fps) * 10.0));
145 float simplified_fps = (float)left_part + ((float)right_part / 10.0);
146 llSetText(llGetRegionName() + " "
147 + (string)left_part + "." + (string)right_part
149 + (string)llRound(simplified_fps / MAX_SIM_FPS * 100.0)
153 llSetText("--", <0.0, 0.0, 0.0>, 0.0);