Prim_Animation_Compiler_1984.lsl 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // :CATEGORY:Bird
  2. // :NAME:flamingo
  3. // :AUTHOR:Ferd Frederix
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:38:53
  6. // :ID:314
  7. // :NUM:420
  8. // :REV:1
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // Compiler for prim animation
  12. // :CODE:
  13. // This script produces optimized LSL code that can be triggered by link messages.
  14. // fred@mitsi.com
  15. // 3-7-2012
  16. // Rev B, added a missing } at the end of multiple recordings.
  17. // Author: Ferd Frederix
  18. // Based on an excellent script by Allen Firethorn
  19. // This is free software, it is not for sale at any price
  20. // Tunable stuff:
  21. integer OpenSim = FALSE; // Set to FALSE for Second Life to save memory
  22. string fast="Fast"; // Set this to an empty string if you don't want to use the fast animation
  23. integer debug = FALSE; // set to TRUE to see stuff inside as it runs
  24. list animations; // holds a list of all animation names
  25. list receivedData; // the data from the main program
  26. integer STRIDE = 5; // size of the data packets in receivedData
  27. integer currentLine; // the line we are processing
  28. // Link messages
  29. integer CLEAR = -234756;
  30. integer DATA = -234757;
  31. integer COMPILE = -234758;
  32. integer DIE = -234759;
  33. DEBUG(string msg)
  34. {
  35. if (debug) llOwnerSay("// " + msg);
  36. }
  37. // speak without the name of the prim in the way
  38. SayCode (string story){
  39. llOwnerSay (story);
  40. llSleep(0.1);
  41. }
  42. default {
  43. link_message(integer sender_num,integer num, string msg, key id) {
  44. if (num == DIE && msg =="die") // clear
  45. {
  46. llOwnerSay("Compiler has been removed");
  47. if (! debug) {
  48. llRemoveInventory(llGetScriptName());
  49. }
  50. }
  51. if (num == CLEAR) // clear
  52. {
  53. animations = [];
  54. receivedData = [];
  55. currentLine = 0;
  56. llOwnerSay("Compiler Ready");
  57. }
  58. else if (num == DATA) // data
  59. {
  60. // data formatted like this:
  61. // name|primnum|vector Pos|rotation rot|vector size
  62. // test1|2|<0.026306,-0.150208,0.191069>|<-0.000008,0.956309,-0.292356,0.000000>|<0.074010,0.074010,0.074010>
  63. list primList = llParseString2List(msg,["|"],[]);
  64. string name = llList2String(primList,0);
  65. receivedData += name;
  66. receivedData += (float) llList2String(primList,1); // prim Number or ms to sleep
  67. receivedData += (vector) llList2String(primList,2); // pos
  68. receivedData += (rotation) llList2String(primList,3); // rot
  69. receivedData += (vector) llList2String(primList,4); // size
  70. // Store the name of the animation if it is not already stored
  71. integer i = llListFindList(animations, [name]);
  72. if( i < 0 ){
  73. DEBUG("Adding Animation named " + name);
  74. animations += name;
  75. }
  76. currentLine++;
  77. }
  78. else if (num == COMPILE) // finish, compile it
  79. {
  80. //DEBUG("Animations:" + llDumpList2String(animations,":"));
  81. //DEBUG("Length:" + ((string) llGetListLength(animations)));
  82. //DEBUG("history:" + llDumpList2String(receivedData,":"));
  83. //DEBUG("Length:" + ((string) llGetListLength(receivedData)));
  84. string code;
  85. integer i;
  86. llOwnerSay("Compiler processing " + (string)currentLine + " prim movements and " + (string) llGetListLength(animations) + " animations");
  87. llOwnerSay("Copy everything below this line and paste it into a new script\n");
  88. string oldname = llGetObjectName ();
  89. llSetObjectName ("Compiler");
  90. vector scale = llGetScale();
  91. SayCode("// Prim animation compiler //\n"
  92. + "// Ferd Frederix - http://www.outworldz.com\n"
  93. + "integer playbackchannel = 1; // The default llMessageLinked number\n"
  94. + "rotation calcChildRot(rotation rdeltaRot){\n"
  95. + "\tif (llGetAttached())\n"
  96. + "\t\treturn rdeltaRot/llGetLocalRot();\n"
  97. + "\telse\n"
  98. + "\t\treturn rdeltaRot/llGetRootRotation();\n"
  99. + "}\n"
  100. + "vector originalScale = "
  101. + (string) scale
  102. + ";"
  103. );
  104. // Go through each animation and create a function for each one
  105. for(i = 0; i < llGetListLength(animations); i++){
  106. integer j;
  107. string animationName = llList2String(animations, i);
  108. //DEBUG("Processing " + animationName);
  109. SayCode(animationName
  110. + "(){\n"
  111. + "\tvector currentSize = llGetScale();\n"
  112. + "\tfloat scaleby = currentSize.x/originalScale.x;\n"
  113. );
  114. //Read through the list and print out the instructions for this animation
  115. integer count = llGetListLength(receivedData);
  116. for(j=0; j < count; j += STRIDE)
  117. {
  118. string name = llList2String(receivedData,j);
  119. float primNum = (float) llList2String(receivedData,j+1);
  120. //DEBUG("name: " + name + " Prim Num: " + primNum);
  121. if( name == animationName){
  122. if(primNum > 1){ // not a root prim or sleep
  123. SayCode( "\tllSetLinkPrimitiveParams"
  124. + fast
  125. + "("
  126. + (string) ((integer)primNum)
  127. + ", [PRIM_POSITION, "
  128. + (string) llList2Vector(receivedData,j+2)
  129. + "*scaleby, "
  130. + "PRIM_ROTATION,calcChildRot("
  131. + (string) llList2Rot(receivedData,j+3)
  132. + "), "
  133. + "PRIM_SIZE, "
  134. + (string) llList2Vector(receivedData,j+4)
  135. + "*scaleby]);"
  136. );
  137. } else {
  138. SayCode("\tllSleep("
  139. +(string)(primNum*-1) // negative numbers are sleep times
  140. +");"
  141. );
  142. }
  143. } // if name
  144. } // for j
  145. SayCode ("\n}");
  146. } // for animations
  147. SayCode (
  148. "\n\n"
  149. + "default{\n"
  150. );
  151. if (!OpenSim)
  152. SayCode("\tstate_entry(){\n"
  153. +"\t\tllSetMemoryLimit(llGetUsedMemory() + 512);\n"
  154. + "\t\t}");
  155. code = "\n\tlink_message(integer sender_num, integer num, string message, key id){\n"+
  156. "\t\tif(num == playbackchannel){\n";
  157. for(i=0; i<llGetListLength(animations);i++){
  158. code+="\t\t\tif(message == \""+llList2String(animations,i)+"\"){\n"+
  159. "\t\t\t\t"+llList2String(animations,i)+"();\n"+
  160. "\t\t\t}\n";
  161. }
  162. code += "\t\t}\n"+
  163. "\t}\n}";
  164. SayCode(code);
  165. SayCode("// Done! Copy everything above to a new script, and Search/Replace the time stamp and Compiler: on the left to be blank");
  166. llSetObjectName (oldname);
  167. }
  168. }
  169. }