ExtendedPhysics.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyrightD
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using System.Text;
  32. using System.Threading;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.CoreModules;
  35. using OpenSim.Region.Framework;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. using OpenSim.Region.Physics.Manager;
  39. using Mono.Addins;
  40. using Nini.Config;
  41. using log4net;
  42. using OpenMetaverse;
  43. namespace OpenSim.Region.OptionalModules.Scripting
  44. {
  45. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
  46. public class ExtendedPhysics : INonSharedRegionModule
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. private static string LogHeader = "[EXTENDED PHYSICS]";
  50. // =============================================================
  51. // Since BulletSim is a plugin, this these values aren't defined easily in one place.
  52. // This table must correspond to an identical table in BSScene.
  53. // Per scene functions. See BSScene.
  54. // Per avatar functions. See BSCharacter.
  55. // Per prim functions. See BSPrim.
  56. public const string PhysFunctGetLinksetType = "BulletSim.GetLinksetType";
  57. public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType";
  58. public const string PhysFunctChangeLinkFixed = "BulletSim.ChangeLinkFixed";
  59. public const string PhysFunctChangeLinkType = "BulletSim.ChangeLinkType";
  60. public const string PhysFunctGetLinkType = "BulletSim.GetLinkType";
  61. public const string PhysFunctChangeLinkParams = "BulletSim.ChangeLinkParams";
  62. // =============================================================
  63. private IConfig Configuration { get; set; }
  64. private bool Enabled { get; set; }
  65. private Scene BaseScene { get; set; }
  66. private IScriptModuleComms Comms { get; set; }
  67. #region INonSharedRegionModule
  68. public string Name { get { return this.GetType().Name; } }
  69. public void Initialise(IConfigSource config)
  70. {
  71. BaseScene = null;
  72. Enabled = false;
  73. Configuration = null;
  74. Comms = null;
  75. try
  76. {
  77. if ((Configuration = config.Configs["ExtendedPhysics"]) != null)
  78. {
  79. Enabled = Configuration.GetBoolean("Enabled", Enabled);
  80. }
  81. }
  82. catch (Exception e)
  83. {
  84. m_log.ErrorFormat("{0} Initialization error: {0}", LogHeader, e);
  85. }
  86. m_log.InfoFormat("{0} module {1} enabled", LogHeader, (Enabled ? "is" : "is not"));
  87. }
  88. public void Close()
  89. {
  90. if (BaseScene != null)
  91. {
  92. BaseScene.EventManager.OnObjectAddedToScene -= EventManager_OnObjectAddedToScene;
  93. BaseScene.EventManager.OnSceneObjectPartUpdated -= EventManager_OnSceneObjectPartUpdated;
  94. BaseScene = null;
  95. }
  96. }
  97. public void AddRegion(Scene scene)
  98. {
  99. }
  100. public void RemoveRegion(Scene scene)
  101. {
  102. if (BaseScene != null && BaseScene == scene)
  103. {
  104. Close();
  105. }
  106. }
  107. public void RegionLoaded(Scene scene)
  108. {
  109. if (!Enabled) return;
  110. BaseScene = scene;
  111. Comms = BaseScene.RequestModuleInterface<IScriptModuleComms>();
  112. if (Comms == null)
  113. {
  114. m_log.WarnFormat("{0} ScriptModuleComms interface not defined", LogHeader);
  115. Enabled = false;
  116. return;
  117. }
  118. // Register as LSL functions all the [ScriptInvocation] marked methods.
  119. Comms.RegisterScriptInvocations(this);
  120. Comms.RegisterConstants(this);
  121. // When an object is modified, we might need to update its extended physics parameters
  122. BaseScene.EventManager.OnObjectAddedToScene += EventManager_OnObjectAddedToScene;
  123. BaseScene.EventManager.OnSceneObjectPartUpdated += EventManager_OnSceneObjectPartUpdated;
  124. }
  125. public Type ReplaceableInterface { get { return null; } }
  126. #endregion // INonSharedRegionModule
  127. private void EventManager_OnObjectAddedToScene(SceneObjectGroup obj)
  128. {
  129. }
  130. // Event generated when some property of a prim changes.
  131. private void EventManager_OnSceneObjectPartUpdated(SceneObjectPart sop, bool isFullUpdate)
  132. {
  133. }
  134. [ScriptConstant]
  135. public const int PHYS_CENTER_OF_MASS = 1 << 0;
  136. [ScriptInvocation]
  137. public string physGetEngineType(UUID hostID, UUID scriptID)
  138. {
  139. string ret = string.Empty;
  140. if (BaseScene.PhysicsScene != null)
  141. {
  142. ret = BaseScene.PhysicsScene.EngineType;
  143. }
  144. return ret;
  145. }
  146. [ScriptConstant]
  147. public const int PHYS_LINKSET_TYPE_CONSTRAINT = 0;
  148. [ScriptConstant]
  149. public const int PHYS_LINKSET_TYPE_COMPOUND = 1;
  150. [ScriptConstant]
  151. public const int PHYS_LINKSET_TYPE_MANUAL = 2;
  152. [ScriptInvocation]
  153. public int physSetLinksetType(UUID hostID, UUID scriptID, int linksetType)
  154. {
  155. int ret = -1;
  156. if (!Enabled) return ret;
  157. // The part that is requesting the change.
  158. SceneObjectPart requestingPart = BaseScene.GetSceneObjectPart(hostID);
  159. if (requestingPart != null)
  160. {
  161. // The change is always made to the root of a linkset.
  162. SceneObjectGroup containingGroup = requestingPart.ParentGroup;
  163. SceneObjectPart rootPart = containingGroup.RootPart;
  164. if (rootPart != null)
  165. {
  166. PhysicsActor rootPhysActor = rootPart.PhysActor;
  167. if (rootPhysActor != null)
  168. {
  169. if (rootPhysActor.IsPhysical)
  170. {
  171. // Change a physical linkset by making non-physical, waiting for one heartbeat so all
  172. // the prim and linkset state is updated, changing the type and making the
  173. // linkset physical again.
  174. containingGroup.ScriptSetPhysicsStatus(false);
  175. Thread.Sleep(150); // longer than one heartbeat tick
  176. // A kludge for the moment.
  177. // Since compound linksets move the children but don't generate position updates to the
  178. // simulator, it is possible for compound linkset children to have out-of-sync simulator
  179. // and physical positions. The following causes the simulator to push the real child positions
  180. // down into the physics engine to get everything synced.
  181. containingGroup.UpdateGroupPosition(containingGroup.AbsolutePosition);
  182. containingGroup.UpdateGroupRotationR(containingGroup.GroupRotation);
  183. object[] parms2 = { rootPhysActor, null, linksetType };
  184. ret = MakeIntError(rootPhysActor.Extension(PhysFunctSetLinksetType, parms2));
  185. Thread.Sleep(150); // longer than one heartbeat tick
  186. containingGroup.ScriptSetPhysicsStatus(true);
  187. }
  188. else
  189. {
  190. // Non-physical linksets don't have a physical instantiation so there is no state to
  191. // worry about being updated.
  192. object[] parms2 = { rootPhysActor, null, linksetType };
  193. ret = MakeIntError(rootPhysActor.Extension(PhysFunctSetLinksetType, parms2));
  194. }
  195. }
  196. else
  197. {
  198. m_log.WarnFormat("{0} physSetLinksetType: root part does not have a physics actor. rootName={1}, hostID={2}",
  199. LogHeader, rootPart.Name, hostID);
  200. }
  201. }
  202. else
  203. {
  204. m_log.WarnFormat("{0} physSetLinksetType: root part does not exist. RequestingPartName={1}, hostID={2}",
  205. LogHeader, requestingPart.Name, hostID);
  206. }
  207. }
  208. else
  209. {
  210. m_log.WarnFormat("{0} physSetLinsetType: cannot find script object in scene. hostID={1}", LogHeader, hostID);
  211. }
  212. return ret;
  213. }
  214. [ScriptInvocation]
  215. public int physGetLinksetType(UUID hostID, UUID scriptID)
  216. {
  217. int ret = -1;
  218. if (!Enabled) return ret;
  219. // The part that is requesting the change.
  220. SceneObjectPart requestingPart = BaseScene.GetSceneObjectPart(hostID);
  221. if (requestingPart != null)
  222. {
  223. // The type is is always on the root of a linkset.
  224. SceneObjectGroup containingGroup = requestingPart.ParentGroup;
  225. SceneObjectPart rootPart = containingGroup.RootPart;
  226. if (rootPart != null)
  227. {
  228. PhysicsActor rootPhysActor = rootPart.PhysActor;
  229. if (rootPhysActor != null)
  230. {
  231. object[] parms2 = { rootPhysActor, null };
  232. ret = MakeIntError(rootPhysActor.Extension(PhysFunctGetLinksetType, parms2));
  233. }
  234. else
  235. {
  236. m_log.WarnFormat("{0} physGetLinksetType: root part does not have a physics actor. rootName={1}, hostID={2}",
  237. LogHeader, rootPart.Name, hostID);
  238. }
  239. }
  240. else
  241. {
  242. m_log.WarnFormat("{0} physGetLinksetType: root part does not exist. RequestingPartName={1}, hostID={2}",
  243. LogHeader, requestingPart.Name, hostID);
  244. }
  245. }
  246. else
  247. {
  248. m_log.WarnFormat("{0} physGetLinsetType: cannot find script object in scene. hostID={1}", LogHeader, hostID);
  249. }
  250. return ret;
  251. }
  252. [ScriptConstant]
  253. public const int PHYS_LINK_TYPE_FIXED = 1234;
  254. [ScriptConstant]
  255. public const int PHYS_LINK_TYPE_HINGE = 4;
  256. [ScriptConstant]
  257. public const int PHYS_LINK_TYPE_SPRING = 9;
  258. [ScriptConstant]
  259. public const int PHYS_LINK_TYPE_6DOF = 6;
  260. [ScriptConstant]
  261. public const int PHYS_LINK_TYPE_SLIDER = 7;
  262. // physChangeLinkType(integer linkNum, integer typeCode)
  263. [ScriptInvocation]
  264. public int physChangeLinkType(UUID hostID, UUID scriptID, int linkNum, int typeCode)
  265. {
  266. int ret = -1;
  267. if (!Enabled) return ret;
  268. PhysicsActor rootPhysActor;
  269. PhysicsActor childPhysActor;
  270. if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
  271. {
  272. object[] parms2 = { rootPhysActor, childPhysActor, typeCode };
  273. ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkType, parms2));
  274. }
  275. return ret;
  276. }
  277. // physGetLinkType(integer linkNum)
  278. [ScriptInvocation]
  279. public int physGetLinkType(UUID hostID, UUID scriptID, int linkNum)
  280. {
  281. int ret = -1;
  282. if (!Enabled) return ret;
  283. PhysicsActor rootPhysActor;
  284. PhysicsActor childPhysActor;
  285. if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
  286. {
  287. object[] parms2 = { rootPhysActor, childPhysActor };
  288. ret = MakeIntError(rootPhysActor.Extension(PhysFunctGetLinkType, parms2));
  289. }
  290. return ret;
  291. }
  292. // physChangeLinkFixed(integer linkNum)
  293. // Change the link between the root and the linkNum into a fixed, static physical connection.
  294. [ScriptInvocation]
  295. public int physChangeLinkFixed(UUID hostID, UUID scriptID, int linkNum)
  296. {
  297. int ret = -1;
  298. if (!Enabled) return ret;
  299. PhysicsActor rootPhysActor;
  300. PhysicsActor childPhysActor;
  301. if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
  302. {
  303. object[] parms2 = { rootPhysActor, childPhysActor , PHYS_LINK_TYPE_FIXED };
  304. ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkType, parms2));
  305. }
  306. return ret;
  307. }
  308. // Code for specifying params.
  309. // The choice if 14400 is arbitrary and only serves to catch parameter code misuse.
  310. public const int PHYS_PARAM_MIN = 14401;
  311. [ScriptConstant]
  312. public const int PHYS_PARAM_FRAMEINA_LOC = 14401;
  313. [ScriptConstant]
  314. public const int PHYS_PARAM_FRAMEINA_ROT = 14402;
  315. [ScriptConstant]
  316. public const int PHYS_PARAM_FRAMEINB_LOC = 14403;
  317. [ScriptConstant]
  318. public const int PHYS_PARAM_FRAMEINB_ROT = 14404;
  319. [ScriptConstant]
  320. public const int PHYS_PARAM_LINEAR_LIMIT_LOW = 14405;
  321. [ScriptConstant]
  322. public const int PHYS_PARAM_LINEAR_LIMIT_HIGH = 14406;
  323. [ScriptConstant]
  324. public const int PHYS_PARAM_ANGULAR_LIMIT_LOW = 14407;
  325. [ScriptConstant]
  326. public const int PHYS_PARAM_ANGULAR_LIMIT_HIGH = 14408;
  327. [ScriptConstant]
  328. public const int PHYS_PARAM_USE_FRAME_OFFSET = 14409;
  329. [ScriptConstant]
  330. public const int PHYS_PARAM_ENABLE_TRANSMOTOR = 14410;
  331. [ScriptConstant]
  332. public const int PHYS_PARAM_TRANSMOTOR_MAXVEL = 14411;
  333. [ScriptConstant]
  334. public const int PHYS_PARAM_TRANSMOTOR_MAXFORCE = 14412;
  335. [ScriptConstant]
  336. public const int PHYS_PARAM_CFM = 14413;
  337. [ScriptConstant]
  338. public const int PHYS_PARAM_ERP = 14414;
  339. [ScriptConstant]
  340. public const int PHYS_PARAM_SOLVER_ITERATIONS = 14415;
  341. [ScriptConstant]
  342. public const int PHYS_PARAM_SPRING_AXIS_ENABLE = 14416;
  343. [ScriptConstant]
  344. public const int PHYS_PARAM_SPRING_DAMPING = 14417;
  345. [ScriptConstant]
  346. public const int PHYS_PARAM_SPRING_STIFFNESS = 14418;
  347. [ScriptConstant]
  348. public const int PHYS_PARAM_LINK_TYPE = 14419;
  349. [ScriptConstant]
  350. public const int PHYS_PARAM_USE_LINEAR_FRAMEA = 14420;
  351. [ScriptConstant]
  352. public const int PHYS_PARAM_SPRING_EQUILIBRIUM_POINT = 14421;
  353. public const int PHYS_PARAM_MAX = 14421;
  354. // Used when specifying a parameter that has settings for the three linear and three angular axis
  355. [ScriptConstant]
  356. public const int PHYS_AXIS_ALL = -1;
  357. [ScriptConstant]
  358. public const int PHYS_AXIS_LINEAR_ALL = -2;
  359. [ScriptConstant]
  360. public const int PHYS_AXIS_ANGULAR_ALL = -3;
  361. [ScriptConstant]
  362. public const int PHYS_AXIS_LINEAR_X = 0;
  363. [ScriptConstant]
  364. public const int PHYS_AXIS_LINEAR_Y = 1;
  365. [ScriptConstant]
  366. public const int PHYS_AXIS_LINEAR_Z = 2;
  367. [ScriptConstant]
  368. public const int PHYS_AXIS_ANGULAR_X = 3;
  369. [ScriptConstant]
  370. public const int PHYS_AXIS_ANGULAR_Y = 4;
  371. [ScriptConstant]
  372. public const int PHYS_AXIS_ANGULAR_Z = 5;
  373. // physChangeLinkParams(integer linkNum, [ PHYS_PARAM_*, value, PHYS_PARAM_*, value, ...])
  374. [ScriptInvocation]
  375. public int physChangeLinkParams(UUID hostID, UUID scriptID, int linkNum, object[] parms)
  376. {
  377. int ret = -1;
  378. if (!Enabled) return ret;
  379. PhysicsActor rootPhysActor;
  380. PhysicsActor childPhysActor;
  381. if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
  382. {
  383. object[] parms2 = AddToBeginningOfArray(rootPhysActor, childPhysActor, parms);
  384. ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkParams, parms2));
  385. }
  386. return ret;
  387. }
  388. private bool GetRootPhysActor(UUID hostID, out PhysicsActor rootPhysActor)
  389. {
  390. SceneObjectGroup containingGroup;
  391. SceneObjectPart rootPart;
  392. return GetRootPhysActor(hostID, out containingGroup, out rootPart, out rootPhysActor);
  393. }
  394. private bool GetRootPhysActor(UUID hostID, out SceneObjectGroup containingGroup, out SceneObjectPart rootPart, out PhysicsActor rootPhysActor)
  395. {
  396. bool ret = false;
  397. rootPhysActor = null;
  398. containingGroup = null;
  399. rootPart = null;
  400. SceneObjectPart requestingPart;
  401. requestingPart = BaseScene.GetSceneObjectPart(hostID);
  402. if (requestingPart != null)
  403. {
  404. // The type is is always on the root of a linkset.
  405. containingGroup = requestingPart.ParentGroup;
  406. if (containingGroup != null && !containingGroup.IsDeleted)
  407. {
  408. rootPart = containingGroup.RootPart;
  409. if (rootPart != null)
  410. {
  411. rootPhysActor = rootPart.PhysActor;
  412. if (rootPhysActor != null)
  413. {
  414. ret = true;
  415. }
  416. else
  417. {
  418. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not have a physics actor. rootName={1}, hostID={2}",
  419. LogHeader, rootPart.Name, hostID);
  420. }
  421. }
  422. else
  423. {
  424. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not exist. RequestingPartName={1}, hostID={2}",
  425. LogHeader, requestingPart.Name, hostID);
  426. }
  427. }
  428. else
  429. {
  430. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Containing group missing or deleted. hostID={1}", LogHeader, hostID);
  431. }
  432. }
  433. else
  434. {
  435. m_log.WarnFormat("{0} GetRootAndChildPhysActors: cannot find script object in scene. hostID={1}", LogHeader, hostID);
  436. }
  437. return ret;
  438. }
  439. // Find the root and child PhysActors based on the linkNum.
  440. // Return 'true' if both are found and returned.
  441. private bool GetRootAndChildPhysActors(UUID hostID, int linkNum, out PhysicsActor rootPhysActor, out PhysicsActor childPhysActor)
  442. {
  443. bool ret = false;
  444. rootPhysActor = null;
  445. childPhysActor = null;
  446. SceneObjectGroup containingGroup;
  447. SceneObjectPart rootPart;
  448. if (GetRootPhysActor(hostID, out containingGroup, out rootPart, out rootPhysActor))
  449. {
  450. SceneObjectPart linkPart = containingGroup.GetLinkNumPart(linkNum);
  451. if (linkPart != null)
  452. {
  453. childPhysActor = linkPart.PhysActor;
  454. if (childPhysActor != null)
  455. {
  456. ret = true;
  457. }
  458. else
  459. {
  460. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Link part has no physical actor. rootName={1}, hostID={2}, linknum={3}",
  461. LogHeader, rootPart.Name, hostID, linkNum);
  462. }
  463. }
  464. else
  465. {
  466. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Could not find linknum part. rootName={1}, hostID={2}, linknum={3}",
  467. LogHeader, rootPart.Name, hostID, linkNum);
  468. }
  469. }
  470. else
  471. {
  472. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not have a physics actor. rootName={1}, hostID={2}",
  473. LogHeader, rootPart.Name, hostID);
  474. }
  475. return ret;
  476. }
  477. // Return an array of objects with the passed object as the first object of a new array
  478. private object[] AddToBeginningOfArray(object firstOne, object secondOne, object[] prevArray)
  479. {
  480. object[] newArray = new object[2 + prevArray.Length];
  481. newArray[0] = firstOne;
  482. newArray[1] = secondOne;
  483. prevArray.CopyTo(newArray, 2);
  484. return newArray;
  485. }
  486. // Extension() returns an object. Convert that object into the integer error we expect to return.
  487. private int MakeIntError(object extensionRet)
  488. {
  489. int ret = -1;
  490. if (extensionRet != null)
  491. {
  492. try
  493. {
  494. ret = (int)extensionRet;
  495. }
  496. catch
  497. {
  498. ret = -1;
  499. }
  500. }
  501. return ret;
  502. }
  503. }
  504. }