lua_api.cpp 94 KB

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