-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
2096 lines (1925 loc) · 65.2 KB
/
main.cpp
File metadata and controls
2096 lines (1925 loc) · 65.2 KB
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
// This file is part of SmallBASIC
//
// Plugin for raylib games library - https://www.raylib.com/
//
// This program is distributed under the terms of the GPL v2.0 or later
// Download the GNU Public License (GPL) from www.gnu.org
//
// Copyright(C) 2021 Chris Warren-Smith
#include "config.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic push
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#pragma GCC diagnostic ignored "-Wenum-compare"
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#include <raylib/raylib/src/raylib.h>
#include <raylib/raylib/src/raymath.h>
#include <raygui/src/raygui.h>
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
#include <physac/src/physac.h>
#include <GLFW/glfw3.h>
#include <cstring>
#include "robin-hood-hashing/src/include/robin_hood.h"
#include "include/var.h"
#include "include/module.h"
#include "include/param.h"
#include "physac.h"
#define MAX_INPUTBOX_LENGTH 1024
#define MAX_FILEPATH_LENGTH 4096
robin_hood::unordered_map<int, AudioStream> _audioStream;
robin_hood::unordered_map<int, Font> _fontMap;
robin_hood::unordered_map<int, Image> _imageMap;
robin_hood::unordered_map<int, Matrix> _matrixMap;
robin_hood::unordered_map<int, Mesh> _meshMap;
robin_hood::unordered_map<int, Model> _modelMap;
robin_hood::unordered_map<int, ModelAnimation> _modelAnimationMap;
robin_hood::unordered_map<int, Music> _musicMap;
robin_hood::unordered_map<int, PhysicsBody> _physicsMap;
robin_hood::unordered_map<int, RenderTexture2D> _renderMap;
robin_hood::unordered_map<int, Sound> _soundMap;
robin_hood::unordered_map<int, Texture2D> _textureMap;
robin_hood::unordered_map<int, Wave> _waveMap;
robin_hood::unordered_map<int, AutomationEventList> _automationEventListMap;
int _nextId = 1;
#define CLS_AUDIOSTREAM 1
#define CLS_FONTMAP 2
#define CLS_IMAGEMAP 3
#define CLS_MATRIXMAP 4
#define CLS_MESHMAP 5
#define CLS_MODELMAP 6
#define CLS_MODELANIMATIONMAP 7
#define CLS_MUSICMAP 8
#define CLS_PHYSICSMAP 9
#define CLS_RENDERMAP 10
#define CLS_SOUNDMAP 12
#define CLS_TEXTUREMAP 13
#define CLS_WAVEMAP 14
#define CLS_AUTOMATIONEVENTLISTMAP 15
PhysicsBody get_physics_body(var_p_t var) {
PhysicsBody result;
int id = var->v.fn.id;
if (id != -1 && _physicsMap.find(id) != _physicsMap.end()) {
result = _physicsMap.at(id);
} else {
result = nullptr;
}
return result;
}
static Vector3 get_array_elem_vec3(var_p_t array, int index) {
Vector3 result;
int size = v_asize(array);
if (index >= 0 && index < size) {
var_p_t elem = v_elem(array, index);
if (elem->type == V_ARRAY) {
result.x = get_array_elem_num(elem, 0);
result.y = get_array_elem_num(elem, 1);
result.z = get_array_elem_num(elem, 2);
}
}
return result;
}
static Vector3 get_map_vec3(var_p_t map, const char *name) {
Vector3 result;
var_p_t array = map_get(map, name);
if (is_array(array, 3)) {
result.x = get_array_elem_num(array, 0);
result.y = get_array_elem_num(array, 1);
result.z = get_array_elem_num(array, 2);
} else if (is_map(array)) {
result.x = get_map_num(array, "x");
result.y = get_map_num(array, "y");
result.z = get_map_num(array, "z");
} else {
TraceLog(LOG_FATAL, "Vector3 not found");
}
return result;
}
static Color get_param_color(int argc, slib_par_t *params, int n) {
Color result;
if (n >= 0 && n < argc && params[n].var_p->type == V_INT) {
var_int_t c = params[n].var_p->v.i;
uint8_t r = (c & 0xff000000) >> 24;
uint8_t g = (c & 0xff0000) >> 16;
uint8_t b = (c & 0xff00) >> 8;
uint8_t a = (c & 0xff);
result = {r, g, b, a};
} else if (is_param_array(argc, params, n)) {
result.r = get_array_elem_num(params[n].var_p, 0);
result.g = get_array_elem_num(params[n].var_p, 1);
result.b = get_array_elem_num(params[n].var_p, 2);
if (v_asize(params[n].var_p) == 4) {
result.a = get_array_elem_num(params[n].var_p, 3);
} else {
result.a = 255;
}
} if (is_param_map(argc, params, n)) {
result.r = get_map_num(params[n].var_p, "r");
result.g = get_map_num(params[n].var_p, "g");
result.b = get_map_num(params[n].var_p, "b");
result.a = get_map_num(params[n].var_p, "a");
}
return result;
}
static Rectangle get_param_rect(int argc, slib_par_t *params, int n) {
Rectangle result;
if (is_param_map(argc, params, n)) {
result.x = get_map_num(params[n].var_p, "x");
result.y = get_map_num(params[n].var_p, "y");
result.width = get_map_num(params[n].var_p, "width");
result.height = get_map_num(params[n].var_p, "height");
} else if (is_param_array(argc, params, n)) {
result.x = get_array_elem_num(params[n].var_p, 0);
result.y = get_array_elem_num(params[n].var_p, 1);
result.width = get_array_elem_num(params[n].var_p, 2);
result.height = get_array_elem_num(params[n].var_p, 3);
}
return result;
}
static NPatchInfo get_param_npatch(int argc, slib_par_t *params, int n) {
NPatchInfo result;
if (is_param_map(argc, params, n) && is_map(map_get(params[n].var_p, "source"))) {
var_p_t map = params[n].var_p;
var_p_t source = map_get(map, "source");
result.source.x = get_map_num(source, "x");
result.source.y = get_map_num(source, "y");
result.source.width = get_map_num(source, "width");
result.source.height = get_map_num(source, "height");
result.left = get_map_num(map, "left");
result.top = get_map_num(map, "top");
result.right = get_map_num(map, "right");
result.bottom = get_map_num(map, "bottom");
result.layout = get_map_num(map, "layout");
} else {
TraceLog(LOG_FATAL, "NPatchInfo not found");
}
return result;
}
static Vector2 get_array_elem_vec2(var_p_t array, int index) {
Vector2 result;
int size = v_asize(array);
if (index >= 0 && index < size) {
var_p_t elem = v_elem(array, index);
if (elem->type == V_ARRAY) {
result.x = get_array_elem_num(elem, 0);
result.y = get_array_elem_num(elem, 1);
}
}
return result;
}
static Vector2 get_map_vec2(var_p_t map, const char *name) {
Vector2 result;
var_p_t array = map_get(map, name);
if (is_array(array, 2)) {
result.x = get_array_elem_num(array, 0);
result.y = get_array_elem_num(array, 1);
} else if (is_map(array)) {
var_p_t var = map_get(map, name);
result.x = get_map_num(var, "x");
result.y = get_map_num(var, "y");
} else {
TraceLog(LOG_FATAL, "Vector2 not found");
}
return result;
}
static Camera2D get_camera_2d(int argc, slib_par_t *params, int n) {
Camera2D result;
if (is_param_array(argc, params, n)) {
var_p_t array = params[n].var_p;
result.offset = get_array_elem_vec2(array, 0);
result.target = get_array_elem_vec2(array, 1);
result.rotation = get_array_elem_num(array, 2);
result.zoom = get_array_elem_num(array, 3);
} else if (is_param_map(argc, params, n)) {
var_p_t map = params[n].var_p;
result.offset = get_map_vec2(map, "offset");
result.target = get_map_vec2(map, "target");
result.rotation = get_map_num(map, "rotation");
result.zoom = get_map_num(map, "zoom");
} else {
TraceLog(LOG_FATAL, "Camera2D not found");
}
return result;
}
static Vector2 *get_param_vec2_array(int argc, slib_par_t *params, int n) {
static Vector2 data[10];
Vector2 *result;
if (is_param_array(argc, params, n)) {
var_p_t array = params[n].var_p;
int size = v_asize(array);
for (int i = 0; i < size && i < 10; i++) {
data[i] = get_array_elem_vec2(array, i);
}
result = (Vector2 *)&data;
} else {
result = nullptr;
}
return result;
}
static Vector3 *get_param_vec3_array(int argc, slib_par_t *params, int n) {
static Vector3 data[10];
Vector3 *result;
if (is_param_array(argc, params, n)) {
var_p_t array = params[n].var_p;
int size = v_asize(array);
for (int i = 0; i < size && i < 10; i++) {
data[i] = get_array_elem_vec3(array, i);
}
result = (Vector3 *)&data;
} else {
result = nullptr;
}
return result;
}
static Vector2 get_param_vec2(int argc, slib_par_t *params, int n) {
Vector2 result;
if (is_param_map(argc, params, n)) {
result.x = get_map_num(params[n].var_p, "x");
result.y = get_map_num(params[n].var_p, "y");
} else if (is_param_array(argc, params, n)) {
result.x = get_array_elem_num(params[n].var_p, 0);
result.y = get_array_elem_num(params[n].var_p, 1);
} else {
result.x = 0.0;
result.y = 0.0;
}
return result;
}
static Vector3 get_param_vec3(int argc, slib_par_t *params, int n) {
Vector3 result;
if (is_param_map(argc, params, n)) {
result.x = get_map_num(params[n].var_p, "x");
result.y = get_map_num(params[n].var_p, "y");
result.z = get_map_num(params[n].var_p, "z");
} else if (is_param_array(argc, params, n)) {
result.x = get_array_elem_num(params[n].var_p, 0);
result.y = get_array_elem_num(params[n].var_p, 1);
result.z = get_array_elem_num(params[n].var_p, 2);
} else {
result.x = 0;
result.y = 0;
result.z = 0;
}
return result;
}
static Vector4 get_param_vec4(int argc, slib_par_t *params, int n) {
Vector4 result;
if (is_param_map(argc, params, n)) {
result.x = get_map_num(params[n].var_p, "x");
result.y = get_map_num(params[n].var_p, "y");
result.z = get_map_num(params[n].var_p, "z");
result.w = get_map_num(params[n].var_p, "w");
} else if (is_param_array(argc, params, n)) {
result.x = get_array_elem_num(params[n].var_p, 0);
result.y = get_array_elem_num(params[n].var_p, 1);
result.z = get_array_elem_num(params[n].var_p, 2);
result.w = get_array_elem_num(params[n].var_p, 3);
} else {
result.x = 0;
result.y = 0;
result.z = 0;
result.w = 0;
}
return result;
}
static Shader get_param_shader(int argc, slib_par_t *params, int arg) {
Shader result;
if (is_param_map(argc, params, arg)) {
result.id = get_id(params, arg);
var_p_t var = map_get(params[arg].var_p, "locs");
if (v_is_type(var, V_INT)) {
result.locs = (int *)(var->v.i);
} else {
result.locs = nullptr;
}
} else {
TraceLog(LOG_FATAL, "Shader not found");
}
return result;
}
static BoundingBox get_param_bounding_box(int argc, slib_par_t *params, int n) {
BoundingBox result;
if (is_param_array(argc, params, n)) {
var_p_t array = params[n].var_p;
result.min = get_array_elem_vec3(array, 0);
result.max = get_array_elem_vec3(array, 1);
} else if (is_param_map(argc, params, n)) {
var_p_t map = params[n].var_p;
result.min = get_map_vec3(map, "min");
result.max = get_map_vec3(map, "max");
} else {
result.min.x = 0;
result.min.y = 0;
result.min.z = 0;
result.max.x = 0;
result.max.y = 0;
result.max.z = 0;
}
return result;
}
static Ray get_param_ray(int argc, slib_par_t *params, int n) {
Ray result;
if (is_param_map(argc, params, n)) {
var_p_t map = params[n].var_p;
result.position = get_map_vec3(map, "position");
result.direction = get_map_vec3(map, "direction");
}
return result;
}
static FilePathList get_param_filepathlist(int argc, slib_par_t *params, int n) {
FilePathList result;
if (is_param_array(argc, params, n)) {
var_p_t array = params[n].var_p;
result.count = v_asize(array);
result.capacity = result.count;
result.paths = (char **)malloc(result.capacity * sizeof(char *));
for (unsigned index = 0; index < result.count; index++) {
result.paths[index] = (char *)malloc(MAX_FILEPATH_LENGTH * sizeof(char));
var_p_t elem = v_elem(array, index);
if (elem->type == V_STR) {
TextCopy(result.paths[index], elem->v.p.ptr);
} else {
result.paths[index][0] = '\0';
}
}
}
return result;
}
static Camera3D get_camera_3d(int argc, slib_par_t *params, int n) {
Camera3D result;
if (is_param_array(argc, params, n)) {
var_p_t array = params[n].var_p;
result.position = get_array_elem_vec3(array, 0);
result.target = get_array_elem_vec3(array, 1);
result.up = get_array_elem_vec3(array, 2);
result.fovy = get_array_elem_num(array, 3);
result.projection = get_array_elem_num(array, 4);
} else if (is_param_map(argc, params, n)) {
var_p_t map = params[n].var_p;
result.position = get_map_vec3(map, "position");
result.target = get_map_vec3(map, "target");
result.up = get_map_vec3(map, "up");
result.fovy = get_map_num(map, "fovy");
result.projection = get_map_num(map, "projection");
} else {
TraceLog(LOG_FATAL, "Camera3D not found");
}
return result;
}
static void set_camera_3d(var_p_t var, Camera3D *camera) {
var_p_t v_position;
var_p_t v_target;
var_p_t v_up;
if (is_array(var, 5)) {
v_position = v_elem(var, 0);
v_target = v_elem(var, 1);
v_up = v_elem(var, 2);
} else if (v_is_type(var, V_MAP)) {
v_position = map_get(var, "position");
v_target = map_get(var, "target");
v_up = map_get(var, "up");
} else {
v_position = nullptr;
v_target = nullptr;
v_up = nullptr;
}
if (is_array(v_position, 3)) {
v_setreal(v_elem(v_position, 0), camera->position.x);
v_setreal(v_elem(v_position, 1), camera->position.y);
v_setreal(v_elem(v_position, 2), camera->position.z);
} else {
TraceLog(LOG_FATAL, "Camera3D position not found");
}
if (is_array(v_target, 3)) {
v_setreal(v_elem(v_target, 0), camera->target.x);
v_setreal(v_elem(v_target, 1), camera->target.y);
v_setreal(v_elem(v_target, 2), camera->target.z);
} else {
TraceLog(LOG_FATAL, "Camera3D target not found");
}
if (is_array(v_up, 3)) {
v_setreal(v_elem(v_up, 0), camera->up.x);
v_setreal(v_elem(v_up, 1), camera->up.y);
v_setreal(v_elem(v_up, 2), camera->up.z);
} else {
TraceLog(LOG_FATAL, "Camera3D up not found");
}
}
static int get_audiostream_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _audioStream.find(id) != _audioStream.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "AudioStream not found");
}
return result;
}
static int get_font_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
// the passed in variable is a map
int id = get_id(params, arg);
if (id != -1 && _fontMap.find(id) != _fontMap.end()) {
// the map contained an ID field with a live value
result = id;
}
}
if (result == -1) {
error(retval, "Font not found");
}
return result;
}
static int get_image_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _imageMap.find(id) != _imageMap.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "Image not found");
}
return result;
}
static int get_mesh_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _meshMap.find(id) != _meshMap.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "Mesh not found");
}
return result;
}
static int get_texture_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _textureMap.find(id) != _textureMap.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "Texture not found");
}
return result;
}
static int get_model_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _modelMap.find(id) != _modelMap.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "Model not found");
}
return result;
}
static int get_model_animation_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _modelAnimationMap.find(id) != _modelAnimationMap.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "Model Animation not found");
}
return result;
}
static int get_physics_body_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _physicsMap.find(id) != _physicsMap.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "PhysicsBody not found");
}
return result;
}
static int get_render_texture_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _renderMap.find(id) != _renderMap.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "RenderTexture not found");
}
return result;
}
static int get_matrix_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _matrixMap.find(id) != _matrixMap.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "Matrix not found");
}
return result;
}
static int get_music_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _musicMap.find(id) != _musicMap.end()) {
_musicMap.at(id).looping = map_get_int(params[arg].var_p, "looping", 0);
result = id;
}
}
if (result == -1) {
error(retval, "Music not found");
}
return result;
}
static int get_wave_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _waveMap.find(id) != _waveMap.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "Wave not found");
}
return result;
}
static int get_sound_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _soundMap.find(id) != _soundMap.end()) {
result = id;
}
}
if (result == -1) {
error(retval, "Sound not found");
}
return result;
}
static int get_automationeventlist_id(int argc, slib_par_t *params, int arg, var_t *retval) {
int result = -1;
if (is_param_map(argc, params, arg)) {
int id = get_id(params, arg);
if (id != -1 && _automationEventListMap.find(id) != _automationEventListMap.end()) {
result = id;
}
}
if (result == -1 && retval != nullptr) {
error(retval, "AutomationEventList not found");
}
return result;
}
static void v_setrect(var_t *var, int width, int height, int id) {
map_init_id(var, id);
v_setint(map_add_var(var, "width", 0), width);
v_setint(map_add_var(var, "height", 0), height);
}
static void v_setrect(var_t *var, Rectangle &rect) {
map_init(var);
v_setreal(map_add_var(var, "x", 0), rect.x);
v_setreal(map_add_var(var, "y", 0), rect.y);
v_setreal(map_add_var(var, "width", 0), rect.width);
v_setreal(map_add_var(var, "height", 0), rect.height);
}
static void v_setvec2(var_t *var, Vector2 &vec2) {
map_init(var);
v_setreal(map_add_var(var, "x", 0), vec2.x);
v_setreal(map_add_var(var, "y", 0), vec2.y);
}
static void v_setvec3(var_t *var, Vector3 &vec3) {
map_init(var);
v_setreal(map_add_var(var, "x", 0), vec3.x);
v_setreal(map_add_var(var, "y", 0), vec3.y);
v_setreal(map_add_var(var, "z", 0), vec3.z);
}
static void v_setvec4(var_t *var, Vector4 &vec4) {
map_init(var);
v_setreal(map_add_var(var, "x", 0), vec4.x);
v_setreal(map_add_var(var, "y", 0), vec4.y);
v_setreal(map_add_var(var, "z", 0), vec4.z);
v_setreal(map_add_var(var, "w", 0), vec4.w);
}
static void v_setboundingbox(var_t *var, BoundingBox &box) {
map_init(var);
v_setvec3(map_add_var(var, "min", 0), box.min);
v_setvec3(map_add_var(var, "max", 0), box.max);
}
static void v_setcolor(var_t *var, Color &c) {
var_int_t color = ((0x00000000) | (c.r << 24) | (c.g << 16) | (c.b << 8) | (c.a));
v_setint(var, color);
}
static void v_setaudiostream(var_t *var, AudioStream &audioStream) {
int id = ++_nextId;
_audioStream[id] = audioStream;
map_init_id(var, id, CLS_AUDIOSTREAM);
v_setint(map_add_var(var, "sampleRate", 0), audioStream.sampleRate);
v_setint(map_add_var(var, "sampleSize", 0), audioStream.sampleSize);
v_setint(map_add_var(var, "channels", 0), audioStream.channels);
}
static void v_setfont(var_t *var, Font &font) {
auto id = ++_nextId;
_fontMap[id] = font;
map_init_id(var, id, CLS_FONTMAP);
v_setint(map_add_var(var, "baseSize", 0), font.baseSize);
v_setint(map_add_var(var, "charsCount", 0), font.glyphCount);
}
static void v_setphysics(var_t *var, PhysicsBody &physics) {
if (physics != NULL) {
auto id = ++_nextId;
_physicsMap[id] = physics;
create(physics, var, id);
} else {
v_setint(var, 0);
}
}
static void v_setshader(var_t *var, Shader &shader) {
map_init_id(var, shader.id);
v_setint(map_add_var(var, "locs", 0), (var_int_t)shader.locs);
}
static void v_settexture2d(var_t *var, Texture2D &texture) {
int id = ++_nextId;
_textureMap[id] = texture;
v_setrect(var, texture.width, texture.height, id);
v_setint(map_add_var(var, "id", 0), texture.id);
v_setint(map_add_var(var, "mipmaps", 0), texture.mipmaps);
v_setint(map_add_var(var, "format", 0), texture.format);
}
static void v_setimage(var_t *var, Image &image) {
int id = ++_nextId;
_imageMap[id] = image;
v_setrect(var, image.width, image.height, id);
}
static void v_setmesh(var_t *var, Mesh &mesh) {
int id = ++_nextId;
_meshMap[id] = mesh;
map_init_id(var, id, CLS_MESHMAP);
v_setint(map_add_var(var, "vertexCount", 0), mesh.vertexCount);
v_setint(map_add_var(var, "triangleCount", 0), mesh.triangleCount);
}
static void v_setmatrix(var_t *var, Matrix &matrix) {
int id = ++_nextId;
_matrixMap[id] = matrix;
map_init_id(var, id, CLS_MATRIXMAP);
}
static void v_setmodel(var_t *var, Model &model) {
auto id = ++_nextId;
_modelMap[id] = model;
map_init_id(var, id, CLS_MODELMAP);
v_setint(map_add_var(var, "meshCount", 0), model.meshCount);
v_setint(map_add_var(var, "materialCount", 0), model.materialCount);
v_setint(map_add_var(var, "boneCount", 0), model.boneCount);
}
static void v_setmusic(var_t *var, Music &music) {
int id = ++_nextId;
_musicMap[id] = music;
map_init_id(var, id, CLS_MUSICMAP);
v_setint(map_add_var(var, "frameCount", 0), music.frameCount);
v_setint(map_add_var(var, "looping", 0), music.looping);
v_setint(map_add_var(var, "ctxType", 0), music.ctxType);
}
static void v_setmodel_animation(var_t *var, ModelAnimation *anims, int animsCount) {
v_toarray1(var, animsCount);
for (int i = 0; i < animsCount; i++) {
var_t *v_anim = v_elem(var, i);
auto id = ++_nextId;
_modelAnimationMap[id] = anims[i];
map_init_id(v_anim, id, CLS_MODELANIMATIONMAP);
int frameCount = anims[i].frameCount;
int boneCount = anims[i].boneCount;
map_add_var(v_anim, "frameCount", frameCount);
map_add_var(v_anim, "boneCount", boneCount);
var_t *v_framePoses = map_add_var(v_anim, "framePoses", 0);
v_tomatrix(v_framePoses, frameCount, boneCount);
for (int frame = 0; frame < frameCount; frame++) {
for (int bone = 0; bone < boneCount; bone++) {
var_t *v_transform = v_elem(v_framePoses, ((boneCount * frame) + bone));
map_init(v_transform);
v_setvec3(map_add_var(v_transform, "translation", 0), anims[0].framePoses[frame][bone].translation);
v_setvec3(map_add_var(v_transform, "scale", 0), anims[0].framePoses[frame][bone].scale);
}
}
}
}
static void v_setraycollision(var_t *var, RayCollision &info) {
map_init(var);
v_setint(map_add_var(var, "hit", 0), info.hit);
v_setint(map_add_var(var, "distance", 0), info.distance);
v_setvec3(map_add_var(var, "point", 0), info.point);
v_setvec3(map_add_var(var, "normal", 0), info.normal);
}
static void v_setray(var_t *var, Ray &ray) {
map_init(var);
v_setvec3(map_add_var(var, "position", 0), ray.position);
v_setvec3(map_add_var(var, "direction", 0), ray.direction);
}
static void v_setsound(var_t *var, Sound &sound) {
int id = ++_nextId;
_soundMap[id] = sound;
map_init_id(var, id, CLS_SOUNDMAP);
v_setint(map_add_var(var, "frameCount", 0), sound.frameCount);
}
static void v_setwave(var_t *var, Wave &wave) {
int id = ++_nextId;
_waveMap[id] = wave;
map_init_id(var, id, CLS_WAVEMAP);
v_setint(map_add_var(var, "frameCount", 0), wave.frameCount);
v_setint(map_add_var(var, "sampleRate", 0), wave.sampleRate);
v_setint(map_add_var(var, "sampleSize", 0), wave.sampleSize);
v_setint(map_add_var(var, "channels", 0), wave.channels);
}
static void v_setfilepathlist(var_t *var, FilePathList &filePathList) {
map_init(var);
v_setint(map_add_var(var, "count", 0), filePathList.count);
var_t *v_paths = map_add_var(var, "paths", 0);
v_toarray1(v_paths, filePathList.count);
for (unsigned index = 0; index < filePathList.count; index++) {
var_p_t elem = v_elem(v_paths, index);
v_setstr(elem, filePathList.paths[index]);
}
}
static AutomationEvent get_param_automationevent(int argc, slib_par_t *params, int n) {
static AutomationEvent result;
if (is_param_map(argc, params, n)) {
var_p_t map = params[n].var_p;
int position = map_get_int(map, "position", -1);
int id = get_automationeventlist_id(argc, params, 0, nullptr);
if (position != -1 && id != -1 ) {
AutomationEventList *atomationEventList = &_automationEventListMap.at(id);
if ((unsigned)position < atomationEventList->count) {
result = atomationEventList->events[position];
}
}
}
return result;
}
static void v_setautomationeventlist(var_t *var, AutomationEventList &automationEventList) {
int id = ++_nextId;
_automationEventListMap[id] = automationEventList;
map_init_id(var, id, CLS_AUTOMATIONEVENTLISTMAP);
v_setint(map_add_var(var, "count", 0), automationEventList.count);
var_t *v_events = map_add_var(var, "events", 0);
v_toarray1(v_events, automationEventList.count);
for (unsigned i = 0; i < automationEventList.count; i++) {
var_p_t elem = v_elem(v_events, i);
map_init_id(elem, id);
v_setint(map_add_var(elem, "frame", 0), automationEventList.events[i].frame);
v_setint(map_add_var(elem, "type", 0), automationEventList.events[i].type);
v_setint(map_add_var(elem, "position", 0), i);
}
}
static int cmd_updateautomationeventlist(int argc, slib_par_t *params, var_t *retval) {
int result;
int id = get_automationeventlist_id(argc, params, 0, retval);
if (id != -1) {
AutomationEventList copiedAtomationEventList = _automationEventListMap.at(id);
v_setautomationeventlist(retval, copiedAtomationEventList);
result = 1;
} else {
result = 0;
}
return result;
}
//
// Apply Custom Square image convolution kernel
//
static int cmd_imagekernelconvolution(int argc, slib_par_t *params, var_t *retval) {
int result;
int image_id = get_image_id(argc, params, 0, retval);
if (image_id != -1 && is_param_array(argc, params, 1)) {
var_p_t array = params[1].var_p;
int kernelSize = v_asize(array);
float *kernel = new float[kernelSize];
for (int i = 0; i < kernelSize; i++) {
kernel[i] = get_num(v_elem(array, i));
}
ImageKernelConvolution(&_imageMap.at(image_id), kernel, kernelSize);
delete [] kernel;
result = 1;
} else {
result = 0;
}
return result;
}
#include "proc.h"
#include "func.h"
static int cmd_setshadervalue(int argc, slib_par_t *params, var_t *retval) {
auto shader = get_param_shader(argc, params, 0);
auto uniformLoc = get_param_int(argc, params, 1, 0);
auto uniformType = get_param_int(argc, params, 3, SHADER_UNIFORM_FLOAT);
auto count = get_param_int(argc, params, 4, 1);
Vector3 vec3;
Vector2 vec2;
float num;
switch (uniformType) {
case SHADER_UNIFORM_FLOAT:
num = get_param_num(argc, params, 2, 0);
SetShaderValueV(shader, uniformLoc, &num, uniformType, count);
break;
case SHADER_UNIFORM_VEC2:
vec2 = get_param_vec2(argc, params, 2);
SetShaderValueV(shader, uniformLoc, &vec2, uniformType, count);
break;
case SHADER_UNIFORM_VEC3:
vec3 = get_param_vec3(argc, params, 2);
SetShaderValueV(shader, uniformLoc, &vec3, uniformType, count);
break;
default:
error(retval, "Uniform type not implemented");
break;
}
return 1;
}
static int cmd_updatecamera(int argc, slib_par_t *params, var_t *retval) {
auto camera = get_camera_3d(argc, params, 0);
if (argc == 4) {
auto movement = get_param_vec3(argc, params, 1);
auto rotation = get_param_vec3(argc, params, 2);
auto zoom = get_param_num(argc, params, 3, 0);
UpdateCameraPro(&camera, movement, rotation, zoom);
} else {
auto mode = get_param_int(argc, params, 1, CAMERA_FREE);
UpdateCamera(&camera, mode);
}
set_camera_3d(params[0].var_p, &camera);
return 1;
}
static int cmd_loadmodelanimations(int argc, slib_par_t *params, var_t *retval) {
auto fileName = get_param_str(argc, params, 0, NULL);
int animsCount = 0;
auto anims = LoadModelAnimations(fileName, &animsCount);
v_setmodel_animation(retval, anims, animsCount);
RL_FREE(anims);
return 1;
}
static int cmd_setmodeldiffusetexture(int argc, slib_par_t *params, var_t *retval) {
int result;
int modelId = get_model_id(argc, params, 0, retval);
int textureId = get_texture_id(argc, params, 1, retval);
if (modelId != -1 && textureId != -1) {
_modelMap.at(modelId).materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = _textureMap.at(textureId);
result = 1;
} else {
result = 0;
}
return result;
}
static int cmd_setmodeltransform(int argc, slib_par_t *params, var_t *retval) {
int result;
int modelId = get_model_id(argc, params, 0, retval);
auto x = get_param_int(argc, params, 1, 0);
auto y = get_param_int(argc, params, 2, 0);
auto z = get_param_int(argc, params, 3, 0);
if (modelId != -1) {
_modelMap.at(modelId).transform = MatrixTranslate(x, y, z);
result = 1;
} else {
result = 0;
}
return result;
}
static int cmd_loadrendertexture(int argc, slib_par_t *params, var_t *retval) {
auto width = get_param_int(argc, params, 0, 0);
auto height = get_param_int(argc, params, 1, 0);
auto renderId = ++_nextId;
auto renderTexture = LoadRenderTexture(width, height);
_renderMap[renderId] = renderTexture;
map_init_id(retval, renderId, CLS_RENDERMAP);
auto textureId = ++_nextId;
_textureMap[textureId] = renderTexture.texture;
var_p_t texture = map_add_var(retval, "texture", 0);
v_setrect(texture, renderTexture.texture.width, renderTexture.texture.height, textureId);
return 1;
}
static int cmd_loadshader(int argc, slib_par_t *params, var_t *retval) {
auto vsFileName = get_param_str(argc, params, 0, NULL);
auto fsFileName = get_param_str(argc, params, 1, NULL);