lua_TerrainPatch.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_TerrainPatch.h"
  4. #include "Base.h"
  5. #include "Camera.h"
  6. #include "Game.h"
  7. #include "MeshPart.h"
  8. #include "Node.h"
  9. #include "PhysicsController.h"
  10. #include "Scene.h"
  11. #include "Terrain.h"
  12. #include "TerrainPatch.h"
  13. #include "lua_CameraType.h"
  14. namespace gameplay
  15. {
  16. void luaRegister_TerrainPatch()
  17. {
  18. const luaL_Reg lua_members[] =
  19. {
  20. {"cameraChanged", lua_TerrainPatch_cameraChanged},
  21. {"getBoundingBox", lua_TerrainPatch_getBoundingBox},
  22. {"getMaterial", lua_TerrainPatch_getMaterial},
  23. {"getMaterialCount", lua_TerrainPatch_getMaterialCount},
  24. {NULL, NULL}
  25. };
  26. const luaL_Reg* lua_statics = NULL;
  27. std::vector<std::string> scopePath;
  28. gameplay::ScriptUtil::registerClass("TerrainPatch", lua_members, NULL, NULL, lua_statics, scopePath);
  29. }
  30. static TerrainPatch* getInstance(lua_State* state)
  31. {
  32. void* userdata = luaL_checkudata(state, 1, "TerrainPatch");
  33. luaL_argcheck(state, userdata != NULL, 1, "'TerrainPatch' expected.");
  34. return (TerrainPatch*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  35. }
  36. int lua_TerrainPatch_cameraChanged(lua_State* state)
  37. {
  38. // Get the number of parameters.
  39. int paramCount = lua_gettop(state);
  40. // Attempt to match the parameters to a valid binding.
  41. switch (paramCount)
  42. {
  43. case 2:
  44. {
  45. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  46. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  47. {
  48. // Get parameter 1 off the stack.
  49. bool param1Valid;
  50. gameplay::ScriptUtil::LuaArray<Camera> param1 = gameplay::ScriptUtil::getObjectPointer<Camera>(2, "Camera", false, &param1Valid);
  51. if (!param1Valid)
  52. {
  53. lua_pushstring(state, "Failed to convert parameter 1 to type 'Camera'.");
  54. lua_error(state);
  55. }
  56. TerrainPatch* instance = getInstance(state);
  57. instance->cameraChanged(param1);
  58. return 0;
  59. }
  60. lua_pushstring(state, "lua_TerrainPatch_cameraChanged - Failed to match the given parameters to a valid function signature.");
  61. lua_error(state);
  62. break;
  63. }
  64. default:
  65. {
  66. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  67. lua_error(state);
  68. break;
  69. }
  70. }
  71. return 0;
  72. }
  73. int lua_TerrainPatch_getBoundingBox(lua_State* state)
  74. {
  75. // Get the number of parameters.
  76. int paramCount = lua_gettop(state);
  77. // Attempt to match the parameters to a valid binding.
  78. switch (paramCount)
  79. {
  80. case 2:
  81. {
  82. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  83. lua_type(state, 2) == LUA_TBOOLEAN)
  84. {
  85. // Get parameter 1 off the stack.
  86. bool param1 = gameplay::ScriptUtil::luaCheckBool(state, 2);
  87. TerrainPatch* instance = getInstance(state);
  88. void* returnPtr = (void*)&(instance->getBoundingBox(param1));
  89. if (returnPtr)
  90. {
  91. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  92. object->instance = returnPtr;
  93. object->owns = false;
  94. luaL_getmetatable(state, "BoundingBox");
  95. lua_setmetatable(state, -2);
  96. }
  97. else
  98. {
  99. lua_pushnil(state);
  100. }
  101. return 1;
  102. }
  103. lua_pushstring(state, "lua_TerrainPatch_getBoundingBox - Failed to match the given parameters to a valid function signature.");
  104. lua_error(state);
  105. break;
  106. }
  107. default:
  108. {
  109. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  110. lua_error(state);
  111. break;
  112. }
  113. }
  114. return 0;
  115. }
  116. int lua_TerrainPatch_getMaterial(lua_State* state)
  117. {
  118. // Get the number of parameters.
  119. int paramCount = lua_gettop(state);
  120. // Attempt to match the parameters to a valid binding.
  121. switch (paramCount)
  122. {
  123. case 1:
  124. {
  125. if ((lua_type(state, 1) == LUA_TUSERDATA))
  126. {
  127. TerrainPatch* instance = getInstance(state);
  128. void* returnPtr = (void*)instance->getMaterial();
  129. if (returnPtr)
  130. {
  131. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  132. object->instance = returnPtr;
  133. object->owns = false;
  134. luaL_getmetatable(state, "Material");
  135. lua_setmetatable(state, -2);
  136. }
  137. else
  138. {
  139. lua_pushnil(state);
  140. }
  141. return 1;
  142. }
  143. lua_pushstring(state, "lua_TerrainPatch_getMaterial - Failed to match the given parameters to a valid function signature.");
  144. lua_error(state);
  145. break;
  146. }
  147. case 2:
  148. {
  149. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  150. lua_type(state, 2) == LUA_TNUMBER)
  151. {
  152. // Get parameter 1 off the stack.
  153. int param1 = (int)luaL_checkint(state, 2);
  154. TerrainPatch* instance = getInstance(state);
  155. void* returnPtr = (void*)instance->getMaterial(param1);
  156. if (returnPtr)
  157. {
  158. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  159. object->instance = returnPtr;
  160. object->owns = false;
  161. luaL_getmetatable(state, "Material");
  162. lua_setmetatable(state, -2);
  163. }
  164. else
  165. {
  166. lua_pushnil(state);
  167. }
  168. return 1;
  169. }
  170. lua_pushstring(state, "lua_TerrainPatch_getMaterial - Failed to match the given parameters to a valid function signature.");
  171. lua_error(state);
  172. break;
  173. }
  174. default:
  175. {
  176. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  177. lua_error(state);
  178. break;
  179. }
  180. }
  181. return 0;
  182. }
  183. int lua_TerrainPatch_getMaterialCount(lua_State* state)
  184. {
  185. // Get the number of parameters.
  186. int paramCount = lua_gettop(state);
  187. // Attempt to match the parameters to a valid binding.
  188. switch (paramCount)
  189. {
  190. case 1:
  191. {
  192. if ((lua_type(state, 1) == LUA_TUSERDATA))
  193. {
  194. TerrainPatch* instance = getInstance(state);
  195. unsigned int result = instance->getMaterialCount();
  196. // Push the return value onto the stack.
  197. lua_pushunsigned(state, result);
  198. return 1;
  199. }
  200. lua_pushstring(state, "lua_TerrainPatch_getMaterialCount - Failed to match the given parameters to a valid function signature.");
  201. lua_error(state);
  202. break;
  203. }
  204. default:
  205. {
  206. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  207. lua_error(state);
  208. break;
  209. }
  210. }
  211. return 0;
  212. }
  213. }