diff --git a/Scripts/r2_applier.lsl b/Scripts/r2_applier.lsl index 2ae40ca..6c20512 100644 --- a/Scripts/r2_applier.lsl +++ b/Scripts/r2_applier.lsl @@ -3,6 +3,8 @@ // Copyright 2020 Serie Sumei // v2.0 - 09May2020 - New applier script +// v2.1 - 21Jun2020 - Rework skin data to not use JSON functions +// v2.1-os08-1 - 21Jun2020 - Updates to compile on OpenSimulator 0.8 // This script loads a notecard with skin and eye texture UUIDs // and listens for link messages with button names to @@ -23,10 +25,10 @@ // Halcyon and older OpenSimulator builds may not have the Bakes on Mesh // constants defined. If you get a compiler error that these are not defined // uncomment the following lines: -// string IMG_USE_BAKED_UPPER = ""; -// string IMG_USE_BAKED_LOWER = "" ; -// string IMG_USE_BAKED_HEAD = ""; -// string IMG_USE_BAKED_EYES = ""; +string IMG_USE_BAKED_UPPER = ""; +string IMG_USE_BAKED_LOWER = "" ; +string IMG_USE_BAKED_HEAD = ""; +string IMG_USE_BAKED_EYES = ""; integer DEFAULT_APP_ID = 20181024; integer app_id; @@ -38,14 +40,18 @@ key notecard_qid; integer line; integer reading_notecard = FALSE; string current_section; -string current_buffer; +list current_buffer; // Skin textures +// skin_config stores 5 sub-elements: section, thumbnail, head, upper, lower +integer skin_stride = 5; list skin_config; list skin_map; list skin_thumbnails; -// Skin textures +// Eye textures +// eye_config stores 3 sub-elements: section, thumbnail, eyes +integer eye_stride = 3; list eye_config; list eye_map; list eye_thumbnails; @@ -89,13 +95,6 @@ integer keyapp2chan(integer id) { return 0x80000000 | ((integer)("0x" + (string)llGetOwner()) ^ id); } -send_region(string region) { - string skin_tex = llJsonGetValue(current_buffer, [region]); - if (skin_tex != "") { - send("TEXTURE," + region + "," + skin_tex); - } -} - // Send the list of skin_thumbnails back to the HUD for display send_skin_thumbnails() { llMessageLinked(LINK_THIS, LINK_RUTH_HUD, llList2CSV( @@ -118,24 +117,30 @@ send_eye_thumbnails() { ), ""); } +// This is the v1 TEXTURE API +send_texture(string region, string tex) { + if (region != "" && tex != "") { + send("TEXTURE," + region + "," + tex); + } +} + apply_skin_texture(string button) { log("r2_applier: button=" + button); if (button == "bom") { // Note: if you get a compiler error that these are undefined // uncomment the lines near the top of this script - send("TEXTURE,upper," + (string)IMG_USE_BAKED_UPPER); - send("TEXTURE,lower," + (string)IMG_USE_BAKED_LOWER); - send("TEXTURE,head," + (string)IMG_USE_BAKED_HEAD); + send_texture("head", IMG_USE_BAKED_HEAD); + send_texture("upper", IMG_USE_BAKED_UPPER); + send_texture("lower", IMG_USE_BAKED_LOWER); return; } integer i = llListFindList(skin_map, [button]); if (i >= 0) { - current_buffer = llList2String(skin_config, i); - send_region("head"); - send_region("upper"); - send_region("lower"); + send_texture("head", llList2String(skin_config, (i * skin_stride) + 2)); + send_texture("upper", llList2String(skin_config, (i * skin_stride) + 3)); + send_texture("lower", llList2String(skin_config, (i * skin_stride) + 4)); } } @@ -143,18 +148,16 @@ apply_eye_texture(string button) { log("r2_applier: button=" + button); if (button == "bom") { - send("TEXTURE,lefteye," + (string)IMG_USE_BAKED_EYES); - send("TEXTURE,righteye," + (string)IMG_USE_BAKED_EYES); + send_texture("lefteye", IMG_USE_BAKED_EYES); + send_texture("righteye", IMG_USE_BAKED_EYES); return; } integer i = llListFindList(eye_map, [button]); if (i >= 0) { - current_buffer = llList2String(eye_config, i); - string eye_tex = llJsonGetValue(current_buffer, ["eyes"]); - send("TEXTURE,lefteye," + (string)eye_tex); - send("TEXTURE,righteye," + (string)eye_tex); -// send_region("eyes"); + string eye_tex = llList2String(eye_config, (i * eye_stride) + 2); + send_texture("lefteye", eye_tex); + send_texture("righteye", eye_tex); } } @@ -192,7 +195,8 @@ load_notecard(string name) { log("r2_applier: Reading notecard: " + notecard_name); if (can_haz_notecard(notecard_name)) { line = 0; - current_buffer = ""; + // Need to pre-load current_buffer, must be at least the longest stride + current_buffer = ["", "", "", "", ""]; reading_notecard = TRUE; skin_config = []; skin_map = []; @@ -208,14 +212,16 @@ save_section() { // Save what we have log(" " + current_section + " " + (string)current_buffer); string value; - value = llJsonGetValue(current_buffer, ["thumbnail"]); + + // Get thumbnail + value = llList2String(current_buffer, 1); + if (llGetSubString(current_section, 0, 3) == "skin") { skin_config += current_buffer; skin_map += llGetSubString(current_section, 4, -1); - if (value != "" && value != JSON_INVALID) { + if (value != "") { // Move the thumbnail UUID to that list skin_thumbnails += value; - current_buffer = llJsonSetValue(current_buffer, ["thumbnail"], JSON_DELETE); } else { skin_thumbnails += ""; } @@ -223,17 +229,17 @@ save_section() { else if (llGetSubString(current_section, 0, 3) == "eyes") { eye_config += current_buffer; eye_map += llGetSubString(current_section, 4, -1); - if (value != "" && value != JSON_INVALID) { + if (value != "") { // Move the thumbnail UUID to that list eye_thumbnails += value; - current_buffer = llJsonSetValue(current_buffer, ["thumbnail"], JSON_DELETE); } else { eye_thumbnails += ""; } } // Clean up for next line - current_buffer = ""; + // Need to pre-load current_buffer, must be at least the longest stride + current_buffer = ["", "", "", "", ""]; current_section = ""; } @@ -254,6 +260,7 @@ read_config(string data) { if (end != 0) { // Well-formed section header current_section = llGetSubString(data, 1, end-1); + current_buffer = llListReplaceList(current_buffer, [current_section], 0, 0); log("Reading section " + current_section); } } else { @@ -267,23 +274,23 @@ read_config(string data) { if (attr == "head" || attr == "omegaHead") { // Save head - current_buffer = llJsonSetValue(current_buffer, ["head"], value); + current_buffer = llListReplaceList(current_buffer, [value], 2, 2); } else if (attr == "upper" || attr == "lolasSkin") { // Save upper body - current_buffer = llJsonSetValue(current_buffer, ["upper"], value); + current_buffer = llListReplaceList(current_buffer, [value], 3, 3); } else if (attr == "lower" || attr == "skin") { // Save upper body - current_buffer = llJsonSetValue(current_buffer, ["lower"], value); + current_buffer = llListReplaceList(current_buffer, [value], 4, 4); } else if (attr == "thumbnail") { // Save upper body - current_buffer = llJsonSetValue(current_buffer, ["thumbnail"], value); + current_buffer = llListReplaceList(current_buffer, [value], 1, 1); } else if (attr == "eyes") { // Save eyes - current_buffer = llJsonSetValue(current_buffer, ["eyes"], value); + current_buffer = llListReplaceList(current_buffer, [value], 2, 2); } else { // llOwnerSay("Unknown configuration value: " + name + " on line " + (string)line); diff --git a/Scripts/ro2_hud_control.lsl b/Scripts/ro2_hud_control.lsl index 35a9da0..c916428 100644 --- a/Scripts/ro2_hud_control.lsl +++ b/Scripts/ro2_hud_control.lsl @@ -6,10 +6,20 @@ // v2.0 12Apr2020 - Based on ru2_hud_control.lsl v3.2 // v2.1 12Apr2020 - New simpler alpha HUD // v2.2 13May2020 - Rework skin panel +// v2.3 21Jun2020 - Updates to compile on OpenSimulator 0.8 +// v2.3-os08-1 21Jun2020 - Uncomment constants for OpenSimulator 0.8 // This is a heavily modified version of Shin's RC3 HUD scripts for alpha // and skin selections. +// Older OpenSimulator builds may not have the PRIM_ALPHA_MODE_* +// constants defined. If you get a compiler error that these are not defined +// uncomment the following lines: +integer PRIM_ALPHA_MODE_NONE = 0; +integer PRIM_ALPHA_MODE_BLEND = 1; +integer PRIM_ALPHA_MODE_MASK = 2; +integer PRIM_ALPHA_MODE_EMISSIVE = 3; + // The app ID is used on calculating the actual channel number used for communication // and must match in both the HUD and receivers. integer APP_ID = 20181024; @@ -165,7 +175,7 @@ integer do_fp = FALSE; // Skin / Bakes on Mesh integer current_skin = -1; integer current_eye = -1; -integer alpha_mode = PRIM_ALPHA_MODE_MASK; +integer alpha_mode; integer mask_cutoff = 128; // Map skin selections to button faces @@ -296,55 +306,11 @@ adjust_pos() { } -// ***** -// get/set alpha values in JSON buffer - -// j - JSON value storage -// name - link_name -// face - integer face, -1 returns the unmasked 16 bit value -// Internal JSON values are ones complement, ie a 1 bit means the face is not visible -integer json_get_alpha(string j, string name, integer face) { - integer cur_val = (integer)llJsonGetValue(j, [name]); - if (face < 0) { - // All faces, return aggregate value masked to 16 bits - cur_val = ~cur_val & 0xffff; - } else { - cur_val = (cur_val & (1 << face)) == 0; - } - return cur_val; -} - -// j - JSON value storage -// name - link_name -// face - integer face, -1 sets all 16 bits in the value -// value - alpha boolean, 0 = invisible, 1 = visible -// Internal JSON values are ones complement, ie a 1 bit means the face is not visible -string json_set_alpha(string j, string name, integer face, integer value) { - value = !value; // logical NOT for internal storage - integer cur_val = (integer)llJsonGetValue(j, [name]); - integer mask; - integer cmd; - if (face < 0) { - // All faces - mask = 0x0000; - // One's complement - cmd = -value; - } else { - mask = ~(1 << face); - cmd = (value << face); - } - // Mask final value to 16 bits - cur_val = ((cur_val & mask) | cmd) & 0xffff; - return llJsonSetValue(j, [name], (string)(cur_val)); -} -// ***** - - // Set the alpha val of all links matching name set_alpha(string name, integer face, float alpha) { log("set_alpha(): name="+name+" face="+(string)face+" alpha="+(string)alpha); send_csv(["ALPHA", name, face, alpha]); - current_alpha = json_set_alpha(current_alpha, name, face, (integer)alpha); +// current_alpha = json_set_alpha(current_alpha, name, face, (integer)alpha); integer link; for (; link < num_links; ++link) { // Set color for all matching link names @@ -368,11 +334,11 @@ set_alpha_section(string section_name, integer alpha) { if (alpha < 0) { // Toggle the current value log("json: " + current_alpha); - alpha = !json_get_alpha(current_alpha, section_name, 0); +// alpha = !json_get_alpha(current_alpha, section_name, 0); log("val: " + (string)alpha); } send_csv(["ALPHA", section_name, 0, alpha]); - current_alpha = json_set_alpha(current_alpha, section_name, 0, (integer)alpha); +// current_alpha = json_set_alpha(current_alpha, section_name, 0, (integer)alpha); } } } @@ -384,7 +350,7 @@ reset_alpha(float alpha) { for (section = 0; section < len; ++section) { string section_name = llList2String(alpha_buttons, section); send_csv(["ALPHA", section_name, 0, alpha]); - current_alpha = json_set_alpha(current_alpha, section_name, 0, (integer)alpha); +// current_alpha = json_set_alpha(current_alpha, section_name, 0, (integer)alpha); } // Reset HUD buttons @@ -482,6 +448,8 @@ init() { last_attach = llGetAttached(); log("state_entry() attached=" + (string)last_attach); + alpha_mode = PRIM_ALPHA_MODE_MASK; + r2channel = keyapp2chan(APP_ID); llListen(r2channel+1, "", "", ""); llMessageLinked(LINK_THIS, LINK_RUTH_APP, llList2CSV(["appid", APP_ID]), "");