lua_api.cpp 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095
  1. /*
  2. * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "color4.h"
  6. #include "console_server.h"
  7. #include "debug_line.h"
  8. #include "device.h"
  9. #include "gui.h"
  10. #include "input_device.h"
  11. #include "input_manager.h"
  12. #include "intersection.h"
  13. #include "lua_environment.h"
  14. #include "lua_stack.h"
  15. #include "math_types.h"
  16. #include "math_utils.h"
  17. #include "matrix4x4.h"
  18. #include "physics_world.h"
  19. #include "plane.h"
  20. #include "profiler.h"
  21. #include "quaternion.h"
  22. #include "render_world.h"
  23. #include "resource_manager.h"
  24. #include "resource_package.h"
  25. #include "scene_graph.h"
  26. #include "sound_world.h"
  27. #include "string_stream.h"
  28. #include "temp_allocator.h"
  29. #include "unit_manager.h"
  30. #include "vector2.h"
  31. #include "vector3.h"
  32. #include "world.h"
  33. namespace crown
  34. {
  35. struct LightInfo
  36. {
  37. const char* name;
  38. LightType::Enum type;
  39. };
  40. static LightInfo s_light[] =
  41. {
  42. { "directional", LightType::DIRECTIONAL },
  43. { "omni", LightType::OMNI },
  44. { "spot", LightType::SPOT }
  45. };
  46. CE_STATIC_ASSERT(CE_COUNTOF(s_light) == LightType::COUNT);
  47. struct ProjectionInfo
  48. {
  49. const char* name;
  50. ProjectionType::Enum type;
  51. };
  52. static ProjectionInfo s_projection[] =
  53. {
  54. { "orthographic", ProjectionType::ORTHOGRAPHIC },
  55. { "perspective", ProjectionType::PERSPECTIVE }
  56. };
  57. CE_STATIC_ASSERT(CE_COUNTOF(s_projection) == ProjectionType::COUNT);
  58. struct RaycastInfo
  59. {
  60. const char* name;
  61. RaycastMode::Enum mode;
  62. };
  63. static RaycastInfo s_raycast[] =
  64. {
  65. { "closest", RaycastMode::CLOSEST },
  66. { "all", RaycastMode::ALL }
  67. };
  68. CE_STATIC_ASSERT(CE_COUNTOF(s_raycast) == RaycastMode::COUNT);
  69. static LightType::Enum name_to_light_type(const char* name)
  70. {
  71. for (uint32_t i = 0; i < CE_COUNTOF(s_light); ++i)
  72. {
  73. if (strcmp(s_light[i].name, name) == 0)
  74. return s_light[i].type;
  75. }
  76. return LightType::COUNT;
  77. }
  78. static ProjectionType::Enum name_to_projection_type(const char* name)
  79. {
  80. for (uint32_t i = 0; i < CE_COUNTOF(s_projection); ++i)
  81. {
  82. if (strcmp(s_projection[i].name, name) == 0)
  83. return s_projection[i].type;
  84. }
  85. return ProjectionType::COUNT;
  86. }
  87. static RaycastMode::Enum name_to_raycast_mode(const char* name)
  88. {
  89. for (uint32_t i = 0; i < CE_COUNTOF(s_raycast); ++i)
  90. {
  91. if (strcmp(s_raycast[i].name, name) == 0)
  92. return s_raycast[i].mode;
  93. }
  94. return RaycastMode::COUNT;
  95. }
  96. static int math_ray_plane_intersection(lua_State* L)
  97. {
  98. LuaStack stack(L);
  99. const Plane p = plane::from_point_and_normal(stack.get_vector3(3)
  100. , stack.get_vector3(4)
  101. );
  102. const float t = ray_plane_intersection(stack.get_vector3(1)
  103. , stack.get_vector3(2)
  104. , p
  105. );
  106. stack.push_float(t);
  107. return 1;
  108. }
  109. static int math_ray_disc_intersection(lua_State* L)
  110. {
  111. LuaStack stack(L);
  112. const float t = ray_disc_intersection(stack.get_vector3(1)
  113. , stack.get_vector3(2)
  114. , stack.get_vector3(3)
  115. , stack.get_float(4)
  116. , stack.get_vector3(5)
  117. );
  118. stack.push_float(t);
  119. return 1;
  120. }
  121. static int math_ray_sphere_intersection(lua_State* L)
  122. {
  123. LuaStack stack(L);
  124. Sphere s;
  125. s.c = stack.get_vector3(3);
  126. s.r = stack.get_float(4);
  127. const float t = ray_sphere_intersection(stack.get_vector3(1)
  128. , stack.get_vector3(2)
  129. , s
  130. );
  131. stack.push_float(t);
  132. return 1;
  133. }
  134. static int math_ray_obb_intersection(lua_State* L)
  135. {
  136. LuaStack stack(L);
  137. const float t = ray_obb_intersection(stack.get_vector3(1)
  138. , stack.get_vector3(2)
  139. , stack.get_matrix4x4(3)
  140. , stack.get_vector3(4)
  141. );
  142. stack.push_float(t);
  143. return 1;
  144. }
  145. static int vector3_new(lua_State* L)
  146. {
  147. LuaStack stack(L);
  148. stack.push_vector3(vector3(stack.get_float(1), stack.get_float(2), stack.get_float(3)));
  149. return 1;
  150. }
  151. static int vector3_ctor(lua_State* L)
  152. {
  153. LuaStack stack(L);
  154. stack.remove(1); // Remove table
  155. return vector3_new(L);
  156. }
  157. static int vector3_x(lua_State* L)
  158. {
  159. LuaStack stack(L);
  160. stack.push_float(stack.get_vector3(1).x);
  161. return 1;
  162. }
  163. static int vector3_y(lua_State* L)
  164. {
  165. LuaStack stack(L);
  166. stack.push_float(stack.get_vector3(1).y);
  167. return 1;
  168. }
  169. static int vector3_z(lua_State* L)
  170. {
  171. LuaStack stack(L);
  172. stack.push_float(stack.get_vector3(1).z);
  173. return 1;
  174. }
  175. static int vector3_set_x(lua_State* L)
  176. {
  177. LuaStack stack(L);
  178. stack.get_vector3(1).x = stack.get_float(2);
  179. return 0;
  180. }
  181. static int vector3_set_y(lua_State* L)
  182. {
  183. LuaStack stack(L);
  184. stack.get_vector3(1).y = stack.get_float(2);
  185. return 0;
  186. }
  187. static int vector3_set_z(lua_State* L)
  188. {
  189. LuaStack stack(L);
  190. stack.get_vector3(1).z = stack.get_float(2);
  191. return 0;
  192. }
  193. static int vector3_elements(lua_State* L)
  194. {
  195. LuaStack stack(L);
  196. Vector3& a = stack.get_vector3(1);
  197. stack.push_float(a.x);
  198. stack.push_float(a.y);
  199. stack.push_float(a.z);
  200. return 3;
  201. }
  202. static int vector3_add(lua_State* L)
  203. {
  204. LuaStack stack(L);
  205. stack.push_vector3(stack.get_vector3(1) + stack.get_vector3(2));
  206. return 1;
  207. }
  208. static int vector3_subtract(lua_State* L)
  209. {
  210. LuaStack stack(L);
  211. stack.push_vector3(stack.get_vector3(1) - stack.get_vector3(2));
  212. return 1;
  213. }
  214. static int vector3_multiply(lua_State* L)
  215. {
  216. LuaStack stack(L);
  217. stack.push_vector3(stack.get_vector3(1) * stack.get_float(2));
  218. return 1;
  219. }
  220. static int vector3_dot(lua_State* L)
  221. {
  222. LuaStack stack(L);
  223. stack.push_float(dot(stack.get_vector3(1), stack.get_vector3(2)));
  224. return 1;
  225. }
  226. static int vector3_cross(lua_State* L)
  227. {
  228. LuaStack stack(L);
  229. stack.push_vector3(cross(stack.get_vector3(1), stack.get_vector3(2)));
  230. return 1;
  231. }
  232. static int vector3_equal(lua_State* L)
  233. {
  234. LuaStack stack(L);
  235. stack.push_bool(stack.get_vector3(1) == stack.get_vector3(2));
  236. return 1;
  237. }
  238. static int vector3_length(lua_State* L)
  239. {
  240. LuaStack stack(L);
  241. stack.push_float(length(stack.get_vector3(1)));
  242. return 1;
  243. }
  244. static int vector3_length_squared(lua_State* L)
  245. {
  246. LuaStack stack(L);
  247. stack.push_float(length_squared(stack.get_vector3(1)));
  248. return 1;
  249. }
  250. static int vector3_set_length(lua_State* L)
  251. {
  252. LuaStack stack(L);
  253. set_length(stack.get_vector3(1), stack.get_float(2));
  254. return 0;
  255. }
  256. static int vector3_normalize(lua_State* L)
  257. {
  258. LuaStack stack(L);
  259. stack.push_vector3(normalize(stack.get_vector3(1)));
  260. return 1;
  261. }
  262. static int vector3_distance(lua_State* L)
  263. {
  264. LuaStack stack(L);
  265. stack.push_float(distance(stack.get_vector3(1), stack.get_vector3(2)));
  266. return 1;
  267. }
  268. static int vector3_distance_squared(lua_State* L)
  269. {
  270. LuaStack stack(L);
  271. stack.push_float(distance_squared(stack.get_vector3(1), stack.get_vector3(2)));
  272. return 1;
  273. }
  274. static int vector3_angle(lua_State* L)
  275. {
  276. LuaStack stack(L);
  277. stack.push_float(angle(stack.get_vector3(1), stack.get_vector3(2)));
  278. return 1;
  279. }
  280. static int vector3_max(lua_State* L)
  281. {
  282. LuaStack stack(L);
  283. stack.push_vector3(max(stack.get_vector3(1), stack.get_vector3(2)));
  284. return 1;
  285. }
  286. static int vector3_min(lua_State* L)
  287. {
  288. LuaStack stack(L);
  289. stack.push_vector3(min(stack.get_vector3(1), stack.get_vector3(2)));
  290. return 1;
  291. }
  292. static int vector3_lerp(lua_State* L)
  293. {
  294. LuaStack stack(L);
  295. stack.push_vector3(lerp(stack.get_vector3(1), stack.get_vector3(2), stack.get_float(3)));
  296. return 1;
  297. }
  298. static int vector3_forward(lua_State* L)
  299. {
  300. LuaStack stack(L);
  301. stack.push_vector3(VECTOR3_FORWARD);
  302. return 1;
  303. }
  304. static int vector3_backward(lua_State* L)
  305. {
  306. LuaStack stack(L);
  307. stack.push_vector3(VECTOR3_BACKWARD);
  308. return 1;
  309. }
  310. static int vector3_left(lua_State* L)
  311. {
  312. LuaStack stack(L);
  313. stack.push_vector3(VECTOR3_LEFT);
  314. return 1;
  315. }
  316. static int vector3_right(lua_State* L)
  317. {
  318. LuaStack stack(L);
  319. stack.push_vector3(VECTOR3_RIGHT);
  320. return 1;
  321. }
  322. static int vector3_up(lua_State* L)
  323. {
  324. LuaStack stack(L);
  325. stack.push_vector3(VECTOR3_UP);
  326. return 1;
  327. }
  328. static int vector3_down(lua_State* L)
  329. {
  330. LuaStack stack(L);
  331. stack.push_vector3(VECTOR3_DOWN);
  332. return 1;
  333. }
  334. static int vector3_zero(lua_State* L)
  335. {
  336. LuaStack stack(L);
  337. stack.push_vector3(VECTOR3_ZERO);
  338. return 1;
  339. }
  340. static int vector3_to_string(lua_State* L)
  341. {
  342. LuaStack stack(L);
  343. const Vector3 v = stack.get_vector3(1);
  344. char buf[256];
  345. snprintf(buf, sizeof(buf), "%.4f %.4f %.4f", v.x, v.y, v.z);
  346. stack.push_string(buf);
  347. return 1;
  348. }
  349. static int vector2_new(lua_State* L)
  350. {
  351. LuaStack stack(L);
  352. stack.push_vector2(vector2(stack.get_float(1), stack.get_float(2)));
  353. return 1;
  354. }
  355. static int vector2_ctor(lua_State* L)
  356. {
  357. LuaStack stack(L);
  358. stack.remove(1); // Remove table
  359. return vector2_new(L);
  360. }
  361. static int vector3box_new(lua_State* L)
  362. {
  363. LuaStack stack(L);
  364. if (stack.num_args() == 0)
  365. stack.push_vector3box(VECTOR3_ZERO);
  366. else if (stack.num_args() == 1)
  367. stack.push_vector3box(stack.get_vector3(1));
  368. else
  369. stack.push_vector3box(vector3(stack.get_float(1)
  370. , stack.get_float(2)
  371. , stack.get_float(3)));
  372. return 1;
  373. }
  374. static int vector3box_ctor(lua_State* L)
  375. {
  376. LuaStack stack(L);
  377. stack.remove(1); // Remove table
  378. return vector3box_new(L);
  379. }
  380. static int vector3box_store(lua_State* L)
  381. {
  382. LuaStack stack(L);
  383. Vector3& v = stack.get_vector3box(1);
  384. if (stack.num_args() == 2)
  385. v = stack.get_vector3(2);
  386. else
  387. v = vector3(stack.get_float(2)
  388. , stack.get_float(3)
  389. , stack.get_float(4));
  390. return 0;
  391. }
  392. static int vector3box_unbox(lua_State* L)
  393. {
  394. LuaStack stack(L);
  395. stack.push_vector3(stack.get_vector3box(1));
  396. return 1;
  397. }
  398. static int vector3box_tostring(lua_State* L)
  399. {
  400. LuaStack stack(L);
  401. Vector3& v = stack.get_vector3box(1);
  402. stack.push_fstring("Vector3Box (%p)", &v);
  403. return 1;
  404. }
  405. static int matrix4x4_new(lua_State* L)
  406. {
  407. LuaStack stack(L);
  408. stack.push_matrix4x4(matrix4x4(stack.get_float(1)
  409. , stack.get_float(2)
  410. , stack.get_float(3)
  411. , stack.get_float(4)
  412. , stack.get_float(5)
  413. , stack.get_float(6)
  414. , stack.get_float(7)
  415. , stack.get_float(8)
  416. , stack.get_float(9)
  417. , stack.get_float(10)
  418. , stack.get_float(11)
  419. , stack.get_float(12)
  420. , stack.get_float(13)
  421. , stack.get_float(14)
  422. , stack.get_float(15)
  423. , stack.get_float(16)));
  424. return 1;
  425. }
  426. static int matrix4x4_ctor(lua_State* L)
  427. {
  428. LuaStack stack(L);
  429. stack.remove(1); // Remove table
  430. return matrix4x4_new(L);
  431. }
  432. static int matrix4x4_from_quaternion(lua_State* L)
  433. {
  434. LuaStack stack(L);
  435. stack.push_matrix4x4(matrix4x4(stack.get_quaternion(1), vector3(0, 0, 0)));
  436. return 1;
  437. }
  438. static int matrix4x4_from_translation(lua_State* L)
  439. {
  440. LuaStack stack(L);
  441. stack.push_matrix4x4(matrix4x4(QUATERNION_IDENTITY, stack.get_vector3(1)));
  442. return 1;
  443. }
  444. static int matrix4x4_from_quaternion_translation(lua_State* L)
  445. {
  446. LuaStack stack(L);
  447. stack.push_matrix4x4(matrix4x4(stack.get_quaternion(1), stack.get_vector3(2)));
  448. return 1;
  449. }
  450. static int matrix4x4_from_axes(lua_State* L)
  451. {
  452. LuaStack stack(L);
  453. stack.push_matrix4x4(matrix4x4(stack.get_vector3(1), stack.get_vector3(2), stack.get_vector3(3), stack.get_vector3(4)));
  454. return 1;
  455. }
  456. static int matrix4x4_copy(lua_State* L)
  457. {
  458. LuaStack stack(L);
  459. stack.push_matrix4x4(stack.get_matrix4x4(1));
  460. return 1;
  461. }
  462. static int matrix4x4_add(lua_State* L)
  463. {
  464. LuaStack stack(L);
  465. stack.push_matrix4x4(stack.get_matrix4x4(1) + stack.get_matrix4x4(2));
  466. return 1;
  467. }
  468. static int matrix4x4_subtract(lua_State* L)
  469. {
  470. LuaStack stack(L);
  471. stack.push_matrix4x4(stack.get_matrix4x4(1) - stack.get_matrix4x4(2));
  472. return 1;
  473. }
  474. static int matrix4x4_multiply(lua_State* L)
  475. {
  476. LuaStack stack(L);
  477. stack.push_matrix4x4(stack.get_matrix4x4(1) * stack.get_matrix4x4(2));
  478. return 1;
  479. }
  480. static int matrix4x4_transpose(lua_State* L)
  481. {
  482. LuaStack stack(L);
  483. stack.push_matrix4x4(transpose(stack.get_matrix4x4(1)));
  484. return 1;
  485. }
  486. static int matrix4x4_determinant(lua_State* L)
  487. {
  488. LuaStack stack(L);
  489. stack.push_float(determinant(stack.get_matrix4x4(1)));
  490. return 1;
  491. }
  492. static int matrix4x4_invert(lua_State* L)
  493. {
  494. LuaStack stack(L);
  495. stack.push_matrix4x4(invert(stack.get_matrix4x4(1)));
  496. return 1;
  497. }
  498. static int matrix4x4_x(lua_State* L)
  499. {
  500. LuaStack stack(L);
  501. stack.push_vector3(x(stack.get_matrix4x4(1)));
  502. return 1;
  503. }
  504. static int matrix4x4_y(lua_State* L)
  505. {
  506. LuaStack stack(L);
  507. stack.push_vector3(y(stack.get_matrix4x4(1)));
  508. return 1;
  509. }
  510. static int matrix4x4_z(lua_State* L)
  511. {
  512. LuaStack stack(L);
  513. stack.push_vector3(z(stack.get_matrix4x4(1)));
  514. return 1;
  515. }
  516. static int matrix4x4_set_x(lua_State* L)
  517. {
  518. LuaStack stack(L);
  519. set_x(stack.get_matrix4x4(1), stack.get_vector3(2));
  520. return 0;
  521. }
  522. static int matrix4x4_set_y(lua_State* L)
  523. {
  524. LuaStack stack(L);
  525. set_y(stack.get_matrix4x4(1), stack.get_vector3(2));
  526. return 0;
  527. }
  528. static int matrix4x4_set_z(lua_State* L)
  529. {
  530. LuaStack stack(L);
  531. set_z(stack.get_matrix4x4(1), stack.get_vector3(2));
  532. return 0;
  533. }
  534. static int matrix4x4_translation(lua_State* L)
  535. {
  536. LuaStack stack(L);
  537. stack.push_vector3(translation(stack.get_matrix4x4(1)));
  538. return 1;
  539. }
  540. static int matrix4x4_set_translation(lua_State* L)
  541. {
  542. LuaStack stack(L);
  543. set_translation(stack.get_matrix4x4(1), stack.get_vector3(2));
  544. return 0;
  545. }
  546. static int matrix4x4_rotation(lua_State* L)
  547. {
  548. LuaStack stack(L);
  549. stack.push_quaternion(rotation(stack.get_matrix4x4(1)));
  550. return 1;
  551. }
  552. static int matrix4x4_set_rotation(lua_State* L)
  553. {
  554. LuaStack stack(L);
  555. set_rotation(stack.get_matrix4x4(1), stack.get_quaternion(2));
  556. return 0;
  557. }
  558. static int matrix4x4_identity(lua_State* L)
  559. {
  560. LuaStack stack(L);
  561. stack.push_matrix4x4(MATRIX4X4_IDENTITY);
  562. return 1;
  563. }
  564. static int matrix4x4_transform(lua_State* L)
  565. {
  566. LuaStack stack(L);
  567. stack.push_vector3(stack.get_vector3(2) * stack.get_matrix4x4(1));
  568. return 1;
  569. }
  570. static int matrix4x4_to_string(lua_State* L)
  571. {
  572. LuaStack stack(L);
  573. Matrix4x4& a = stack.get_matrix4x4(1);
  574. char buf[1024];
  575. snprintf(buf, sizeof(buf),
  576. "%.4f, %.4f, %.4f, %.4f\n"
  577. "%.4f, %.4f, %.4f, %.4f\n"
  578. "%.4f, %.4f, %.4f, %.4f\n"
  579. "%.4f, %.4f, %.4f, %.4f"
  580. , a.x.x, a.x.y, a.x.z, a.y.w
  581. , a.y.x, a.y.y, a.y.z, a.y.w
  582. , a.z.x, a.z.y, a.z.z, a.z.w
  583. , a.t.x, a.t.y, a.t.z, a.t.w
  584. );
  585. stack.push_string(buf);
  586. return 1;
  587. }
  588. static int matrix4x4box_new(lua_State* L)
  589. {
  590. LuaStack stack(L);
  591. if (stack.num_args() == 0)
  592. stack.push_matrix4x4(MATRIX4X4_IDENTITY);
  593. else
  594. stack.push_matrix4x4box(stack.get_matrix4x4(1));
  595. return 1;
  596. }
  597. static int matrix4x4box_ctor(lua_State* L)
  598. {
  599. LuaStack stack(L);
  600. stack.remove(1); // Remove table
  601. return matrix4x4box_new(L);
  602. }
  603. static int matrix4x4box_store(lua_State* L)
  604. {
  605. LuaStack stack(L);
  606. stack.get_matrix4x4box(1) = stack.get_matrix4x4(2);
  607. return 0;
  608. }
  609. static int matrix4x4box_unbox(lua_State* L)
  610. {
  611. LuaStack stack(L);
  612. stack.push_matrix4x4(stack.get_matrix4x4box(1));
  613. return 1;
  614. }
  615. static int matrix4x4box_tostring(lua_State* L)
  616. {
  617. LuaStack stack(L);
  618. Matrix4x4& m = stack.get_matrix4x4box(1);
  619. stack.push_fstring("Matrix4x4Box (%p)", &m);
  620. return 1;
  621. }
  622. static int quaternion_new(lua_State* L)
  623. {
  624. LuaStack stack(L);
  625. stack.push_quaternion(quaternion(stack.get_vector3(1), stack.get_float(2)));
  626. return 1;
  627. }
  628. static int quaternion_ctor(lua_State* L)
  629. {
  630. LuaStack stack(L);
  631. stack.remove(1); // Remove table
  632. return quaternion_new(L);
  633. }
  634. static int quaternion_negate(lua_State* L)
  635. {
  636. LuaStack stack(L);
  637. stack.push_quaternion(-stack.get_quaternion(1));
  638. return 1;
  639. }
  640. static int quaternion_identity(lua_State* L)
  641. {
  642. LuaStack stack(L);
  643. stack.push_quaternion(QUATERNION_IDENTITY);
  644. return 1;
  645. }
  646. static int quaternion_dot(lua_State* L)
  647. {
  648. LuaStack stack(L);
  649. stack.push_float(dot(stack.get_quaternion(1), stack.get_quaternion(2)));
  650. return 1;
  651. }
  652. static int quaternion_length(lua_State* L)
  653. {
  654. LuaStack stack(L);
  655. stack.push_float(length(stack.get_quaternion(1)));
  656. return 1;
  657. }
  658. static int quaternion_normalize(lua_State* L)
  659. {
  660. LuaStack stack(L);
  661. stack.push_quaternion(normalize(stack.get_quaternion(1)));
  662. return 1;
  663. }
  664. static int quaternion_conjugate(lua_State* L)
  665. {
  666. LuaStack stack(L);
  667. stack.push_quaternion(conjugate(stack.get_quaternion(1)));
  668. return 1;
  669. }
  670. static int quaternion_inverse(lua_State* L)
  671. {
  672. LuaStack stack(L);
  673. stack.push_quaternion(inverse(stack.get_quaternion(1)));
  674. return 1;
  675. }
  676. static int quaternion_multiply(lua_State* L)
  677. {
  678. LuaStack stack(L);
  679. stack.push_quaternion(stack.get_quaternion(1) * stack.get_quaternion(2));
  680. return 1;
  681. }
  682. static int quaternion_multiply_by_scalar(lua_State* L)
  683. {
  684. LuaStack stack(L);
  685. stack.push_quaternion(stack.get_quaternion(1) * stack.get_float(2));
  686. return 1;
  687. }
  688. static int quaternion_power(lua_State* L)
  689. {
  690. LuaStack stack(L);
  691. stack.push_quaternion(power(stack.get_quaternion(1), stack.get_float(2)));
  692. return 1;
  693. }
  694. static int quaternion_elements(lua_State* L)
  695. {
  696. LuaStack stack(L);
  697. const Quaternion& q = stack.get_quaternion(1);
  698. stack.push_float(q.x);
  699. stack.push_float(q.y);
  700. stack.push_float(q.z);
  701. stack.push_float(q.w);
  702. return 4;
  703. }
  704. static int quaternion_look(lua_State* L)
  705. {
  706. LuaStack stack(L);
  707. const Vector3 up = stack.num_args() == 2 ? stack.get_vector3(2) : VECTOR3_YAXIS;
  708. stack.push_quaternion(look(stack.get_vector3(1), up));
  709. return 1;
  710. }
  711. static int quaternion_right(lua_State* L)
  712. {
  713. LuaStack stack(L);
  714. stack.push_vector3(right(stack.get_quaternion(1)));
  715. return 1;
  716. }
  717. static int quaternion_up(lua_State* L)
  718. {
  719. LuaStack stack(L);
  720. stack.push_vector3(up(stack.get_quaternion(1)));
  721. return 1;
  722. }
  723. static int quaternion_forward(lua_State* L)
  724. {
  725. LuaStack stack(L);
  726. stack.push_vector3(forward(stack.get_quaternion(1)));
  727. return 1;
  728. }
  729. static int quaternion_lerp(lua_State* L)
  730. {
  731. LuaStack stack(L);
  732. stack.push_quaternion(lerp(stack.get_quaternion(1), stack.get_quaternion(2), stack.get_float(3)));
  733. return 1;
  734. }
  735. static int quaternion_to_string(lua_State* L)
  736. {
  737. LuaStack stack(L);
  738. const Quaternion q = stack.get_quaternion(1);
  739. char buf[256];
  740. snprintf(buf, sizeof(buf), "%.4f %.4f %.4f %.4f", q.x, q.y, q.z, q.w);
  741. stack.push_string(buf);
  742. return 1;
  743. }
  744. static int quaternionbox_new(lua_State* L)
  745. {
  746. LuaStack stack(L);
  747. if (stack.num_args() == 0)
  748. stack.push_quaternionbox(QUATERNION_IDENTITY);
  749. else if (stack.num_args() == 1)
  750. stack.push_quaternionbox(stack.get_quaternion(1));
  751. else
  752. stack.push_quaternionbox(quaternion(stack.get_float(1)
  753. , stack.get_float(2)
  754. , stack.get_float(3)
  755. , stack.get_float(4)));
  756. return 1;
  757. }
  758. static int quaternionbox_ctor(lua_State* L)
  759. {
  760. LuaStack stack(L);
  761. stack.remove(1); // Remove table
  762. return quaternionbox_new(L);
  763. }
  764. static int quaternionbox_store(lua_State* L)
  765. {
  766. LuaStack stack(L);
  767. Quaternion& q = stack.get_quaternionbox(1);
  768. if (stack.num_args() == 2)
  769. q = stack.get_quaternion(2);
  770. else
  771. q = quaternion(stack.get_float(2)
  772. , stack.get_float(3)
  773. , stack.get_float(4)
  774. , stack.get_float(5));
  775. return 0;
  776. }
  777. static int quaternionbox_unbox(lua_State* L)
  778. {
  779. LuaStack stack(L);
  780. Quaternion& q = stack.get_quaternionbox(1);
  781. stack.push_quaternion(q);
  782. return 1;
  783. }
  784. static int quaternionbox_tostring(lua_State* L)
  785. {
  786. LuaStack stack(L);
  787. Quaternion& q = stack.get_quaternionbox(1);
  788. stack.push_fstring("QuaternionBox (%p)", &q);
  789. return 1;
  790. }
  791. static int color4_new(lua_State* L)
  792. {
  793. LuaStack stack(L);
  794. stack.push_quaternion(quaternion(stack.get_float(1)
  795. , stack.get_float(2)
  796. , stack.get_float(3)
  797. , stack.get_float(4)));
  798. return 1;
  799. }
  800. static int color4_ctor(lua_State* L)
  801. {
  802. LuaStack stack(L);
  803. stack.remove(1); // Remove table
  804. return color4_new(L);
  805. }
  806. static int lightuserdata_add(lua_State* L)
  807. {
  808. LuaStack stack(L);
  809. const Vector3& a = stack.get_vector3(1);
  810. const Vector3& b = stack.get_vector3(2);
  811. stack.push_vector3(a + b);
  812. return 1;
  813. }
  814. static int lightuserdata_sub(lua_State* L)
  815. {
  816. LuaStack stack(L);
  817. const Vector3& a = stack.get_vector3(1);
  818. const Vector3& b = stack.get_vector3(2);
  819. stack.push_vector3(a - b);
  820. return 1;
  821. }
  822. static int lightuserdata_mul(lua_State* L)
  823. {
  824. LuaStack stack(L);
  825. const int i = stack.is_number(1) ? 1 : 2;
  826. stack.push_vector3(stack.get_float(i) * stack.get_vector3(3-i));
  827. return 1;
  828. }
  829. static int lightuserdata_unm(lua_State* L)
  830. {
  831. LuaStack stack(L);
  832. stack.push_vector3(-stack.get_vector3(1));
  833. return 1;
  834. }
  835. static int lightuserdata_index(lua_State* L)
  836. {
  837. LuaStack stack(L);
  838. Vector3& v = stack.get_vector3(1);
  839. const char* s = stack.get_string(2);
  840. switch (s[0])
  841. {
  842. case 'x': stack.push_float(v.x); return 1;
  843. case 'y': stack.push_float(v.y); return 1;
  844. case 'z': stack.push_float(v.z); return 1;
  845. default: LUA_ASSERT(false, stack, "Bad index: '%c'", s[0]); break;
  846. }
  847. return 0;
  848. }
  849. static int lightuserdata_newindex(lua_State* L)
  850. {
  851. LuaStack stack(L);
  852. Vector3& v = stack.get_vector3(1);
  853. const char* s = stack.get_string(2);
  854. const float value = stack.get_float(3);
  855. switch (s[0])
  856. {
  857. case 'x': v.x = value; break;
  858. case 'y': v.y = value; break;
  859. case 'z': v.z = value; break;
  860. default: LUA_ASSERT(false, stack, "Bad index: '%c'", s[0]); break;
  861. }
  862. return 0;
  863. }
  864. static int input_device_name(lua_State* L, InputDevice& id)
  865. {
  866. LuaStack stack(L);
  867. stack.push_string(id.name());
  868. return 1;
  869. }
  870. static int input_device_connected(lua_State* L, InputDevice& id)
  871. {
  872. LuaStack stack(L);
  873. stack.push_bool(id.connected());
  874. return 1;
  875. }
  876. static int input_device_num_buttons(lua_State* L, InputDevice& id)
  877. {
  878. LuaStack stack(L);
  879. stack.push_int(id.num_buttons());
  880. return 1;
  881. }
  882. static int input_device_num_axes(lua_State* L, InputDevice& id)
  883. {
  884. LuaStack stack(L);
  885. stack.push_int(id.num_axes());
  886. return 1;
  887. }
  888. static int input_device_pressed(lua_State* L, InputDevice& id)
  889. {
  890. LuaStack stack(L);
  891. stack.push_bool(id.pressed(stack.get_int(1)));
  892. return 1;
  893. }
  894. static int input_device_released(lua_State* L, InputDevice& id)
  895. {
  896. LuaStack stack(L);
  897. stack.push_bool(id.released(stack.get_int(1)));
  898. return 1;
  899. }
  900. static int input_device_any_pressed(lua_State* L, InputDevice& id)
  901. {
  902. LuaStack stack(L);
  903. stack.push_bool(id.any_pressed());
  904. return 1;
  905. }
  906. static int input_device_any_released(lua_State* L, InputDevice& id)
  907. {
  908. LuaStack stack(L);
  909. stack.push_bool(id.any_released());
  910. return 1;
  911. }
  912. static int input_device_axis(lua_State* L, InputDevice& id)
  913. {
  914. LuaStack stack(L);
  915. stack.push_vector3(id.axis(stack.get_int(1)));
  916. return 1;
  917. }
  918. static int input_device_button_name(lua_State* L, InputDevice& id)
  919. {
  920. LuaStack stack(L);
  921. stack.push_string(id.button_name(stack.get_int(1)));
  922. return 1;
  923. }
  924. static int input_device_axis_name(lua_State* L, InputDevice& id)
  925. {
  926. LuaStack stack(L);
  927. stack.push_string(id.axis_name(stack.get_int(1)));
  928. return 1;
  929. }
  930. static int input_device_button_id(lua_State* L, InputDevice& id)
  931. {
  932. LuaStack stack(L);
  933. stack.push_int(id.button_id(stack.get_string_id_32(1)));
  934. return 1;
  935. }
  936. static int input_device_axis_id(lua_State* L, InputDevice& id)
  937. {
  938. LuaStack stack(L);
  939. stack.push_int(id.axis_id(stack.get_string_id_32(1)));
  940. return 1;
  941. }
  942. #define KEYBOARD_FN(name) keyboard_##name
  943. #define MOUSE_FN(name) mouse_##name
  944. #define TOUCH_FN(name) touch_##name
  945. #define JOYPAD_FN(index, name) joypad_##name##index
  946. #define KEYBOARD(name) static int KEYBOARD_FN(name)(lua_State* L)\
  947. { return input_device_##name(L, *device()->input_manager()->keyboard()); }
  948. #define MOUSE(name) static int MOUSE_FN(name)(lua_State* L)\
  949. { return input_device_##name(L, *device()->input_manager()->mouse()); }
  950. #define TOUCH(name) static int TOUCH_FN(name)(lua_State* L)\
  951. { return input_device_##name(L, *device()->input_manager()->touch()); }
  952. #define JOYPAD(index, name) static int JOYPAD_FN(index, name)(lua_State* L)\
  953. { return input_device_##name(L, *device()->input_manager()->joypad(index)); }
  954. KEYBOARD(name)
  955. KEYBOARD(connected)
  956. KEYBOARD(num_buttons)
  957. KEYBOARD(num_axes)
  958. KEYBOARD(pressed)
  959. KEYBOARD(released)
  960. KEYBOARD(any_pressed)
  961. KEYBOARD(any_released)
  962. // KEYBOARD(axis)
  963. KEYBOARD(button_name)
  964. // KEYBOARD(axis_name)
  965. KEYBOARD(button_id)
  966. // KEYBOARD(axis_id)
  967. MOUSE(name)
  968. MOUSE(connected)
  969. MOUSE(num_buttons)
  970. MOUSE(num_axes)
  971. MOUSE(pressed)
  972. MOUSE(released)
  973. MOUSE(any_pressed)
  974. MOUSE(any_released)
  975. MOUSE(axis)
  976. MOUSE(button_name)
  977. MOUSE(axis_name)
  978. MOUSE(button_id)
  979. MOUSE(axis_id)
  980. TOUCH(name)
  981. TOUCH(connected)
  982. TOUCH(num_buttons)
  983. TOUCH(num_axes)
  984. TOUCH(pressed)
  985. TOUCH(released)
  986. TOUCH(any_pressed)
  987. TOUCH(any_released)
  988. TOUCH(axis)
  989. TOUCH(button_name)
  990. TOUCH(axis_name)
  991. TOUCH(button_id)
  992. TOUCH(axis_id)
  993. JOYPAD(0, name)
  994. JOYPAD(0, connected)
  995. JOYPAD(0, num_buttons)
  996. JOYPAD(0, num_axes)
  997. JOYPAD(0, pressed)
  998. JOYPAD(0, released)
  999. JOYPAD(0, any_pressed)
  1000. JOYPAD(0, any_released)
  1001. JOYPAD(0, axis)
  1002. JOYPAD(0, button_name)
  1003. JOYPAD(0, axis_name)
  1004. JOYPAD(0, button_id)
  1005. JOYPAD(0, axis_id)
  1006. JOYPAD(1, name)
  1007. JOYPAD(1, connected)
  1008. JOYPAD(1, num_buttons)
  1009. JOYPAD(1, num_axes)
  1010. JOYPAD(1, pressed)
  1011. JOYPAD(1, released)
  1012. JOYPAD(1, any_pressed)
  1013. JOYPAD(1, any_released)
  1014. JOYPAD(1, axis)
  1015. JOYPAD(1, button_name)
  1016. JOYPAD(1, axis_name)
  1017. JOYPAD(1, button_id)
  1018. JOYPAD(1, axis_id)
  1019. JOYPAD(2, name)
  1020. JOYPAD(2, connected)
  1021. JOYPAD(2, num_buttons)
  1022. JOYPAD(2, num_axes)
  1023. JOYPAD(2, pressed)
  1024. JOYPAD(2, released)
  1025. JOYPAD(2, any_pressed)
  1026. JOYPAD(2, any_released)
  1027. JOYPAD(2, axis)
  1028. JOYPAD(2, button_name)
  1029. JOYPAD(2, axis_name)
  1030. JOYPAD(2, button_id)
  1031. JOYPAD(2, axis_id)
  1032. JOYPAD(3, name)
  1033. JOYPAD(3, connected)
  1034. JOYPAD(3, num_buttons)
  1035. JOYPAD(3, num_axes)
  1036. JOYPAD(3, pressed)
  1037. JOYPAD(3, released)
  1038. JOYPAD(3, any_pressed)
  1039. JOYPAD(3, any_released)
  1040. JOYPAD(3, axis)
  1041. JOYPAD(3, button_name)
  1042. JOYPAD(3, axis_name)
  1043. JOYPAD(3, button_id)
  1044. JOYPAD(3, axis_id)
  1045. static int world_spawn_unit(lua_State* L)
  1046. {
  1047. LuaStack stack(L);
  1048. const int nargs = stack.num_args();
  1049. const StringId64 name = stack.get_resource_id(2);
  1050. const Vector3& pos = nargs > 2 ? stack.get_vector3(3) : VECTOR3_ZERO;
  1051. const Quaternion& rot = nargs > 3 ? stack.get_quaternion(4) : QUATERNION_IDENTITY;
  1052. LUA_ASSERT(device()->resource_manager()->can_get(UNIT_TYPE, name), stack, "Unit not found");
  1053. stack.push_unit(stack.get_world(1)->spawn_unit(name, pos, rot));
  1054. return 1;
  1055. }
  1056. static int world_destroy_unit(lua_State* L)
  1057. {
  1058. LuaStack stack(L);
  1059. stack.get_world(1)->destroy_unit(stack.get_unit(2));
  1060. return 0;
  1061. }
  1062. static int world_num_units(lua_State* L)
  1063. {
  1064. LuaStack stack(L);
  1065. stack.push_int(stack.get_world(1)->num_units());
  1066. return 1;
  1067. }
  1068. static int world_units(lua_State* L)
  1069. {
  1070. LuaStack stack(L);
  1071. TempAllocator1024 alloc;
  1072. Array<UnitId> units(alloc);
  1073. stack.get_world(1)->units(units);
  1074. const uint32_t num = array::size(units);
  1075. stack.push_table(num);
  1076. for (uint32_t i = 0; i < num; ++i)
  1077. {
  1078. stack.push_key_begin((int32_t) i + 1);
  1079. stack.push_unit(units[i]);
  1080. stack.push_key_end();
  1081. }
  1082. return 1;
  1083. }
  1084. static int world_camera(lua_State* L)
  1085. {
  1086. LuaStack stack(L);
  1087. stack.push_camera(stack.get_world(1)->camera(stack.get_unit(2)));
  1088. return 1;
  1089. }
  1090. static int camera_set_projection_type(lua_State* L)
  1091. {
  1092. LuaStack stack(L);
  1093. const char* name = stack.get_string(3);
  1094. const ProjectionType::Enum pt = name_to_projection_type(name);
  1095. LUA_ASSERT(pt != ProjectionType::COUNT, stack, "Unknown projection type: '%s'", name);
  1096. stack.get_world(1)->set_camera_projection_type(stack.get_camera(2), pt);
  1097. return 0;
  1098. }
  1099. static int camera_projection_type(lua_State* L)
  1100. {
  1101. LuaStack stack(L);
  1102. ProjectionType::Enum type = stack.get_world(1)->camera_projection_type(stack.get_camera(2));
  1103. stack.push_string(s_projection[type].name);
  1104. return 1;
  1105. }
  1106. static int camera_fov(lua_State* L)
  1107. {
  1108. LuaStack stack(L);
  1109. stack.push_float(stack.get_world(1)->camera_fov(stack.get_camera(2)));
  1110. return 1;
  1111. }
  1112. static int camera_set_fov(lua_State* L)
  1113. {
  1114. LuaStack stack(L);
  1115. stack.get_world(1)->set_camera_fov(stack.get_camera(2), stack.get_float(3));
  1116. return 0;
  1117. }
  1118. static int camera_aspect(lua_State* L)
  1119. {
  1120. LuaStack stack(L);
  1121. stack.push_float(stack.get_world(1)->camera_aspect(stack.get_camera(2)));
  1122. return 1;
  1123. }
  1124. static int camera_set_aspect(lua_State* L)
  1125. {
  1126. LuaStack stack(L);
  1127. stack.get_world(1)->set_camera_aspect(stack.get_camera(2), stack.get_float(3));
  1128. return 0;
  1129. }
  1130. static int camera_near_clip_distance(lua_State* L)
  1131. {
  1132. LuaStack stack(L);
  1133. stack.push_float(stack.get_world(1)->camera_near_clip_distance(stack.get_camera(2)));
  1134. return 1;
  1135. }
  1136. static int camera_set_near_clip_distance(lua_State* L)
  1137. {
  1138. LuaStack stack(L);
  1139. stack.get_world(1)->set_camera_near_clip_distance(stack.get_camera(2), stack.get_float(3));
  1140. return 0;
  1141. }
  1142. static int camera_far_clip_distance(lua_State* L)
  1143. {
  1144. LuaStack stack(L);
  1145. stack.push_float(stack.get_world(1)->camera_far_clip_distance(stack.get_camera(2)));
  1146. return 1;
  1147. }
  1148. static int camera_set_far_clip_distance(lua_State* L)
  1149. {
  1150. LuaStack stack(L);
  1151. stack.get_world(1)->set_camera_far_clip_distance(stack.get_camera(2), stack.get_float(3));
  1152. return 0;
  1153. }
  1154. static int camera_set_orthographic_metrics(lua_State* L)
  1155. {
  1156. LuaStack stack(L);
  1157. stack.get_world(1)->set_camera_orthographic_metrics(stack.get_camera(2), stack.get_float(3), stack.get_float(4),
  1158. stack.get_float(5), stack.get_float(6));
  1159. return 0;
  1160. }
  1161. static int camera_set_viewport_metrics(lua_State* L)
  1162. {
  1163. LuaStack stack(L);
  1164. stack.get_world(1)->set_camera_viewport_metrics(stack.get_camera(2), stack.get_int(3), stack.get_int(4),
  1165. stack.get_int(5), stack.get_int(6));
  1166. return 0;
  1167. }
  1168. static int camera_screen_to_world(lua_State* L)
  1169. {
  1170. LuaStack stack(L);
  1171. stack.push_vector3(stack.get_world(1)->camera_screen_to_world(stack.get_camera(2), stack.get_vector3(3)));
  1172. return 1;
  1173. }
  1174. static int camera_world_to_screen(lua_State* L)
  1175. {
  1176. LuaStack stack(L);
  1177. stack.push_vector3(stack.get_world(1)->camera_world_to_screen(stack.get_camera(2), stack.get_vector3(3)));
  1178. return 1;
  1179. }
  1180. static int world_update_animations(lua_State* L)
  1181. {
  1182. LuaStack stack(L);
  1183. stack.get_world(1)->update_animations(stack.get_float(2));
  1184. return 0;
  1185. }
  1186. static int world_update_scene(lua_State* L)
  1187. {
  1188. LuaStack stack(L);
  1189. stack.get_world(1)->update_scene(stack.get_float(2));
  1190. return 0;
  1191. }
  1192. static int world_update(lua_State* L)
  1193. {
  1194. LuaStack stack(L);
  1195. stack.get_world(1)->update(stack.get_float(2));
  1196. return 0;
  1197. }
  1198. static int world_play_sound(lua_State* L)
  1199. {
  1200. LuaStack stack(L);
  1201. const int32_t nargs = stack.num_args();
  1202. World* world = stack.get_world(1);
  1203. const StringId64 name = stack.get_resource_id(2);
  1204. const bool loop = nargs > 2 ? stack.get_bool(3) : false;
  1205. const float volume = nargs > 3 ? stack.get_float(4) : 1.0f;
  1206. const Vector3& pos = nargs > 4 ? stack.get_vector3(5) : VECTOR3_ZERO;
  1207. const float range = nargs > 5 ? stack.get_float(6) : 1000.0f;
  1208. LUA_ASSERT(device()->resource_manager()->can_get(SOUND_TYPE, name), stack, "Sound not found");
  1209. stack.push_sound_instance_id(world->play_sound(name, loop, volume, pos, range));
  1210. return 1;
  1211. }
  1212. static int world_stop_sound(lua_State* L)
  1213. {
  1214. LuaStack stack(L);
  1215. stack.get_world(1)->stop_sound(stack.get_sound_instance_id(2));
  1216. return 0;
  1217. }
  1218. static int world_link_sound(lua_State* L)
  1219. {
  1220. LuaStack stack(L);
  1221. stack.get_world(1)->link_sound(stack.get_sound_instance_id(2)
  1222. , stack.get_unit(3)
  1223. , stack.get_int(4)
  1224. );
  1225. return 0;
  1226. }
  1227. static int world_set_listener_pose(lua_State* L)
  1228. {
  1229. LuaStack stack(L);
  1230. stack.get_world(1)->set_listener_pose(stack.get_matrix4x4(2));
  1231. return 0;
  1232. }
  1233. static int world_set_sound_position(lua_State* L)
  1234. {
  1235. LuaStack stack(L);
  1236. stack.get_world(1)->set_sound_position(stack.get_sound_instance_id(2), stack.get_vector3(3));
  1237. return 0;
  1238. }
  1239. static int world_set_sound_range(lua_State* L)
  1240. {
  1241. LuaStack stack(L);
  1242. stack.get_world(1)->set_sound_range(stack.get_sound_instance_id(2),
  1243. stack.get_float(3));
  1244. return 0;
  1245. }
  1246. static int world_set_sound_volume(lua_State* L)
  1247. {
  1248. LuaStack stack(L);
  1249. stack.get_world(1)->set_sound_volume(stack.get_sound_instance_id(2), stack.get_float(3));
  1250. return 0;
  1251. }
  1252. static int world_create_debug_line(lua_State* L)
  1253. {
  1254. LuaStack stack(L);
  1255. stack.push_debug_line(stack.get_world(1)->create_debug_line(stack.get_bool(2)));
  1256. return 1;
  1257. }
  1258. static int world_destroy_debug_line(lua_State* L)
  1259. {
  1260. LuaStack stack(L);
  1261. stack.get_world(1)->destroy_debug_line(*stack.get_debug_line(2));
  1262. return 0;
  1263. }
  1264. static int world_load_level(lua_State* L)
  1265. {
  1266. LuaStack stack(L);
  1267. const int nargs = stack.num_args();
  1268. const StringId64 name = stack.get_resource_id(2);
  1269. const Vector3& pos = nargs > 2 ? stack.get_vector3(3) : VECTOR3_ZERO;
  1270. const Quaternion& rot = nargs > 3 ? stack.get_quaternion(4) : QUATERNION_IDENTITY;
  1271. LUA_ASSERT(device()->resource_manager()->can_get(LEVEL_TYPE, name), stack, "Level not found");
  1272. stack.push_level(stack.get_world(1)->load_level(name, pos, rot));
  1273. return 1;
  1274. }
  1275. static int world_scene_graph(lua_State* L)
  1276. {
  1277. LuaStack stack(L);
  1278. stack.push_scene_graph(stack.get_world(1)->scene_graph());
  1279. return 1;
  1280. }
  1281. static int world_render_world(lua_State* L)
  1282. {
  1283. LuaStack stack(L);
  1284. stack.push_render_world(stack.get_world(1)->render_world());
  1285. return 1;
  1286. }
  1287. static int world_physics_world(lua_State* L)
  1288. {
  1289. LuaStack stack(L);
  1290. stack.push_physics_world(stack.get_world(1)->physics_world());
  1291. return 1;
  1292. }
  1293. static int world_sound_world(lua_State* L)
  1294. {
  1295. LuaStack stack(L);
  1296. stack.push_sound_world(stack.get_world(1)->sound_world());
  1297. return 1;
  1298. }
  1299. static int world_tostring(lua_State* L)
  1300. {
  1301. LuaStack stack(L);
  1302. World* w = stack.get_world(1);
  1303. stack.push_fstring("World (%p)", w);
  1304. return 1;
  1305. }
  1306. static int scene_graph_create(lua_State* L)
  1307. {
  1308. LuaStack stack(L);
  1309. stack.push_transform(stack.get_scene_graph(1)->create(stack.get_unit(2), MATRIX4X4_IDENTITY));
  1310. return 1;
  1311. }
  1312. static int scene_graph_destroy(lua_State* L)
  1313. {
  1314. LuaStack stack(L);
  1315. stack.get_scene_graph(1)->destroy(stack.get_transform(2));
  1316. return 0;
  1317. }
  1318. static int scene_graph_transform_instances(lua_State* L)
  1319. {
  1320. LuaStack stack(L);
  1321. stack.push_transform(stack.get_scene_graph(1)->get(stack.get_unit(2)));
  1322. return 1;
  1323. }
  1324. static int scene_graph_local_position(lua_State* L)
  1325. {
  1326. LuaStack stack(L);
  1327. stack.push_vector3(stack.get_scene_graph(1)->local_position(stack.get_transform(2)));
  1328. return 1;
  1329. }
  1330. static int scene_graph_local_rotation(lua_State* L)
  1331. {
  1332. LuaStack stack(L);
  1333. stack.push_quaternion(stack.get_scene_graph(1)->local_rotation(stack.get_transform(2)));
  1334. return 1;
  1335. }
  1336. static int scene_graph_local_scale(lua_State* L)
  1337. {
  1338. LuaStack stack(L);
  1339. stack.push_vector3(stack.get_scene_graph(1)->local_scale(stack.get_transform(2)));
  1340. return 1;
  1341. }
  1342. static int scene_graph_local_pose(lua_State* L)
  1343. {
  1344. LuaStack stack(L);
  1345. stack.push_matrix4x4(stack.get_scene_graph(1)->local_pose(stack.get_transform(2)));
  1346. return 1;
  1347. }
  1348. static int scene_graph_world_position(lua_State* L)
  1349. {
  1350. LuaStack stack(L);
  1351. stack.push_vector3(stack.get_scene_graph(1)->world_position(stack.get_transform(2)));
  1352. return 1;
  1353. }
  1354. static int scene_graph_world_rotation(lua_State* L)
  1355. {
  1356. LuaStack stack(L);
  1357. stack.push_quaternion(stack.get_scene_graph(1)->world_rotation(stack.get_transform(2)));
  1358. return 1;
  1359. }
  1360. static int scene_graph_world_pose(lua_State* L)
  1361. {
  1362. LuaStack stack(L);
  1363. stack.push_matrix4x4(stack.get_scene_graph(1)->world_pose(stack.get_transform(2)));
  1364. return 1;
  1365. }
  1366. static int scene_graph_set_local_position(lua_State* L)
  1367. {
  1368. LuaStack stack(L);
  1369. stack.get_scene_graph(1)->set_local_position(stack.get_transform(2), stack.get_vector3(3));
  1370. return 0;
  1371. }
  1372. static int scene_graph_set_local_rotation(lua_State* L)
  1373. {
  1374. LuaStack stack(L);
  1375. stack.get_scene_graph(1)->set_local_rotation(stack.get_transform(2), stack.get_quaternion(3));
  1376. return 0;
  1377. }
  1378. static int scene_graph_set_local_scale(lua_State* L)
  1379. {
  1380. LuaStack stack(L);
  1381. stack.get_scene_graph(1)->set_local_scale(stack.get_transform(2), stack.get_vector3(3));
  1382. return 0;
  1383. }
  1384. static int scene_graph_set_local_pose(lua_State* L)
  1385. {
  1386. LuaStack stack(L);
  1387. stack.get_scene_graph(1)->set_local_pose(stack.get_transform(2), stack.get_matrix4x4(3));
  1388. return 0;
  1389. }
  1390. static int scene_graph_link(lua_State* L)
  1391. {
  1392. LuaStack stack(L);
  1393. stack.get_scene_graph(1)->link(stack.get_transform(2), stack.get_transform(3));
  1394. return 0;
  1395. }
  1396. static int scene_graph_unlink(lua_State* L)
  1397. {
  1398. LuaStack stack(L);
  1399. stack.get_scene_graph(1)->unlink(stack.get_transform(2));
  1400. return 0;
  1401. }
  1402. static int unit_manager_create(lua_State* L)
  1403. {
  1404. LuaStack stack(L);
  1405. if (stack.num_args() == 1)
  1406. stack.push_unit(device()->unit_manager()->create(*stack.get_world(1)));
  1407. else
  1408. stack.push_unit(device()->unit_manager()->create());
  1409. return 1;
  1410. }
  1411. static int unit_manager_alive(lua_State* L)
  1412. {
  1413. LuaStack stack(L);
  1414. stack.push_bool(device()->unit_manager()->alive(stack.get_unit(1)));
  1415. return 1;
  1416. }
  1417. static int render_world_create_mesh(lua_State* L)
  1418. {
  1419. LuaStack stack(L);
  1420. RenderWorld* rw = stack.get_render_world(1);
  1421. UnitId unit = stack.get_unit(2);
  1422. MeshRendererDesc desc;
  1423. desc.mesh_resource = stack.get_resource_id(3);
  1424. desc.geometry_name = stack.get_string_id_32(4);
  1425. desc.material_resource = stack.get_resource_id(5);
  1426. desc.visible = stack.get_bool(6);
  1427. stack.push_mesh_instance(rw->create_mesh(unit, desc, MATRIX4X4_IDENTITY));
  1428. return 1;
  1429. }
  1430. static int render_world_destroy_mesh(lua_State* L)
  1431. {
  1432. LuaStack stack(L);
  1433. stack.get_render_world(1)->destroy_mesh(stack.get_mesh_instance(2));
  1434. return 0;
  1435. }
  1436. static int render_world_mesh_instances(lua_State* L)
  1437. {
  1438. LuaStack stack(L);
  1439. RenderWorld* rw = stack.get_render_world(1);
  1440. UnitId unit = stack.get_unit(2);
  1441. MeshInstance inst = rw->first_mesh(unit);
  1442. stack.push_table();
  1443. for (uint32_t i = 0; rw->is_valid(inst); ++i, inst = rw->next_mesh(inst))
  1444. {
  1445. stack.push_key_begin(i+1);
  1446. stack.push_mesh_instance(inst);
  1447. stack.push_key_end();
  1448. }
  1449. return 1;
  1450. }
  1451. static int render_world_mesh_obb(lua_State* L)
  1452. {
  1453. LuaStack stack(L);
  1454. OBB obb = stack.get_render_world(1)->mesh_obb(stack.get_mesh_instance(2));
  1455. stack.push_matrix4x4(obb.tm);
  1456. stack.push_vector3(obb.half_extents);
  1457. return 2;
  1458. }
  1459. static int render_world_set_mesh_visible(lua_State* L)
  1460. {
  1461. LuaStack stack(L);
  1462. stack.get_render_world(1)->set_mesh_visible(stack.get_mesh_instance(2), stack.get_bool(3));
  1463. return 0;
  1464. }
  1465. static int render_world_create_sprite(lua_State* L)
  1466. {
  1467. LuaStack stack(L);
  1468. RenderWorld* rw = stack.get_render_world(1);
  1469. UnitId unit = stack.get_unit(2);
  1470. SpriteRendererDesc desc;
  1471. desc.sprite_resource = stack.get_resource_id(3);
  1472. desc.material_resource = stack.get_resource_id(4);
  1473. desc.visible = stack.get_bool(5);
  1474. stack.push_sprite_instance(rw->create_sprite(unit, desc, MATRIX4X4_IDENTITY));
  1475. return 1;
  1476. }
  1477. static int render_world_destroy_sprite(lua_State* L)
  1478. {
  1479. LuaStack stack(L);
  1480. stack.get_render_world(1)->destroy_sprite(stack.get_sprite_instance(2));
  1481. return 0;
  1482. }
  1483. static int render_world_sprite_instances(lua_State* L)
  1484. {
  1485. LuaStack stack(L);
  1486. RenderWorld* rw = stack.get_render_world(1);
  1487. UnitId unit = stack.get_unit(2);
  1488. SpriteInstance inst = rw->first_sprite(unit);
  1489. stack.push_table();
  1490. for (uint32_t i = 0; rw->is_valid(inst); ++i, inst = rw->next_sprite(inst))
  1491. {
  1492. stack.push_key_begin(i+1);
  1493. stack.push_sprite_instance(inst);
  1494. stack.push_key_end();
  1495. }
  1496. return 1;
  1497. }
  1498. static int render_world_set_sprite_visible(lua_State* L)
  1499. {
  1500. LuaStack stack(L);
  1501. stack.get_render_world(1)->set_sprite_visible(stack.get_sprite_instance(2), stack.get_bool(3));
  1502. return 0;
  1503. }
  1504. static int render_world_set_sprite_frame(lua_State* L)
  1505. {
  1506. LuaStack stack(L);
  1507. stack.get_render_world(1)->set_sprite_frame(stack.get_sprite_instance(2), stack.get_int(3));
  1508. return 0;
  1509. }
  1510. static int render_world_create_light(lua_State* L)
  1511. {
  1512. LuaStack stack(L);
  1513. const char* name = stack.get_string(3);
  1514. const LightType::Enum lt = name_to_light_type(name);
  1515. LUA_ASSERT(lt != LightType::COUNT, stack, "Unknown light type: '%s'", name);
  1516. LightDesc ld;
  1517. ld.type = lt;
  1518. ld.range = stack.get_float(4);
  1519. ld.intensity = stack.get_float(5);
  1520. ld.spot_angle = stack.get_float(6);
  1521. ld.color = stack.get_vector3(7);
  1522. stack.push_light_instance(stack.get_render_world(1)->create_light(stack.get_unit(2), ld, MATRIX4X4_IDENTITY));
  1523. return 1;
  1524. }
  1525. static int render_world_destroy_light(lua_State* L)
  1526. {
  1527. LuaStack stack(L);
  1528. stack.get_render_world(1)->destroy_light(stack.get_light_instance(2));
  1529. return 0;
  1530. }
  1531. static int render_world_light_instances(lua_State* L)
  1532. {
  1533. LuaStack stack(L);
  1534. stack.push_light_instance(stack.get_render_world(1)->light(stack.get_unit(2)));
  1535. return 1;
  1536. }
  1537. static int render_world_light_type(lua_State* L)
  1538. {
  1539. LuaStack stack(L);
  1540. LightType::Enum type = stack.get_render_world(1)->light_type(stack.get_light_instance(2));
  1541. stack.push_string(s_light[type].name);
  1542. return 1;
  1543. }
  1544. static int render_world_light_color(lua_State* L)
  1545. {
  1546. LuaStack stack(L);
  1547. stack.push_color4(stack.get_render_world(1)->light_color(stack.get_light_instance(2)));
  1548. return 1;
  1549. }
  1550. static int render_world_light_range(lua_State* L)
  1551. {
  1552. LuaStack stack(L);
  1553. stack.push_float(stack.get_render_world(1)->light_range(stack.get_light_instance(2)));
  1554. return 1;
  1555. }
  1556. static int render_world_light_intensity(lua_State* L)
  1557. {
  1558. LuaStack stack(L);
  1559. stack.push_float(stack.get_render_world(1)->light_intensity(stack.get_light_instance(2)));
  1560. return 1;
  1561. }
  1562. static int render_world_light_spot_angle(lua_State* L)
  1563. {
  1564. LuaStack stack(L);
  1565. stack.push_float(stack.get_render_world(1)->light_spot_angle(stack.get_light_instance(2)));
  1566. return 1;
  1567. }
  1568. static int render_world_set_light_type(lua_State* L)
  1569. {
  1570. LuaStack stack(L);
  1571. const char* name = stack.get_string(3);
  1572. const LightType::Enum lt = name_to_light_type(name);
  1573. LUA_ASSERT(lt != LightType::COUNT, stack, "Unknown light type: '%s'", name);
  1574. stack.get_render_world(1)->set_light_type(stack.get_light_instance(2), lt);
  1575. return 0;
  1576. }
  1577. static int render_world_set_light_color(lua_State* L)
  1578. {
  1579. LuaStack stack(L);
  1580. stack.get_render_world(1)->set_light_color(stack.get_light_instance(2), stack.get_color4(3));
  1581. return 0;
  1582. }
  1583. static int render_world_set_light_range(lua_State* L)
  1584. {
  1585. LuaStack stack(L);
  1586. stack.get_render_world(1)->set_light_range(stack.get_light_instance(2), stack.get_float(3));
  1587. return 0;
  1588. }
  1589. static int render_world_set_light_intensity(lua_State* L)
  1590. {
  1591. LuaStack stack(L);
  1592. stack.get_render_world(1)->set_light_intensity(stack.get_light_instance(2), stack.get_float(3));
  1593. return 0;
  1594. }
  1595. static int render_world_set_light_spot_angle(lua_State* L)
  1596. {
  1597. LuaStack stack(L);
  1598. stack.get_render_world(1)->set_light_spot_angle(stack.get_light_instance(2), stack.get_float(3));
  1599. return 0;
  1600. }
  1601. static int render_world_enable_debug_drawing(lua_State* L)
  1602. {
  1603. LuaStack stack(L);
  1604. stack.get_render_world(1)->enable_debug_drawing(stack.get_bool(2));
  1605. return 0;
  1606. }
  1607. static int physics_world_actor_instances(lua_State* L)
  1608. {
  1609. LuaStack stack(L);
  1610. ActorInstance inst = stack.get_physics_world(1)->actor(stack.get_unit(2));
  1611. if (inst.i == UINT32_MAX)
  1612. stack.push_nil();
  1613. else
  1614. stack.push_actor(inst);
  1615. return 1;
  1616. }
  1617. static int physics_world_actor_world_position(lua_State* L)
  1618. {
  1619. LuaStack stack(L);
  1620. stack.push_vector3(stack.get_physics_world(1)->actor_world_position(stack.get_actor(2)));
  1621. return 1;
  1622. }
  1623. static int physics_world_actor_world_rotation(lua_State* L)
  1624. {
  1625. LuaStack stack(L);
  1626. stack.push_quaternion(stack.get_physics_world(1)->actor_world_rotation(stack.get_actor(2)));
  1627. return 1;
  1628. }
  1629. static int physics_world_actor_world_pose(lua_State* L)
  1630. {
  1631. LuaStack stack(L);
  1632. stack.push_matrix4x4(stack.get_physics_world(1)->actor_world_pose(stack.get_actor(2)));
  1633. return 1;
  1634. }
  1635. static int physics_world_teleport_actor_world_position(lua_State* L)
  1636. {
  1637. LuaStack stack(L);
  1638. stack.get_physics_world(1)->teleport_actor_world_position(stack.get_actor(2), stack.get_vector3(3));
  1639. return 0;
  1640. }
  1641. static int physics_world_teleport_actor_world_rotation(lua_State* L)
  1642. {
  1643. LuaStack stack(L);
  1644. stack.get_physics_world(1)->teleport_actor_world_rotation(stack.get_actor(2), stack.get_quaternion(3));
  1645. return 0;
  1646. }
  1647. static int physics_world_teleport_actor_world_pose(lua_State* L)
  1648. {
  1649. LuaStack stack(L);
  1650. stack.get_physics_world(1)->teleport_actor_world_pose(stack.get_actor(2), stack.get_matrix4x4(3));
  1651. return 0;
  1652. }
  1653. static int physics_world_actor_center_of_mass(lua_State* L)
  1654. {
  1655. LuaStack stack(L);
  1656. stack.push_vector3(stack.get_physics_world(1)->actor_center_of_mass(stack.get_actor(2)));
  1657. return 1;
  1658. }
  1659. static int physics_world_enable_actor_gravity(lua_State* L)
  1660. {
  1661. LuaStack stack(L);
  1662. stack.get_physics_world(1)->enable_actor_gravity(stack.get_actor(2));
  1663. return 0;
  1664. }
  1665. static int physics_world_disable_actor_gravity(lua_State* L)
  1666. {
  1667. LuaStack stack(L);
  1668. stack.get_physics_world(1)->disable_actor_gravity(stack.get_actor(2));
  1669. return 0;
  1670. }
  1671. static int physics_world_enable_actor_collision(lua_State* L)
  1672. {
  1673. LuaStack stack(L);
  1674. stack.get_physics_world(1)->enable_actor_collision(stack.get_actor(2));
  1675. return 0;
  1676. }
  1677. static int physics_world_disable_actor_collision(lua_State* L)
  1678. {
  1679. LuaStack stack(L);
  1680. stack.get_physics_world(1)->disable_actor_collision(stack.get_actor(2));
  1681. return 0;
  1682. }
  1683. static int physics_world_set_actor_collision_filter(lua_State* L)
  1684. {
  1685. LuaStack stack(L);
  1686. stack.get_physics_world(1)->set_actor_collision_filter(stack.get_actor(2), stack.get_string_id_32(3));
  1687. return 0;
  1688. }
  1689. static int physics_world_set_actor_kinematic(lua_State* L)
  1690. {
  1691. LuaStack stack(L);
  1692. stack.get_physics_world(1)->set_actor_kinematic(stack.get_actor(2), stack.get_bool(3));
  1693. return 0;
  1694. }
  1695. static int physics_world_move_actor(lua_State* L)
  1696. {
  1697. LuaStack stack(L);
  1698. stack.get_physics_world(1)->move_actor(stack.get_actor(2), stack.get_vector3(3));
  1699. return 0;
  1700. }
  1701. static int physics_world_is_static(lua_State* L)
  1702. {
  1703. LuaStack stack(L);
  1704. stack.push_bool(stack.get_physics_world(1)->is_static(stack.get_actor(2)));
  1705. return 1;
  1706. }
  1707. static int physics_world_is_dynamic(lua_State* L)
  1708. {
  1709. LuaStack stack(L);
  1710. stack.push_bool(stack.get_physics_world(1)->is_dynamic(stack.get_actor(2)));
  1711. return 1;
  1712. }
  1713. static int physics_world_is_kinematic(lua_State* L)
  1714. {
  1715. LuaStack stack(L);
  1716. stack.push_bool(stack.get_physics_world(1)->is_kinematic(stack.get_actor(2)));
  1717. return 1;
  1718. }
  1719. static int physics_world_is_nonkinematic(lua_State* L)
  1720. {
  1721. LuaStack stack(L);
  1722. stack.push_bool(stack.get_physics_world(1)->is_nonkinematic(stack.get_actor(2)));
  1723. return 1;
  1724. }
  1725. static int physics_world_actor_linear_damping(lua_State* L)
  1726. {
  1727. LuaStack stack(L);
  1728. stack.push_float(stack.get_physics_world(1)->actor_linear_damping(stack.get_actor(2)));
  1729. return 1;
  1730. }
  1731. static int physics_world_set_actor_linear_damping(lua_State* L)
  1732. {
  1733. LuaStack stack(L);
  1734. stack.get_physics_world(1)->set_actor_linear_damping(stack.get_actor(2), stack.get_float(3));
  1735. return 0;
  1736. }
  1737. static int physics_world_actor_angular_damping(lua_State* L)
  1738. {
  1739. LuaStack stack(L);
  1740. stack.push_float(stack.get_physics_world(1)->actor_angular_damping(stack.get_actor(2)));
  1741. return 1;
  1742. }
  1743. static int physics_world_set_actor_angular_damping(lua_State* L)
  1744. {
  1745. LuaStack stack(L);
  1746. stack.get_physics_world(1)->set_actor_angular_damping(stack.get_actor(2), stack.get_float(3));
  1747. return 0;
  1748. }
  1749. static int physics_world_actor_linear_velocity(lua_State* L)
  1750. {
  1751. LuaStack stack(L);
  1752. stack.push_vector3(stack.get_physics_world(1)->actor_linear_velocity(stack.get_actor(2)));
  1753. return 1;
  1754. }
  1755. static int physics_world_set_actor_linear_velocity(lua_State* L)
  1756. {
  1757. LuaStack stack(L);
  1758. stack.get_physics_world(1)->set_actor_linear_velocity(stack.get_actor(2), stack.get_vector3(3));
  1759. return 0;
  1760. }
  1761. static int physics_world_actor_angular_velocity(lua_State* L)
  1762. {
  1763. LuaStack stack(L);
  1764. stack.push_vector3(stack.get_physics_world(1)->actor_angular_velocity(stack.get_actor(2)));
  1765. return 1;
  1766. }
  1767. static int physics_world_set_actor_angular_velocity(lua_State* L)
  1768. {
  1769. LuaStack stack(L);
  1770. stack.get_physics_world(1)->set_actor_angular_velocity(stack.get_actor(2), stack.get_vector3(3));
  1771. return 0;
  1772. }
  1773. static int physics_world_add_actor_impulse(lua_State* L)
  1774. {
  1775. LuaStack stack(L);
  1776. stack.get_physics_world(1)->add_actor_impulse(stack.get_actor(2), stack.get_vector3(3));
  1777. return 0;
  1778. }
  1779. static int physics_world_add_actor_impulse_at(lua_State* L)
  1780. {
  1781. LuaStack stack(L);
  1782. stack.get_physics_world(1)->add_actor_impulse_at(stack.get_actor(2), stack.get_vector3(3), stack.get_vector3(4));
  1783. return 0;
  1784. }
  1785. static int physics_world_add_actor_torque_impulse(lua_State* L)
  1786. {
  1787. LuaStack stack(L);
  1788. stack.get_physics_world(1)->add_actor_torque_impulse(stack.get_actor(2), stack.get_vector3(3));
  1789. return 0;
  1790. }
  1791. static int physics_world_push_actor(lua_State* L)
  1792. {
  1793. LuaStack stack(L);
  1794. stack.get_physics_world(1)->push_actor(stack.get_actor(2), stack.get_vector3(3), stack.get_float(4));
  1795. return 0;
  1796. }
  1797. static int physics_world_push_actor_at(lua_State* L)
  1798. {
  1799. LuaStack stack(L);
  1800. stack.get_physics_world(1)->push_actor_at(stack.get_actor(2), stack.get_vector3(3), stack.get_float(4), stack.get_vector3(5));
  1801. return 0;
  1802. }
  1803. static int physics_world_is_sleeping(lua_State* L)
  1804. {
  1805. LuaStack stack(L);
  1806. stack.push_bool(stack.get_physics_world(1)->is_sleeping(stack.get_actor(2)));
  1807. return 1;
  1808. }
  1809. static int physics_world_wake_up(lua_State* L)
  1810. {
  1811. LuaStack stack(L);
  1812. stack.get_physics_world(1)->wake_up(stack.get_actor(2));
  1813. return 0;
  1814. }
  1815. static int physics_world_controller_instances(lua_State* L)
  1816. {
  1817. LuaStack stack(L);
  1818. stack.push_controller(stack.get_physics_world(1)->controller(stack.get_unit(2)));
  1819. return 1;
  1820. }
  1821. static int physics_world_move_controller(lua_State* L)
  1822. {
  1823. LuaStack stack(L);
  1824. stack.get_physics_world(1)->move_controller(stack.get_controller(2), stack.get_vector3(3));
  1825. return 0;
  1826. }
  1827. static int physics_world_create_joint(lua_State* L)
  1828. {
  1829. LuaStack stack(L);
  1830. JointDesc jd;
  1831. jd.type = JointType::SPRING;
  1832. jd.anchor_0 = vector3(0, -2, 0);
  1833. jd.anchor_1 = vector3(0, 2, 0);
  1834. jd.break_force = 999999.0f;
  1835. jd.hinge.axis = vector3(1, 0, 0);
  1836. jd.hinge.lower_limit = -3.14f / 4.0f;
  1837. jd.hinge.upper_limit = 3.14f / 4.0f;
  1838. jd.hinge.bounciness = 12.0f;
  1839. stack.get_physics_world(1)->create_joint(stack.get_actor(2), stack.get_actor(3), jd);
  1840. return 0;
  1841. }
  1842. static int physics_world_gravity(lua_State* L)
  1843. {
  1844. LuaStack stack(L);
  1845. stack.push_vector3(stack.get_physics_world(1)->gravity());
  1846. return 1;
  1847. }
  1848. static int physics_world_set_gravity(lua_State* L)
  1849. {
  1850. LuaStack stack(L);
  1851. stack.get_physics_world(1)->set_gravity(stack.get_vector3(2));
  1852. return 0;
  1853. }
  1854. static int physics_world_raycast(lua_State* L)
  1855. {
  1856. LuaStack stack(L);
  1857. PhysicsWorld* world = stack.get_physics_world(1);
  1858. const char* name = stack.get_string(5);
  1859. const RaycastMode::Enum mode = name_to_raycast_mode(name);
  1860. LUA_ASSERT(mode != RaycastMode::COUNT, stack, "Unknown raycast mode: '%s'", name);
  1861. TempAllocator1024 ta;
  1862. Array<RaycastHit> hits(ta);
  1863. world->raycast(stack.get_vector3(2)
  1864. , stack.get_vector3(3)
  1865. , stack.get_float(4)
  1866. , mode
  1867. , hits
  1868. );
  1869. stack.push_table();
  1870. for (uint32_t i = 0; i < array::size(hits); ++i)
  1871. {
  1872. stack.push_key_begin(i+1);
  1873. stack.push_actor(hits[i].actor);
  1874. stack.push_key_end();
  1875. }
  1876. return 1;
  1877. }
  1878. static int physics_world_enable_debug_drawing(lua_State* L)
  1879. {
  1880. LuaStack stack(L);
  1881. stack.get_physics_world(1)->enable_debug_drawing(stack.get_bool(2));
  1882. return 0;
  1883. }
  1884. static int physics_world_tostring(lua_State* L)
  1885. {
  1886. LuaStack stack(L);
  1887. PhysicsWorld* pw = stack.get_physics_world(1);
  1888. stack.push_fstring("PhysicsWorld (%p)", pw);
  1889. return 1;
  1890. }
  1891. static int sound_world_stop_all(lua_State* L)
  1892. {
  1893. LuaStack stack(L);
  1894. stack.get_sound_world(1)->stop_all();
  1895. return 0;
  1896. }
  1897. static int sound_world_pause_all(lua_State* L)
  1898. {
  1899. LuaStack stack(L);
  1900. stack.get_sound_world(1)->pause_all();
  1901. return 0;
  1902. }
  1903. static int sound_world_resume_all(lua_State* L)
  1904. {
  1905. LuaStack stack(L);
  1906. stack.get_sound_world(1)->resume_all();
  1907. return 0;
  1908. }
  1909. static int sound_world_is_playing(lua_State* L)
  1910. {
  1911. LuaStack stack(L);
  1912. stack.push_bool(stack.get_sound_world(1)->is_playing(stack.get_sound_instance_id(2)));
  1913. return 1;
  1914. }
  1915. static int sound_world_tostring(lua_State* L)
  1916. {
  1917. LuaStack stack(L);
  1918. SoundWorld* sw = stack.get_sound_world(1);
  1919. stack.push_fstring("SoundWorld (%p)", sw);
  1920. return 1;
  1921. }
  1922. static int device_platform(lua_State* L)
  1923. {
  1924. LuaStack stack(L);
  1925. stack.push_string(device()->platform());
  1926. return 1;
  1927. }
  1928. static int device_architecture(lua_State* L)
  1929. {
  1930. LuaStack stack(L);
  1931. stack.push_string(device()->architecture());
  1932. return 1;
  1933. }
  1934. static int device_version(lua_State* L)
  1935. {
  1936. LuaStack stack(L);
  1937. stack.push_string(device()->version());
  1938. return 1;
  1939. }
  1940. static int device_last_delta_time(lua_State* L)
  1941. {
  1942. LuaStack stack(L);
  1943. stack.push_float(device()->last_delta_time());
  1944. return 1;
  1945. }
  1946. static int device_quit(lua_State* /*L*/)
  1947. {
  1948. device()->quit();
  1949. return 0;
  1950. }
  1951. static int device_resolution(lua_State* L)
  1952. {
  1953. LuaStack stack(L);
  1954. uint16_t w, h;
  1955. device()->resolution(w, h);
  1956. stack.push_int(w);
  1957. stack.push_int(h);
  1958. return 2;
  1959. }
  1960. static int device_create_world(lua_State* L)
  1961. {
  1962. LuaStack stack(L);
  1963. stack.push_world(device()->create_world());
  1964. return 1;
  1965. }
  1966. static int device_destroy_world(lua_State* L)
  1967. {
  1968. LuaStack stack(L);
  1969. device()->destroy_world(*stack.get_world(1));
  1970. return 0;
  1971. }
  1972. static int device_render_world(lua_State* L)
  1973. {
  1974. LuaStack stack(L);
  1975. device()->render_world(*stack.get_world(1), stack.get_camera(2));
  1976. return 0;
  1977. }
  1978. static int device_create_resource_package(lua_State* L)
  1979. {
  1980. LuaStack stack(L);
  1981. stack.push_resource_package(device()->create_resource_package(stack.get_resource_id(1)));
  1982. return 1;
  1983. }
  1984. static int device_destroy_resource_package(lua_State* L)
  1985. {
  1986. LuaStack stack(L);
  1987. device()->destroy_resource_package(*stack.get_resource_package(1));
  1988. return 0;
  1989. }
  1990. static int device_console_send(lua_State* L)
  1991. {
  1992. using namespace string_stream;
  1993. LuaStack stack(L);
  1994. TempAllocator1024 alloc;
  1995. StringStream json(alloc);
  1996. json << "{";
  1997. /* table is in the stack at index 'i' */
  1998. stack.push_nil(); /* first key */
  1999. while (stack.next(1) != 0)
  2000. {
  2001. /* uses 'key' (at index -2) and 'value' (at index -1) */
  2002. json << "\"" << stack.get_string(-2) << "\":\"" << stack.get_string(-1) << "\",";
  2003. /* removes 'value'; keeps 'key' for next iteration */
  2004. stack.pop(1);
  2005. }
  2006. /* pop key */
  2007. stack.pop(1);
  2008. json << "}";
  2009. console_server_globals::console()->send(c_str(json));
  2010. return 0;
  2011. }
  2012. static int device_can_get(lua_State* L)
  2013. {
  2014. LuaStack stack(L);
  2015. const StringId64 type(stack.get_string(1));
  2016. stack.push_bool(device()->resource_manager()->can_get(type, stack.get_resource_id(2)));
  2017. return 1;
  2018. }
  2019. static int device_enable_resource_autoload(lua_State* L)
  2020. {
  2021. LuaStack stack(L);
  2022. device()->resource_manager()->enable_autoload(stack.get_bool(1));
  2023. return 0;
  2024. }
  2025. static int profiler_enter_scope(lua_State* L)
  2026. {
  2027. LuaStack stack(L);
  2028. profiler::enter_profile_scope(stack.get_string(1));
  2029. return 0;
  2030. }
  2031. static int profiler_leave_scope(lua_State* L)
  2032. {
  2033. LuaStack stack(L);
  2034. profiler::leave_profile_scope();
  2035. return 0;
  2036. }
  2037. static int profiler_record(lua_State* L)
  2038. {
  2039. LuaStack stack(L);
  2040. const char* name = stack.get_string(1);
  2041. if (stack.is_number(2))
  2042. profiler::record_float(name, stack.get_float(2));
  2043. else
  2044. profiler::record_vector3(name, stack.get_vector3(2));
  2045. return 0;
  2046. }
  2047. static int debug_line_add_line(lua_State* L)
  2048. {
  2049. LuaStack stack(L);
  2050. stack.get_debug_line(1)->add_line(stack.get_vector3(2)
  2051. , stack.get_vector3(3)
  2052. , stack.get_color4(4)
  2053. );
  2054. return 0;
  2055. }
  2056. static int debug_line_add_axes(lua_State* L)
  2057. {
  2058. LuaStack stack(L);
  2059. const float len = stack.num_args() == 3
  2060. ? stack.get_float(3)
  2061. : 1.0f
  2062. ;
  2063. stack.get_debug_line(1)->add_axes(stack.get_matrix4x4(2), len);
  2064. return 0;
  2065. }
  2066. static int debug_line_add_circle(lua_State* L)
  2067. {
  2068. LuaStack stack(L);
  2069. const uint32_t segments = stack.num_args() >= 6
  2070. ? stack.get_int(6)
  2071. : DebugLine::NUM_SEGMENTS
  2072. ;
  2073. stack.get_debug_line(1)->add_circle(stack.get_vector3(2)
  2074. , stack.get_float(3)
  2075. , stack.get_vector3(4)
  2076. , stack.get_color4(5)
  2077. , segments
  2078. );
  2079. return 0;
  2080. }
  2081. static int debug_line_add_cone(lua_State* L)
  2082. {
  2083. LuaStack stack(L);
  2084. const uint32_t segments = stack.num_args() >= 6
  2085. ? stack.get_int(6)
  2086. : DebugLine::NUM_SEGMENTS
  2087. ;
  2088. stack.get_debug_line(1)->add_cone(stack.get_vector3(2)
  2089. , stack.get_vector3(3)
  2090. , stack.get_float(4)
  2091. , stack.get_color4(5)
  2092. , segments
  2093. );
  2094. return 0;
  2095. }
  2096. static int debug_line_add_sphere(lua_State* L)
  2097. {
  2098. LuaStack stack(L);
  2099. const uint32_t segments = stack.num_args() >= 5
  2100. ? stack.get_int(5)
  2101. : DebugLine::NUM_SEGMENTS
  2102. ;
  2103. stack.get_debug_line(1)->add_sphere(stack.get_vector3(2)
  2104. , stack.get_float(3)
  2105. , stack.get_color4(4)
  2106. , segments
  2107. );
  2108. return 0;
  2109. }
  2110. static int debug_line_add_obb(lua_State* L)
  2111. {
  2112. LuaStack stack(L);
  2113. stack.get_debug_line(1)->add_obb(stack.get_matrix4x4(2)
  2114. , stack.get_vector3(3)
  2115. , stack.get_color4(4)
  2116. );
  2117. return 0;
  2118. }
  2119. static int debug_line_reset(lua_State* L)
  2120. {
  2121. LuaStack stack(L);
  2122. stack.get_debug_line(1)->reset();
  2123. return 0;
  2124. }
  2125. static int debug_line_submit(lua_State* L)
  2126. {
  2127. LuaStack stack(L);
  2128. stack.get_debug_line(1)->submit();
  2129. return 0;
  2130. }
  2131. static int debug_line_tostring(lua_State* L)
  2132. {
  2133. LuaStack stack(L);
  2134. stack.push_fstring("DebugLine (%p)", stack.get_debug_line(1));
  2135. return 1;
  2136. }
  2137. static int resource_package_load(lua_State* L)
  2138. {
  2139. LuaStack stack(L);
  2140. stack.get_resource_package(1)->load();
  2141. return 0;
  2142. }
  2143. static int resource_package_unload(lua_State* L)
  2144. {
  2145. LuaStack stack(L);
  2146. stack.get_resource_package(1)->unload();
  2147. return 0;
  2148. }
  2149. static int resource_package_flush(lua_State* L)
  2150. {
  2151. LuaStack stack(L);
  2152. stack.get_resource_package(1)->flush();
  2153. return 0;
  2154. }
  2155. static int resource_package_has_loaded(lua_State* L)
  2156. {
  2157. LuaStack stack(L);
  2158. stack.push_bool(stack.get_resource_package(1)->has_loaded());
  2159. return 1;
  2160. }
  2161. static int resource_package_tostring(lua_State* L)
  2162. {
  2163. LuaStack stack(L);
  2164. ResourcePackage* package = stack.get_resource_package(1);
  2165. stack.push_fstring("ResourcePackage (%p)", package);
  2166. return 1;
  2167. }
  2168. static int material_set_float(lua_State* L)
  2169. {
  2170. LuaStack stack(L);
  2171. stack.get_material(1)->set_float(stack.get_string(2), stack.get_float(3));
  2172. return 0;
  2173. }
  2174. static int material_set_vector2(lua_State* L)
  2175. {
  2176. LuaStack stack(L);
  2177. stack.get_material(1)->set_vector2(stack.get_string(2), stack.get_vector2(3));
  2178. return 0;
  2179. }
  2180. static int material_set_vector3(lua_State* L)
  2181. {
  2182. LuaStack stack(L);
  2183. stack.get_material(1)->set_vector3(stack.get_string(2), stack.get_vector3(3));
  2184. return 0;
  2185. }
  2186. static int gui_resolution(lua_State* L)
  2187. {
  2188. LuaStack stack(L);
  2189. const Vector2 resolution = stack.get_gui(1)->resolution();
  2190. stack.push_int(resolution.x);
  2191. stack.push_int(resolution.y);
  2192. return 2;
  2193. }
  2194. static int gui_move(lua_State* L)
  2195. {
  2196. LuaStack stack(L);
  2197. stack.get_gui(1)->move(stack.get_vector2(2));
  2198. return 0;
  2199. }
  2200. static int gui_screen_to_gui(lua_State* L)
  2201. {
  2202. LuaStack stack(L);
  2203. stack.push_vector2(stack.get_gui(1)->screen_to_gui(stack.get_vector2(2)));
  2204. return 1;
  2205. }
  2206. static int gui_draw_rectangle(lua_State* L)
  2207. {
  2208. LuaStack stack(L);
  2209. stack.get_gui(1)->draw_rectangle(stack.get_vector3(2), stack.get_vector2(3),
  2210. stack.get_color4(4));
  2211. return 0;
  2212. }
  2213. static int gui_draw_image(lua_State* L)
  2214. {
  2215. LuaStack stack(L);
  2216. stack.get_gui(1)->draw_image(stack.get_string(2), stack.get_vector3(3),
  2217. stack.get_vector2(4), stack.get_color4(5));
  2218. return 0;
  2219. }
  2220. static int gui_draw_image_uv(lua_State* L)
  2221. {
  2222. LuaStack stack(L);
  2223. stack.get_gui(1)->draw_image_uv(stack.get_string(2), stack.get_vector3(3),
  2224. stack.get_vector2(4), stack.get_vector2(5), stack.get_vector2(6), stack.get_color4(7));
  2225. return 0;
  2226. }
  2227. static int gui_draw_text(lua_State* L)
  2228. {
  2229. LuaStack stack(L);
  2230. stack.get_gui(1)->draw_text(stack.get_string(2), stack.get_string(3), stack.get_int(4),
  2231. stack.get_vector3(5), stack.get_color4(6));
  2232. return 0;
  2233. }
  2234. static int window_show(lua_State* L)
  2235. {
  2236. LuaStack stack(L);
  2237. // window()->show();
  2238. return 0;
  2239. }
  2240. static int window_hide(lua_State* L)
  2241. {
  2242. LuaStack stack(L);
  2243. // window()->hide();
  2244. return 0;
  2245. }
  2246. static int window_resize(lua_State* L)
  2247. {
  2248. LuaStack stack(L);
  2249. // window()->resize(stack.get_int(1), stack.get_int(2));
  2250. return 0;
  2251. }
  2252. static int window_move(lua_State* L)
  2253. {
  2254. LuaStack stack(L);
  2255. // window()->move(stack.get_int(1), stack.get_int(2));
  2256. return 0;
  2257. }
  2258. static int window_minimize(lua_State* /*L*/)
  2259. {
  2260. // window()->minimize();
  2261. return 0;
  2262. }
  2263. static int window_restore(lua_State* /*L*/)
  2264. {
  2265. // window()->restore();
  2266. return 0;
  2267. }
  2268. static int window_is_resizable(lua_State* L)
  2269. {
  2270. LuaStack stack(L);
  2271. stack.push_bool(/*window()->is_resizable()*/ false);
  2272. return 1;
  2273. }
  2274. static int window_set_resizable(lua_State* L)
  2275. {
  2276. LuaStack stack(L);
  2277. // window()->set_resizable(stack.get_bool(1));
  2278. return 0;
  2279. }
  2280. static int window_title(lua_State* L)
  2281. {
  2282. LuaStack stack(L);
  2283. // stack.push_string(window()->title());
  2284. stack.push_string("");
  2285. return 1;
  2286. }
  2287. static int window_set_title(lua_State* L)
  2288. {
  2289. LuaStack stack(L);
  2290. // window()->set_title(stack.get_string(1));
  2291. return 0;
  2292. }
  2293. void load_api(LuaEnvironment& env)
  2294. {
  2295. env.load_module_function("Math", "ray_plane_intersection", math_ray_plane_intersection);
  2296. env.load_module_function("Math", "ray_disc_intersection", math_ray_disc_intersection);
  2297. env.load_module_function("Math", "ray_sphere_intersection", math_ray_sphere_intersection);
  2298. env.load_module_function("Math", "ray_obb_intersection", math_ray_obb_intersection);
  2299. env.load_module_function("Vector3", "new", vector3_new);
  2300. env.load_module_function("Vector3", "x", vector3_x);
  2301. env.load_module_function("Vector3", "y", vector3_y);
  2302. env.load_module_function("Vector3", "z", vector3_z);
  2303. env.load_module_function("Vector3", "set_x", vector3_set_x);
  2304. env.load_module_function("Vector3", "set_y", vector3_set_y);
  2305. env.load_module_function("Vector3", "set_z", vector3_set_z);
  2306. env.load_module_function("Vector3", "elements", vector3_elements);
  2307. env.load_module_function("Vector3", "add", vector3_add);
  2308. env.load_module_function("Vector3", "subtract", vector3_subtract);
  2309. env.load_module_function("Vector3", "multiply", vector3_multiply);
  2310. env.load_module_function("Vector3", "dot", vector3_dot);
  2311. env.load_module_function("Vector3", "cross", vector3_cross);
  2312. env.load_module_function("Vector3", "equal", vector3_equal);
  2313. env.load_module_function("Vector3", "length", vector3_length);
  2314. env.load_module_function("Vector3", "length_squared", vector3_length_squared);
  2315. env.load_module_function("Vector3", "set_length", vector3_set_length);
  2316. env.load_module_function("Vector3", "normalize", vector3_normalize);
  2317. env.load_module_function("Vector3", "distance", vector3_distance);
  2318. env.load_module_function("Vector3", "distance_squared", vector3_distance_squared);
  2319. env.load_module_function("Vector3", "angle", vector3_angle);
  2320. env.load_module_function("Vector3", "max", vector3_max);
  2321. env.load_module_function("Vector3", "min", vector3_min);
  2322. env.load_module_function("Vector3", "lerp", vector3_lerp);
  2323. env.load_module_function("Vector3", "forward", vector3_forward);
  2324. env.load_module_function("Vector3", "backward", vector3_backward);
  2325. env.load_module_function("Vector3", "left", vector3_left);
  2326. env.load_module_function("Vector3", "right", vector3_right);
  2327. env.load_module_function("Vector3", "up", vector3_up);
  2328. env.load_module_function("Vector3", "down", vector3_down);
  2329. env.load_module_function("Vector3", "zero", vector3_zero);
  2330. env.load_module_function("Vector3", "to_string", vector3_to_string);
  2331. env.load_module_constructor("Vector3", vector3_ctor);
  2332. env.load_module_function("Vector2", "new", vector2_new);
  2333. env.load_module_constructor("Vector2", vector2_ctor);
  2334. env.load_module_function("Vector3Box", "new", vector3box_new);
  2335. env.load_module_function("Vector3Box", "store", vector3box_store);
  2336. env.load_module_function("Vector3Box", "unbox", vector3box_unbox);
  2337. env.load_module_function("Vector3Box", "__index", "Vector3Box");
  2338. env.load_module_function("Vector3Box", "__tostring", vector3box_tostring);
  2339. env.load_module_constructor("Vector3Box", vector3box_ctor);
  2340. env.load_module_function("Matrix4x4", "new", matrix4x4_new);
  2341. env.load_module_function("Matrix4x4", "from_quaternion", matrix4x4_from_quaternion);
  2342. env.load_module_function("Matrix4x4", "from_translation", matrix4x4_from_translation);
  2343. env.load_module_function("Matrix4x4", "from_quaternion_translation", matrix4x4_from_quaternion_translation);
  2344. env.load_module_function("Matrix4x4", "from_axes", matrix4x4_from_axes);
  2345. env.load_module_function("Matrix4x4", "copy", matrix4x4_copy);
  2346. env.load_module_function("Matrix4x4", "add", matrix4x4_add);
  2347. env.load_module_function("Matrix4x4", "subtract", matrix4x4_subtract);
  2348. env.load_module_function("Matrix4x4", "multiply", matrix4x4_multiply);
  2349. env.load_module_function("Matrix4x4", "transpose", matrix4x4_transpose);
  2350. env.load_module_function("Matrix4x4", "determinant", matrix4x4_determinant);
  2351. env.load_module_function("Matrix4x4", "invert", matrix4x4_invert);
  2352. env.load_module_function("Matrix4x4", "x", matrix4x4_x);
  2353. env.load_module_function("Matrix4x4", "y", matrix4x4_y);
  2354. env.load_module_function("Matrix4x4", "z", matrix4x4_z);
  2355. env.load_module_function("Matrix4x4", "set_x", matrix4x4_set_x);
  2356. env.load_module_function("Matrix4x4", "set_y", matrix4x4_set_y);
  2357. env.load_module_function("Matrix4x4", "set_z", matrix4x4_set_z);
  2358. env.load_module_function("Matrix4x4", "translation", matrix4x4_translation);
  2359. env.load_module_function("Matrix4x4", "set_translation", matrix4x4_set_translation);
  2360. env.load_module_function("Matrix4x4", "rotation", matrix4x4_rotation);
  2361. env.load_module_function("Matrix4x4", "set_rotation", matrix4x4_set_rotation);
  2362. env.load_module_function("Matrix4x4", "identity", matrix4x4_identity);
  2363. env.load_module_function("Matrix4x4", "transform", matrix4x4_transform);
  2364. env.load_module_function("Matrix4x4", "to_string", matrix4x4_to_string);
  2365. env.load_module_constructor("Matrix4x4", matrix4x4_ctor);
  2366. env.load_module_function("Matrix4x4Box", "new", matrix4x4box_new);
  2367. env.load_module_function("Matrix4x4Box", "store", matrix4x4box_store);
  2368. env.load_module_function("Matrix4x4Box", "unbox", matrix4x4box_unbox);
  2369. env.load_module_function("Matrix4x4Box", "__index", "Matrix4x4Box");
  2370. env.load_module_function("Matrix4x4Box", "__tostring", matrix4x4box_tostring);
  2371. env.load_module_constructor("Matrix4x4Box", matrix4x4box_ctor);
  2372. env.load_module_function("Quaternion", "new", quaternion_new);
  2373. env.load_module_function("Quaternion", "negate", quaternion_negate);
  2374. env.load_module_function("Quaternion", "identity", quaternion_identity);
  2375. env.load_module_function("Quaternion", "multiply", quaternion_multiply);
  2376. env.load_module_function("Quaternion", "multiply_by_scalar", quaternion_multiply_by_scalar);
  2377. env.load_module_function("Quaternion", "dot", quaternion_dot);
  2378. env.load_module_function("Quaternion", "length", quaternion_length);
  2379. env.load_module_function("Quaternion", "normalize", quaternion_normalize);
  2380. env.load_module_function("Quaternion", "conjugate", quaternion_conjugate);
  2381. env.load_module_function("Quaternion", "inverse", quaternion_inverse);
  2382. env.load_module_function("Quaternion", "power", quaternion_power);
  2383. env.load_module_function("Quaternion", "elements", quaternion_elements);
  2384. env.load_module_function("Quaternion", "look", quaternion_look);
  2385. env.load_module_function("Quaternion", "right", quaternion_right);
  2386. env.load_module_function("Quaternion", "up", quaternion_up);
  2387. env.load_module_function("Quaternion", "forward", quaternion_forward);
  2388. env.load_module_function("Quaternion", "lerp", quaternion_lerp);
  2389. env.load_module_function("Quaternion", "to_string", quaternion_to_string);
  2390. env.load_module_constructor("Quaternion", quaternion_ctor);
  2391. env.load_module_function("QuaternionBox", "new", quaternionbox_new);
  2392. env.load_module_function("QuaternionBox", "store", quaternionbox_store);
  2393. env.load_module_function("QuaternionBox", "unbox", quaternionbox_unbox);
  2394. env.load_module_function("QuaternionBox", "__index", "QuaternionBox");
  2395. env.load_module_function("QuaternionBox", "__tostring", quaternionbox_tostring);
  2396. env.load_module_constructor("QuaternionBox", quaternionbox_ctor);
  2397. env.load_module_function("Color4", "new", color4_new);
  2398. env.load_module_function("Color4", "to_string", quaternion_to_string);
  2399. env.load_module_constructor("Color4", color4_ctor);
  2400. env.load_module_function("Lightuserdata_mt", "__add", lightuserdata_add);
  2401. env.load_module_function("Lightuserdata_mt", "__sub", lightuserdata_sub);
  2402. env.load_module_function("Lightuserdata_mt", "__mul", lightuserdata_mul);
  2403. env.load_module_function("Lightuserdata_mt", "__unm", lightuserdata_unm);
  2404. env.load_module_function("Lightuserdata_mt", "__index", lightuserdata_index);
  2405. env.load_module_function("Lightuserdata_mt", "__newindex", lightuserdata_newindex);
  2406. env.load_module_function("Keyboard", "name", KEYBOARD_FN(name));
  2407. env.load_module_function("Keyboard", "connected", KEYBOARD_FN(connected));
  2408. env.load_module_function("Keyboard", "num_buttons", KEYBOARD_FN(num_buttons));
  2409. env.load_module_function("Keyboard", "num_axes", KEYBOARD_FN(num_axes));
  2410. env.load_module_function("Keyboard", "pressed", KEYBOARD_FN(pressed));
  2411. env.load_module_function("Keyboard", "released", KEYBOARD_FN(released));
  2412. env.load_module_function("Keyboard", "any_pressed", KEYBOARD_FN(any_pressed));
  2413. env.load_module_function("Keyboard", "any_released", KEYBOARD_FN(any_released));
  2414. env.load_module_function("Keyboard", "button_name", KEYBOARD_FN(button_name));
  2415. env.load_module_function("Keyboard", "button_id", KEYBOARD_FN(button_id));
  2416. env.load_module_function("Mouse", "name", MOUSE_FN(name));
  2417. env.load_module_function("Mouse", "connected", MOUSE_FN(connected));
  2418. env.load_module_function("Mouse", "num_buttons", MOUSE_FN(num_buttons));
  2419. env.load_module_function("Mouse", "num_axes", MOUSE_FN(num_axes));
  2420. env.load_module_function("Mouse", "pressed", MOUSE_FN(pressed));
  2421. env.load_module_function("Mouse", "released", MOUSE_FN(released));
  2422. env.load_module_function("Mouse", "any_pressed", MOUSE_FN(any_pressed));
  2423. env.load_module_function("Mouse", "any_released", MOUSE_FN(any_released));
  2424. env.load_module_function("Mouse", "axis", MOUSE_FN(axis));
  2425. env.load_module_function("Mouse", "button_name", MOUSE_FN(button_name));
  2426. env.load_module_function("Mouse", "axis_name", MOUSE_FN(axis_name));
  2427. env.load_module_function("Mouse", "button_id", MOUSE_FN(button_id));
  2428. env.load_module_function("Mouse", "axis_id", MOUSE_FN(axis_id));
  2429. env.load_module_function("Touch", "name", TOUCH_FN(name));
  2430. env.load_module_function("Touch", "connected", TOUCH_FN(connected));
  2431. env.load_module_function("Touch", "num_buttons", TOUCH_FN(num_buttons));
  2432. env.load_module_function("Touch", "num_axes", TOUCH_FN(num_axes));
  2433. env.load_module_function("Touch", "pressed", TOUCH_FN(pressed));
  2434. env.load_module_function("Touch", "released", TOUCH_FN(released));
  2435. env.load_module_function("Touch", "any_pressed", TOUCH_FN(any_pressed));
  2436. env.load_module_function("Touch", "any_released", TOUCH_FN(any_released));
  2437. env.load_module_function("Touch", "axis", TOUCH_FN(axis));
  2438. env.load_module_function("Touch", "button_name", TOUCH_FN(button_name));
  2439. env.load_module_function("Touch", "axis_name", TOUCH_FN(axis_name));
  2440. env.load_module_function("Touch", "button_id", TOUCH_FN(button_id));
  2441. env.load_module_function("Touch", "axis_id", TOUCH_FN(axis_id));
  2442. env.load_module_function("Pad1", "name", JOYPAD_FN(0, name));
  2443. env.load_module_function("Pad1", "connected", JOYPAD_FN(0, connected));
  2444. env.load_module_function("Pad1", "num_buttons", JOYPAD_FN(0, num_buttons));
  2445. env.load_module_function("Pad1", "num_axes", JOYPAD_FN(0, num_axes));
  2446. env.load_module_function("Pad1", "pressed", JOYPAD_FN(0, pressed));
  2447. env.load_module_function("Pad1", "released", JOYPAD_FN(0, released));
  2448. env.load_module_function("Pad1", "any_pressed", JOYPAD_FN(0, any_pressed));
  2449. env.load_module_function("Pad1", "any_released", JOYPAD_FN(0, any_released));
  2450. env.load_module_function("Pad1", "axis", JOYPAD_FN(0, axis));
  2451. env.load_module_function("Pad1", "button_name", JOYPAD_FN(0, button_name));
  2452. env.load_module_function("Pad1", "axis_name", JOYPAD_FN(0, axis_name));
  2453. env.load_module_function("Pad1", "button_id", JOYPAD_FN(0, button_id));
  2454. env.load_module_function("Pad1", "axis_id", JOYPAD_FN(0, axis_id));
  2455. env.load_module_function("Pad2", "name", JOYPAD_FN(1, name));
  2456. env.load_module_function("Pad2", "connected", JOYPAD_FN(1, connected));
  2457. env.load_module_function("Pad2", "num_buttons", JOYPAD_FN(1, num_buttons));
  2458. env.load_module_function("Pad2", "num_axes", JOYPAD_FN(1, num_axes));
  2459. env.load_module_function("Pad2", "pressed", JOYPAD_FN(1, pressed));
  2460. env.load_module_function("Pad2", "released", JOYPAD_FN(1, released));
  2461. env.load_module_function("Pad2", "any_pressed", JOYPAD_FN(1, any_pressed));
  2462. env.load_module_function("Pad2", "any_released", JOYPAD_FN(1, any_released));
  2463. env.load_module_function("Pad2", "axis", JOYPAD_FN(1, axis));
  2464. env.load_module_function("Pad2", "button_name", JOYPAD_FN(1, button_name));
  2465. env.load_module_function("Pad2", "axis_name", JOYPAD_FN(1, axis_name));
  2466. env.load_module_function("Pad2", "button_id", JOYPAD_FN(1, button_id));
  2467. env.load_module_function("Pad2", "axis_id", JOYPAD_FN(1, axis_id));
  2468. env.load_module_function("Pad3", "name", JOYPAD_FN(2, name));
  2469. env.load_module_function("Pad3", "connected", JOYPAD_FN(2, connected));
  2470. env.load_module_function("Pad3", "num_buttons", JOYPAD_FN(2, num_buttons));
  2471. env.load_module_function("Pad3", "num_axes", JOYPAD_FN(2, num_axes));
  2472. env.load_module_function("Pad3", "pressed", JOYPAD_FN(2, pressed));
  2473. env.load_module_function("Pad3", "released", JOYPAD_FN(2, released));
  2474. env.load_module_function("Pad3", "any_pressed", JOYPAD_FN(2, any_pressed));
  2475. env.load_module_function("Pad3", "any_released", JOYPAD_FN(2, any_released));
  2476. env.load_module_function("Pad3", "axis", JOYPAD_FN(2, axis));
  2477. env.load_module_function("Pad3", "button_name", JOYPAD_FN(2, button_name));
  2478. env.load_module_function("Pad3", "axis_name", JOYPAD_FN(2, axis_name));
  2479. env.load_module_function("Pad3", "button_id", JOYPAD_FN(2, button_id));
  2480. env.load_module_function("Pad3", "axis_id", JOYPAD_FN(2, axis_id));
  2481. env.load_module_function("Pad4", "name", JOYPAD_FN(3, name));
  2482. env.load_module_function("Pad4", "connected", JOYPAD_FN(3, connected));
  2483. env.load_module_function("Pad4", "num_buttons", JOYPAD_FN(3, num_buttons));
  2484. env.load_module_function("Pad4", "num_axes", JOYPAD_FN(3, num_axes));
  2485. env.load_module_function("Pad4", "pressed", JOYPAD_FN(3, pressed));
  2486. env.load_module_function("Pad4", "released", JOYPAD_FN(3, released));
  2487. env.load_module_function("Pad4", "any_pressed", JOYPAD_FN(3, any_pressed));
  2488. env.load_module_function("Pad4", "any_released", JOYPAD_FN(3, any_released));
  2489. env.load_module_function("Pad4", "axis", JOYPAD_FN(3, axis));
  2490. env.load_module_function("Pad4", "button_name", JOYPAD_FN(3, button_name));
  2491. env.load_module_function("Pad4", "axis_name", JOYPAD_FN(3, axis_name));
  2492. env.load_module_function("Pad4", "button_id", JOYPAD_FN(3, button_id));
  2493. env.load_module_function("Pad4", "axis_id", JOYPAD_FN(3, axis_id));
  2494. env.load_module_function("World", "spawn_unit", world_spawn_unit);
  2495. env.load_module_function("World", "destroy_unit", world_destroy_unit);
  2496. env.load_module_function("World", "num_units", world_num_units);
  2497. env.load_module_function("World", "units", world_units);
  2498. env.load_module_function("World", "camera", world_camera);
  2499. env.load_module_function("World", "set_camera_projection_type", camera_set_projection_type);
  2500. env.load_module_function("World", "camera_projection_type", camera_projection_type);
  2501. env.load_module_function("World", "camera_fov", camera_fov);
  2502. env.load_module_function("World", "set_camera_fov", camera_set_fov);
  2503. env.load_module_function("World", "camera_aspect", camera_aspect);
  2504. env.load_module_function("World", "set_camera_aspect", camera_set_aspect);
  2505. env.load_module_function("World", "camera_near_clip_distance", camera_near_clip_distance);
  2506. env.load_module_function("World", "set_camera_near_clip_distance", camera_set_near_clip_distance);
  2507. env.load_module_function("World", "camera_far_clip_distance", camera_far_clip_distance);
  2508. env.load_module_function("World", "set_camera_far_clip_distance", camera_set_far_clip_distance);
  2509. env.load_module_function("World", "set_camera_orthographic_metrics", camera_set_orthographic_metrics);
  2510. env.load_module_function("World", "set_camera_viewport_metrics", camera_set_viewport_metrics);
  2511. env.load_module_function("World", "camera_screen_to_world", camera_screen_to_world);
  2512. env.load_module_function("World", "camera_world_to_screen", camera_world_to_screen);
  2513. env.load_module_function("World", "update_animations", world_update_animations);
  2514. env.load_module_function("World", "update_scene", world_update_scene);
  2515. env.load_module_function("World", "update", world_update);
  2516. env.load_module_function("World", "play_sound", world_play_sound);
  2517. env.load_module_function("World", "stop_sound", world_stop_sound);
  2518. env.load_module_function("World", "link_sound", world_link_sound);
  2519. env.load_module_function("World", "set_listener_pose", world_set_listener_pose);
  2520. env.load_module_function("World", "set_sound_position", world_set_sound_position);
  2521. env.load_module_function("World", "set_sound_range", world_set_sound_range);
  2522. env.load_module_function("World", "set_sound_volume", world_set_sound_volume);
  2523. env.load_module_function("World", "create_debug_line", world_create_debug_line);
  2524. env.load_module_function("World", "destroy_debug_line", world_destroy_debug_line);
  2525. env.load_module_function("World", "load_level", world_load_level);
  2526. env.load_module_function("World", "scene_graph", world_scene_graph);
  2527. env.load_module_function("World", "render_world", world_render_world);
  2528. env.load_module_function("World", "physics_world", world_physics_world);
  2529. env.load_module_function("World", "sound_world", world_sound_world);
  2530. env.load_module_function("World", "__index", "World");
  2531. env.load_module_function("World", "__tostring", world_tostring);
  2532. env.load_module_function("SceneGraph", "create", scene_graph_create);
  2533. env.load_module_function("SceneGraph", "destroy", scene_graph_destroy);
  2534. env.load_module_function("SceneGraph", "transform_instances", scene_graph_transform_instances);
  2535. env.load_module_function("SceneGraph", "local_position", scene_graph_local_position);
  2536. env.load_module_function("SceneGraph", "local_rotation", scene_graph_local_rotation);
  2537. env.load_module_function("SceneGraph", "local_scale", scene_graph_local_scale);
  2538. env.load_module_function("SceneGraph", "local_pose", scene_graph_local_pose);
  2539. env.load_module_function("SceneGraph", "world_position", scene_graph_world_position);
  2540. env.load_module_function("SceneGraph", "world_rotation", scene_graph_world_rotation);
  2541. env.load_module_function("SceneGraph", "world_pose", scene_graph_world_pose);
  2542. env.load_module_function("SceneGraph", "set_local_position", scene_graph_set_local_position);
  2543. env.load_module_function("SceneGraph", "set_local_rotation", scene_graph_set_local_rotation);
  2544. env.load_module_function("SceneGraph", "set_local_scale", scene_graph_set_local_scale);
  2545. env.load_module_function("SceneGraph", "set_local_pose", scene_graph_set_local_pose);
  2546. env.load_module_function("SceneGraph", "link", scene_graph_link);
  2547. env.load_module_function("SceneGraph", "unlink", scene_graph_unlink);
  2548. env.load_module_function("UnitManager", "create", unit_manager_create);
  2549. env.load_module_function("UnitManager", "alive", unit_manager_alive);
  2550. env.load_module_function("RenderWorld", "create_mesh", render_world_create_mesh);
  2551. env.load_module_function("RenderWorld", "destroy_mesh", render_world_destroy_mesh);
  2552. env.load_module_function("RenderWorld", "mesh_instances", render_world_mesh_instances);
  2553. env.load_module_function("RenderWorld", "mesh_obb", render_world_mesh_obb);
  2554. env.load_module_function("RenderWorld", "set_mesh_visible", render_world_set_mesh_visible);
  2555. env.load_module_function("RenderWorld", "create_sprite", render_world_create_sprite);
  2556. env.load_module_function("RenderWorld", "destroy_sprite", render_world_destroy_sprite);
  2557. env.load_module_function("RenderWorld", "sprite_instances", render_world_sprite_instances);
  2558. env.load_module_function("RenderWorld", "set_sprite_frame", render_world_set_sprite_frame);
  2559. env.load_module_function("RenderWorld", "set_sprite_visible", render_world_set_sprite_visible);
  2560. env.load_module_function("RenderWorld", "create_light", render_world_create_light);
  2561. env.load_module_function("RenderWorld", "destroy_light", render_world_destroy_light);
  2562. env.load_module_function("RenderWorld", "light_instances", render_world_light_instances);
  2563. env.load_module_function("RenderWorld", "light_type", render_world_light_type);
  2564. env.load_module_function("RenderWorld", "light_color", render_world_light_color);
  2565. env.load_module_function("RenderWorld", "light_range", render_world_light_range);
  2566. env.load_module_function("RenderWorld", "light_intensity", render_world_light_intensity);
  2567. env.load_module_function("RenderWorld", "light_spot_angle", render_world_light_spot_angle);
  2568. env.load_module_function("RenderWorld", "set_light_type", render_world_set_light_type);
  2569. env.load_module_function("RenderWorld", "set_light_color", render_world_set_light_color);
  2570. env.load_module_function("RenderWorld", "set_light_range", render_world_set_light_range);
  2571. env.load_module_function("RenderWorld", "set_light_intensity", render_world_set_light_intensity);
  2572. env.load_module_function("RenderWorld", "set_light_spot_angle", render_world_set_light_spot_angle);
  2573. env.load_module_function("RenderWorld", "enable_debug_drawing", render_world_enable_debug_drawing);
  2574. env.load_module_function("PhysicsWorld", "actor_instances", physics_world_actor_instances);
  2575. env.load_module_function("PhysicsWorld", "actor_world_position", physics_world_actor_world_position);
  2576. env.load_module_function("PhysicsWorld", "actor_world_rotation", physics_world_actor_world_rotation);
  2577. env.load_module_function("PhysicsWorld", "actor_world_pose", physics_world_actor_world_pose);
  2578. env.load_module_function("PhysicsWorld", "teleport_actor_world_position", physics_world_teleport_actor_world_position);
  2579. env.load_module_function("PhysicsWorld", "teleport_actor_world_rotation", physics_world_teleport_actor_world_rotation);
  2580. env.load_module_function("PhysicsWorld", "teleport_actor_world_pose", physics_world_teleport_actor_world_pose);
  2581. env.load_module_function("PhysicsWorld", "actor_center_of_mass", physics_world_actor_center_of_mass);
  2582. env.load_module_function("PhysicsWorld", "enable_actor_gravity", physics_world_enable_actor_gravity);
  2583. env.load_module_function("PhysicsWorld", "disable_actor_gravity", physics_world_disable_actor_gravity);
  2584. env.load_module_function("PhysicsWorld", "enable_actor_collision", physics_world_enable_actor_collision);
  2585. env.load_module_function("PhysicsWorld", "disable_actor_collision", physics_world_disable_actor_collision);
  2586. env.load_module_function("PhysicsWorld", "set_actor_collision_filter", physics_world_set_actor_collision_filter);
  2587. env.load_module_function("PhysicsWorld", "set_actor_kinematic", physics_world_set_actor_kinematic);
  2588. env.load_module_function("PhysicsWorld", "move_actor", physics_world_move_actor);
  2589. env.load_module_function("PhysicsWorld", "is_static", physics_world_is_static);
  2590. env.load_module_function("PhysicsWorld", "is_dynamic", physics_world_is_dynamic);
  2591. env.load_module_function("PhysicsWorld", "is_kinematic", physics_world_is_kinematic);
  2592. env.load_module_function("PhysicsWorld", "is_nonkinematic", physics_world_is_nonkinematic);
  2593. env.load_module_function("PhysicsWorld", "actor_linear_damping", physics_world_actor_linear_damping);
  2594. env.load_module_function("PhysicsWorld", "set_actor_linear_damping", physics_world_set_actor_linear_damping);
  2595. env.load_module_function("PhysicsWorld", "actor_angular_damping", physics_world_actor_angular_damping);
  2596. env.load_module_function("PhysicsWorld", "set_actor_angular_damping", physics_world_set_actor_angular_damping);
  2597. env.load_module_function("PhysicsWorld", "actor_linear_velocity", physics_world_actor_linear_velocity);
  2598. env.load_module_function("PhysicsWorld", "set_actor_linear_velocity", physics_world_set_actor_linear_velocity);
  2599. env.load_module_function("PhysicsWorld", "actor_angular_velocity", physics_world_actor_angular_velocity);
  2600. env.load_module_function("PhysicsWorld", "set_actor_angular_velocity", physics_world_set_actor_angular_velocity);
  2601. env.load_module_function("PhysicsWorld", "add_actor_impulse", physics_world_add_actor_impulse);
  2602. env.load_module_function("PhysicsWorld", "add_actor_impulse_at", physics_world_add_actor_impulse_at);
  2603. env.load_module_function("PhysicsWorld", "add_actor_torque_impulse", physics_world_add_actor_torque_impulse);
  2604. env.load_module_function("PhysicsWorld", "push_actor", physics_world_push_actor);
  2605. env.load_module_function("PhysicsWorld", "push_actor_at", physics_world_push_actor_at);
  2606. env.load_module_function("PhysicsWorld", "is_sleeping", physics_world_is_sleeping);
  2607. env.load_module_function("PhysicsWorld", "wake_up", physics_world_wake_up);
  2608. env.load_module_function("PhysicsWorld", "controller_instances", physics_world_controller_instances);
  2609. env.load_module_function("PhysicsWorld", "move_controller", physics_world_move_controller);
  2610. env.load_module_function("PhysicsWorld", "create_joint", physics_world_create_joint);
  2611. env.load_module_function("PhysicsWorld", "gravity", physics_world_gravity);
  2612. env.load_module_function("PhysicsWorld", "set_gravity", physics_world_set_gravity);
  2613. env.load_module_function("PhysicsWorld", "raycast", physics_world_raycast);
  2614. env.load_module_function("PhysicsWorld", "enable_debug_drawing", physics_world_enable_debug_drawing);
  2615. env.load_module_function("PhysicsWorld", "__index", "PhysicsWorld");
  2616. env.load_module_function("PhysicsWorld", "__tostring", physics_world_tostring);
  2617. env.load_module_function("SoundWorld", "stop_all", sound_world_stop_all);
  2618. env.load_module_function("SoundWorld", "pause_all", sound_world_pause_all);
  2619. env.load_module_function("SoundWorld", "resume_all", sound_world_resume_all);
  2620. env.load_module_function("SoundWorld", "is_playing", sound_world_is_playing);
  2621. env.load_module_function("SoundWorld", "__index", "SoundWorld");
  2622. env.load_module_function("SoundWorld", "__tostring", sound_world_tostring);
  2623. env.load_module_function("Device", "platform", device_platform);
  2624. env.load_module_function("Device", "architecture", device_architecture);
  2625. env.load_module_function("Device", "version", device_version);
  2626. env.load_module_function("Device", "last_delta_time", device_last_delta_time);
  2627. env.load_module_function("Device", "quit", device_quit);
  2628. env.load_module_function("Device", "resolution", device_resolution);
  2629. env.load_module_function("Device", "create_world", device_create_world);
  2630. env.load_module_function("Device", "destroy_world", device_destroy_world);
  2631. env.load_module_function("Device", "render_world", device_render_world);
  2632. env.load_module_function("Device", "create_resource_package", device_create_resource_package);
  2633. env.load_module_function("Device", "destroy_resource_package", device_destroy_resource_package);
  2634. env.load_module_function("Device", "console_send", device_console_send);
  2635. env.load_module_function("Device", "can_get", device_can_get);
  2636. env.load_module_function("Device", "enable_resource_autoload", device_enable_resource_autoload);
  2637. env.load_module_function("Profiler", "enter_scope", profiler_enter_scope);
  2638. env.load_module_function("Profiler", "leave_scope", profiler_leave_scope);
  2639. env.load_module_function("Profiler", "record", profiler_record);
  2640. env.load_module_function("DebugLine", "add_line", debug_line_add_line);
  2641. env.load_module_function("DebugLine", "add_axes", debug_line_add_axes);
  2642. env.load_module_function("DebugLine", "add_circle", debug_line_add_circle);
  2643. env.load_module_function("DebugLine", "add_cone", debug_line_add_cone);
  2644. env.load_module_function("DebugLine", "add_sphere", debug_line_add_sphere);
  2645. env.load_module_function("DebugLine", "add_obb", debug_line_add_obb);
  2646. env.load_module_function("DebugLine", "reset", debug_line_reset);
  2647. env.load_module_function("DebugLine", "submit", debug_line_submit);
  2648. env.load_module_function("DebugLine", "__index", "DebugLine");
  2649. env.load_module_function("DebugLine", "__tostring", debug_line_tostring);
  2650. env.load_module_function("ResourcePackage", "load", resource_package_load);
  2651. env.load_module_function("ResourcePackage", "unload", resource_package_unload);
  2652. env.load_module_function("ResourcePackage", "flush", resource_package_flush);
  2653. env.load_module_function("ResourcePackage", "has_loaded", resource_package_has_loaded);
  2654. env.load_module_function("ResourcePackage", "__index", "ResourcePackage");
  2655. env.load_module_function("ResourcePackage", "__tostring", resource_package_tostring);
  2656. env.load_module_function("Material", "set_float", material_set_float);
  2657. env.load_module_function("Material", "set_vector2", material_set_vector2);
  2658. env.load_module_function("Material", "set_vector3", material_set_vector3);
  2659. env.load_module_function("Gui", "resolution", gui_resolution);
  2660. env.load_module_function("Gui", "move", gui_move);
  2661. env.load_module_function("Gui", "screen_to_gui", gui_screen_to_gui);
  2662. env.load_module_function("Gui", "draw_rectangle", gui_draw_rectangle);
  2663. env.load_module_function("Gui", "draw_image", gui_draw_image);
  2664. env.load_module_function("Gui", "draw_image_uv", gui_draw_image_uv);
  2665. env.load_module_function("Gui", "draw_text", gui_draw_text);
  2666. env.load_module_function("Window", "show", window_show);
  2667. env.load_module_function("Window", "hide", window_hide);
  2668. env.load_module_function("Window", "resize", window_resize);
  2669. env.load_module_function("Window", "move", window_move);
  2670. env.load_module_function("Window", "minimize", window_minimize);
  2671. env.load_module_function("Window", "restore", window_restore);
  2672. env.load_module_function("Window", "is_resizable", window_is_resizable);
  2673. env.load_module_function("Window", "set_resizable", window_set_resizable);
  2674. env.load_module_function("Window", "title", window_title);
  2675. env.load_module_function("Window", "set_title", window_set_title);
  2676. }
  2677. } // namespace crown