lua_api.cpp 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129
  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 (u32 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 (u32 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 (u32 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 f32 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 f32 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 f32 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 f32 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 f32 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 u32 num = array::size(units);
  1075. stack.push_table(num);
  1076. for (u32 i = 0; i < num; ++i)
  1077. {
  1078. stack.push_key_begin((s32) 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 s32 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 f32 volume = nargs > 3 ? stack.get_float(4) : 1.0f;
  1206. const Vector3& pos = nargs > 4 ? stack.get_vector3(5) : VECTOR3_ZERO;
  1207. const f32 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), stack.get_float(3));
  1243. return 0;
  1244. }
  1245. static int world_set_sound_volume(lua_State* L)
  1246. {
  1247. LuaStack stack(L);
  1248. stack.get_world(1)->set_sound_volume(stack.get_sound_instance_id(2), stack.get_float(3));
  1249. return 0;
  1250. }
  1251. static int world_create_debug_line(lua_State* L)
  1252. {
  1253. LuaStack stack(L);
  1254. stack.push_debug_line(stack.get_world(1)->create_debug_line(stack.get_bool(2)));
  1255. return 1;
  1256. }
  1257. static int world_destroy_debug_line(lua_State* L)
  1258. {
  1259. LuaStack stack(L);
  1260. stack.get_world(1)->destroy_debug_line(*stack.get_debug_line(2));
  1261. return 0;
  1262. }
  1263. static int world_load_level(lua_State* L)
  1264. {
  1265. LuaStack stack(L);
  1266. const int nargs = stack.num_args();
  1267. const StringId64 name = stack.get_resource_id(2);
  1268. const Vector3& pos = nargs > 2 ? stack.get_vector3(3) : VECTOR3_ZERO;
  1269. const Quaternion& rot = nargs > 3 ? stack.get_quaternion(4) : QUATERNION_IDENTITY;
  1270. LUA_ASSERT(device()->resource_manager()->can_get(LEVEL_TYPE, name), stack, "Level not found");
  1271. stack.push_level(stack.get_world(1)->load_level(name, pos, rot));
  1272. return 1;
  1273. }
  1274. static int world_scene_graph(lua_State* L)
  1275. {
  1276. LuaStack stack(L);
  1277. stack.push_scene_graph(stack.get_world(1)->scene_graph());
  1278. return 1;
  1279. }
  1280. static int world_render_world(lua_State* L)
  1281. {
  1282. LuaStack stack(L);
  1283. stack.push_render_world(stack.get_world(1)->render_world());
  1284. return 1;
  1285. }
  1286. static int world_physics_world(lua_State* L)
  1287. {
  1288. LuaStack stack(L);
  1289. stack.push_physics_world(stack.get_world(1)->physics_world());
  1290. return 1;
  1291. }
  1292. static int world_sound_world(lua_State* L)
  1293. {
  1294. LuaStack stack(L);
  1295. stack.push_sound_world(stack.get_world(1)->sound_world());
  1296. return 1;
  1297. }
  1298. static int world_tostring(lua_State* L)
  1299. {
  1300. LuaStack stack(L);
  1301. World* w = stack.get_world(1);
  1302. stack.push_fstring("World (%p)", w);
  1303. return 1;
  1304. }
  1305. static int scene_graph_create(lua_State* L)
  1306. {
  1307. LuaStack stack(L);
  1308. stack.push_transform(stack.get_scene_graph(1)->create(stack.get_unit(2), MATRIX4X4_IDENTITY));
  1309. return 1;
  1310. }
  1311. static int scene_graph_destroy(lua_State* L)
  1312. {
  1313. LuaStack stack(L);
  1314. stack.get_scene_graph(1)->destroy(stack.get_transform(2));
  1315. return 0;
  1316. }
  1317. static int scene_graph_transform_instances(lua_State* L)
  1318. {
  1319. LuaStack stack(L);
  1320. stack.push_transform(stack.get_scene_graph(1)->get(stack.get_unit(2)));
  1321. return 1;
  1322. }
  1323. static int scene_graph_local_position(lua_State* L)
  1324. {
  1325. LuaStack stack(L);
  1326. stack.push_vector3(stack.get_scene_graph(1)->local_position(stack.get_transform(2)));
  1327. return 1;
  1328. }
  1329. static int scene_graph_local_rotation(lua_State* L)
  1330. {
  1331. LuaStack stack(L);
  1332. stack.push_quaternion(stack.get_scene_graph(1)->local_rotation(stack.get_transform(2)));
  1333. return 1;
  1334. }
  1335. static int scene_graph_local_scale(lua_State* L)
  1336. {
  1337. LuaStack stack(L);
  1338. stack.push_vector3(stack.get_scene_graph(1)->local_scale(stack.get_transform(2)));
  1339. return 1;
  1340. }
  1341. static int scene_graph_local_pose(lua_State* L)
  1342. {
  1343. LuaStack stack(L);
  1344. stack.push_matrix4x4(stack.get_scene_graph(1)->local_pose(stack.get_transform(2)));
  1345. return 1;
  1346. }
  1347. static int scene_graph_world_position(lua_State* L)
  1348. {
  1349. LuaStack stack(L);
  1350. stack.push_vector3(stack.get_scene_graph(1)->world_position(stack.get_transform(2)));
  1351. return 1;
  1352. }
  1353. static int scene_graph_world_rotation(lua_State* L)
  1354. {
  1355. LuaStack stack(L);
  1356. stack.push_quaternion(stack.get_scene_graph(1)->world_rotation(stack.get_transform(2)));
  1357. return 1;
  1358. }
  1359. static int scene_graph_world_pose(lua_State* L)
  1360. {
  1361. LuaStack stack(L);
  1362. stack.push_matrix4x4(stack.get_scene_graph(1)->world_pose(stack.get_transform(2)));
  1363. return 1;
  1364. }
  1365. static int scene_graph_set_local_position(lua_State* L)
  1366. {
  1367. LuaStack stack(L);
  1368. stack.get_scene_graph(1)->set_local_position(stack.get_transform(2), stack.get_vector3(3));
  1369. return 0;
  1370. }
  1371. static int scene_graph_set_local_rotation(lua_State* L)
  1372. {
  1373. LuaStack stack(L);
  1374. stack.get_scene_graph(1)->set_local_rotation(stack.get_transform(2), stack.get_quaternion(3));
  1375. return 0;
  1376. }
  1377. static int scene_graph_set_local_scale(lua_State* L)
  1378. {
  1379. LuaStack stack(L);
  1380. stack.get_scene_graph(1)->set_local_scale(stack.get_transform(2), stack.get_vector3(3));
  1381. return 0;
  1382. }
  1383. static int scene_graph_set_local_pose(lua_State* L)
  1384. {
  1385. LuaStack stack(L);
  1386. stack.get_scene_graph(1)->set_local_pose(stack.get_transform(2), stack.get_matrix4x4(3));
  1387. return 0;
  1388. }
  1389. static int scene_graph_link(lua_State* L)
  1390. {
  1391. LuaStack stack(L);
  1392. stack.get_scene_graph(1)->link(stack.get_transform(2), stack.get_transform(3));
  1393. return 0;
  1394. }
  1395. static int scene_graph_unlink(lua_State* L)
  1396. {
  1397. LuaStack stack(L);
  1398. stack.get_scene_graph(1)->unlink(stack.get_transform(2));
  1399. return 0;
  1400. }
  1401. static int unit_manager_create(lua_State* L)
  1402. {
  1403. LuaStack stack(L);
  1404. if (stack.num_args() == 1)
  1405. stack.push_unit(device()->unit_manager()->create(*stack.get_world(1)));
  1406. else
  1407. stack.push_unit(device()->unit_manager()->create());
  1408. return 1;
  1409. }
  1410. static int unit_manager_alive(lua_State* L)
  1411. {
  1412. LuaStack stack(L);
  1413. stack.push_bool(device()->unit_manager()->alive(stack.get_unit(1)));
  1414. return 1;
  1415. }
  1416. static int render_world_create_mesh(lua_State* L)
  1417. {
  1418. LuaStack stack(L);
  1419. RenderWorld* rw = stack.get_render_world(1);
  1420. UnitId unit = stack.get_unit(2);
  1421. MeshRendererDesc desc;
  1422. desc.mesh_resource = stack.get_resource_id(3);
  1423. desc.geometry_name = stack.get_string_id_32(4);
  1424. desc.material_resource = stack.get_resource_id(5);
  1425. desc.visible = stack.get_bool(6);
  1426. stack.push_mesh_instance(rw->create_mesh(unit, desc, MATRIX4X4_IDENTITY));
  1427. return 1;
  1428. }
  1429. static int render_world_destroy_mesh(lua_State* L)
  1430. {
  1431. LuaStack stack(L);
  1432. stack.get_render_world(1)->destroy_mesh(stack.get_mesh_instance(2));
  1433. return 0;
  1434. }
  1435. static int render_world_mesh_instances(lua_State* L)
  1436. {
  1437. LuaStack stack(L);
  1438. RenderWorld* rw = stack.get_render_world(1);
  1439. UnitId unit = stack.get_unit(2);
  1440. MeshInstance inst = rw->first_mesh(unit);
  1441. stack.push_table();
  1442. for (u32 i = 0; rw->is_valid(inst); ++i, inst = rw->next_mesh(inst))
  1443. {
  1444. stack.push_key_begin(i+1);
  1445. stack.push_mesh_instance(inst);
  1446. stack.push_key_end();
  1447. }
  1448. return 1;
  1449. }
  1450. static int render_world_mesh_obb(lua_State* L)
  1451. {
  1452. LuaStack stack(L);
  1453. OBB obb = stack.get_render_world(1)->mesh_obb(stack.get_mesh_instance(2));
  1454. stack.push_matrix4x4(obb.tm);
  1455. stack.push_vector3(obb.half_extents);
  1456. return 2;
  1457. }
  1458. static int render_world_set_mesh_visible(lua_State* L)
  1459. {
  1460. LuaStack stack(L);
  1461. stack.get_render_world(1)->set_mesh_visible(stack.get_mesh_instance(2), stack.get_bool(3));
  1462. return 0;
  1463. }
  1464. static int render_world_create_sprite(lua_State* L)
  1465. {
  1466. LuaStack stack(L);
  1467. RenderWorld* rw = stack.get_render_world(1);
  1468. UnitId unit = stack.get_unit(2);
  1469. SpriteRendererDesc desc;
  1470. desc.sprite_resource = stack.get_resource_id(3);
  1471. desc.material_resource = stack.get_resource_id(4);
  1472. desc.visible = stack.get_bool(5);
  1473. stack.push_sprite_instance(rw->create_sprite(unit, desc, MATRIX4X4_IDENTITY));
  1474. return 1;
  1475. }
  1476. static int render_world_destroy_sprite(lua_State* L)
  1477. {
  1478. LuaStack stack(L);
  1479. stack.get_render_world(1)->destroy_sprite(stack.get_sprite_instance(2));
  1480. return 0;
  1481. }
  1482. static int render_world_sprite_instances(lua_State* L)
  1483. {
  1484. LuaStack stack(L);
  1485. RenderWorld* rw = stack.get_render_world(1);
  1486. UnitId unit = stack.get_unit(2);
  1487. SpriteInstance inst = rw->first_sprite(unit);
  1488. stack.push_table();
  1489. for (u32 i = 0; rw->is_valid(inst); ++i, inst = rw->next_sprite(inst))
  1490. {
  1491. stack.push_key_begin(i+1);
  1492. stack.push_sprite_instance(inst);
  1493. stack.push_key_end();
  1494. }
  1495. return 1;
  1496. }
  1497. static int render_world_set_sprite_visible(lua_State* L)
  1498. {
  1499. LuaStack stack(L);
  1500. stack.get_render_world(1)->set_sprite_visible(stack.get_sprite_instance(2), stack.get_bool(3));
  1501. return 0;
  1502. }
  1503. static int render_world_set_sprite_frame(lua_State* L)
  1504. {
  1505. LuaStack stack(L);
  1506. stack.get_render_world(1)->set_sprite_frame(stack.get_sprite_instance(2), stack.get_int(3));
  1507. return 0;
  1508. }
  1509. static int render_world_create_light(lua_State* L)
  1510. {
  1511. LuaStack stack(L);
  1512. const char* name = stack.get_string(3);
  1513. const LightType::Enum lt = name_to_light_type(name);
  1514. LUA_ASSERT(lt != LightType::COUNT, stack, "Unknown light type: '%s'", name);
  1515. LightDesc ld;
  1516. ld.type = lt;
  1517. ld.range = stack.get_float(4);
  1518. ld.intensity = stack.get_float(5);
  1519. ld.spot_angle = stack.get_float(6);
  1520. ld.color = stack.get_vector3(7);
  1521. stack.push_light_instance(stack.get_render_world(1)->create_light(stack.get_unit(2), ld, MATRIX4X4_IDENTITY));
  1522. return 1;
  1523. }
  1524. static int render_world_destroy_light(lua_State* L)
  1525. {
  1526. LuaStack stack(L);
  1527. stack.get_render_world(1)->destroy_light(stack.get_light_instance(2));
  1528. return 0;
  1529. }
  1530. static int render_world_light_instances(lua_State* L)
  1531. {
  1532. LuaStack stack(L);
  1533. stack.push_light_instance(stack.get_render_world(1)->light(stack.get_unit(2)));
  1534. return 1;
  1535. }
  1536. static int render_world_light_type(lua_State* L)
  1537. {
  1538. LuaStack stack(L);
  1539. LightType::Enum type = stack.get_render_world(1)->light_type(stack.get_light_instance(2));
  1540. stack.push_string(s_light[type].name);
  1541. return 1;
  1542. }
  1543. static int render_world_light_color(lua_State* L)
  1544. {
  1545. LuaStack stack(L);
  1546. stack.push_color4(stack.get_render_world(1)->light_color(stack.get_light_instance(2)));
  1547. return 1;
  1548. }
  1549. static int render_world_light_range(lua_State* L)
  1550. {
  1551. LuaStack stack(L);
  1552. stack.push_float(stack.get_render_world(1)->light_range(stack.get_light_instance(2)));
  1553. return 1;
  1554. }
  1555. static int render_world_light_intensity(lua_State* L)
  1556. {
  1557. LuaStack stack(L);
  1558. stack.push_float(stack.get_render_world(1)->light_intensity(stack.get_light_instance(2)));
  1559. return 1;
  1560. }
  1561. static int render_world_light_spot_angle(lua_State* L)
  1562. {
  1563. LuaStack stack(L);
  1564. stack.push_float(stack.get_render_world(1)->light_spot_angle(stack.get_light_instance(2)));
  1565. return 1;
  1566. }
  1567. static int render_world_set_light_type(lua_State* L)
  1568. {
  1569. LuaStack stack(L);
  1570. const char* name = stack.get_string(3);
  1571. const LightType::Enum lt = name_to_light_type(name);
  1572. LUA_ASSERT(lt != LightType::COUNT, stack, "Unknown light type: '%s'", name);
  1573. stack.get_render_world(1)->set_light_type(stack.get_light_instance(2), lt);
  1574. return 0;
  1575. }
  1576. static int render_world_set_light_color(lua_State* L)
  1577. {
  1578. LuaStack stack(L);
  1579. stack.get_render_world(1)->set_light_color(stack.get_light_instance(2), stack.get_color4(3));
  1580. return 0;
  1581. }
  1582. static int render_world_set_light_range(lua_State* L)
  1583. {
  1584. LuaStack stack(L);
  1585. stack.get_render_world(1)->set_light_range(stack.get_light_instance(2), stack.get_float(3));
  1586. return 0;
  1587. }
  1588. static int render_world_set_light_intensity(lua_State* L)
  1589. {
  1590. LuaStack stack(L);
  1591. stack.get_render_world(1)->set_light_intensity(stack.get_light_instance(2), stack.get_float(3));
  1592. return 0;
  1593. }
  1594. static int render_world_set_light_spot_angle(lua_State* L)
  1595. {
  1596. LuaStack stack(L);
  1597. stack.get_render_world(1)->set_light_spot_angle(stack.get_light_instance(2), stack.get_float(3));
  1598. return 0;
  1599. }
  1600. static int render_world_enable_debug_drawing(lua_State* L)
  1601. {
  1602. LuaStack stack(L);
  1603. stack.get_render_world(1)->enable_debug_drawing(stack.get_bool(2));
  1604. return 0;
  1605. }
  1606. static int physics_world_actor_instances(lua_State* L)
  1607. {
  1608. LuaStack stack(L);
  1609. ActorInstance inst = stack.get_physics_world(1)->actor(stack.get_unit(2));
  1610. if (inst.i == UINT32_MAX)
  1611. stack.push_nil();
  1612. else
  1613. stack.push_actor(inst);
  1614. return 1;
  1615. }
  1616. static int physics_world_actor_world_position(lua_State* L)
  1617. {
  1618. LuaStack stack(L);
  1619. stack.push_vector3(stack.get_physics_world(1)->actor_world_position(stack.get_actor(2)));
  1620. return 1;
  1621. }
  1622. static int physics_world_actor_world_rotation(lua_State* L)
  1623. {
  1624. LuaStack stack(L);
  1625. stack.push_quaternion(stack.get_physics_world(1)->actor_world_rotation(stack.get_actor(2)));
  1626. return 1;
  1627. }
  1628. static int physics_world_actor_world_pose(lua_State* L)
  1629. {
  1630. LuaStack stack(L);
  1631. stack.push_matrix4x4(stack.get_physics_world(1)->actor_world_pose(stack.get_actor(2)));
  1632. return 1;
  1633. }
  1634. static int physics_world_teleport_actor_world_position(lua_State* L)
  1635. {
  1636. LuaStack stack(L);
  1637. stack.get_physics_world(1)->teleport_actor_world_position(stack.get_actor(2), stack.get_vector3(3));
  1638. return 0;
  1639. }
  1640. static int physics_world_teleport_actor_world_rotation(lua_State* L)
  1641. {
  1642. LuaStack stack(L);
  1643. stack.get_physics_world(1)->teleport_actor_world_rotation(stack.get_actor(2), stack.get_quaternion(3));
  1644. return 0;
  1645. }
  1646. static int physics_world_teleport_actor_world_pose(lua_State* L)
  1647. {
  1648. LuaStack stack(L);
  1649. stack.get_physics_world(1)->teleport_actor_world_pose(stack.get_actor(2), stack.get_matrix4x4(3));
  1650. return 0;
  1651. }
  1652. static int physics_world_actor_center_of_mass(lua_State* L)
  1653. {
  1654. LuaStack stack(L);
  1655. stack.push_vector3(stack.get_physics_world(1)->actor_center_of_mass(stack.get_actor(2)));
  1656. return 1;
  1657. }
  1658. static int physics_world_enable_actor_gravity(lua_State* L)
  1659. {
  1660. LuaStack stack(L);
  1661. stack.get_physics_world(1)->enable_actor_gravity(stack.get_actor(2));
  1662. return 0;
  1663. }
  1664. static int physics_world_disable_actor_gravity(lua_State* L)
  1665. {
  1666. LuaStack stack(L);
  1667. stack.get_physics_world(1)->disable_actor_gravity(stack.get_actor(2));
  1668. return 0;
  1669. }
  1670. static int physics_world_enable_actor_collision(lua_State* L)
  1671. {
  1672. LuaStack stack(L);
  1673. stack.get_physics_world(1)->enable_actor_collision(stack.get_actor(2));
  1674. return 0;
  1675. }
  1676. static int physics_world_disable_actor_collision(lua_State* L)
  1677. {
  1678. LuaStack stack(L);
  1679. stack.get_physics_world(1)->disable_actor_collision(stack.get_actor(2));
  1680. return 0;
  1681. }
  1682. static int physics_world_set_actor_collision_filter(lua_State* L)
  1683. {
  1684. LuaStack stack(L);
  1685. stack.get_physics_world(1)->set_actor_collision_filter(stack.get_actor(2), stack.get_string_id_32(3));
  1686. return 0;
  1687. }
  1688. static int physics_world_set_actor_kinematic(lua_State* L)
  1689. {
  1690. LuaStack stack(L);
  1691. stack.get_physics_world(1)->set_actor_kinematic(stack.get_actor(2), stack.get_bool(3));
  1692. return 0;
  1693. }
  1694. static int physics_world_move_actor(lua_State* L)
  1695. {
  1696. LuaStack stack(L);
  1697. stack.get_physics_world(1)->move_actor(stack.get_actor(2), stack.get_vector3(3));
  1698. return 0;
  1699. }
  1700. static int physics_world_is_static(lua_State* L)
  1701. {
  1702. LuaStack stack(L);
  1703. stack.push_bool(stack.get_physics_world(1)->is_static(stack.get_actor(2)));
  1704. return 1;
  1705. }
  1706. static int physics_world_is_dynamic(lua_State* L)
  1707. {
  1708. LuaStack stack(L);
  1709. stack.push_bool(stack.get_physics_world(1)->is_dynamic(stack.get_actor(2)));
  1710. return 1;
  1711. }
  1712. static int physics_world_is_kinematic(lua_State* L)
  1713. {
  1714. LuaStack stack(L);
  1715. stack.push_bool(stack.get_physics_world(1)->is_kinematic(stack.get_actor(2)));
  1716. return 1;
  1717. }
  1718. static int physics_world_is_nonkinematic(lua_State* L)
  1719. {
  1720. LuaStack stack(L);
  1721. stack.push_bool(stack.get_physics_world(1)->is_nonkinematic(stack.get_actor(2)));
  1722. return 1;
  1723. }
  1724. static int physics_world_actor_linear_damping(lua_State* L)
  1725. {
  1726. LuaStack stack(L);
  1727. stack.push_float(stack.get_physics_world(1)->actor_linear_damping(stack.get_actor(2)));
  1728. return 1;
  1729. }
  1730. static int physics_world_set_actor_linear_damping(lua_State* L)
  1731. {
  1732. LuaStack stack(L);
  1733. stack.get_physics_world(1)->set_actor_linear_damping(stack.get_actor(2), stack.get_float(3));
  1734. return 0;
  1735. }
  1736. static int physics_world_actor_angular_damping(lua_State* L)
  1737. {
  1738. LuaStack stack(L);
  1739. stack.push_float(stack.get_physics_world(1)->actor_angular_damping(stack.get_actor(2)));
  1740. return 1;
  1741. }
  1742. static int physics_world_set_actor_angular_damping(lua_State* L)
  1743. {
  1744. LuaStack stack(L);
  1745. stack.get_physics_world(1)->set_actor_angular_damping(stack.get_actor(2), stack.get_float(3));
  1746. return 0;
  1747. }
  1748. static int physics_world_actor_linear_velocity(lua_State* L)
  1749. {
  1750. LuaStack stack(L);
  1751. stack.push_vector3(stack.get_physics_world(1)->actor_linear_velocity(stack.get_actor(2)));
  1752. return 1;
  1753. }
  1754. static int physics_world_set_actor_linear_velocity(lua_State* L)
  1755. {
  1756. LuaStack stack(L);
  1757. stack.get_physics_world(1)->set_actor_linear_velocity(stack.get_actor(2), stack.get_vector3(3));
  1758. return 0;
  1759. }
  1760. static int physics_world_actor_angular_velocity(lua_State* L)
  1761. {
  1762. LuaStack stack(L);
  1763. stack.push_vector3(stack.get_physics_world(1)->actor_angular_velocity(stack.get_actor(2)));
  1764. return 1;
  1765. }
  1766. static int physics_world_set_actor_angular_velocity(lua_State* L)
  1767. {
  1768. LuaStack stack(L);
  1769. stack.get_physics_world(1)->set_actor_angular_velocity(stack.get_actor(2), stack.get_vector3(3));
  1770. return 0;
  1771. }
  1772. static int physics_world_add_actor_impulse(lua_State* L)
  1773. {
  1774. LuaStack stack(L);
  1775. stack.get_physics_world(1)->add_actor_impulse(stack.get_actor(2), stack.get_vector3(3));
  1776. return 0;
  1777. }
  1778. static int physics_world_add_actor_impulse_at(lua_State* L)
  1779. {
  1780. LuaStack stack(L);
  1781. stack.get_physics_world(1)->add_actor_impulse_at(stack.get_actor(2), stack.get_vector3(3), stack.get_vector3(4));
  1782. return 0;
  1783. }
  1784. static int physics_world_add_actor_torque_impulse(lua_State* L)
  1785. {
  1786. LuaStack stack(L);
  1787. stack.get_physics_world(1)->add_actor_torque_impulse(stack.get_actor(2), stack.get_vector3(3));
  1788. return 0;
  1789. }
  1790. static int physics_world_push_actor(lua_State* L)
  1791. {
  1792. LuaStack stack(L);
  1793. stack.get_physics_world(1)->push_actor(stack.get_actor(2), stack.get_vector3(3), stack.get_float(4));
  1794. return 0;
  1795. }
  1796. static int physics_world_push_actor_at(lua_State* L)
  1797. {
  1798. LuaStack stack(L);
  1799. stack.get_physics_world(1)->push_actor_at(stack.get_actor(2), stack.get_vector3(3), stack.get_float(4), stack.get_vector3(5));
  1800. return 0;
  1801. }
  1802. static int physics_world_is_sleeping(lua_State* L)
  1803. {
  1804. LuaStack stack(L);
  1805. stack.push_bool(stack.get_physics_world(1)->is_sleeping(stack.get_actor(2)));
  1806. return 1;
  1807. }
  1808. static int physics_world_wake_up(lua_State* L)
  1809. {
  1810. LuaStack stack(L);
  1811. stack.get_physics_world(1)->wake_up(stack.get_actor(2));
  1812. return 0;
  1813. }
  1814. static int physics_world_controller_instances(lua_State* L)
  1815. {
  1816. LuaStack stack(L);
  1817. stack.push_controller(stack.get_physics_world(1)->controller(stack.get_unit(2)));
  1818. return 1;
  1819. }
  1820. static int physics_world_move_controller(lua_State* L)
  1821. {
  1822. LuaStack stack(L);
  1823. stack.get_physics_world(1)->move_controller(stack.get_controller(2), stack.get_vector3(3));
  1824. return 0;
  1825. }
  1826. static int physics_world_create_joint(lua_State* L)
  1827. {
  1828. LuaStack stack(L);
  1829. JointDesc jd;
  1830. jd.type = JointType::SPRING;
  1831. jd.anchor_0 = vector3(0, -2, 0);
  1832. jd.anchor_1 = vector3(0, 2, 0);
  1833. jd.break_force = 999999.0f;
  1834. jd.hinge.axis = vector3(1, 0, 0);
  1835. jd.hinge.lower_limit = -3.14f / 4.0f;
  1836. jd.hinge.upper_limit = 3.14f / 4.0f;
  1837. jd.hinge.bounciness = 12.0f;
  1838. stack.get_physics_world(1)->create_joint(stack.get_actor(2), stack.get_actor(3), jd);
  1839. return 0;
  1840. }
  1841. static int physics_world_gravity(lua_State* L)
  1842. {
  1843. LuaStack stack(L);
  1844. stack.push_vector3(stack.get_physics_world(1)->gravity());
  1845. return 1;
  1846. }
  1847. static int physics_world_set_gravity(lua_State* L)
  1848. {
  1849. LuaStack stack(L);
  1850. stack.get_physics_world(1)->set_gravity(stack.get_vector3(2));
  1851. return 0;
  1852. }
  1853. static int physics_world_raycast(lua_State* L)
  1854. {
  1855. LuaStack stack(L);
  1856. PhysicsWorld* world = stack.get_physics_world(1);
  1857. const char* name = stack.get_string(5);
  1858. const RaycastMode::Enum mode = name_to_raycast_mode(name);
  1859. LUA_ASSERT(mode != RaycastMode::COUNT, stack, "Unknown raycast mode: '%s'", name);
  1860. TempAllocator1024 ta;
  1861. Array<RaycastHit> hits(ta);
  1862. world->raycast(stack.get_vector3(2)
  1863. , stack.get_vector3(3)
  1864. , stack.get_float(4)
  1865. , mode
  1866. , hits
  1867. );
  1868. stack.push_table();
  1869. for (u32 i = 0; i < array::size(hits); ++i)
  1870. {
  1871. stack.push_key_begin(i+1);
  1872. stack.push_actor(hits[i].actor);
  1873. stack.push_key_end();
  1874. }
  1875. return 1;
  1876. }
  1877. static int physics_world_enable_debug_drawing(lua_State* L)
  1878. {
  1879. LuaStack stack(L);
  1880. stack.get_physics_world(1)->enable_debug_drawing(stack.get_bool(2));
  1881. return 0;
  1882. }
  1883. static int physics_world_tostring(lua_State* L)
  1884. {
  1885. LuaStack stack(L);
  1886. PhysicsWorld* pw = stack.get_physics_world(1);
  1887. stack.push_fstring("PhysicsWorld (%p)", pw);
  1888. return 1;
  1889. }
  1890. static int sound_world_stop_all(lua_State* L)
  1891. {
  1892. LuaStack stack(L);
  1893. stack.get_sound_world(1)->stop_all();
  1894. return 0;
  1895. }
  1896. static int sound_world_pause_all(lua_State* L)
  1897. {
  1898. LuaStack stack(L);
  1899. stack.get_sound_world(1)->pause_all();
  1900. return 0;
  1901. }
  1902. static int sound_world_resume_all(lua_State* L)
  1903. {
  1904. LuaStack stack(L);
  1905. stack.get_sound_world(1)->resume_all();
  1906. return 0;
  1907. }
  1908. static int sound_world_is_playing(lua_State* L)
  1909. {
  1910. LuaStack stack(L);
  1911. stack.push_bool(stack.get_sound_world(1)->is_playing(stack.get_sound_instance_id(2)));
  1912. return 1;
  1913. }
  1914. static int sound_world_tostring(lua_State* L)
  1915. {
  1916. LuaStack stack(L);
  1917. SoundWorld* sw = stack.get_sound_world(1);
  1918. stack.push_fstring("SoundWorld (%p)", sw);
  1919. return 1;
  1920. }
  1921. static int device_argv(lua_State* L)
  1922. {
  1923. LuaStack stack(L);
  1924. const int argc = device()->argc();
  1925. const char** argv = device()->argv();
  1926. stack.push_table(argc);
  1927. for (int i = 0; i < argc; ++i)
  1928. {
  1929. stack.push_key_begin(i + 1);
  1930. stack.push_string(argv[i]);
  1931. stack.push_key_end();
  1932. }
  1933. return 1;
  1934. }
  1935. static int device_platform(lua_State* L)
  1936. {
  1937. LuaStack stack(L);
  1938. stack.push_string(device()->platform());
  1939. return 1;
  1940. }
  1941. static int device_architecture(lua_State* L)
  1942. {
  1943. LuaStack stack(L);
  1944. stack.push_string(device()->architecture());
  1945. return 1;
  1946. }
  1947. static int device_version(lua_State* L)
  1948. {
  1949. LuaStack stack(L);
  1950. stack.push_string(device()->version());
  1951. return 1;
  1952. }
  1953. static int device_last_delta_time(lua_State* L)
  1954. {
  1955. LuaStack stack(L);
  1956. stack.push_float(device()->last_delta_time());
  1957. return 1;
  1958. }
  1959. static int device_quit(lua_State* /*L*/)
  1960. {
  1961. device()->quit();
  1962. return 0;
  1963. }
  1964. static int device_resolution(lua_State* L)
  1965. {
  1966. LuaStack stack(L);
  1967. u16 w, h;
  1968. device()->resolution(w, h);
  1969. stack.push_int(w);
  1970. stack.push_int(h);
  1971. return 2;
  1972. }
  1973. static int device_create_world(lua_State* L)
  1974. {
  1975. LuaStack stack(L);
  1976. stack.push_world(device()->create_world());
  1977. return 1;
  1978. }
  1979. static int device_destroy_world(lua_State* L)
  1980. {
  1981. LuaStack stack(L);
  1982. device()->destroy_world(*stack.get_world(1));
  1983. return 0;
  1984. }
  1985. static int device_render_world(lua_State* L)
  1986. {
  1987. LuaStack stack(L);
  1988. device()->render_world(*stack.get_world(1), stack.get_camera(2));
  1989. return 0;
  1990. }
  1991. static int device_create_resource_package(lua_State* L)
  1992. {
  1993. LuaStack stack(L);
  1994. stack.push_resource_package(device()->create_resource_package(stack.get_resource_id(1)));
  1995. return 1;
  1996. }
  1997. static int device_destroy_resource_package(lua_State* L)
  1998. {
  1999. LuaStack stack(L);
  2000. device()->destroy_resource_package(*stack.get_resource_package(1));
  2001. return 0;
  2002. }
  2003. static int device_console_send(lua_State* L)
  2004. {
  2005. using namespace string_stream;
  2006. LuaStack stack(L);
  2007. TempAllocator1024 alloc;
  2008. StringStream json(alloc);
  2009. json << "{";
  2010. /* table is in the stack at index 'i' */
  2011. stack.push_nil(); /* first key */
  2012. while (stack.next(1) != 0)
  2013. {
  2014. /* uses 'key' (at index -2) and 'value' (at index -1) */
  2015. json << "\"" << stack.get_string(-2) << "\":\"" << stack.get_string(-1) << "\",";
  2016. /* removes 'value'; keeps 'key' for next iteration */
  2017. stack.pop(1);
  2018. }
  2019. /* pop key */
  2020. stack.pop(1);
  2021. json << "}";
  2022. console_server_globals::console()->send(c_str(json));
  2023. return 0;
  2024. }
  2025. static int device_can_get(lua_State* L)
  2026. {
  2027. LuaStack stack(L);
  2028. const StringId64 type(stack.get_string(1));
  2029. stack.push_bool(device()->resource_manager()->can_get(type, stack.get_resource_id(2)));
  2030. return 1;
  2031. }
  2032. static int device_enable_resource_autoload(lua_State* L)
  2033. {
  2034. LuaStack stack(L);
  2035. device()->resource_manager()->enable_autoload(stack.get_bool(1));
  2036. return 0;
  2037. }
  2038. static int profiler_enter_scope(lua_State* L)
  2039. {
  2040. LuaStack stack(L);
  2041. profiler::enter_profile_scope(stack.get_string(1));
  2042. return 0;
  2043. }
  2044. static int profiler_leave_scope(lua_State* L)
  2045. {
  2046. LuaStack stack(L);
  2047. profiler::leave_profile_scope();
  2048. return 0;
  2049. }
  2050. static int profiler_record(lua_State* L)
  2051. {
  2052. LuaStack stack(L);
  2053. const char* name = stack.get_string(1);
  2054. if (stack.is_number(2))
  2055. profiler::record_float(name, stack.get_float(2));
  2056. else
  2057. profiler::record_vector3(name, stack.get_vector3(2));
  2058. return 0;
  2059. }
  2060. static int debug_line_add_line(lua_State* L)
  2061. {
  2062. LuaStack stack(L);
  2063. stack.get_debug_line(1)->add_line(stack.get_vector3(2)
  2064. , stack.get_vector3(3)
  2065. , stack.get_color4(4)
  2066. );
  2067. return 0;
  2068. }
  2069. static int debug_line_add_axes(lua_State* L)
  2070. {
  2071. LuaStack stack(L);
  2072. const f32 len = stack.num_args() == 3
  2073. ? stack.get_float(3)
  2074. : 1.0f
  2075. ;
  2076. stack.get_debug_line(1)->add_axes(stack.get_matrix4x4(2), len);
  2077. return 0;
  2078. }
  2079. static int debug_line_add_circle(lua_State* L)
  2080. {
  2081. LuaStack stack(L);
  2082. const u32 segments = stack.num_args() >= 6
  2083. ? stack.get_int(6)
  2084. : DebugLine::NUM_SEGMENTS
  2085. ;
  2086. stack.get_debug_line(1)->add_circle(stack.get_vector3(2)
  2087. , stack.get_float(3)
  2088. , stack.get_vector3(4)
  2089. , stack.get_color4(5)
  2090. , segments
  2091. );
  2092. return 0;
  2093. }
  2094. static int debug_line_add_cone(lua_State* L)
  2095. {
  2096. LuaStack stack(L);
  2097. const u32 segments = stack.num_args() >= 6
  2098. ? stack.get_int(6)
  2099. : DebugLine::NUM_SEGMENTS
  2100. ;
  2101. stack.get_debug_line(1)->add_cone(stack.get_vector3(2)
  2102. , stack.get_vector3(3)
  2103. , stack.get_float(4)
  2104. , stack.get_color4(5)
  2105. , segments
  2106. );
  2107. return 0;
  2108. }
  2109. static int debug_line_add_sphere(lua_State* L)
  2110. {
  2111. LuaStack stack(L);
  2112. const u32 segments = stack.num_args() >= 5
  2113. ? stack.get_int(5)
  2114. : DebugLine::NUM_SEGMENTS
  2115. ;
  2116. stack.get_debug_line(1)->add_sphere(stack.get_vector3(2)
  2117. , stack.get_float(3)
  2118. , stack.get_color4(4)
  2119. , segments
  2120. );
  2121. return 0;
  2122. }
  2123. static int debug_line_add_obb(lua_State* L)
  2124. {
  2125. LuaStack stack(L);
  2126. stack.get_debug_line(1)->add_obb(stack.get_matrix4x4(2)
  2127. , stack.get_vector3(3)
  2128. , stack.get_color4(4)
  2129. );
  2130. return 0;
  2131. }
  2132. static int debug_line_reset(lua_State* L)
  2133. {
  2134. LuaStack stack(L);
  2135. stack.get_debug_line(1)->reset();
  2136. return 0;
  2137. }
  2138. static int debug_line_submit(lua_State* L)
  2139. {
  2140. LuaStack stack(L);
  2141. stack.get_debug_line(1)->submit();
  2142. return 0;
  2143. }
  2144. static int debug_line_tostring(lua_State* L)
  2145. {
  2146. LuaStack stack(L);
  2147. stack.push_fstring("DebugLine (%p)", stack.get_debug_line(1));
  2148. return 1;
  2149. }
  2150. static int resource_package_load(lua_State* L)
  2151. {
  2152. LuaStack stack(L);
  2153. stack.get_resource_package(1)->load();
  2154. return 0;
  2155. }
  2156. static int resource_package_unload(lua_State* L)
  2157. {
  2158. LuaStack stack(L);
  2159. stack.get_resource_package(1)->unload();
  2160. return 0;
  2161. }
  2162. static int resource_package_flush(lua_State* L)
  2163. {
  2164. LuaStack stack(L);
  2165. stack.get_resource_package(1)->flush();
  2166. return 0;
  2167. }
  2168. static int resource_package_has_loaded(lua_State* L)
  2169. {
  2170. LuaStack stack(L);
  2171. stack.push_bool(stack.get_resource_package(1)->has_loaded());
  2172. return 1;
  2173. }
  2174. static int resource_package_tostring(lua_State* L)
  2175. {
  2176. LuaStack stack(L);
  2177. ResourcePackage* package = stack.get_resource_package(1);
  2178. stack.push_fstring("ResourcePackage (%p)", package);
  2179. return 1;
  2180. }
  2181. static int material_set_float(lua_State* L)
  2182. {
  2183. LuaStack stack(L);
  2184. stack.get_material(1)->set_float(stack.get_string(2), stack.get_float(3));
  2185. return 0;
  2186. }
  2187. static int material_set_vector2(lua_State* L)
  2188. {
  2189. LuaStack stack(L);
  2190. stack.get_material(1)->set_vector2(stack.get_string(2), stack.get_vector2(3));
  2191. return 0;
  2192. }
  2193. static int material_set_vector3(lua_State* L)
  2194. {
  2195. LuaStack stack(L);
  2196. stack.get_material(1)->set_vector3(stack.get_string(2), stack.get_vector3(3));
  2197. return 0;
  2198. }
  2199. static int gui_resolution(lua_State* L)
  2200. {
  2201. LuaStack stack(L);
  2202. const Vector2 resolution = stack.get_gui(1)->resolution();
  2203. stack.push_int(resolution.x);
  2204. stack.push_int(resolution.y);
  2205. return 2;
  2206. }
  2207. static int gui_move(lua_State* L)
  2208. {
  2209. LuaStack stack(L);
  2210. stack.get_gui(1)->move(stack.get_vector2(2));
  2211. return 0;
  2212. }
  2213. static int gui_screen_to_gui(lua_State* L)
  2214. {
  2215. LuaStack stack(L);
  2216. stack.push_vector2(stack.get_gui(1)->screen_to_gui(stack.get_vector2(2)));
  2217. return 1;
  2218. }
  2219. static int gui_draw_rectangle(lua_State* L)
  2220. {
  2221. LuaStack stack(L);
  2222. stack.get_gui(1)->draw_rectangle(stack.get_vector3(2), stack.get_vector2(3),
  2223. stack.get_color4(4));
  2224. return 0;
  2225. }
  2226. static int gui_draw_image(lua_State* L)
  2227. {
  2228. LuaStack stack(L);
  2229. stack.get_gui(1)->draw_image(stack.get_string(2), stack.get_vector3(3),
  2230. stack.get_vector2(4), stack.get_color4(5));
  2231. return 0;
  2232. }
  2233. static int gui_draw_image_uv(lua_State* L)
  2234. {
  2235. LuaStack stack(L);
  2236. stack.get_gui(1)->draw_image_uv(stack.get_string(2), stack.get_vector3(3),
  2237. stack.get_vector2(4), stack.get_vector2(5), stack.get_vector2(6), stack.get_color4(7));
  2238. return 0;
  2239. }
  2240. static int gui_draw_text(lua_State* L)
  2241. {
  2242. LuaStack stack(L);
  2243. stack.get_gui(1)->draw_text(stack.get_string(2), stack.get_string(3), stack.get_int(4),
  2244. stack.get_vector3(5), stack.get_color4(6));
  2245. return 0;
  2246. }
  2247. static int display_modes(lua_State* L)
  2248. {
  2249. LuaStack stack(L);
  2250. TempAllocator1024 ta;
  2251. Array<DisplayMode> modes(ta);
  2252. device()->display()->modes(modes);
  2253. stack.push_table(array::size(modes));
  2254. for (u32 i = 0; i < array::size(modes); ++i)
  2255. {
  2256. stack.push_key_begin(i+1);
  2257. stack.push_table(3);
  2258. {
  2259. stack.push_key_begin("id");
  2260. stack.push_int(modes[i].id);
  2261. stack.push_key_end();
  2262. stack.push_key_begin("width");
  2263. stack.push_int(modes[i].width);
  2264. stack.push_key_end();
  2265. stack.push_key_begin("height");
  2266. stack.push_int(modes[i].height);
  2267. stack.push_key_end();
  2268. }
  2269. stack.push_key_end();
  2270. }
  2271. return 1;
  2272. }
  2273. static int display_set_mode(lua_State* L)
  2274. {
  2275. LuaStack stack(L);
  2276. device()->display()->set_mode(stack.get_int(1));
  2277. return 0;
  2278. }
  2279. static int window_show(lua_State* L)
  2280. {
  2281. LuaStack stack(L);
  2282. device()->window()->show();
  2283. return 0;
  2284. }
  2285. static int window_hide(lua_State* L)
  2286. {
  2287. LuaStack stack(L);
  2288. device()->window()->hide();
  2289. return 0;
  2290. }
  2291. static int window_resize(lua_State* L)
  2292. {
  2293. LuaStack stack(L);
  2294. device()->window()->resize(stack.get_int(1), stack.get_int(2));
  2295. return 0;
  2296. }
  2297. static int window_move(lua_State* L)
  2298. {
  2299. LuaStack stack(L);
  2300. device()->window()->move(stack.get_int(1), stack.get_int(2));
  2301. return 0;
  2302. }
  2303. static int window_minimize(lua_State* /*L*/)
  2304. {
  2305. device()->window()->minimize();
  2306. return 0;
  2307. }
  2308. static int window_restore(lua_State* /*L*/)
  2309. {
  2310. device()->window()->restore();
  2311. return 0;
  2312. }
  2313. static int window_title(lua_State* L)
  2314. {
  2315. LuaStack stack(L);
  2316. stack.push_string(device()->window()->title());
  2317. return 1;
  2318. }
  2319. static int window_set_title(lua_State* L)
  2320. {
  2321. LuaStack stack(L);
  2322. device()->window()->set_title(stack.get_string(1));
  2323. return 0;
  2324. }
  2325. void load_api(LuaEnvironment& env)
  2326. {
  2327. env.load_module_function("Math", "ray_plane_intersection", math_ray_plane_intersection);
  2328. env.load_module_function("Math", "ray_disc_intersection", math_ray_disc_intersection);
  2329. env.load_module_function("Math", "ray_sphere_intersection", math_ray_sphere_intersection);
  2330. env.load_module_function("Math", "ray_obb_intersection", math_ray_obb_intersection);
  2331. env.load_module_function("Vector3", "new", vector3_new);
  2332. env.load_module_function("Vector3", "x", vector3_x);
  2333. env.load_module_function("Vector3", "y", vector3_y);
  2334. env.load_module_function("Vector3", "z", vector3_z);
  2335. env.load_module_function("Vector3", "set_x", vector3_set_x);
  2336. env.load_module_function("Vector3", "set_y", vector3_set_y);
  2337. env.load_module_function("Vector3", "set_z", vector3_set_z);
  2338. env.load_module_function("Vector3", "elements", vector3_elements);
  2339. env.load_module_function("Vector3", "add", vector3_add);
  2340. env.load_module_function("Vector3", "subtract", vector3_subtract);
  2341. env.load_module_function("Vector3", "multiply", vector3_multiply);
  2342. env.load_module_function("Vector3", "dot", vector3_dot);
  2343. env.load_module_function("Vector3", "cross", vector3_cross);
  2344. env.load_module_function("Vector3", "equal", vector3_equal);
  2345. env.load_module_function("Vector3", "length", vector3_length);
  2346. env.load_module_function("Vector3", "length_squared", vector3_length_squared);
  2347. env.load_module_function("Vector3", "set_length", vector3_set_length);
  2348. env.load_module_function("Vector3", "normalize", vector3_normalize);
  2349. env.load_module_function("Vector3", "distance", vector3_distance);
  2350. env.load_module_function("Vector3", "distance_squared", vector3_distance_squared);
  2351. env.load_module_function("Vector3", "angle", vector3_angle);
  2352. env.load_module_function("Vector3", "max", vector3_max);
  2353. env.load_module_function("Vector3", "min", vector3_min);
  2354. env.load_module_function("Vector3", "lerp", vector3_lerp);
  2355. env.load_module_function("Vector3", "forward", vector3_forward);
  2356. env.load_module_function("Vector3", "backward", vector3_backward);
  2357. env.load_module_function("Vector3", "left", vector3_left);
  2358. env.load_module_function("Vector3", "right", vector3_right);
  2359. env.load_module_function("Vector3", "up", vector3_up);
  2360. env.load_module_function("Vector3", "down", vector3_down);
  2361. env.load_module_function("Vector3", "zero", vector3_zero);
  2362. env.load_module_function("Vector3", "to_string", vector3_to_string);
  2363. env.load_module_constructor("Vector3", vector3_ctor);
  2364. env.load_module_function("Vector2", "new", vector2_new);
  2365. env.load_module_constructor("Vector2", vector2_ctor);
  2366. env.load_module_function("Vector3Box", "new", vector3box_new);
  2367. env.load_module_function("Vector3Box", "store", vector3box_store);
  2368. env.load_module_function("Vector3Box", "unbox", vector3box_unbox);
  2369. env.load_module_function("Vector3Box", "__index", "Vector3Box");
  2370. env.load_module_function("Vector3Box", "__tostring", vector3box_tostring);
  2371. env.load_module_constructor("Vector3Box", vector3box_ctor);
  2372. env.load_module_function("Matrix4x4", "new", matrix4x4_new);
  2373. env.load_module_function("Matrix4x4", "from_quaternion", matrix4x4_from_quaternion);
  2374. env.load_module_function("Matrix4x4", "from_translation", matrix4x4_from_translation);
  2375. env.load_module_function("Matrix4x4", "from_quaternion_translation", matrix4x4_from_quaternion_translation);
  2376. env.load_module_function("Matrix4x4", "from_axes", matrix4x4_from_axes);
  2377. env.load_module_function("Matrix4x4", "copy", matrix4x4_copy);
  2378. env.load_module_function("Matrix4x4", "add", matrix4x4_add);
  2379. env.load_module_function("Matrix4x4", "subtract", matrix4x4_subtract);
  2380. env.load_module_function("Matrix4x4", "multiply", matrix4x4_multiply);
  2381. env.load_module_function("Matrix4x4", "transpose", matrix4x4_transpose);
  2382. env.load_module_function("Matrix4x4", "determinant", matrix4x4_determinant);
  2383. env.load_module_function("Matrix4x4", "invert", matrix4x4_invert);
  2384. env.load_module_function("Matrix4x4", "x", matrix4x4_x);
  2385. env.load_module_function("Matrix4x4", "y", matrix4x4_y);
  2386. env.load_module_function("Matrix4x4", "z", matrix4x4_z);
  2387. env.load_module_function("Matrix4x4", "set_x", matrix4x4_set_x);
  2388. env.load_module_function("Matrix4x4", "set_y", matrix4x4_set_y);
  2389. env.load_module_function("Matrix4x4", "set_z", matrix4x4_set_z);
  2390. env.load_module_function("Matrix4x4", "translation", matrix4x4_translation);
  2391. env.load_module_function("Matrix4x4", "set_translation", matrix4x4_set_translation);
  2392. env.load_module_function("Matrix4x4", "rotation", matrix4x4_rotation);
  2393. env.load_module_function("Matrix4x4", "set_rotation", matrix4x4_set_rotation);
  2394. env.load_module_function("Matrix4x4", "identity", matrix4x4_identity);
  2395. env.load_module_function("Matrix4x4", "transform", matrix4x4_transform);
  2396. env.load_module_function("Matrix4x4", "to_string", matrix4x4_to_string);
  2397. env.load_module_constructor("Matrix4x4", matrix4x4_ctor);
  2398. env.load_module_function("Matrix4x4Box", "new", matrix4x4box_new);
  2399. env.load_module_function("Matrix4x4Box", "store", matrix4x4box_store);
  2400. env.load_module_function("Matrix4x4Box", "unbox", matrix4x4box_unbox);
  2401. env.load_module_function("Matrix4x4Box", "__index", "Matrix4x4Box");
  2402. env.load_module_function("Matrix4x4Box", "__tostring", matrix4x4box_tostring);
  2403. env.load_module_constructor("Matrix4x4Box", matrix4x4box_ctor);
  2404. env.load_module_function("Quaternion", "new", quaternion_new);
  2405. env.load_module_function("Quaternion", "negate", quaternion_negate);
  2406. env.load_module_function("Quaternion", "identity", quaternion_identity);
  2407. env.load_module_function("Quaternion", "multiply", quaternion_multiply);
  2408. env.load_module_function("Quaternion", "multiply_by_scalar", quaternion_multiply_by_scalar);
  2409. env.load_module_function("Quaternion", "dot", quaternion_dot);
  2410. env.load_module_function("Quaternion", "length", quaternion_length);
  2411. env.load_module_function("Quaternion", "normalize", quaternion_normalize);
  2412. env.load_module_function("Quaternion", "conjugate", quaternion_conjugate);
  2413. env.load_module_function("Quaternion", "inverse", quaternion_inverse);
  2414. env.load_module_function("Quaternion", "power", quaternion_power);
  2415. env.load_module_function("Quaternion", "elements", quaternion_elements);
  2416. env.load_module_function("Quaternion", "look", quaternion_look);
  2417. env.load_module_function("Quaternion", "right", quaternion_right);
  2418. env.load_module_function("Quaternion", "up", quaternion_up);
  2419. env.load_module_function("Quaternion", "forward", quaternion_forward);
  2420. env.load_module_function("Quaternion", "lerp", quaternion_lerp);
  2421. env.load_module_function("Quaternion", "to_string", quaternion_to_string);
  2422. env.load_module_constructor("Quaternion", quaternion_ctor);
  2423. env.load_module_function("QuaternionBox", "new", quaternionbox_new);
  2424. env.load_module_function("QuaternionBox", "store", quaternionbox_store);
  2425. env.load_module_function("QuaternionBox", "unbox", quaternionbox_unbox);
  2426. env.load_module_function("QuaternionBox", "__index", "QuaternionBox");
  2427. env.load_module_function("QuaternionBox", "__tostring", quaternionbox_tostring);
  2428. env.load_module_constructor("QuaternionBox", quaternionbox_ctor);
  2429. env.load_module_function("Color4", "new", color4_new);
  2430. env.load_module_function("Color4", "to_string", quaternion_to_string);
  2431. env.load_module_constructor("Color4", color4_ctor);
  2432. env.load_module_function("Lightuserdata_mt", "__add", lightuserdata_add);
  2433. env.load_module_function("Lightuserdata_mt", "__sub", lightuserdata_sub);
  2434. env.load_module_function("Lightuserdata_mt", "__mul", lightuserdata_mul);
  2435. env.load_module_function("Lightuserdata_mt", "__unm", lightuserdata_unm);
  2436. env.load_module_function("Lightuserdata_mt", "__index", lightuserdata_index);
  2437. env.load_module_function("Lightuserdata_mt", "__newindex", lightuserdata_newindex);
  2438. env.load_module_function("Keyboard", "name", KEYBOARD_FN(name));
  2439. env.load_module_function("Keyboard", "connected", KEYBOARD_FN(connected));
  2440. env.load_module_function("Keyboard", "num_buttons", KEYBOARD_FN(num_buttons));
  2441. env.load_module_function("Keyboard", "num_axes", KEYBOARD_FN(num_axes));
  2442. env.load_module_function("Keyboard", "pressed", KEYBOARD_FN(pressed));
  2443. env.load_module_function("Keyboard", "released", KEYBOARD_FN(released));
  2444. env.load_module_function("Keyboard", "any_pressed", KEYBOARD_FN(any_pressed));
  2445. env.load_module_function("Keyboard", "any_released", KEYBOARD_FN(any_released));
  2446. env.load_module_function("Keyboard", "button_name", KEYBOARD_FN(button_name));
  2447. env.load_module_function("Keyboard", "button_id", KEYBOARD_FN(button_id));
  2448. env.load_module_function("Mouse", "name", MOUSE_FN(name));
  2449. env.load_module_function("Mouse", "connected", MOUSE_FN(connected));
  2450. env.load_module_function("Mouse", "num_buttons", MOUSE_FN(num_buttons));
  2451. env.load_module_function("Mouse", "num_axes", MOUSE_FN(num_axes));
  2452. env.load_module_function("Mouse", "pressed", MOUSE_FN(pressed));
  2453. env.load_module_function("Mouse", "released", MOUSE_FN(released));
  2454. env.load_module_function("Mouse", "any_pressed", MOUSE_FN(any_pressed));
  2455. env.load_module_function("Mouse", "any_released", MOUSE_FN(any_released));
  2456. env.load_module_function("Mouse", "axis", MOUSE_FN(axis));
  2457. env.load_module_function("Mouse", "button_name", MOUSE_FN(button_name));
  2458. env.load_module_function("Mouse", "axis_name", MOUSE_FN(axis_name));
  2459. env.load_module_function("Mouse", "button_id", MOUSE_FN(button_id));
  2460. env.load_module_function("Mouse", "axis_id", MOUSE_FN(axis_id));
  2461. env.load_module_function("Touch", "name", TOUCH_FN(name));
  2462. env.load_module_function("Touch", "connected", TOUCH_FN(connected));
  2463. env.load_module_function("Touch", "num_buttons", TOUCH_FN(num_buttons));
  2464. env.load_module_function("Touch", "num_axes", TOUCH_FN(num_axes));
  2465. env.load_module_function("Touch", "pressed", TOUCH_FN(pressed));
  2466. env.load_module_function("Touch", "released", TOUCH_FN(released));
  2467. env.load_module_function("Touch", "any_pressed", TOUCH_FN(any_pressed));
  2468. env.load_module_function("Touch", "any_released", TOUCH_FN(any_released));
  2469. env.load_module_function("Touch", "axis", TOUCH_FN(axis));
  2470. env.load_module_function("Touch", "button_name", TOUCH_FN(button_name));
  2471. env.load_module_function("Touch", "axis_name", TOUCH_FN(axis_name));
  2472. env.load_module_function("Touch", "button_id", TOUCH_FN(button_id));
  2473. env.load_module_function("Touch", "axis_id", TOUCH_FN(axis_id));
  2474. env.load_module_function("Pad1", "name", JOYPAD_FN(0, name));
  2475. env.load_module_function("Pad1", "connected", JOYPAD_FN(0, connected));
  2476. env.load_module_function("Pad1", "num_buttons", JOYPAD_FN(0, num_buttons));
  2477. env.load_module_function("Pad1", "num_axes", JOYPAD_FN(0, num_axes));
  2478. env.load_module_function("Pad1", "pressed", JOYPAD_FN(0, pressed));
  2479. env.load_module_function("Pad1", "released", JOYPAD_FN(0, released));
  2480. env.load_module_function("Pad1", "any_pressed", JOYPAD_FN(0, any_pressed));
  2481. env.load_module_function("Pad1", "any_released", JOYPAD_FN(0, any_released));
  2482. env.load_module_function("Pad1", "axis", JOYPAD_FN(0, axis));
  2483. env.load_module_function("Pad1", "button_name", JOYPAD_FN(0, button_name));
  2484. env.load_module_function("Pad1", "axis_name", JOYPAD_FN(0, axis_name));
  2485. env.load_module_function("Pad1", "button_id", JOYPAD_FN(0, button_id));
  2486. env.load_module_function("Pad1", "axis_id", JOYPAD_FN(0, axis_id));
  2487. env.load_module_function("Pad2", "name", JOYPAD_FN(1, name));
  2488. env.load_module_function("Pad2", "connected", JOYPAD_FN(1, connected));
  2489. env.load_module_function("Pad2", "num_buttons", JOYPAD_FN(1, num_buttons));
  2490. env.load_module_function("Pad2", "num_axes", JOYPAD_FN(1, num_axes));
  2491. env.load_module_function("Pad2", "pressed", JOYPAD_FN(1, pressed));
  2492. env.load_module_function("Pad2", "released", JOYPAD_FN(1, released));
  2493. env.load_module_function("Pad2", "any_pressed", JOYPAD_FN(1, any_pressed));
  2494. env.load_module_function("Pad2", "any_released", JOYPAD_FN(1, any_released));
  2495. env.load_module_function("Pad2", "axis", JOYPAD_FN(1, axis));
  2496. env.load_module_function("Pad2", "button_name", JOYPAD_FN(1, button_name));
  2497. env.load_module_function("Pad2", "axis_name", JOYPAD_FN(1, axis_name));
  2498. env.load_module_function("Pad2", "button_id", JOYPAD_FN(1, button_id));
  2499. env.load_module_function("Pad2", "axis_id", JOYPAD_FN(1, axis_id));
  2500. env.load_module_function("Pad3", "name", JOYPAD_FN(2, name));
  2501. env.load_module_function("Pad3", "connected", JOYPAD_FN(2, connected));
  2502. env.load_module_function("Pad3", "num_buttons", JOYPAD_FN(2, num_buttons));
  2503. env.load_module_function("Pad3", "num_axes", JOYPAD_FN(2, num_axes));
  2504. env.load_module_function("Pad3", "pressed", JOYPAD_FN(2, pressed));
  2505. env.load_module_function("Pad3", "released", JOYPAD_FN(2, released));
  2506. env.load_module_function("Pad3", "any_pressed", JOYPAD_FN(2, any_pressed));
  2507. env.load_module_function("Pad3", "any_released", JOYPAD_FN(2, any_released));
  2508. env.load_module_function("Pad3", "axis", JOYPAD_FN(2, axis));
  2509. env.load_module_function("Pad3", "button_name", JOYPAD_FN(2, button_name));
  2510. env.load_module_function("Pad3", "axis_name", JOYPAD_FN(2, axis_name));
  2511. env.load_module_function("Pad3", "button_id", JOYPAD_FN(2, button_id));
  2512. env.load_module_function("Pad3", "axis_id", JOYPAD_FN(2, axis_id));
  2513. env.load_module_function("Pad4", "name", JOYPAD_FN(3, name));
  2514. env.load_module_function("Pad4", "connected", JOYPAD_FN(3, connected));
  2515. env.load_module_function("Pad4", "num_buttons", JOYPAD_FN(3, num_buttons));
  2516. env.load_module_function("Pad4", "num_axes", JOYPAD_FN(3, num_axes));
  2517. env.load_module_function("Pad4", "pressed", JOYPAD_FN(3, pressed));
  2518. env.load_module_function("Pad4", "released", JOYPAD_FN(3, released));
  2519. env.load_module_function("Pad4", "any_pressed", JOYPAD_FN(3, any_pressed));
  2520. env.load_module_function("Pad4", "any_released", JOYPAD_FN(3, any_released));
  2521. env.load_module_function("Pad4", "axis", JOYPAD_FN(3, axis));
  2522. env.load_module_function("Pad4", "button_name", JOYPAD_FN(3, button_name));
  2523. env.load_module_function("Pad4", "axis_name", JOYPAD_FN(3, axis_name));
  2524. env.load_module_function("Pad4", "button_id", JOYPAD_FN(3, button_id));
  2525. env.load_module_function("Pad4", "axis_id", JOYPAD_FN(3, axis_id));
  2526. env.load_module_function("World", "spawn_unit", world_spawn_unit);
  2527. env.load_module_function("World", "destroy_unit", world_destroy_unit);
  2528. env.load_module_function("World", "num_units", world_num_units);
  2529. env.load_module_function("World", "units", world_units);
  2530. env.load_module_function("World", "camera", world_camera);
  2531. env.load_module_function("World", "set_camera_projection_type", camera_set_projection_type);
  2532. env.load_module_function("World", "camera_projection_type", camera_projection_type);
  2533. env.load_module_function("World", "camera_fov", camera_fov);
  2534. env.load_module_function("World", "set_camera_fov", camera_set_fov);
  2535. env.load_module_function("World", "camera_aspect", camera_aspect);
  2536. env.load_module_function("World", "set_camera_aspect", camera_set_aspect);
  2537. env.load_module_function("World", "camera_near_clip_distance", camera_near_clip_distance);
  2538. env.load_module_function("World", "set_camera_near_clip_distance", camera_set_near_clip_distance);
  2539. env.load_module_function("World", "camera_far_clip_distance", camera_far_clip_distance);
  2540. env.load_module_function("World", "set_camera_far_clip_distance", camera_set_far_clip_distance);
  2541. env.load_module_function("World", "set_camera_orthographic_metrics", camera_set_orthographic_metrics);
  2542. env.load_module_function("World", "set_camera_viewport_metrics", camera_set_viewport_metrics);
  2543. env.load_module_function("World", "camera_screen_to_world", camera_screen_to_world);
  2544. env.load_module_function("World", "camera_world_to_screen", camera_world_to_screen);
  2545. env.load_module_function("World", "update_animations", world_update_animations);
  2546. env.load_module_function("World", "update_scene", world_update_scene);
  2547. env.load_module_function("World", "update", world_update);
  2548. env.load_module_function("World", "play_sound", world_play_sound);
  2549. env.load_module_function("World", "stop_sound", world_stop_sound);
  2550. env.load_module_function("World", "link_sound", world_link_sound);
  2551. env.load_module_function("World", "set_listener_pose", world_set_listener_pose);
  2552. env.load_module_function("World", "set_sound_position", world_set_sound_position);
  2553. env.load_module_function("World", "set_sound_range", world_set_sound_range);
  2554. env.load_module_function("World", "set_sound_volume", world_set_sound_volume);
  2555. env.load_module_function("World", "create_debug_line", world_create_debug_line);
  2556. env.load_module_function("World", "destroy_debug_line", world_destroy_debug_line);
  2557. env.load_module_function("World", "load_level", world_load_level);
  2558. env.load_module_function("World", "scene_graph", world_scene_graph);
  2559. env.load_module_function("World", "render_world", world_render_world);
  2560. env.load_module_function("World", "physics_world", world_physics_world);
  2561. env.load_module_function("World", "sound_world", world_sound_world);
  2562. env.load_module_function("World", "__index", "World");
  2563. env.load_module_function("World", "__tostring", world_tostring);
  2564. env.load_module_function("SceneGraph", "create", scene_graph_create);
  2565. env.load_module_function("SceneGraph", "destroy", scene_graph_destroy);
  2566. env.load_module_function("SceneGraph", "transform_instances", scene_graph_transform_instances);
  2567. env.load_module_function("SceneGraph", "local_position", scene_graph_local_position);
  2568. env.load_module_function("SceneGraph", "local_rotation", scene_graph_local_rotation);
  2569. env.load_module_function("SceneGraph", "local_scale", scene_graph_local_scale);
  2570. env.load_module_function("SceneGraph", "local_pose", scene_graph_local_pose);
  2571. env.load_module_function("SceneGraph", "world_position", scene_graph_world_position);
  2572. env.load_module_function("SceneGraph", "world_rotation", scene_graph_world_rotation);
  2573. env.load_module_function("SceneGraph", "world_pose", scene_graph_world_pose);
  2574. env.load_module_function("SceneGraph", "set_local_position", scene_graph_set_local_position);
  2575. env.load_module_function("SceneGraph", "set_local_rotation", scene_graph_set_local_rotation);
  2576. env.load_module_function("SceneGraph", "set_local_scale", scene_graph_set_local_scale);
  2577. env.load_module_function("SceneGraph", "set_local_pose", scene_graph_set_local_pose);
  2578. env.load_module_function("SceneGraph", "link", scene_graph_link);
  2579. env.load_module_function("SceneGraph", "unlink", scene_graph_unlink);
  2580. env.load_module_function("UnitManager", "create", unit_manager_create);
  2581. env.load_module_function("UnitManager", "alive", unit_manager_alive);
  2582. env.load_module_function("RenderWorld", "create_mesh", render_world_create_mesh);
  2583. env.load_module_function("RenderWorld", "destroy_mesh", render_world_destroy_mesh);
  2584. env.load_module_function("RenderWorld", "mesh_instances", render_world_mesh_instances);
  2585. env.load_module_function("RenderWorld", "mesh_obb", render_world_mesh_obb);
  2586. env.load_module_function("RenderWorld", "set_mesh_visible", render_world_set_mesh_visible);
  2587. env.load_module_function("RenderWorld", "create_sprite", render_world_create_sprite);
  2588. env.load_module_function("RenderWorld", "destroy_sprite", render_world_destroy_sprite);
  2589. env.load_module_function("RenderWorld", "sprite_instances", render_world_sprite_instances);
  2590. env.load_module_function("RenderWorld", "set_sprite_frame", render_world_set_sprite_frame);
  2591. env.load_module_function("RenderWorld", "set_sprite_visible", render_world_set_sprite_visible);
  2592. env.load_module_function("RenderWorld", "create_light", render_world_create_light);
  2593. env.load_module_function("RenderWorld", "destroy_light", render_world_destroy_light);
  2594. env.load_module_function("RenderWorld", "light_instances", render_world_light_instances);
  2595. env.load_module_function("RenderWorld", "light_type", render_world_light_type);
  2596. env.load_module_function("RenderWorld", "light_color", render_world_light_color);
  2597. env.load_module_function("RenderWorld", "light_range", render_world_light_range);
  2598. env.load_module_function("RenderWorld", "light_intensity", render_world_light_intensity);
  2599. env.load_module_function("RenderWorld", "light_spot_angle", render_world_light_spot_angle);
  2600. env.load_module_function("RenderWorld", "set_light_type", render_world_set_light_type);
  2601. env.load_module_function("RenderWorld", "set_light_color", render_world_set_light_color);
  2602. env.load_module_function("RenderWorld", "set_light_range", render_world_set_light_range);
  2603. env.load_module_function("RenderWorld", "set_light_intensity", render_world_set_light_intensity);
  2604. env.load_module_function("RenderWorld", "set_light_spot_angle", render_world_set_light_spot_angle);
  2605. env.load_module_function("RenderWorld", "enable_debug_drawing", render_world_enable_debug_drawing);
  2606. env.load_module_function("PhysicsWorld", "actor_instances", physics_world_actor_instances);
  2607. env.load_module_function("PhysicsWorld", "actor_world_position", physics_world_actor_world_position);
  2608. env.load_module_function("PhysicsWorld", "actor_world_rotation", physics_world_actor_world_rotation);
  2609. env.load_module_function("PhysicsWorld", "actor_world_pose", physics_world_actor_world_pose);
  2610. env.load_module_function("PhysicsWorld", "teleport_actor_world_position", physics_world_teleport_actor_world_position);
  2611. env.load_module_function("PhysicsWorld", "teleport_actor_world_rotation", physics_world_teleport_actor_world_rotation);
  2612. env.load_module_function("PhysicsWorld", "teleport_actor_world_pose", physics_world_teleport_actor_world_pose);
  2613. env.load_module_function("PhysicsWorld", "actor_center_of_mass", physics_world_actor_center_of_mass);
  2614. env.load_module_function("PhysicsWorld", "enable_actor_gravity", physics_world_enable_actor_gravity);
  2615. env.load_module_function("PhysicsWorld", "disable_actor_gravity", physics_world_disable_actor_gravity);
  2616. env.load_module_function("PhysicsWorld", "enable_actor_collision", physics_world_enable_actor_collision);
  2617. env.load_module_function("PhysicsWorld", "disable_actor_collision", physics_world_disable_actor_collision);
  2618. env.load_module_function("PhysicsWorld", "set_actor_collision_filter", physics_world_set_actor_collision_filter);
  2619. env.load_module_function("PhysicsWorld", "set_actor_kinematic", physics_world_set_actor_kinematic);
  2620. env.load_module_function("PhysicsWorld", "move_actor", physics_world_move_actor);
  2621. env.load_module_function("PhysicsWorld", "is_static", physics_world_is_static);
  2622. env.load_module_function("PhysicsWorld", "is_dynamic", physics_world_is_dynamic);
  2623. env.load_module_function("PhysicsWorld", "is_kinematic", physics_world_is_kinematic);
  2624. env.load_module_function("PhysicsWorld", "is_nonkinematic", physics_world_is_nonkinematic);
  2625. env.load_module_function("PhysicsWorld", "actor_linear_damping", physics_world_actor_linear_damping);
  2626. env.load_module_function("PhysicsWorld", "set_actor_linear_damping", physics_world_set_actor_linear_damping);
  2627. env.load_module_function("PhysicsWorld", "actor_angular_damping", physics_world_actor_angular_damping);
  2628. env.load_module_function("PhysicsWorld", "set_actor_angular_damping", physics_world_set_actor_angular_damping);
  2629. env.load_module_function("PhysicsWorld", "actor_linear_velocity", physics_world_actor_linear_velocity);
  2630. env.load_module_function("PhysicsWorld", "set_actor_linear_velocity", physics_world_set_actor_linear_velocity);
  2631. env.load_module_function("PhysicsWorld", "actor_angular_velocity", physics_world_actor_angular_velocity);
  2632. env.load_module_function("PhysicsWorld", "set_actor_angular_velocity", physics_world_set_actor_angular_velocity);
  2633. env.load_module_function("PhysicsWorld", "add_actor_impulse", physics_world_add_actor_impulse);
  2634. env.load_module_function("PhysicsWorld", "add_actor_impulse_at", physics_world_add_actor_impulse_at);
  2635. env.load_module_function("PhysicsWorld", "add_actor_torque_impulse", physics_world_add_actor_torque_impulse);
  2636. env.load_module_function("PhysicsWorld", "push_actor", physics_world_push_actor);
  2637. env.load_module_function("PhysicsWorld", "push_actor_at", physics_world_push_actor_at);
  2638. env.load_module_function("PhysicsWorld", "is_sleeping", physics_world_is_sleeping);
  2639. env.load_module_function("PhysicsWorld", "wake_up", physics_world_wake_up);
  2640. env.load_module_function("PhysicsWorld", "controller_instances", physics_world_controller_instances);
  2641. env.load_module_function("PhysicsWorld", "move_controller", physics_world_move_controller);
  2642. env.load_module_function("PhysicsWorld", "create_joint", physics_world_create_joint);
  2643. env.load_module_function("PhysicsWorld", "gravity", physics_world_gravity);
  2644. env.load_module_function("PhysicsWorld", "set_gravity", physics_world_set_gravity);
  2645. env.load_module_function("PhysicsWorld", "raycast", physics_world_raycast);
  2646. env.load_module_function("PhysicsWorld", "enable_debug_drawing", physics_world_enable_debug_drawing);
  2647. env.load_module_function("PhysicsWorld", "__index", "PhysicsWorld");
  2648. env.load_module_function("PhysicsWorld", "__tostring", physics_world_tostring);
  2649. env.load_module_function("SoundWorld", "stop_all", sound_world_stop_all);
  2650. env.load_module_function("SoundWorld", "pause_all", sound_world_pause_all);
  2651. env.load_module_function("SoundWorld", "resume_all", sound_world_resume_all);
  2652. env.load_module_function("SoundWorld", "is_playing", sound_world_is_playing);
  2653. env.load_module_function("SoundWorld", "__index", "SoundWorld");
  2654. env.load_module_function("SoundWorld", "__tostring", sound_world_tostring);
  2655. env.load_module_function("Device", "argv", device_argv);
  2656. env.load_module_function("Device", "platform", device_platform);
  2657. env.load_module_function("Device", "architecture", device_architecture);
  2658. env.load_module_function("Device", "version", device_version);
  2659. env.load_module_function("Device", "last_delta_time", device_last_delta_time);
  2660. env.load_module_function("Device", "quit", device_quit);
  2661. env.load_module_function("Device", "resolution", device_resolution);
  2662. env.load_module_function("Device", "create_world", device_create_world);
  2663. env.load_module_function("Device", "destroy_world", device_destroy_world);
  2664. env.load_module_function("Device", "render_world", device_render_world);
  2665. env.load_module_function("Device", "create_resource_package", device_create_resource_package);
  2666. env.load_module_function("Device", "destroy_resource_package", device_destroy_resource_package);
  2667. env.load_module_function("Device", "console_send", device_console_send);
  2668. env.load_module_function("Device", "can_get", device_can_get);
  2669. env.load_module_function("Device", "enable_resource_autoload", device_enable_resource_autoload);
  2670. env.load_module_function("Profiler", "enter_scope", profiler_enter_scope);
  2671. env.load_module_function("Profiler", "leave_scope", profiler_leave_scope);
  2672. env.load_module_function("Profiler", "record", profiler_record);
  2673. env.load_module_function("DebugLine", "add_line", debug_line_add_line);
  2674. env.load_module_function("DebugLine", "add_axes", debug_line_add_axes);
  2675. env.load_module_function("DebugLine", "add_circle", debug_line_add_circle);
  2676. env.load_module_function("DebugLine", "add_cone", debug_line_add_cone);
  2677. env.load_module_function("DebugLine", "add_sphere", debug_line_add_sphere);
  2678. env.load_module_function("DebugLine", "add_obb", debug_line_add_obb);
  2679. env.load_module_function("DebugLine", "reset", debug_line_reset);
  2680. env.load_module_function("DebugLine", "submit", debug_line_submit);
  2681. env.load_module_function("DebugLine", "__index", "DebugLine");
  2682. env.load_module_function("DebugLine", "__tostring", debug_line_tostring);
  2683. env.load_module_function("ResourcePackage", "load", resource_package_load);
  2684. env.load_module_function("ResourcePackage", "unload", resource_package_unload);
  2685. env.load_module_function("ResourcePackage", "flush", resource_package_flush);
  2686. env.load_module_function("ResourcePackage", "has_loaded", resource_package_has_loaded);
  2687. env.load_module_function("ResourcePackage", "__index", "ResourcePackage");
  2688. env.load_module_function("ResourcePackage", "__tostring", resource_package_tostring);
  2689. env.load_module_function("Material", "set_float", material_set_float);
  2690. env.load_module_function("Material", "set_vector2", material_set_vector2);
  2691. env.load_module_function("Material", "set_vector3", material_set_vector3);
  2692. env.load_module_function("Gui", "resolution", gui_resolution);
  2693. env.load_module_function("Gui", "move", gui_move);
  2694. env.load_module_function("Gui", "screen_to_gui", gui_screen_to_gui);
  2695. env.load_module_function("Gui", "draw_rectangle", gui_draw_rectangle);
  2696. env.load_module_function("Gui", "draw_image", gui_draw_image);
  2697. env.load_module_function("Gui", "draw_image_uv", gui_draw_image_uv);
  2698. env.load_module_function("Gui", "draw_text", gui_draw_text);
  2699. env.load_module_function("Display", "modes", display_modes);
  2700. env.load_module_function("Display", "set_mode", display_set_mode);
  2701. env.load_module_function("Window", "show", window_show);
  2702. env.load_module_function("Window", "hide", window_hide);
  2703. env.load_module_function("Window", "resize", window_resize);
  2704. env.load_module_function("Window", "move", window_move);
  2705. env.load_module_function("Window", "minimize", window_minimize);
  2706. env.load_module_function("Window", "restore", window_restore);
  2707. env.load_module_function("Window", "title", window_title);
  2708. env.load_module_function("Window", "set_title", window_set_title);
  2709. }
  2710. } // namespace crown