lua_api.cpp 93 KB

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