Store 0.lsl 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. // :CATEGORY:Prim Animator
  2. // :NAME:Archipelis scripts for prim animator
  3. // :AUTHOR:Ferd Frederix
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:38:48
  6. // :ID:52
  7. // :NUM:73
  8. // :REV:2
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // Prim storage Script
  12. // Should be named Store 0, Store 1 Stor32 etc.
  13. // As you need more storage, just copy it and increment the number
  14. // :CODE:
  15. // Prim Animator DB
  16. // 06/20/2011
  17. // Author Ferd Frederix
  18. // Prim Storage script.
  19. // Copyright 2011 Fred Beckhusen - all rights reserved
  20. integer debug =FALSE;
  21. // return codes
  22. integer playchannel = 2000; // the script to do the actual playback
  23. integer countchannel= 2001; // the script to do the actual playback
  24. // constants
  25. integer MAX = 999; // Maximum number of anims per script, if set to very high, oit clamps with free memory < 1000
  26. integer full = FALSE; // this script RAM is full
  27. // Commands
  28. integer Erase = 100; // erase command
  29. integer Add = 101; // add a coordinate
  30. integer Publish = 102; // save to db
  31. integer Name = 103; // send Name to db
  32. integer Password = 104; // send Password to db
  33. integer Play = 105; //
  34. // vars
  35. integer myNum = 0; // the number at the end of this script name 0, 1, 2....
  36. integer imax; // total records in store
  37. integer datum; // the load counter increments as we load anims from db
  38. string MyName;
  39. string MyPassword;
  40. // remote db reading
  41. key kHttpRequestID;
  42. // lists
  43. list names; // a list of distnct animation names stored here
  44. list db; // name, prin num, pos, rot, size
  45. integer STRIDE = 5; // 4 items in the above list
  46. integer recordcount = 0; // how many anims are stored
  47. vector vRootScale ; // the initial size when the prims were recorded
  48. vector vScaleChange = <1,1,1>; // The change percent if resized
  49. GetScale(vector orig_size)
  50. {
  51. //Debug ("Size:" + (string) orig_size);
  52. vRootScale = orig_size; // save the size when we recorded the prims
  53. vector newScale = llGetScale();
  54. vScaleChange.x = newScale.x / vRootScale.x;
  55. vScaleChange.y = newScale.y / vRootScale.y;
  56. vScaleChange.z = newScale.z / vRootScale.z;
  57. }
  58. rotation calcChildRot(rotation rdeltaRot)
  59. {
  60. if (llGetAttached())
  61. return rdeltaRot/llGetLocalRot();
  62. else
  63. return rdeltaRot/llGetRootRotation();
  64. }
  65. // Start saving records. The first record is the prim size.
  66. StartPublishing ()
  67. {
  68. imax = llGetListLength(db);
  69. datum = 0; // point to the first record, counts as we load records
  70. integer howmany = imax / STRIDE ;
  71. llOwnerSay((string) howmany + " movements recorded - now saving to server.");
  72. string url;
  73. // cannot save or delete unless we are the first prim to Publish
  74. string save;
  75. string erase = "0";
  76. if (myNum == 0) {
  77. erase = "1";
  78. save = "Save";
  79. }
  80. //Debug( "Saving Size:" + (string) llGetScale());
  81. url = "http://secondlife.mitsi.com/cgi/animate.plx?Type=";
  82. url += save;
  83. url += "&Name=" + llEscapeURL(MyName) + "&Password=" + llEscapeURL(MyPassword);
  84. url += "&Delete=";
  85. url += erase;
  86. url += "&aniName=RootPosition" ;
  87. url += "&PrimNum=" + (string) 0;
  88. url += "&Size=" + (string) llGetScale(); // save the scale as the first record
  89. url += "&Pos=<1,1,1>" ;
  90. url += "&Rot=<0,0,0,1>" ;
  91. Debug(url);
  92. kHttpRequestID = llHTTPRequest(url, [], "");
  93. }
  94. Put()
  95. {
  96. if (datum < imax)
  97. {
  98. string sAniName = llList2String (db, datum);
  99. float fprimNum = llList2Float (db, datum+1);
  100. vector vprimPos = llList2Vector (db, datum+2);
  101. rotation rprimRot = llList2Rot (db, datum+3) ;
  102. vector vprimSize = llList2Vector (db, datum+4);
  103. string url = "http://secondlife.mitsi.com/cgi/animate.plx?Type=Save&Name=" + llEscapeURL(MyName) + "&Password=" + llEscapeURL(MyPassword);
  104. url += "&aniName=" + llEscapeURL(sAniName);
  105. url += "&PrimNum=" + (string) fprimNum;
  106. url += "&Pos=" + (string) vprimPos;
  107. url += "&Rot=" + (string) rprimRot;
  108. url += "&Size=" + (string) vprimSize;
  109. Debug(url);
  110. if ((datum/STRIDE) % 10 == 0 && datum)
  111. llMessageLinked(LINK_THIS,countchannel,"Saved " + (string) (datum/STRIDE) + " records","");
  112. kHttpRequestID = llHTTPRequest(url, [], "");
  113. llSleep(1);
  114. datum += STRIDE;
  115. }
  116. else
  117. {
  118. llMessageLinked(LINK_THIS,countchannel,(string) (datum/STRIDE) + " movements saved.","");
  119. llSleep(2.0);
  120. llMessageLinked(LINK_THIS,countchannel,"","");
  121. }
  122. }
  123. Debug(string msg)
  124. {
  125. if (debug)
  126. llOwnerSay(llGetScriptName() + ":" + msg);
  127. }
  128. default
  129. {
  130. state_entry()
  131. {
  132. string name = llGetScriptName();
  133. list parts = llParseString2List(name,[" "],[""]);
  134. myNum = llList2Integer(parts,1);
  135. vRootScale = llGetScale();
  136. Add += 10 * myNum;
  137. }
  138. link_message(integer sender_num, integer num, string msg, key id)
  139. {
  140. Debug("cmd:" + (string) num + ":" + msg);
  141. // valid commands only.
  142. if (num != Erase && num != Play && num != Add && num != Publish && num != Name && num!= Password)
  143. return;
  144. Debug("cmd:" + (string) num + ":" + msg);
  145. if (num == Erase)
  146. {
  147. db = [];
  148. Debug((string) myNum + " erased " );
  149. full = FALSE;
  150. recordcount = 0;
  151. return;
  152. }
  153. else if (num == Add)
  154. {
  155. if (full)
  156. {
  157. Debug((string) myNum + " pass Add on to " + (string) (num +10));
  158. llMessageLinked(LINK_THIS,num +10,msg,id);
  159. return;
  160. }
  161. //Debug("Add");
  162. list vecs = llParseString2List(msg,["|"],[""]);
  163. // Debug(llDumpList2String(vecs,"---"));
  164. string name= llList2String(vecs,0);
  165. if (llListFindList(names,[name]) == -1)
  166. names += name;
  167. float fNum = (float) (llList2String(vecs,1));
  168. vector vPos = (vector) (llList2String(vecs,2));
  169. rotation rRot = (rotation) (llList2String(vecs,3));
  170. vector vprimSize = (vector) (llList2String(vecs,4));
  171. db += name;
  172. db += fNum;
  173. db += vPos;
  174. db += rRot;
  175. db += vprimSize;
  176. recordcount ++;
  177. Debug("Store contains " + (string) recordcount + "Records");
  178. //if (recordcount> MAX)
  179. //{
  180. // Debug("Full, record count = " + (string) recordcount);
  181. // full++;
  182. //}
  183. if (llGetFreeMemory() < 1000)
  184. {
  185. Debug("Full");
  186. full++;
  187. }
  188. Debug("Free:" + (string) llGetFreeMemory());
  189. }
  190. else if (num == Name)
  191. {
  192. MyName = msg;
  193. }
  194. else if (num == Password)
  195. {
  196. MyPassword = msg;
  197. }
  198. else if (num == Play)
  199. {
  200. if (llListFindList(names,[msg]) == -1)
  201. {
  202. Debug("Animation " + msg + " not found");
  203. return;
  204. }
  205. integer currpos;
  206. integer end = recordcount * STRIDE;
  207. // play back all we find
  208. for (currpos = 0; currpos < end; currpos+= STRIDE)
  209. {
  210. if ( msg == llList2String(db,currpos) )
  211. {
  212. float fPrim = (float) llList2String(db,currpos+1);
  213. vector vPos = (vector) llList2String(db,currpos+2);
  214. rotation rRot = (rotation) llList2String (db,currpos+3);
  215. vector vprimSize = (vector) llList2String(db,currpos+4);
  216. //Debug(msg + "|" + spos + "|" + srot + "|" + sthesize);
  217. GetScale(vRootScale); // original prim size
  218. // set the local pos and locat rot to the prims orientation and position
  219. rRot = calcChildRot(rRot);
  220. if (fPrim < 0)
  221. {
  222. //DebugllOwnerSay("Sleeping " + (string) (fprimNum * -1));
  223. llSleep( fPrim * -1);
  224. }
  225. else if (fPrim > 1 ) // skip root prim
  226. {
  227. vPos.x *= vScaleChange.x;
  228. vprimSize.x *= vScaleChange.x;
  229. vPos.y *= vScaleChange.y;
  230. vprimSize.y *= vScaleChange.y;
  231. vPos.z *= vScaleChange.z;
  232. vprimSize.z *= vScaleChange.z;
  233. Debug("p=" + (string) fPrim
  234. + " l=" + (string) vPos
  235. + " r=" + (string) rRot
  236. + " s=" + (string) vprimSize);
  237. llSetLinkPrimitiveParamsFast((integer) fPrim,[PRIM_POSITION,vPos,PRIM_ROTATION,rRot,PRIM_SIZE,vprimSize]);
  238. }
  239. }
  240. }
  241. }
  242. else if (num == Publish)
  243. {
  244. if (myNum)
  245. llSleep(5); // time to delete the database and save the root prim
  246. StartPublishing();
  247. }
  248. else
  249. {
  250. Debug("Bad command");
  251. }
  252. }
  253. // use for publishing in parallel
  254. http_response(key queryid, integer status, list metadata, string data)
  255. {
  256. if (queryid == kHttpRequestID )
  257. {
  258. if (status == 200) // HTTP success status
  259. {
  260. Debug(data);
  261. if (data == "ok")
  262. {
  263. Put();
  264. return;
  265. }
  266. }
  267. else
  268. {
  269. llOwnerSay("Server Error loading animations");
  270. }
  271. }
  272. }
  273. }