lua_PhysicsGhostObject.cpp 22 KB

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