-
Notifications
You must be signed in to change notification settings - Fork 12
/
init_state.cpp
3128 lines (2750 loc) · 129 KB
/
init_state.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// MIT License
//
// Copyright (c) 2023 Missing Deadlines (Benjamin Wrensch)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// clang-format off
#include "lua_plugin.h"
namespace internal
{
//----------------------------------------------------------------------------//
namespace math_helper
{
//----------------------------------------------------------------------------//
template <typename T> inline auto lerp(const T& x, const T& y, float a) -> T
{
return io_cvt(glm::mix(io_cvt(x), io_cvt(y), a));
}
//----------------------------------------------------------------------------//
template <> inline auto lerp(const float& x, const float& y, float a) -> float
{
return glm::mix(x, y, a);
}
//----------------------------------------------------------------------------//
template <typename T> inline auto slerp(const T& x, const T& y, float a) -> T
{
return io_cvt(glm::slerp(io_cvt(x), io_cvt(y), a));
}
//----------------------------------------------------------------------------//
template <typename T>
inline auto vec_get_component(const T& vec, io_uint32_t idx) -> float
{
return io_cvt(vec)[idx];
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_mul(const T& l, const T& r) -> T
{
return io_cvt(io_cvt(l) * io_cvt(r));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_scale(float s, const T& vec) -> T
{
return io_cvt(s * io_cvt(vec));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_div(const T& x, const T& y) -> T
{
return io_cvt(io_cvt(x) / io_cvt(y));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_add(const T& x, const T& y) -> T
{
return io_cvt(io_cvt(x) + io_cvt(y));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_sub(const T& x, const T& y) -> T
{
return io_cvt(io_cvt(x) - io_cvt(y));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_normalize(const T& x) -> T
{
return io_cvt(glm::normalize(io_cvt(x)));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_length(const T& x) -> float
{
return glm::length(io_cvt(x));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_length2(const T& x) -> float
{
return glm::length2(io_cvt(x));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_distance(const T& x, const T& y) -> float
{
return glm::distance(io_cvt(x), io_cvt(y));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_distance2(const T& x, const T& y) -> float
{
return glm::distance2(io_cvt(x), io_cvt(y));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_cross(const T& x, const T& y) -> T
{
return io_cvt(glm::cross(io_cvt(x), io_cvt(y)));
}
//----------------------------------------------------------------------------//
template <typename T> inline auto vec_dot(const T& x, const T& y) -> float
{
return glm::dot(io_cvt(x), io_cvt(y));
}
//----------------------------------------------------------------------------//
inline auto quat_rotate(const io_quat_t& quat, const io_vec3_t& vec)
{
return io_cvt(io_cvt(quat) * io_cvt(vec));
}
//----------------------------------------------------------------------------//
inline auto quat_inverse(const io_quat_t& quat)
{
return io_cvt(glm::inverse(io_cvt(quat)));
}
//----------------------------------------------------------------------------//
inline auto quat_look_at(const io_vec3_t& dir, io_vec3_t& up)
{
return io_cvt(glm::quatLookAt(io_cvt(dir), io_cvt(up)));
}
//----------------------------------------------------------------------------//
inline auto quat_from_angle_axis(float angle, io_vec3_t& axis)
{
return io_cvt(glm::angleAxis(angle, io_cvt(axis)));
}
//----------------------------------------------------------------------------//
inline auto quat_to_euler_angles(const io_quat_t& quat)
{
return io_cvt(glm::eulerAngles(io_cvt(quat)));
}
//----------------------------------------------------------------------------//
inline auto quat_from_euler_angles(const io_vec3_t& euler)
{
return io_cvt(glm::quat(io_cvt(euler)));
}
//----------------------------------------------------------------------------//
inline auto quat_rotation(const io_vec3_t& x, io_vec3_t& y)
{
return io_cvt(glm::rotation(io_cvt(x), io_cvt(y)));
}
//----------------------------------------------------------------------------//
inline auto calc_random_number_fast(io_uint64_t& seed)
{
seed ^= seed << 13;
seed ^= seed >> 7;
seed ^= seed << 17;
return seed;
}
//----------------------------------------------------------------------------//
inline auto calc_random_float_min_max_fast(float min, float max,
io_uint64_t& seed) -> float
{
return uint32_t(calc_random_number_fast(seed)) /
static_cast<float>(std::numeric_limits<uint32_t>::max()) *
(max - min) +
min;
}
//----------------------------------------------------------------------------//
inline auto calc_random_float_fast(io_uint64_t& seed) -> float
{
return calc_random_float_min_max_fast(0.0f, 1.0f, seed);
}
} // namespace math_helper
// @namespace Components
// @category Components Dummy category.
// @hidden
// @function get_type_id
// @summary Returns the type ID of the component.
// @param component Ref The component.
// @return number value The type ID of the component.
// @function create
// @summary Creates a new component and attaches it to the provided parent entity.
// @param parent_entity Ref The parent entity.
// @function destroy
// @summary Destroys the provided component.
// @param component Ref The component to destroy.
// @function commit_changes
// @summary Commits all changes to the properties of the provided component.
// @param component Ref The component to update.
// @function get_num_active_components
// @summary Returns the total number of active components of this type.
// @return number value Total total number of active components of this type.
// @function get_component_for_entity
// @summary Returns the component for the given entity.
// @param entity Ref The entity.
// @return Ref value The component for the given entity.
// @function is_alive
// @summary Returns true if the referenced component is alive.
// @param component Ref The component.
// @return boolean value True if the component is alive.
// @function get_entity
// @summary Returns the entity the component is assigned to.
// @param component Ref The component.
// @return Ref value The entity the component is assigned to.
// @function get_property
// @summary Returns the requested property as a variant.
// @param component Ref The component.
// @param property_name string The name of the property to retrieve.
// @return Variant value The property as a variant.
// @function set_property
// @summary Sets the requested property to the provided variant value.
// @param component Ref The component.
// @param property_name string The name of the property to set.
// @param value Variant The value to set.
// @function list_properties
// @summary Lists all properties exposed by this component interface.
// @return table value Table containing the names and types of all the exposed properties.
// @namespace Interface
// @category Interface Dummy category.
// @hidden
// @function load
// @summary Loads all functions and types for this scripting interface.
//----------------------------------------------------------------------------//
void script_init_state(sol::state& s)
{
s.open_libraries(sol::lib::base, sol::lib::coroutine, sol::lib::string,
sol::lib::table, sol::lib::bit32);
s["__ScriptIsActive"] = false;
// @namespace Utils
// @category Utils Various utility functions.
s["Utils"] = s.create_table();
// @function execute
// @summary Executes the provided string as a Lua script.
// @param script string The Lua script source to execute.
// @return any value The result of the executed script.
s["Utils"]["execute"] = [&s](const char* code) -> sol::reference {
return s.script(code);
};
// @function load
// @summary Executes the script with the given name.
// @param script_name string The name of the script to load as a module (without the file extension).
// @return any value The result of the executed script.
s["Utils"]["load"] = [&s](const char* script_name) -> sol::reference {
const std::string filepath =
std::string("media/scripts/") + script_name + ".lua";
auto script = internal::load_script(s, filepath.c_str());
if (script.valid())
return script();
return sol::nil;
};
// Used to cache modules using the require function
s["__MODULES"] = s.create_table();
// @function require
// @summary Executes the script with the given name. Executed once for each script. Successive calls return the cached script result.
// @param script_name string The name of the script to execute (without the file extension).
// @return any value The result of the executed script.
s["Utils"]["require"] = [&s](const char* script_name) -> sol::reference {
if (!s["__MODULES"][script_name].valid())
{
const std::string filepath =
std::string("media/scripts/") + script_name + ".lua";
auto script = internal::load_script(s, filepath.c_str());
if (script.valid())
s["__MODULES"][script_name] = script();
}
return s["__MODULES"][script_name];
};
// @namespace Global
// @category Globals Provides various global functions and types.
// @function InvalidRef
// @summary Creates an invalid ref.
// @return Ref value The invalid ref.
s["InvalidRef"] = []() { return io_ref_invalid(); };
// @type Handle
// @summary Handles are used to reference elements of the various subsystems.
// @type PropertyDesc
// @summary Description of a property.
// @member name string
// @member type string
s.new_usertype<io_property_desc_t>("PropertyDesc", sol::no_constructor,
"name", &io_property_desc_t::name, "type",
&io_property_desc_t::type);
// @type Ref
// @summary Reference to entities, components and resources.
s.new_usertype<io_ref_t>("Ref", sol::no_constructor);
// @type Variant
// @summary Special data type that can contain different types of data.
s.new_usertype<io_variant_t>("Variant", sol::no_constructor);
// @type Vec2
// @summary A vector storing two floating point components.
// @member x number
// @member y number
s.new_usertype<io_vec2_t>("Vec2", sol::no_constructor, "x", &io_vec2_t::x,
"y", &io_vec2_t::y);
// @function Vec2
// @summary Initializes a new Vec2.
// @param x number The scalar value to set the components to.
// @return Vec2 value The new vector.
// @function Vec2
// @summary Initializes a new Vec2.
// @param vec Vec2 The vector to copy from.
// @return Vec2 value The new vector.
// @function Vec2
// @summary Initializes a new Vec2.
// @param x number First component.
// @param y number Second component.
// @return Vec2 value The new vector.
s["Vec2"] = sol::overload(
[](float s) -> io_vec2_t {
return {s, s};
},
[](const io_vec2_t& v) -> io_vec2_t {
return {v.x, v.y};
},
[](float x, float y) -> io_vec2_t {
return {x, y};
});
// @type UVec2
// @summary A vector storing two unsigned integer components.
// @member x number
// @member y number
s.new_usertype<io_uvec2_t>("UVec2", sol::no_constructor, "x", &io_uvec2_t::x,
"y", &io_uvec2_t::y);
// @function UVec2
// @summary Initializes a new UVec2.
// @param x number The scalar value to set the components to.
// @return UVec2 value The new vector.
// @function UVec2
// @summary Initializes a new UVec2.
// @param vec UVec2 The vector to copy from.
// @return UVec2 value The new vector.
// @function UVec2
// @summary Initializes a new UVec2.
// @param x number First component.
// @param y number Second component.
// @return UVec2 value The new vector.
s["UVec2"] = sol::overload(
[](uint32_t s) -> io_uvec2_t {
return {s, s};
},
[](const io_uvec2_t& v) -> io_uvec2_t {
return {v.x, v.y};
},
[](uint32_t x, uint32_t y) -> io_uvec2_t {
return {x, y};
});
// @type IVec2
// @summary A vector storing two signed integer components.
// @member x number
// @member y number
s.new_usertype<io_ivec2_t>("IVec2", sol::no_constructor, "x", &io_ivec2_t::x,
"y", &io_ivec2_t::y);
// @function IVec2
// @summary Initializes a new IVec2.
// @param x number The scalar value to set the components to.
// @return IVec2 value The new vector.
// @function IVec2
// @summary Initializes a new IVec2.
// @param vec IVec2 The vector to copy from.
// @return IVec2 value The new vector.
// @function IVec2
// @summary Initializes a new IVec2.
// @param x number First component.
// @param y number Second component.
// @return IVec2 value The new vector.
s["IVec2"] = sol::overload(
[](int32_t s) -> io_ivec2_t {
return {s, s};
},
[](const io_ivec2_t& v) -> io_ivec2_t {
return {v.x, v.y};
},
[](int32_t x, int32_t y) -> io_ivec2_t {
return {x, y};
});
// @type Vec3
// @summary A vector storing three floating point components.
// @member x number
// @member y number
// @member z number
s.new_usertype<io_vec3_t>("Vec3", sol::no_constructor, "x", &io_vec3_t::x,
"y", &io_vec3_t::y, "z", &io_vec3_t::z);
// @function Vec3
// @summary Initializes a new Vec3.
// @param x number The scalar value to set the components to.
// @return Vec3 value The new vector.
// @function Vec3
// @summary Initializes a new Vec3.
// @param vec Vec3 The vector to copy from.
// @return Vec3 value The new vector.
// @function Vec3
// @summary Initializes a new Vec3.
// @param x number First component.
// @param y number Second component.
// @param z number Third component.
// @return Vec3 value The new vector.
s["Vec3"] = sol::overload(
[](float s) -> io_vec3_t {
return {s, s, s};
},
[](const io_vec3_t& v) -> io_vec3_t {
return {v.x, v.y, v.z};
},
[](float x, float y, float z) -> io_vec3_t {
return {x, y, z};
});
// @type UVec3
// @summary A vector storing three unsigned integer components.
// @member x number
// @member y number
// @member z number
s.new_usertype<io_uvec3_t>("UVec3", sol::no_constructor, "x", &io_uvec3_t::x,
"y", &io_uvec3_t::y, "z", &io_uvec3_t::z);
// @function UVec3
// @summary Initializes a new UVec3.
// @param x number The scalar value to set the components to.
// @return UVec3 value The new vector.
// @function UVec3
// @summary Initializes a new UVec3.
// @param vec UVec3 The vector to copy from.
// @return UVec3 value The new vector.
// @function UVec3
// @summary Initializes a new UVec3.
// @param x number First component.
// @param y number Second component.
// @param z number Third component.
// @return UVec3 value The new vector.
s["UVec3"] = sol::overload(
[](io_uint32_t s) -> io_uvec3_t {
return {s, s, s};
},
[](const io_uvec3_t& v) -> io_uvec3_t {
return {v.x, v.y, v.z};
},
[](io_uint32_t x, io_uint32_t y, io_uint32_t z) -> io_uvec3_t {
return {x, y, z};
});
// @type U16Vec3
// @summary A vector storing three unsigned integer components.
// @member x number
// @member y number
// @member z number
s.new_usertype<io_u16vec3_t>("U16Vec3", sol::no_constructor, "x",
&io_u16vec3_t::x, "y", &io_u16vec3_t::y, "z",
&io_u16vec3_t::z);
// @function U16Vec3
// @summary Initializes a new U16Vec3.
// @param x number The scalar value to set the components to.
// @return U16Vec3 value The new vector.
// @function U16Vec3
// @summary Initializes a new U16Vec3.
// @param vec U16Vec3 The vector to copy from.
// @return U16Vec3 value The new vector.
// @function U16Vec3
// @summary Initializes a new U16Vec3.
// @param x number First component.
// @param y number Second component.
// @param z number Third component.
// @return U16Vec3 value The new vector.
s["U16Vec3"] = sol::overload(
[](io_uint16_t s) -> io_u16vec3_t {
return {s, s, s};
},
[](const io_u16vec3_t& v) -> io_u16vec3_t {
return {v.x, v.y, v.z};
},
[](io_uint16_t x, io_uint16_t y, io_uint16_t z) -> io_u16vec3_t {
return {x, y, z};
});
// @type U8Vec3
// @summary A vector storing three unsigned integer components.
// @member x number
// @member y number
// @member z number
s.new_usertype<io_u8vec3_t>("U8Vec3", sol::no_constructor, "x",
&io_u8vec3_t::x, "y", &io_u8vec3_t::y, "z",
&io_u8vec3_t::z);
// @function U8Vec3
// @summary Initializes a new U8Vec3.
// @param x number The scalar value to set the components to.
// @return U8Vec3 value The new vector.
// @function U8Vec3
// @summary Initializes a new U8Vec3.
// @param vec U8Vec3 The vector to copy from.
// @return U8Vec3 value The new vector.
// @function U8Vec3
// @summary Initializes a new U8Vec3.
// @param x number First component.
// @param y number Second component.
// @param z number Third component.
// @return U8Vec3 value The new vector.
s["U8Vec3"] = sol::overload(
[](io_uint8_t s) -> io_u8vec3_t {
return {s, s, s};
},
[](const io_u8vec3_t& v) -> io_u8vec3_t {
return {v.x, v.y, v.z};
},
[](io_uint8_t x, io_uint8_t y, io_uint8_t z) -> io_u8vec3_t {
return {x, y, z};
});
// @type IVec3
// @summary A vector storing three signed integer components.
// @member x number
// @member y number
// @member z number
s.new_usertype<io_ivec3_t>("IVec3", sol::no_constructor, "x", &io_ivec3_t::x,
"y", &io_ivec3_t::y, "z", &io_ivec3_t::z);
// @function IVec3
// @summary Initializes a new IVec3.
// @param x number The scalar value to set the components to.
// @return IVec3 value The new vector.
// @function IVec3
// @summary Initializes a new IVec3.
// @param vec IVec3 The vector to copy from.
// @return IVec3 value The new vector.
// @function IVec3
// @summary Initializes a new IVec3.
// @param x number First component.
// @param y number Second component.
// @param z number Third component.
// @return IVec3 value The new vector.
s["IVec3"] = sol::overload(
[](io_int32_t s) -> io_ivec3_t {
return {s, s, s};
},
[](const io_ivec3_t& v) -> io_ivec3_t {
return {v.x, v.y, v.z};
},
[](io_int32_t x, io_int32_t y, io_int32_t z) -> io_ivec3_t {
return {x, y, z};
});
// @type Vec4
// @summary A vector storing four floating point components.
// @member x number
// @member y number
// @member z number
// @member w number
s.new_usertype<io_vec4_t>("Vec4", sol::no_constructor, "x", &io_vec4_t::x,
"y", &io_vec4_t::y, "z", &io_vec4_t::z, "w",
&io_vec4_t::w);
// @function Vec4
// @summary Initializes a new Vec4.
// @param x number The scalar value to set the components to.
// @return Vec4 value The new vector.
// @function Vec4
// @summary Initializes a new Vec4.
// @param vec Vec4 The vector to copy from.
// @return Vec4 value The new vector.
// @function Vec4
// @summary Initializes a new Vec4.
// @param x number First component.
// @param y number Second component.
// @param z number Third component.
// @param w number Fourth component.
// @return Vec4 value The new vector.
s["Vec4"] = sol::overload(
[](float s) -> io_vec4_t {
return {s, s, s, s};
},
[](const io_vec4_t& v) -> io_vec4_t {
return {v.x, v.y, v.z, v.w};
},
[](float x, float y, float z, float w) -> io_vec4_t {
return {x, y, z, w};
});
// @type UVec4
// @summary A vector storing four unsigned integer components.
// @member x number
// @member y number
// @member z number
// @member w number
s.new_usertype<io_uvec4_t>("UVec4", sol::no_constructor, "x", &io_uvec4_t::x,
"y", &io_uvec4_t::y, "z", &io_uvec4_t::z, "w",
&io_uvec4_t::w);
// @function UVec4
// @summary Initializes a new UVec4.
// @param x number The scalar value to set the components to.
// @return UVec4 value The new vector.
// @function UVec4
// @summary Initializes a new UVec4.
// @param vec UVec4 The vector to copy from.
// @return UVec4 value The new vector.
// @function UVec4
// @summary Initializes a new UVec4.
// @param x number First component.
// @param y number Second component.
// @param z number Third component.
// @param w number Fourth component.
// @return UVec4 value The new vector.
s["UVec4"] = sol::overload(
[](uint32_t s) -> io_uvec4_t {
return {s, s, s, s};
},
[](const io_uvec4_t& v) -> io_uvec4_t {
return {v.x, v.y, v.z, v.w};
},
[](uint32_t x, uint32_t y, uint32_t z, uint32_t w) -> io_uvec4_t {
return {x, y, z, w};
});
// @type IVec4
// @summary A vector storing four signed integer components.
// @member x number
// @member y number
// @member z number
// @member w number
s.new_usertype<io_ivec4_t>("IVec4", sol::no_constructor, "x", &io_ivec4_t::x,
"y", &io_ivec4_t::y, "z", &io_ivec4_t::z, "w",
&io_ivec4_t::w);
// @function IVec4
// @summary Initializes a new IVec4.
// @param x number The scalar value to set the components to.
// @return IVec4 value The new vector.
// @function IVec4
// @summary Initializes a new IVec4.
// @param vec IVec4 The vector to copy from.
// @return IVec4 value The new vector.
// @function IVec4
// @summary Initializes a new IVec4.
// @param x number First component.
// @param y number Second component.
// @param z number Third component.
// @param w number Fourth component.
// @return IVec4 value The new vector.
s["IVec4"] = sol::overload(
[](int32_t s) -> io_ivec4_t {
return {s, s, s, s};
},
[](const io_ivec4_t& v) -> io_ivec4_t {
return {v.x, v.y, v.z, v.w};
},
[](int32_t x, int32_t y, int32_t z, int32_t w) -> io_ivec4_t {
return {x, y, z, w};
});
// @type Quat
// @summary A quaternion with four floating point components.
// @member w number
// @member x number
// @member y number
// @member z number
s.new_usertype<io_quat_t>("Quat", sol::no_constructor, "w", &io_quat_t::w,
"x", &io_quat_t::x, "y", &io_quat_t::y, "z",
&io_quat_t::z);
// @function Quat
// @summary Initializes a new Quat.
// @param x number The scalar value to set the first component to.
// @return Quat value The new quaternion.
// @function Quat
// @summary Initializes a new Quat.
// @param quat Quat The quaternion to copy from.
// @return Quat value The new quaternion.
// @function Quat
// @summary Initializes a new Quat.
// @param w number First component.
// @param x number Second component.
// @param y number Third component.
// @param z number Fourth component.
// @return Quat value The new quaternion.
s["Quat"] =
sol::overload([](float s) -> io_quat_t { return {s}; },
[](const io_quat_t& v) -> io_quat_t {
return {v.w, v.x, v.y, v.z};
},
[](float w, float x, float y, float z) -> io_quat_t {
return {w, x, y, z};
});
// @type HeightmapPixel
// @summary A single pixel used for generating heightmaps.
s.new_usertype<io_plugin_terrain_heightmap_pixel>("HeightmapPixel",
sol::no_constructor);
// @type PathSettings
// @summary Settings used when calculating paths via the Pathfinding related functions.
// @member capsule_radius number The radius of the agent's capsule.
// @member capsule_half_height number The half height of the agent's capsule.
// @member step_height number The maximum step height an agent can take.
// @member cell_size number The size of the cells used for the voxelization.
s.new_usertype<io_pathfinding_path_settings_t>(
"PathSettings", sol::no_constructor, "capsule_radius",
&io_pathfinding_path_settings_t::capsule_radius, "capsule_half_height",
&io_pathfinding_path_settings_t::capsule_half_height, "step_height",
&io_pathfinding_path_settings_t::step_height, "cell_size",
&io_pathfinding_path_settings_t::cell_size);
// @type AnimationDesc
// @summary Describes the animation to play via the animation system.
// @member animation_name string The name of the animation to play.
// @member play_speed number The play speed factor (defaults to 1).
// @member blend_weight number The blend weight (defaults to 1).
// @member blend_in_out_duration number The duration (in seconds) to blend in and out.
// @member priority number The priority. Animations with a higher priority are applied on top.
// @member delay number The delay (in seconds) before the animation starts playing.
// @member looping boolean Set to the if the animation should loop
// @member restore_when_finished boolean Set to the true to restore the initial node transforms when the animation is finished.
s.new_usertype<io_animation_system_animation_desc_t>(
"AnimationDesc", sol::no_constructor, "animation_name",
&io_animation_system_animation_desc_t::animation_name, "play_speed",
&io_animation_system_animation_desc_t::play_speed, "blend_weight",
&io_animation_system_animation_desc_t::blend_weight, "blend_in_out_duration",
&io_animation_system_animation_desc_t::blend_in_out_duration, "priority",
&io_animation_system_animation_desc_t::priority, "delay",
&io_animation_system_animation_desc_t::delay, "looping",
&io_animation_system_animation_desc_t::looping, "restore_when_finished",
&io_animation_system_animation_desc_t::restore_when_finished
);
// @type PhysicsContactEvent
// @summary Physics event fired when contacts between two shapes are detected.
// @member type string The type name.
// @member data PhysicsContactEventData The data of the contact event.
s.new_usertype<lua_physics_contact_event_t>(
"PhysicsContactEvent", sol::no_constructor, "type",
&lua_physics_contact_event_t::type, "data",
&lua_physics_contact_event_t::data);
// @type PhysicsContactEventData
// @summary The data for a single physics contact event.
// @member entity0 Ref The first entity in contact.
// @member entity1 Ref The second entity in contact.
// @member pos Vec3 The position of the contact.
// @member impulse Vec3 The impulse of the contact.
// @member type string The type of the contact. Either "touch_found", "touch_lost", "trigger_touch_found", or "trigger_touch_lost".
s.new_usertype<lua_physics_contact_event_t::event_data_t>(
"PhysicsContactEventData", sol::no_constructor, "entity0",
&lua_physics_contact_event_t::event_data_t::entity0, "entity1",
&lua_physics_contact_event_t::event_data_t::entity1, "pos",
&lua_physics_contact_event_t::event_data_t::pos, "impulse",
&lua_physics_contact_event_t::event_data_t::impulse, "type",
&lua_physics_contact_event_t::event_data_t::type
);
// @type UIAnchor
// @summary Defines an anchor used for creating (rectangle) transforms in the UI system.
s.new_usertype<io_ui_anchor_t>("UIAnchor", sol::no_constructor);
// @type UIAnchorOffsets
// @summary Defines a set of anchor offsets used for creating (rectangle) transforms in the UI system.
s.new_usertype<io_ui_anchor_offsets_t>("UIAnchorOffsets",
sol::no_constructor);
// @type UIRect
// @summary A rectangle defined by a position and extent.
// @member pos Vec2
// @member extent Vec2
s.new_usertype<io_ui_rect_t>("UIRect", sol::no_constructor, "pos",
&io_ui_rect_t::pos, "extent",
&io_ui_rect_t::extent);
// @function UIAnchor
// @summary Initializes a new UI anchor.
// @param anchor number The position in [0, 1] relative to the parent transform.
// @param offset number The absolute offset (in px).
// @return UIAnchor value The new anchor.
s["UIAnchor"] = [](io_float32_t anchor,
io_float32_t offset) -> io_ui_anchor_t {
return {anchor, offset};
};
// @function UIAnchorOffsets
// @summary Initializes a new set of UI anchor offsets.
// @param left number Absolute offset (in px) to the left anchor.
// @param right number Absolute offset (in px) to the right anchor.
// @param top number Absolute offset (in px) to the top anchor.
// @param bottom number Absolute offset (in px) to the bottom anchor.
// @return UIAnchor value The new set of anchor offsets.
s["UIAnchorOffsets"] = [](io_float32_t left, io_float32_t right,
io_float32_t top,
io_float32_t bottom) -> io_ui_anchor_offsets_t {
return {left, right, top, bottom};
};
// @namespace Ref
// @category Ref Functions to interact with refs.
s["Ref"] = s.create_table();
// @function get_type_id
// @summary Returns the ID of the type referenced.
// @param ref Ref The ref.
// @return number value The ID of the type referenced.
s["Ref"]["get_type_id"] = [](io_ref_t ref) {
return ref.type;
};
// @function is_valid
// @summary Returns the ID of the type referenced.
// @param ref Ref The ref.
// @return boolean value True if the given ref is valid.
s["Ref"]["is_valid"] = [](io_ref_t ref) {
return io_ref_is_valid(ref);
};
// @function get_id
// @summary Returns the unique ID of the referenced resource.
// @param ref Ref The ref.
// @return number value The ID of the referenced resource.
s["Ref"]["get_id"] = [](io_ref_t ref) { return ref.id; };
// @namespace Variant
// @category Variant Functions to interact with variants.
s["Variant"] = s.create_table();
// @function from_float
// @summary Creates a new variant storing a single floating point value.
// @param value number The floating point value to set.
// @return Variant value The new variant.
s["Variant"]["from_float"] = [](float value) {
return io_variant_from_float(value);
};
// @function from_int
// @summary Creates a new variant storing a single integer value.
// @param value number The integer value to set.
// @return Variant value The new variant.
s["Variant"]["from_int"] = [](int32_t value) {
return io_variant_from_int(value);
};
// @function from_uint
// @summary Creates a new variant storing a single unsigned integer value.
// @param value number The unsigned integer value to set.
// @return Variant value The new variant.
s["Variant"]["from_uint"] = [](uint32_t value) {
return io_variant_from_uint(value);
};
// @function from_uint8
// @summary Creates a new variant storing a single 8-bit unsigned integer value.
// @param value number The unsigned integer value to set.
// @return Variant value The new variant.
s["Variant"]["from_uint8"] = [](uint32_t value) {
return io_variant_from_uint8(value);
};
// @function from_uint16
// @summary Creates a new variant storing a single 16-bit unsigned integer value.
// @param value number The unsigned integer value to set.
// @return Variant value The new variant.
s["Variant"]["from_uint16"] = [](uint32_t value) {
return io_variant_from_uint16(value);
};
// @function from_string
// @summary Creates a new variant storing a string.
// @param value string The string to set.
// @return Variant value The new variant.
s["Variant"]["from_string"] = [](const char* value) {
return io_variant_from_name(io_base->name_from_string(value));
};
// @function from_vec2
// @summary Creates a new variant storing a vector with two components.
// @param value Vec2 The vector to set.
// @return Variant value The new variant.
s["Variant"]["from_vec2"] = [](const io_vec2_t& value) {
return io_variant_from_vec2(value);
};
// @function from_vec3
// @summary Creates a new variant storing a vector with three components.
// @param value Vec3 The vector to set.
// @return Variant value The new variant.
s["Variant"]["from_vec3"] = [](const io_vec3_t& value) {
return io_variant_from_vec3(value);
};
// @function from_vec4
// @summary Creates a new variant storing a vector with four components.
// @param value Vec4 The vector to set.
// @return Variant value The new variant.
s["Variant"]["from_vec4"] = [](const io_vec4_t& value) {
return io_variant_from_vec4(value);
};
// @function from_quat
// @summary Creates a new variant storing a quaternion with four components.
// @param value Quat The quternion to set.
// @return Variant value The new variant.
s["Variant"]["from_quat"] = [](const io_quat_t& value) {
return io_variant_from_quat(value);
};
// @function from_ivec2
// @summary Creates a new variant storing an integer vector with two components.
// @param value IVec2 The vector to set.
// @return Variant value The new variant.
s["Variant"]["from_ivec2"] = [](const io_ivec2_t& value) {
return io_variant_from_ivec2(value);
};
// @function from_ivec3
// @summary Creates a new variant storing an integer vector with three components.
// @param value IVec3 The vector to set.
// @return Variant value The new variant.
s["Variant"]["from_ivec3"] = [](const io_ivec3_t& value) {
return io_variant_from_ivec3(value);
};
// @function from_ivec4
// @summary Creates a new variant storing an integer vector with fours components.
// @param value IVec4 The vector to set.
// @return Variant value The new variant.
s["Variant"]["from_ivec4"] = [](const io_ivec4_t& value) {
return io_variant_from_ivec4(value);
};
// @function from_uvec2
// @summary Creates a new variant storing an unsigned integer vector with two components.
// @param value UVec2 The vector to set.
// @return Variant value The new variant.