Compiler.lsl 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. // :CATEGORY:XS Pet
  2. // :NAME:XS Pet Robot
  3. // :AUTHOR:Ferd Frederix
  4. // :KEYWORDS: Pet,XS,breed,breedable,companion,Ozimal,Meeroo,Amaretto,critter,Fennux,Pets
  5. // :CREATED:2013-09-06
  6. // :EDITED:2014-01-30 12:24:21
  7. // :ID:988
  8. // :NUM:1457
  9. // :REV:0.50
  10. // :WORLD:Second Life, OpenSim
  11. // :DESCRIPTION:
  12. // XS Pet Compiler
  13. // :CODE:
  14. // Author: Ferd Frederix
  15. // This prim animator compiler is a very useful and easy to use script for Second Life and OpenSim. Setup is very simple. Just drop the two script into the object, click the object, and give your animation a name. Move all the prims around, and click Record. When done, click the Compile button. It writes fast, optimized code for you.
  16. // Downloaded from : http://www.outworldz.com/cgi/freescripts.plx?ID=1691
  17. // This program is free software; you can redistribute it and/or modify it.
  18. // Additional Licenes may apply that prevent you from selling this code
  19. // and these licenses may require you to publish any changes you make on request.
  20. //
  21. // There are literally thousands of hours of work in these scripts. Please respect
  22. // the creators wishes and Copyright law and follow their license requirements.
  23. //
  24. // License information included herein must be included in any script you give out or use.
  25. // Licenses may also be included in the script or comments by the original author, in which case
  26. // the authors license must be followed, and their licenses override any licenses outlined in this header.
  27. //
  28. // You cannot attach a license to any of these scripts to make any license more or less restrictive.
  29. //
  30. // All scripts by avatar Ferd Frederix, unless stated otherwise in the script, are licensed as Creative Commons By Attribution and Non-Commercial.
  31. // Commercial use is NOT allowed - no resale of my scripts in any form.
  32. // This means you cannot sell my scripts but you can give them away if they are FREE.
  33. // Scripts by Ferd Frederix may be sold when included in a new object that actually uses these scripts. Putting my script in a prim and selling it on marketplace does not constitute a build.
  34. // For any reuse or distribution, you must make clear to others the license terms of my works. This is done by leaving headers intact.
  35. // See http://creativecommons.org/licenses/by-nc/3.0/ for more details and the actual license agreement.
  36. // You must leave any author credits and any headers intact in any script you use or publish.
  37. ///////////////////////////////////////////////////////////////////////////////////////////////////
  38. // If you don't like these restrictions and licenses, then don't use these scripts.
  39. //////////////////////// ORIGINAL AUTHORS CODE BEGINS ////////////////////////////////////////////
  40. // This script produces optimized LSL code that can be triggered by link messages.
  41. // fred@mitsi.com
  42. // 3-7-2012
  43. // Rev B, added a missing } at the end of multiple recordings.
  44. // Author: Ferd Frederix
  45. // Based on an excellent script by Allen Firethorn
  46. // This is free software, it is not for sale at any price
  47. // Tunable stuff:
  48. integer OpenSim = FALSE; // Set to FALSE for Second Life to save memory
  49. string fast="Fast"; // Set this to an empty string if you don't want to use the fast animation
  50. integer debug = FALSE; // set to TRUE to see stuff inside as it runs
  51. list animations; // holds a list of all animation names
  52. list receivedData; // the data from the main program
  53. integer STRIDE = 5; // size of the data packets in receivedData
  54. integer currentLine; // the line we are processing
  55. // Link messages
  56. integer CLEAR = -234756;
  57. integer DATA = -234757;
  58. integer COMPILE = -234758;
  59. integer DIE = -234759;
  60. DEBUG(string msg)
  61. {
  62. if (debug) llOwnerSay("// " + msg);
  63. }
  64. // speak without the name of the prim in the way
  65. SayCode (string story){
  66. llOwnerSay (story);
  67. llSleep(0.1);
  68. }
  69. default {
  70. link_message(integer sender_num,integer num, string msg, key id) {
  71. if (num == DIE && msg =="die") // clear
  72. {
  73. llOwnerSay("Compiler has been removed");
  74. if (! debug) {
  75. llRemoveInventory(llGetScriptName());
  76. }
  77. }
  78. if (num == CLEAR) // clear
  79. {
  80. animations = [];
  81. receivedData = [];
  82. currentLine = 0;
  83. llOwnerSay("Compiler Ready");
  84. }
  85. else if (num == DATA) // data
  86. {
  87. // data formatted like this:
  88. // name|primnum|vector Pos|rotation rot|vector size
  89. // test1|2|<0.026306,-0.150208,0.191069>|<-0.000008,0.956309,-0.292356,0.000000>|<0.074010,0.074010,0.074010>
  90. list primList = llParseString2List(msg,["|"],[]);
  91. string name = llList2String(primList,0);
  92. receivedData += name;
  93. receivedData += (float) llList2String(primList,1); // prim Number or ms to sleep
  94. receivedData += (vector) llList2String(primList,2); // pos
  95. receivedData += (rotation) llList2String(primList,3); // rot
  96. receivedData += (vector) llList2String(primList,4); // size
  97. // Store the name of the animation if it is not already stored
  98. integer i = llListFindList(animations, [name]);
  99. if( i < 0 ){
  100. DEBUG("Adding Animation named " + name);
  101. animations += name;
  102. }
  103. currentLine++;
  104. }
  105. else if (num == COMPILE) // finish, compile it
  106. {
  107. //DEBUG("Animations:" + llDumpList2String(animations,":"));
  108. //DEBUG("Length:" + ((string) llGetListLength(animations)));
  109. //DEBUG("history:" + llDumpList2String(receivedData,":"));
  110. //DEBUG("Length:" + ((string) llGetListLength(receivedData)));
  111. string code;
  112. integer i;
  113. llOwnerSay("Compiler processing " + (string)currentLine + " prim movements and " + (string) llGetListLength(animations) + " animations");
  114. llOwnerSay("Copy everything below this line and paste it into a new script\n");
  115. string oldname = llGetObjectName ();
  116. llSetObjectName ("Compiler");
  117. vector scale = llGetScale();
  118. SayCode("// Prim animation compiler //\n"
  119. + "// Ferd Frederix - http://www.outworldz.com\n"
  120. + "integer playbackchannel = 1; // The default llMessageLinked number\n"
  121. + "rotation calcChildRot(rotation rdeltaRot){\n"
  122. + "\tif (llGetAttached())\n"
  123. + "\t\treturn rdeltaRot/llGetLocalRot();\n"
  124. + "\telse\n"
  125. + "\t\treturn rdeltaRot/llGetRootRotation();\n"
  126. + "}\n"
  127. + "vector originalScale = "
  128. + (string) scale
  129. + ";"
  130. );
  131. // Go through each animation and create a function for each one
  132. for(i = 0; i < llGetListLength(animations); i++){
  133. integer j;
  134. string animationName = llList2String(animations, i);
  135. //DEBUG("Processing " + animationName);
  136. SayCode(animationName
  137. + "(){\n"
  138. + "\tvector currentSize = llGetScale();\n"
  139. + "\tfloat scaleby = currentSize.x/originalScale.x;\n"
  140. );
  141. //Read through the list and print out the instructions for this animation
  142. integer count = llGetListLength(receivedData);
  143. for(j=0; j < count; j += STRIDE)
  144. {
  145. string name = llList2String(receivedData,j);
  146. float primNum = (float) llList2String(receivedData,j+1);
  147. //DEBUG("name: " + name + " Prim Num: " + primNum);
  148. if( name == animationName){
  149. if(primNum > 1){ // not a root prim or sleep
  150. SayCode( "\tllSetLinkPrimitiveParams"
  151. + fast
  152. + "("
  153. + (string) ((integer)primNum)
  154. + ", [PRIM_POSITION, "
  155. + (string) llList2Vector(receivedData,j+2)
  156. + "*scaleby, "
  157. + "PRIM_ROTATION,calcChildRot("
  158. + (string) llList2Rot(receivedData,j+3)
  159. + "), "
  160. + "PRIM_SIZE, "
  161. + (string) llList2Vector(receivedData,j+4)
  162. + "*scaleby]);"
  163. );
  164. } else {
  165. SayCode("\tllSleep("
  166. +(string)(primNum*-1) // negative numbers are sleep times
  167. +");"
  168. );
  169. }
  170. } // if name
  171. } // for j
  172. SayCode ("\n}");
  173. } // for animations
  174. SayCode (
  175. "\n\n"
  176. + "default{\n"
  177. );
  178. if (!OpenSim)
  179. SayCode("\tstate_entry(){\n"
  180. +"\t\tllSetMemoryLimit(llGetUsedMemory() + 512);\n"
  181. + "\t\t}");
  182. code = "\n\tlink_message(integer sender_num, integer num, string message, key id){\n"+
  183. "\t\tif(num == playbackchannel){\n";
  184. for(i=0; i<llGetListLength(animations);i++){
  185. code+="\t\t\tif(message == \""+llList2String(animations,i)+"\"){\n"+
  186. "\t\t\t\t"+llList2String(animations,i)+"();\n"+
  187. "\t\t\t}\n";
  188. }
  189. code += "\t\t}\n"+
  190. "\t}\n}";
  191. SayCode(code);
  192. SayCode("// Done! Copy everything above to a new script, and Search/Replace the time stamp and Compiler: on the left to be blank");
  193. llSetObjectName (oldname);
  194. }
  195. }
  196. }