-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathiolite_api.h
3489 lines (3048 loc) · 130 KB
/
iolite_api.h
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.
//----------------------------------------------------------------------------//
// Minimal C/C++ plugin sample
//----------------------------------------------------------------------------//
/*
#include "iolite_api.h"
const struct io_api_manager_i* io_api_manager = 0;
IO_API_EXPORT io_uint32_t IO_API_CALL get_api_version()
{
// Inform IOLITE which version of the API you are using
return IO_API_VERSION;
}
IO_API_EXPORT io_int32_t IO_API_CALL load_plugin(const void* api_manager)
{
// Ensure we can keep accessing the API manager after loading the plugin
io_api_manager = (const struct io_api_manager_i*)api_manager;
// Do something with the API manager, set up your plugin, etc.
return 0; // Return a value < 0 to indicate that the loading of your plugin
// has failed (dependency not available, etc.)
}
IO_API_EXPORT void IO_API_CALL unload_plugin()
{
// Clean up here
}
*/
//----------------------------------------------------------------------------//
// Documentation
//----------------------------------------------------------------------------//
// Functions that return ranges of values
// ----
// Examples: "find_entities_by_name", "collect_nodes_depth_first", etc.
// Usage: To retrieve the total buffer length required, set the
// buffer ptr to nullptr. The length ptr will be updated
// accordingly. If both the buffer ptr and the length ptr are
// provided, the function fills the buffer up to the provided
// length (or less if the total buffer length is smaller) and sets
// the length to the amount of entries written to the
// buffer.
// Note: It's best to avoid calling functions of this type multiple times
// and to pre-allocate a sufficiently large buffer upfront.
// Working with event streams
// ----
// Examples: "on_physics_events", "on_shape_events", etc.
// Usage:
//
// const io_events_header_t* event = begin;
// while (event < end)
// {
// // Check type in header and fetch data via "io_events_get_data(event)"
// // ...
//
// event = io_events_get_next(event);
// }
#ifndef INCLUDE_IO_API
#define INCLUDE_IO_API
//----------------------------------------------------------------------------//
// IOLITE API version
//----------------------------------------------------------------------------//
// The major, minor, and bug fix parts of the IOLITE API version
//----------------------------------------------------------------------------//
#define IO_API_VERSION_MAJOR 0
#define IO_API_VERSION_MINOR 5
#define IO_API_VERSION_BUGFIX 0
// The version of the IOLITE API as a single number
//----------------------------------------------------------------------------//
#define IO_API_VERSION \
((IO_API_VERSION_MAJOR << 24) + (IO_API_VERSION_MINOR << 16) + \
(IO_API_VERSION_BUGFIX << 8) + 0)
// Helpers for retrieving the major, minor, and bug fix part from the version
// number
//----------------------------------------------------------------------------//
#define IO_API_VERSION_GET_MAJOR(_version) ((_version >> 24) & 0xFFu)
#define IO_API_VERSION_GET_MINOR(_version) ((_version >> 16) & 0xFFu)
#define IO_API_VERSION_GET_BUGFIX(_version) ((_version >> 8) & 0xFFu)
//----------------------------------------------------------------------------//
// DLL export helpers
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef _WIN32
//----------------------------------------------------------------------------//
#define IO_API_CALL __stdcall
//----------------------------------------------------------------------------//
#ifdef __cplusplus
//----------------------------------------------------------------------------//
#define IO_API_EXPORT extern "C" __declspec(dllexport)
//----------------------------------------------------------------------------//
#else // __cplusplus
//----------------------------------------------------------------------------//
#define IO_API_EXPORT __declspec(dllexport)
//----------------------------------------------------------------------------//
#endif // __cplusplus
//----------------------------------------------------------------------------//
#else // _WIN32
//----------------------------------------------------------------------------//
#ifdef __cplusplus
//----------------------------------------------------------------------------//
#define IO_API_EXPORT extern "C"
//----------------------------------------------------------------------------//
#else // __cplusplus
//----------------------------------------------------------------------------//
#define IO_API_EXPORT
//----------------------------------------------------------------------------//
#endif
//----------------------------------------------------------------------------//
#define IO_API_CALL
//----------------------------------------------------------------------------//
#endif // _WIN32
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
// Basic types
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#define IO_TRUE 1
#define IO_FALSE 0
//----------------------------------------------------------------------------//
#ifndef __cplusplus
//----------------------------------------------------------------------------//
typedef unsigned char io_bool_t;
#else
typedef bool io_bool_t;
//----------------------------------------------------------------------------//
#endif
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
typedef unsigned char io_uint8_t;
typedef char io_int8_t;
//----------------------------------------------------------------------------//
typedef unsigned short io_uint16_t;
typedef short io_int16_t;
//----------------------------------------------------------------------------//
typedef unsigned int io_uint32_t;
typedef int io_int32_t;
//----------------------------------------------------------------------------//
typedef unsigned long long io_uint64_t;
typedef long long io_int64_t;
//----------------------------------------------------------------------------//
typedef float io_float32_t;
typedef double io_float64_t;
//----------------------------------------------------------------------------//
typedef io_uint32_t io_size_t;
//----------------------------------------------------------------------------//
typedef io_uint64_t io_uuid_t;
typedef io_uint32_t io_ref_type_id_t;
typedef io_uint32_t io_ref_index_t;
typedef io_uint32_t io_ref_id_t;
//----------------------------------------------------------------------------//
// Math related types
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_float32_t x, y;
};
struct
{
io_float32_t r, g;
};
io_float32_t data[2u];
};
} io_vec2_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_float32_t x, y, z;
};
struct
{
io_float32_t r, g, b;
};
io_float32_t data[3u];
};
} io_vec3_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_float32_t x, y, z, w;
};
struct
{
io_float32_t r, g, b, a;
};
io_float32_t data[4u];
};
} io_vec4_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_float32_t w, x, y, z;
};
io_float32_t data[4u];
};
} io_quat_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_int32_t x, y;
};
io_int32_t data[2u];
};
} io_ivec2_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_int32_t x, y, z;
};
io_int32_t data[3u];
};
} io_ivec3_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_int32_t x, y, z, w;
};
io_int32_t data[4u];
};
} io_ivec4_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_uint32_t x, y;
};
io_uint32_t data[2u];
};
} io_uvec2_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_uint32_t x, y, z;
};
io_uint32_t data[3u];
};
} io_uvec3_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_uint8_t x, y, z;
};
io_uint8_t data[3u];
};
} io_u8vec3_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_uint16_t x, y, z;
};
io_uint16_t data[3u];
};
} io_u16vec3_t;
//----------------------------------------------------------------------------//
typedef struct
{
union
{
struct
{
io_uint32_t x, y, z, w;
};
io_uint32_t data[4u];
};
} io_uvec4_t;
//----------------------------------------------------------------------------//
typedef struct
{
io_vec3_t center;
io_float32_t radius;
} io_sphere_t;
//----------------------------------------------------------------------------//
typedef struct
{
io_vec3_t center;
io_vec3_t half_extent;
} io_aabb_t;
//----------------------------------------------------------------------------//
// Math type conversion helpers
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_VEC2_TYPE
//----------------------------------------------------------------------------//
inline io_vec2_t io_cvt(IO_USER_VEC2_TYPE v) { return {v.x, v.y}; }
inline IO_USER_VEC2_TYPE io_cvt(io_vec2_t v) { return {v.x, v.y}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_VEC2_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_VEC3_TYPE
//----------------------------------------------------------------------------//
inline io_vec3_t io_cvt(IO_USER_VEC3_TYPE v) { return {v.x, v.y, v.z}; }
inline IO_USER_VEC3_TYPE io_cvt(io_vec3_t v) { return {v.x, v.y, v.z}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_VEC3_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_VEC4_TYPE
//----------------------------------------------------------------------------//
inline io_vec4_t io_cvt(IO_USER_VEC4_TYPE v) { return {v.x, v.y, v.z, v.w}; }
inline IO_USER_VEC4_TYPE io_cvt(io_vec4_t v) { return {v.x, v.y, v.z, v.w}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_VEC4_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_QUAT_TYPE
//----------------------------------------------------------------------------//
inline io_quat_t io_cvt(IO_USER_QUAT_TYPE v) { return {v.w, v.x, v.y, v.z}; }
//----------------------------------------------------------------------------//
#ifndef IO_USER_QUAT_TYPE_W_LAST
//----------------------------------------------------------------------------//
inline IO_USER_QUAT_TYPE io_cvt(io_quat_t v) { return {v.w, v.x, v.y, v.z}; }
//----------------------------------------------------------------------------//
#else
//----------------------------------------------------------------------------//
inline IO_USER_QUAT_TYPE io_cvt(io_quat_t v) { return {v.x, v.y, v.z, v.w}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_QUAT_TYPE_W_LAST
//----------------------------------------------------------------------------//
#endif // IO_USER_QUAT_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_UVEC2_TYPE
//----------------------------------------------------------------------------//
inline io_uvec2_t io_cvt(IO_USER_UVEC2_TYPE v) { return {v.x, v.y}; }
inline IO_USER_UVEC2_TYPE io_cvt(io_uvec2_t v) { return {v.x, v.y}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_UVEC2_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_UVEC3_TYPE
//----------------------------------------------------------------------------//
inline io_uvec3_t io_cvt(IO_USER_UVEC3_TYPE v) { return {v.x, v.y, v.z}; }
inline IO_USER_UVEC3_TYPE io_cvt(io_uvec3_t v) { return {v.x, v.y, v.z}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_UVEC3_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_U8VEC3_TYPE
//----------------------------------------------------------------------------//
inline io_u8vec3_t io_cvt(IO_USER_U8VEC3_TYPE v) { return {v.x, v.y, v.z}; }
inline IO_USER_U8VEC3_TYPE io_cvt(io_u8vec3_t v) { return {v.x, v.y, v.z}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_U8VEC3_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_U16VEC3_TYPE
//----------------------------------------------------------------------------//
inline io_u16vec3_t io_cvt(IO_USER_U16VEC3_TYPE v) { return {v.x, v.y, v.z}; }
inline IO_USER_U16VEC3_TYPE io_cvt(io_u16vec3_t v) { return {v.x, v.y, v.z}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_U16VEC3_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_UVEC4_TYPE
//----------------------------------------------------------------------------//
inline io_uvec4_t io_cvt(IO_USER_UVEC4_TYPE v) { return {v.x, v.y, v.z, v.w}; }
inline IO_USER_UVEC4_TYPE io_cvt(io_uvec4_t v) { return {v.x, v.y, v.z, v.w}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_UVEC4_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_IVEC2_TYPE
//----------------------------------------------------------------------------//
inline io_ivec2_t io_cvt(IO_USER_IVEC2_TYPE v) { return {v.x, v.y}; }
inline IO_USER_IVEC2_TYPE io_cvt(io_ivec2_t v) { return {v.x, v.y}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_IVEC2_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_IVEC3_TYPE
//----------------------------------------------------------------------------//
inline io_ivec3_t io_cvt(IO_USER_IVEC3_TYPE v) { return {v.x, v.y, v.z}; }
inline IO_USER_IVEC3_TYPE io_cvt(io_ivec3_t v) { return {v.x, v.y, v.z}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_IVEC3_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifdef IO_USER_IVEC4_TYPE
//----------------------------------------------------------------------------//
inline io_ivec4_t io_cvt(IO_USER_IVEC4_TYPE v) { return {v.x, v.y, v.z, v.w}; }
inline IO_USER_IVEC4_TYPE io_cvt(io_ivec4_t v) { return {v.x, v.y, v.z, v.w}; }
//----------------------------------------------------------------------------//
#endif // IO_USER_IVEC4_TYPE
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
// Loosely typed enums and flags
//----------------------------------------------------------------------------//
// Flags specifying which components of a node transform have changed
//----------------------------------------------------------------------------//
enum io_transform_changed_flags_
{
io_transform_changed_flags_position = 0x01u,
io_transform_changed_flags_orientation = 0x02u,
io_transform_changed_flags_size = 0x04u,
};
typedef io_uint8_t io_transform_changed_flags;
// Flags defining the faces of a box
//----------------------------------------------------------------------------//
enum io_box_face_flags_
{
io_box_face_flags_front = 0x01u,
io_box_face_flags_back = 0x02u,
io_box_face_flags_top = 0x04u,
io_box_face_flags_bottom = 0x08u,
io_box_face_flags_left = 0x10u,
io_box_face_flags_right = 0x20u,
io_box_face_flags_all = 0x7Fu
};
typedef io_uint8_t io_box_face_flags;
// Indices for the faces of a box matching the flags above
//----------------------------------------------------------------------------//
enum io_box_face_index_
{
io_box_face_index_front, // Z + 1
io_box_face_index_back, // Z - 1
io_box_face_index_top, // Y + 1
io_box_face_index_bottom, // Y - 1
io_box_face_index_left, // X - 1
io_box_face_index_right // X + 1
};
typedef io_uint8_t io_box_face_index;
// Flags for configuring properties for custom components
//----------------------------------------------------------------------------//
enum io_property_flags_
{
io_property_flags_runtime_only =
0x01u // Indicates that the given property should neither be serialized
// nor exposed in the editor
};
typedef io_uint8_t io_property_flags;
// Vertical text alignment
//----------------------------------------------------------------------------//
enum io_ui_text_align_vertical_
{
io_ui_text_align_vertical_top, // Position text at top
io_ui_text_align_vertical_center, // Position text at vertical center
io_ui_text_align_vertical_bottom // Position text at bottom
};
typedef io_uint32_t io_ui_text_align_vertical;
// Horizontal text alignment
//----------------------------------------------------------------------------//
enum io_ui_text_align_horizontal_
{
io_ui_text_align_horizontal_left, // Position text left
io_ui_text_align_horizontal_center, // Position text at horizontal center
io_ui_text_align_horizontal_right // Position text right
};
typedef io_uint32_t io_ui_text_align_horizontal;
// Various presets for anchors
//----------------------------------------------------------------------------//
enum io_ui_anchor_preset_
{
io_ui_anchor_preset_full_rect, // A full rectangle
io_ui_anchor_preset_top_left, // Anchor at top left
io_ui_anchor_preset_top_right, // Anchor at top right
io_ui_anchor_preset_bottom_right, // Anchor at bottom right
io_ui_anchor_preset_bottom_left, // Anchor at bottom left
io_ui_anchor_preset_center_left, // Anchor at the left center
io_ui_anchor_preset_center_top, // Anchor at the top center
io_ui_anchor_preset_center_right, // Anchor at the right center
io_ui_anchor_preset_center_bottom, // Anchor at the bottom center
io_ui_anchor_preset_center, // Anchor at the center
io_ui_anchor_preset_num
};
typedef io_uint32_t io_ui_anchor_preset;
//----------------------------------------------------------------------------//
enum io_ui_aspect_mode_
{
io_ui_aspect_mode_keep // Keep the aspect ratio (using letter and pillar
// boxing)
};
typedef io_uint32_t io_ui_aspect_mode;
//----------------------------------------------------------------------------//
enum io_ui_text_flag_
{
io_ui_text_flag_wrap = 0x01u // Wrap text
};
typedef io_uint32_t io_ui_text_flag;
//----------------------------------------------------------------------------//
enum io_ui_style_var_
{
io_ui_style_var_text_color, // Color for text (vec4)
io_ui_style_var_text_outline_color, // Color for text outlines (vec4)
io_ui_style_var_text_outline, // The width (in px) of the text outline (float)
// Set to > 0 to add outlines to text
io_ui_style_var_rect_rounding, // Value in [0, 1] that defines the rounding
// radius. Set to > 0 to draw rectangles with
// rounded corners (float)
io_ui_style_var_draw_outline, // Draw outlines with the given width (in px)
// instead of filled shapes
io_ui_style_var_alpha // Global alpha value applied to all draw operations
// (float)
};
typedef io_uint32_t io_ui_style_var;
// Flags used to configure the radius damage applied to the world
//----------------------------------------------------------------------------//
enum io_world_radius_damage_flags_
{
io_radius_damage_flags_fracture = 0x01u, // Apply as fracture
io_radius_damage_flags_use_noise =
0x02u // Apply detail using proecudral noise function
};
typedef io_uint32_t io_world_radius_damage_flags;
// Input key state
//----------------------------------------------------------------------------//
enum io_input_key_state_
{
io_input_key_state_released,
io_input_key_state_pressed,
io_input_key_state_clicked
};
typedef io_uint8_t io_input_key_state;
// Input axis
//----------------------------------------------------------------------------//
enum io_input_axis_
{
io_input_axis_left_x,
io_input_axis_left_y,
io_input_axis_right_x,
io_input_axis_right_y,
io_input_axis_trigger_left,
io_input_axis_trigger_right,
io_input_axis_invalid
};
typedef io_uint8_t io_input_axis;
// Input key
//----------------------------------------------------------------------------//
enum io_input_key_
{
io_input_key_up,
io_input_key_down,
io_input_key_left,
io_input_key_right,
io_input_key_a,
io_input_key_b,
io_input_key_c,
io_input_key_d,
io_input_key_e,
io_input_key_f,
io_input_key_g,
io_input_key_h,
io_input_key_i,
io_input_key_j,
io_input_key_k,
io_input_key_l,
io_input_key_m,
io_input_key_n,
io_input_key_o,
io_input_key_p,
io_input_key_q,
io_input_key_r,
io_input_key_s,
io_input_key_t,
io_input_key_u,
io_input_key_v,
io_input_key_w,
io_input_key_x,
io_input_key_y,
io_input_key_z,
io_input_key_0,
io_input_key_1,
io_input_key_2,
io_input_key_3,
io_input_key_4,
io_input_key_5,
io_input_key_6,
io_input_key_7,
io_input_key_8,
io_input_key_9,
io_input_key_f1,
io_input_key_f2,
io_input_key_f3,
io_input_key_f4,
io_input_key_f5,
io_input_key_f6,
io_input_key_f7,
io_input_key_f8,
io_input_key_f9,
io_input_key_f10,
io_input_key_f11,
io_input_key_f12,
io_input_key_del,
io_input_key_backspace,
io_input_key_tab,
io_input_key_mouse_left,
io_input_key_mouse_right,
io_input_key_mouse_middle,
io_input_key_shift,
io_input_key_alt,
io_input_key_ctrl,
io_input_key_space,
io_input_key_escape,
io_input_key_return,
io_input_key_num_plus,
io_input_key_num_minus,
io_input_key_num_0,
io_input_key_num_1,
io_input_key_num_2,
io_input_key_num_3,
io_input_key_num_4,
io_input_key_num_5,
io_input_key_num_6,
io_input_key_num_7,
io_input_key_num_8,
io_input_key_num_9,
io_input_key_controller_button_a,
io_input_key_controller_button_y,
io_input_key_controller_button_b,
io_input_key_controller_button_x,
io_input_key_any,
io_input_key_invalid,
io_input_key_num_keys
};
typedef io_uint8_t io_input_key;
// The different types supported by variants
//----------------------------------------------------------------------------//
enum io_variant_type_
{
io_variant_type_float = 0xF71E19B,
io_variant_type_int = 0xB888030,
io_variant_type_uint = 0x7C9F0525,
io_variant_type_uint8 = 0x107FA9FD,
io_variant_type_uint16 = 0x2074E8EC,
io_variant_type_uint64 = 0x2074E98F,
io_variant_type_bool = 0x7C94B391,
io_variant_type_name = 0x7C9B0C46,
io_variant_type_vec2 = 0x7C9F7ED5,
io_variant_type_vec3 = 0x7C9F7ED6,
io_variant_type_vec4 = 0x7C9F7ED7,
io_variant_type_quat = 0x7C9D0500,
io_variant_type_ivec2 = 0xFAD7C5E,
io_variant_type_ivec3 = 0xFAD7C5F,
io_variant_type_ivec4 = 0xFAD7C60,
io_variant_type_uvec2 = 0x1086A26A,
io_variant_type_uvec3 = 0x1086A26B,
io_variant_type_u8vec3 = 0x1D0261E3,
io_variant_type_u16vec3 = 0xA87DC2F2,
io_variant_type_uvec4 = 0x1086A26C
};
// Various internal constants used for refs
//----------------------------------------------------------------------------//
enum io_ref_internal_
{
io_ref_internal_max_id = 65534u, // Max valid ID, 2^16 - 2
io_ref_internal_max_gen_id = 253u, // Max valid gen ID, 2^8 - 3
io_ref_internal_max_type_id = 254u, // Max valid type ID, 2^8 - 2
io_ref_internal_invalid_id = 65535u, // Indicates invalid ID
io_ref_internal_invalid_gen_id = 255u, // Indicates invalid generation ID
io_ref_internal_invalid_type_id = 255u, // Indicates invalid type ID
io_ref_internal_is_index_gen_id = 254u // Indicates ID is index
};
//----------------------------------------------------------------------------//
// Data types and type definitions
//----------------------------------------------------------------------------//
// Ref type
//----------------------------------------------------------------------------//
typedef struct
{
io_uint16_t id; // ID of the ref
io_uint8_t gen; // Generation of the ref
io_uint8_t type; // Type ID of the ref
} io_ref_t;
// Name type
//----------------------------------------------------------------------------//
typedef struct
{
io_uint32_t hash;
} io_name_t;
// 16-bit handle type
//----------------------------------------------------------------------------//
typedef struct
{
io_uint16_t internal;
} io_handle16_t;
// 32-bit handle type
//----------------------------------------------------------------------------//
typedef struct
{
io_uint32_t internal;
} io_handle32_t;
// 64-bit handle type
//----------------------------------------------------------------------------//
typedef struct
{
io_uint64_t internal;
} io_handle64_t;
// Variant type
//----------------------------------------------------------------------------//
typedef struct
{
io_name_t type;
io_uint32_t data[4u];
} io_variant_t;
// Property description type
//----------------------------------------------------------------------------//
typedef struct
{
const char* name;
const char* type;
io_property_flags flags;
} io_property_desc_t;
// Callback function for scheduler tasks
//----------------------------------------------------------------------------//
typedef void (*io_scheduler_callback_t)(io_uvec2_t range, io_uint32_t thread_id,
io_uint32_t sub_task_index, void* task);
// Scheduler tasks provide the possibility to spread a given workload to the
// available worker threads of the internal task scheduler.
// Example: If there are 100 workloads set and 10 worker threads available,
// the scheduler (with default settings) divides the task up into 10
// sub tasks. Each of the sub tasks will be in charge of handling 10
// workloads. Each sub task calls the provided callback function
// with a range in [0, 10).
// Usage: Use the "io_init_scheduler_task" function to initialize the task
// and dispatch the task via the functions provided via the
// "io_base_i" interface.
//----------------------------------------------------------------------------//
typedef struct io_scheduler_task_t_
{
// The total number of workloads this task handles.
// Must be greater than 0.
io_uint32_t num_workloads;
// The number of workloads to target per worker thread. Modifying this value
// can be useful for "uneven" workloads, making it possible for worker threads
// to "steal" additional workloads.
// Example: A value of 1 spreads the workloads evenly by creating one sub
// task per available worker thread.
// A value of 2 creates two sub tasks per worker thread. If a
// worker does not finish in time, another worker can "steal" the
// second sub task from it.
// Default: 1
io_uint32_t target_num_sub_tasks_per_worker;
// Callback function called for each of the internal sub-tasks.
// Needs to be valid function pointer provided by the
// user.
io_scheduler_callback_t callback;
// Ooptional dependency which needs to be completed before running this task.
// Default: nullptr
struct io_scheduler_task_t_* dependency;
// The number of currently active sub-tasks.
// Used internally, required to be initialized to 0.
io_uint64_t running_sub_task_count;
} io_scheduler_task_t;
//----------------------------------------------------------------------------//
// Global helper functions, types, and type definitions
//----------------------------------------------------------------------------//
// Initializes a task with the given callback for the given amount of tasks
//----------------------------------------------------------------------------//
inline void io_init_scheduler_task(io_scheduler_task_t* task,
io_uint32_t num_tasks,
io_scheduler_callback_t callback)
{
task->num_workloads = num_tasks;
task->callback = callback;
// Defaults
task->target_num_sub_tasks_per_worker = 1u;
task->dependency = 0u;
// Internal
task->running_sub_task_count = 0u;
}
// Fixed time step accumulator
//
// Example usage:
//
// // Do this once to initialize the accumulator
// static io_fixed_step_accumulator accum;
// io_init(60.0f, &accum);
//
// // Do this every frame
// io_accumulator_add(delta_t, &accum);
//
// while (io_accumulator_step(&accum))
// pos += vel * accum.delta_t;
//----------------------------------------------------------------------------//
typedef struct
{
io_float32_t update_frequency_in_hz; // The fixed update frequency in Hz
// (steps per second).
io_float32_t delta_t; // The delta time (in seconds).
io_float32_t
interpolator; // The interpolation factor that needs to be applied to,
// e.g., smoothen the visual representation.
io_float32_t accumulator; // The accumulated time.
} io_fixed_step_accumulator_t;
// Initializes the provided accumulator. Call this function once when creating a
// new accumulator.
//----------------------------------------------------------------------------//
inline void
io_init_fixed_step_accumulator(io_fixed_step_accumulator_t* accumulator,
io_float32_t update_frequency_in_hz)
{
accumulator->update_frequency_in_hz = update_frequency_in_hz;
accumulator->delta_t = 1.0f / accumulator->update_frequency_in_hz;
accumulator->accumulator = 0.0f;
accumulator->interpolator = 0.0f;
}
// Call this function once per frame for each accumulator providing the variable
// frame delta time.
//----------------------------------------------------------------------------//
inline void io_accumulator_add(io_float32_t delta_t,
io_fixed_step_accumulator_t* accumulator)
{
accumulator->accumulator += delta_t;
}
// Returns true if another fixed step should be executed.
//----------------------------------------------------------------------------//
inline io_bool_t io_accumulator_step(io_fixed_step_accumulator_t* accumulator)
{
io_bool_t stepped = IO_FALSE;
if (accumulator->accumulator >= accumulator->delta_t)
{
accumulator->accumulator -= accumulator->delta_t;
stepped = IO_TRUE;
}
accumulator->interpolator = accumulator->accumulator / accumulator->delta_t;
return stepped;
}
// Returns the minimum of x and y.
//----------------------------------------------------------------------------//
inline io_uint32_t io_min(io_uint32_t x, io_uint32_t y)
{
if (x < y)
return x;
return y;
}
// Returns the maximum of x and y.
//----------------------------------------------------------------------------//
inline io_uint32_t io_max(io_uint32_t x, io_uint32_t y)
{