lua_PhysicsGhostObject.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_PhysicsGhostObject.h"
  4. #include "Animation.h"
  5. #include "AnimationTarget.h"
  6. #include "Base.h"
  7. #include "Game.h"
  8. #include "Node.h"
  9. #include "PhysicsCollisionObject.h"
  10. #include "PhysicsController.h"
  11. #include "PhysicsGhostObject.h"
  12. #include "ScriptController.h"
  13. #include "ScriptTarget.h"
  14. #include "Transform.h"
  15. #include "lua_CurveInterpolationType.h"
  16. #include "lua_PhysicsCollisionObjectCollisionListenerEventType.h"
  17. #include "lua_PhysicsCollisionObjectType.h"
  18. #include "lua_PhysicsCollisionShapeType.h"
  19. namespace gameplay
  20. {
  21. void luaRegister_PhysicsGhostObject()
  22. {
  23. const luaL_Reg lua_members[] =
  24. {
  25. {"addCollisionListener", lua_PhysicsGhostObject_addCollisionListener},
  26. {"collidesWith", lua_PhysicsGhostObject_collidesWith},
  27. {"getCollisionShape", lua_PhysicsGhostObject_getCollisionShape},
  28. {"getNode", lua_PhysicsGhostObject_getNode},
  29. {"getShapeType", lua_PhysicsGhostObject_getShapeType},
  30. {"getType", lua_PhysicsGhostObject_getType},
  31. {"isDynamic", lua_PhysicsGhostObject_isDynamic},
  32. {"isEnabled", lua_PhysicsGhostObject_isEnabled},
  33. {"isKinematic", lua_PhysicsGhostObject_isKinematic},
  34. {"removeCollisionListener", lua_PhysicsGhostObject_removeCollisionListener},
  35. {"setEnabled", lua_PhysicsGhostObject_setEnabled},
  36. {"transformChanged", lua_PhysicsGhostObject_transformChanged},
  37. {NULL, NULL}
  38. };
  39. const luaL_Reg* lua_statics = NULL;
  40. std::vector<std::string> scopePath;
  41. ScriptUtil::registerClass("PhysicsGhostObject", lua_members, NULL, NULL, lua_statics, scopePath);
  42. }
  43. static PhysicsGhostObject* getInstance(lua_State* state)
  44. {
  45. void* userdata = luaL_checkudata(state, 1, "PhysicsGhostObject");
  46. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsGhostObject' expected.");
  47. return (PhysicsGhostObject*)((ScriptUtil::LuaObject*)userdata)->instance;
  48. }
  49. int lua_PhysicsGhostObject_addCollisionListener(lua_State* state)
  50. {
  51. // Get the number of parameters.
  52. int paramCount = lua_gettop(state);
  53. // Attempt to match the parameters to a valid binding.
  54. switch (paramCount)
  55. {
  56. case 2:
  57. {
  58. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  59. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  60. {
  61. // Get parameter 1 off the stack.
  62. ScriptUtil::LuaArray<PhysicsCollisionObject::CollisionListener> param1 = ScriptUtil::getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
  63. PhysicsGhostObject* instance = getInstance(state);
  64. instance->addCollisionListener(param1);
  65. return 0;
  66. }
  67. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  68. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  69. {
  70. // Get parameter 1 off the stack.
  71. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  72. PhysicsGhostObject* instance = getInstance(state);
  73. instance->addCollisionListener(param1);
  74. return 0;
  75. }
  76. else
  77. {
  78. lua_pushstring(state, "lua_PhysicsGhostObject_addCollisionListener - Failed to match the given parameters to a valid function signature.");
  79. lua_error(state);
  80. }
  81. break;
  82. }
  83. case 3:
  84. {
  85. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  86. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  87. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  88. {
  89. // Get parameter 1 off the stack.
  90. ScriptUtil::LuaArray<PhysicsCollisionObject::CollisionListener> param1 = ScriptUtil::getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
  91. // Get parameter 2 off the stack.
  92. ScriptUtil::LuaArray<PhysicsCollisionObject> param2 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
  93. PhysicsGhostObject* instance = getInstance(state);
  94. instance->addCollisionListener(param1, param2);
  95. return 0;
  96. }
  97. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  98. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  99. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  100. {
  101. // Get parameter 1 off the stack.
  102. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  103. // Get parameter 2 off the stack.
  104. ScriptUtil::LuaArray<PhysicsCollisionObject> param2 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
  105. PhysicsGhostObject* instance = getInstance(state);
  106. instance->addCollisionListener(param1, param2);
  107. return 0;
  108. }
  109. else
  110. {
  111. lua_pushstring(state, "lua_PhysicsGhostObject_addCollisionListener - Failed to match the given parameters to a valid function signature.");
  112. lua_error(state);
  113. }
  114. break;
  115. }
  116. default:
  117. {
  118. lua_pushstring(state, "Invalid number of parameters (expected 2 or 3).");
  119. lua_error(state);
  120. break;
  121. }
  122. }
  123. return 0;
  124. }
  125. int lua_PhysicsGhostObject_collidesWith(lua_State* state)
  126. {
  127. // Get the number of parameters.
  128. int paramCount = lua_gettop(state);
  129. // Attempt to match the parameters to a valid binding.
  130. switch (paramCount)
  131. {
  132. case 2:
  133. {
  134. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  135. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  136. {
  137. // Get parameter 1 off the stack.
  138. ScriptUtil::LuaArray<PhysicsCollisionObject> param1 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(2, "PhysicsCollisionObject", false);
  139. PhysicsGhostObject* instance = getInstance(state);
  140. bool result = instance->collidesWith(param1);
  141. // Push the return value onto the stack.
  142. lua_pushboolean(state, result);
  143. return 1;
  144. }
  145. else
  146. {
  147. lua_pushstring(state, "lua_PhysicsGhostObject_collidesWith - Failed to match the given parameters to a valid function signature.");
  148. lua_error(state);
  149. }
  150. break;
  151. }
  152. default:
  153. {
  154. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  155. lua_error(state);
  156. break;
  157. }
  158. }
  159. return 0;
  160. }
  161. int lua_PhysicsGhostObject_getCollisionShape(lua_State* state)
  162. {
  163. // Get the number of parameters.
  164. int paramCount = lua_gettop(state);
  165. // Attempt to match the parameters to a valid binding.
  166. switch (paramCount)
  167. {
  168. case 1:
  169. {
  170. if ((lua_type(state, 1) == LUA_TUSERDATA))
  171. {
  172. PhysicsGhostObject* instance = getInstance(state);
  173. void* returnPtr = (void*)instance->getCollisionShape();
  174. if (returnPtr)
  175. {
  176. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  177. object->instance = returnPtr;
  178. object->owns = false;
  179. luaL_getmetatable(state, "PhysicsCollisionShape");
  180. lua_setmetatable(state, -2);
  181. }
  182. else
  183. {
  184. lua_pushnil(state);
  185. }
  186. return 1;
  187. }
  188. else
  189. {
  190. lua_pushstring(state, "lua_PhysicsGhostObject_getCollisionShape - Failed to match the given parameters to a valid function signature.");
  191. lua_error(state);
  192. }
  193. break;
  194. }
  195. default:
  196. {
  197. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  198. lua_error(state);
  199. break;
  200. }
  201. }
  202. return 0;
  203. }
  204. int lua_PhysicsGhostObject_getNode(lua_State* state)
  205. {
  206. // Get the number of parameters.
  207. int paramCount = lua_gettop(state);
  208. // Attempt to match the parameters to a valid binding.
  209. switch (paramCount)
  210. {
  211. case 1:
  212. {
  213. if ((lua_type(state, 1) == LUA_TUSERDATA))
  214. {
  215. PhysicsGhostObject* instance = getInstance(state);
  216. void* returnPtr = (void*)instance->getNode();
  217. if (returnPtr)
  218. {
  219. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  220. object->instance = returnPtr;
  221. object->owns = false;
  222. luaL_getmetatable(state, "Node");
  223. lua_setmetatable(state, -2);
  224. }
  225. else
  226. {
  227. lua_pushnil(state);
  228. }
  229. return 1;
  230. }
  231. else
  232. {
  233. lua_pushstring(state, "lua_PhysicsGhostObject_getNode - Failed to match the given parameters to a valid function signature.");
  234. lua_error(state);
  235. }
  236. break;
  237. }
  238. default:
  239. {
  240. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  241. lua_error(state);
  242. break;
  243. }
  244. }
  245. return 0;
  246. }
  247. int lua_PhysicsGhostObject_getShapeType(lua_State* state)
  248. {
  249. // Get the number of parameters.
  250. int paramCount = lua_gettop(state);
  251. // Attempt to match the parameters to a valid binding.
  252. switch (paramCount)
  253. {
  254. case 1:
  255. {
  256. if ((lua_type(state, 1) == LUA_TUSERDATA))
  257. {
  258. PhysicsGhostObject* instance = getInstance(state);
  259. PhysicsCollisionShape::Type result = instance->getShapeType();
  260. // Push the return value onto the stack.
  261. lua_pushstring(state, lua_stringFromEnum_PhysicsCollisionShapeType(result));
  262. return 1;
  263. }
  264. else
  265. {
  266. lua_pushstring(state, "lua_PhysicsGhostObject_getShapeType - Failed to match the given parameters to a valid function signature.");
  267. lua_error(state);
  268. }
  269. break;
  270. }
  271. default:
  272. {
  273. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  274. lua_error(state);
  275. break;
  276. }
  277. }
  278. return 0;
  279. }
  280. int lua_PhysicsGhostObject_getType(lua_State* state)
  281. {
  282. // Get the number of parameters.
  283. int paramCount = lua_gettop(state);
  284. // Attempt to match the parameters to a valid binding.
  285. switch (paramCount)
  286. {
  287. case 1:
  288. {
  289. if ((lua_type(state, 1) == LUA_TUSERDATA))
  290. {
  291. PhysicsGhostObject* instance = getInstance(state);
  292. PhysicsCollisionObject::Type result = instance->getType();
  293. // Push the return value onto the stack.
  294. lua_pushstring(state, lua_stringFromEnum_PhysicsCollisionObjectType(result));
  295. return 1;
  296. }
  297. else
  298. {
  299. lua_pushstring(state, "lua_PhysicsGhostObject_getType - Failed to match the given parameters to a valid function signature.");
  300. lua_error(state);
  301. }
  302. break;
  303. }
  304. default:
  305. {
  306. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  307. lua_error(state);
  308. break;
  309. }
  310. }
  311. return 0;
  312. }
  313. int lua_PhysicsGhostObject_isDynamic(lua_State* state)
  314. {
  315. // Get the number of parameters.
  316. int paramCount = lua_gettop(state);
  317. // Attempt to match the parameters to a valid binding.
  318. switch (paramCount)
  319. {
  320. case 1:
  321. {
  322. if ((lua_type(state, 1) == LUA_TUSERDATA))
  323. {
  324. PhysicsGhostObject* instance = getInstance(state);
  325. bool result = instance->isDynamic();
  326. // Push the return value onto the stack.
  327. lua_pushboolean(state, result);
  328. return 1;
  329. }
  330. else
  331. {
  332. lua_pushstring(state, "lua_PhysicsGhostObject_isDynamic - Failed to match the given parameters to a valid function signature.");
  333. lua_error(state);
  334. }
  335. break;
  336. }
  337. default:
  338. {
  339. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  340. lua_error(state);
  341. break;
  342. }
  343. }
  344. return 0;
  345. }
  346. int lua_PhysicsGhostObject_isEnabled(lua_State* state)
  347. {
  348. // Get the number of parameters.
  349. int paramCount = lua_gettop(state);
  350. // Attempt to match the parameters to a valid binding.
  351. switch (paramCount)
  352. {
  353. case 1:
  354. {
  355. if ((lua_type(state, 1) == LUA_TUSERDATA))
  356. {
  357. PhysicsGhostObject* instance = getInstance(state);
  358. bool result = instance->isEnabled();
  359. // Push the return value onto the stack.
  360. lua_pushboolean(state, result);
  361. return 1;
  362. }
  363. else
  364. {
  365. lua_pushstring(state, "lua_PhysicsGhostObject_isEnabled - Failed to match the given parameters to a valid function signature.");
  366. lua_error(state);
  367. }
  368. break;
  369. }
  370. default:
  371. {
  372. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  373. lua_error(state);
  374. break;
  375. }
  376. }
  377. return 0;
  378. }
  379. int lua_PhysicsGhostObject_isKinematic(lua_State* state)
  380. {
  381. // Get the number of parameters.
  382. int paramCount = lua_gettop(state);
  383. // Attempt to match the parameters to a valid binding.
  384. switch (paramCount)
  385. {
  386. case 1:
  387. {
  388. if ((lua_type(state, 1) == LUA_TUSERDATA))
  389. {
  390. PhysicsGhostObject* instance = getInstance(state);
  391. bool result = instance->isKinematic();
  392. // Push the return value onto the stack.
  393. lua_pushboolean(state, result);
  394. return 1;
  395. }
  396. else
  397. {
  398. lua_pushstring(state, "lua_PhysicsGhostObject_isKinematic - Failed to match the given parameters to a valid function signature.");
  399. lua_error(state);
  400. }
  401. break;
  402. }
  403. default:
  404. {
  405. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  406. lua_error(state);
  407. break;
  408. }
  409. }
  410. return 0;
  411. }
  412. int lua_PhysicsGhostObject_removeCollisionListener(lua_State* state)
  413. {
  414. // Get the number of parameters.
  415. int paramCount = lua_gettop(state);
  416. // Attempt to match the parameters to a valid binding.
  417. switch (paramCount)
  418. {
  419. case 2:
  420. {
  421. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  422. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  423. {
  424. // Get parameter 1 off the stack.
  425. ScriptUtil::LuaArray<PhysicsCollisionObject::CollisionListener> param1 = ScriptUtil::getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
  426. PhysicsGhostObject* instance = getInstance(state);
  427. instance->removeCollisionListener(param1);
  428. return 0;
  429. }
  430. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  431. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
  432. {
  433. // Get parameter 1 off the stack.
  434. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  435. PhysicsGhostObject* instance = getInstance(state);
  436. instance->removeCollisionListener(param1);
  437. return 0;
  438. }
  439. else
  440. {
  441. lua_pushstring(state, "lua_PhysicsGhostObject_removeCollisionListener - Failed to match the given parameters to a valid function signature.");
  442. lua_error(state);
  443. }
  444. break;
  445. }
  446. case 3:
  447. {
  448. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  449. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  450. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  451. {
  452. // Get parameter 1 off the stack.
  453. ScriptUtil::LuaArray<PhysicsCollisionObject::CollisionListener> param1 = ScriptUtil::getObjectPointer<PhysicsCollisionObject::CollisionListener>(2, "PhysicsCollisionObjectCollisionListener", false);
  454. // Get parameter 2 off the stack.
  455. ScriptUtil::LuaArray<PhysicsCollisionObject> param2 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
  456. PhysicsGhostObject* instance = getInstance(state);
  457. instance->removeCollisionListener(param1, param2);
  458. return 0;
  459. }
  460. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  461. (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL) &&
  462. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  463. {
  464. // Get parameter 1 off the stack.
  465. ScriptUtil::LuaArray<const char> param1 = ScriptUtil::getString(2, false);
  466. // Get parameter 2 off the stack.
  467. ScriptUtil::LuaArray<PhysicsCollisionObject> param2 = ScriptUtil::getObjectPointer<PhysicsCollisionObject>(3, "PhysicsCollisionObject", false);
  468. PhysicsGhostObject* instance = getInstance(state);
  469. instance->removeCollisionListener(param1, param2);
  470. return 0;
  471. }
  472. else
  473. {
  474. lua_pushstring(state, "lua_PhysicsGhostObject_removeCollisionListener - Failed to match the given parameters to a valid function signature.");
  475. lua_error(state);
  476. }
  477. break;
  478. }
  479. default:
  480. {
  481. lua_pushstring(state, "Invalid number of parameters (expected 2 or 3).");
  482. lua_error(state);
  483. break;
  484. }
  485. }
  486. return 0;
  487. }
  488. int lua_PhysicsGhostObject_setEnabled(lua_State* state)
  489. {
  490. // Get the number of parameters.
  491. int paramCount = lua_gettop(state);
  492. // Attempt to match the parameters to a valid binding.
  493. switch (paramCount)
  494. {
  495. case 2:
  496. {
  497. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  498. lua_type(state, 2) == LUA_TBOOLEAN)
  499. {
  500. // Get parameter 1 off the stack.
  501. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  502. PhysicsGhostObject* instance = getInstance(state);
  503. instance->setEnabled(param1);
  504. return 0;
  505. }
  506. else
  507. {
  508. lua_pushstring(state, "lua_PhysicsGhostObject_setEnabled - Failed to match the given parameters to a valid function signature.");
  509. lua_error(state);
  510. }
  511. break;
  512. }
  513. default:
  514. {
  515. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  516. lua_error(state);
  517. break;
  518. }
  519. }
  520. return 0;
  521. }
  522. int lua_PhysicsGhostObject_transformChanged(lua_State* state)
  523. {
  524. // Get the number of parameters.
  525. int paramCount = lua_gettop(state);
  526. // Attempt to match the parameters to a valid binding.
  527. switch (paramCount)
  528. {
  529. case 3:
  530. {
  531. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  532. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL) &&
  533. lua_type(state, 3) == LUA_TNUMBER)
  534. {
  535. // Get parameter 1 off the stack.
  536. ScriptUtil::LuaArray<Transform> param1 = ScriptUtil::getObjectPointer<Transform>(2, "Transform", false);
  537. // Get parameter 2 off the stack.
  538. long param2 = (long)luaL_checklong(state, 3);
  539. PhysicsGhostObject* instance = getInstance(state);
  540. instance->transformChanged(param1, param2);
  541. return 0;
  542. }
  543. else
  544. {
  545. lua_pushstring(state, "lua_PhysicsGhostObject_transformChanged - Failed to match the given parameters to a valid function signature.");
  546. lua_error(state);
  547. }
  548. break;
  549. }
  550. default:
  551. {
  552. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  553. lua_error(state);
  554. break;
  555. }
  556. }
  557. return 0;
  558. }
  559. }