-
Notifications
You must be signed in to change notification settings - Fork 0
/
raylib.stub
2454 lines (2090 loc) · 112 KB
/
raylib.stub
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
(import (srfi 159)
(srfi 1)
(chibi match))
(c-include "raylib.h")
(c-system-include "stdbool.h")
(define-syntax <<hlpr
(syntax-rules (>>)
((_ () (arg ...)) (syntax-error "<< lambda must have a closing >>"))
((_ (>>) (arg ...))
(syntax-error "<< lambda must have a body after >>"))
((_ (>> body body* ...) (arg ...))
(lambda (arg ...) body body* ...))
((_ (other-arg rest ...) (arg ...))
(<<hlpr (rest ...) (other-arg arg ...)))))
(define-syntax <<
(syntax-rules ()
((_ parts ...)
(<<hlpr (parts ...) ()))))
(define (empty-list? a)
(eq? a '()))
(define (display-nl s)
(display s)
(newline))
(define (foldl fn-it-ac lst . init)
(match init
((? empty-list? _)
(foldl fn-it-ac (cdr lst) (car lst)))
(init
(let loop ((acc (car init))
(rest lst))
(if (empty-list? rest) acc
(loop (fn-it-ac (car rest) acc)
(cdr rest)))))))
(define (join-with strings sep)
(if (eq? strings '()) ""
(foldl
(lambda (it ac)
(string-append ac sep it))
strings)))
(define (struct-type? type-name)
(let ((item (find (<< it >> (eq? (car it) type-name)) *types*)))
(if item
(eq? (cadr (memq 'type: item)) 'struct)
#f)))
(define (generate-arg-list args)
(join-with (map (lambda (arg)
(match arg
((type name)
(cond ((struct-type? type)
(string-append (symbol->string type) " * " (symbol->string name)))
((eq? type 'boolean)
(string-append "bool " (symbol->string name)))
((eq? type 'unsigned-int)
(string-append "unsigned int " (symbol->string name)))
((equal? '(pointer void) type)
(string-append "void * " (symbol->string name)))
((eq? type 'string)
(string-append "char * " (symbol->string name)))
(else (string-append (symbol->string type) " " (symbol->string name))))))) args)
", "))
(define (generate-call-arg-list args)
(join-with (map (lambda (arg)
(match arg
((type name)
(cond
((struct-type? type)
(string-append "*" (symbol->string name)))
((eq? type 'string)
(symbol->string name))
(else (symbol->string name)))))) args)
", "))
(define (generate-return-type return-type)
(cond ((struct-type? return-type)
(string-append (symbol->string return-type) " *"))
((eq? return-type 'boolean) "bool")
(else (symbol->string return-type))))
(define (get-struct-fields type)
(map (<< entry >> (cons (vector-ref (car entry) 0) (cdr entry)))
(let loop ((lst (find (<< it >> (eq? (car it) type)) *types*)))
(if (list? (car lst)) lst
(loop (cdr lst))))))
;; Despite the generate name, this function does generate a copier
;; that allocates char * memory in the case of strings
(define (generate-copy-code struct-type from-name to-name)
(let* ((struct-name (symbol->string struct-type))
(from-name (symbol->string from-name))
(to-name (symbol->string to-name))
(body (let loop ((field-info (get-struct-fields struct-type))
(lines '()))
(if (eq? '() field-info) (join-with lines "\n")
(loop (cdr field-info)
(cons (match (car field-info)
((type name rest ...)
(let ((name (symbol->string name)))
(cond ((struct-type? type)
(string-append "Copy" (symbol->string type) "NoAlloc("
"&(" from-name "->" name "),&(" to-name "->" name "));"))
((eq? type 'string)
(string-append
;; NB. this does alloc strings.
to-name "->" name " = (char*)malloc(sizeof(char)*strlen(" from-name "->" name"));\n"
"str_copy(" to-name "->" name "," from-name "->" name ");\n"))
(else
(string-append to-name "->" name " = " from-name "->" name ";")))))) lines))))))
(string-append "void Copy" struct-name "NoAlloc(" struct-name " * " from-name ", " struct-name " * " to-name "){\n"
body "\n}")))
(define (declare-struct-copier struct-name)
(c-declare (generate-copy-code struct-name 'from_pointer 'to_pointer)))
(define (generate-pointer-passthrough return-type function-name args)
(let ((function-name (symbol->string function-name))
(return-type-name (symbol->string return-type)))
(string-append
(generate-return-type return-type) " " function-name "Pr(" (generate-arg-list args) "){\n"
(cond ((eq? return-type 'void)
(string-append function-name "(" (generate-call-arg-list args) ");\n"))
((not (struct-type? return-type))
(string-append "return " function-name "(" (generate-call-arg-list args) ");\n"))
((struct-type? return-type)
(string-append return-type-name " tmp = " function-name "(" (generate-call-arg-list args) ");\n"
return-type-name " * out = (" return-type-name "*)malloc(sizeof(" return-type-name "));\n"
"Copy" return-type-name "NoAlloc(&tmp,out);"
"return out;\n")))
"}")))
(define (declare-pointer-passthrough-f return-type function-name args)
(c-declare (generate-pointer-passthrough return-type function-name args)))
(define (ensure-string o)
(with-output-to-string (lambda ()
(display o))))
(define (symbol->string* s)
(cond ((symbol? s) (symbol->string s))
((string? s) s)
(else (error (string-append "Error " (ensure-string s) " is neither string nor symbol.")))))
(define (generate-base-array-type-code type)
(let* ((base (symbol->string* type))
(base-ptr (string-append base "*"))
(struct-name (string-append base "Array"))
(struct-name-ptr (string-append struct-name "*"))
(maker-c-symbol (string->symbol
(string-append
"Make" base "Array")))
(maker-symbol (string-append
(string-append "make-" base "-array")))
(getter-c-symbol (string->symbol
(string-append
"Get" base "ArrayEl")))
(getter-symbol (string->symbol
(string-append "get-" base "-array-el")))
(setter-c-symbol (string->symbol
(string-append
"Set" base "ArrayEl")))
(setter-symbol (string->symbol
(string-append "set-" base "-array-el!"))))
(string-append "typedef struct " struct-name " {
int count;
"base-ptr" data;
} " struct-name";
void Free"struct-name"Pr("struct-name-ptr"s){
free(s->data);
free(s);
}
" struct-name-ptr " Make" base "Array(int count){
"struct-name-ptr" a = ("struct-name-ptr")malloc(sizeof("struct-name"));
a->data = ("base-ptr")malloc(sizeof("base")*count);
a->count = count;
return a;
}
"base " Get"base"ArrayEl("struct-name-ptr" s, int index){
return s->data[index % s->count];
}
void Set"base"ArrayEl("struct-name-ptr" s, int index, "base" val){
s->data[index % s->count] = val;
}
")))
(define (symbol-append . args)
(string->symbol (apply string-append (map symbol->string* args))))
(define-syntax declare-c-base-type-array
(er-macro-transformer
(lambda (e r c)
(let* ((type (cadr e))
(struct-type (symbol-append
type "Array"))
(predicate (symbol-append
type "-array?"))
(finalizer (symbol-append
"Free" type "ArrayPr"))
(maker (symbol-append
"make-" type "-array"))
(c-maker (symbol-append
"Make" type "Array"))
(element-getter
(symbol-append
"get-" type "-array-element"))
(c-element-getter
(symbol-append
"Get" type "ArrayEl"))
(element-setter
(symbol-append
"set-" type "-array-element!"))
(c-element-setter
(symbol-append
"Set" type "ArrayEl"))
(count-getter
(symbol-append "get-" type "-array-count")))
`(begin
(c-declare (generate-base-array-type-code ',type))
(define-c-struct ,struct-type
predicate: ,predicate
finalizer: ,finalizer
((pointer ,type) elements)
(int count ,count-getter))
(define-c (free ,struct-type) (,maker ,c-maker) (int))
(define-c ,type (,element-getter ,c-element-getter) (,struct-type int))
(define-c void (,element-setter ,c-element-setter) (,struct-type int ,type)))))))
(declare-c-base-type-array int)
(declare-c-base-type-array float)
(define-syntax declare-pointer-passthrough
(syntax-rules ()
((_ return-type function-name args)
(declare-pointer-passthrough-f (quote return-type)
(quote function-name)
(quote args)))))
;; Type Wrappers
(c-declare "
void FreeImagePr(Image * im){
UnloadImage(*im);
free(im);
}
")
(define-c-struct Image
predicate: image?
finalizer: FreeImagePr
((link void) data)
(int width get-image-width set-image-width!)
(int height get-image-height set-image-height!)
(int mipmaps get-image-mipmaps set-image-mipmaps!)
(int format get-image-format set-image-format!))
(declare-struct-copier 'Image)
(c-declare "
Rectangle * MakeRectanglePr(float x, float y, float w, float h){
Rectangle * r;
r = malloc(sizeof(Rectangle));
r->x = x;
r->y = y;
r->width = w;
r->height = h;
return r;
}
void FreeRectanglePr(Rectangle * r){
free(r);
}
")
(define-c-struct Rectangle
predicate: rectangle?
finalizer: FreeRectanglePr
(float x get-rectangle-x set-rectangle-x!)
(float y get-rectangle-y set-rectangle-y!)
(float width get-rectangle-width set-rectangle-width!)
(float height get-rectangle-height set-rectangle-height!))
(declare-struct-copier 'Rectangle)
(define-c (free Rectangle) (--rectangle MakeRectanglePr) (float float float float))
(c-declare "
Color * MakeColorPr(unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a){
Color * c = malloc(sizeof(Color));
c->r = r;
c->g = g;
c->b = b;
c->a = a;
return c;
}
void FreeColorPr(Color * c){
free(c);
}
")
(define-c-struct Color
predicate: color?
finalizer: FreeColorPr
(unsigned-char r get-color-r set-color-r!)
(unsigned-char g get-color-g set-color-g!)
(unsigned-char b get-color-b set-color-b!)
(unsigned-char a get-color-a set-color-a!))
(declare-struct-copier 'Color)
(define-c (free Color) (--color MakeColorPr) (unsigned-char unsigned-char unsigned-char unsigned-char))
(c-declare "
void FreeVector2Pr(Vector2 * v){
free(v);
}
Vector2 * MakeVector2Pr(float x, float y){
Vector2 * v = (Vector2*)malloc(sizeof(Vector2));
v->x = x;
v->y = y;
return v;
}
")
(define-c-struct Vector2
predicate: vector-2?
finalizer: FreeVector2Pr
(float x get-vector-2-x set-vector-2-x!)
(float y get-vector-2-y set-vector-2-y!))
(declare-struct-copier 'Vector2)
(define-c (free Vector2) (make-vector-2 MakeVector2Pr) (float float))
(c-declare "
Vector3 * MakeVector3Pr(float x, float y, float z){
Vector3 * out = (Vector3*)malloc(sizeof(Vector3));
out->x = x;
out->y = y;
out->z = z;
return out;
}
void FreeVector3Pr(Vector3 * v){
free(v);
}
")
(define-c-struct Vector3
predicate: vector-3?
finalizer: FreeVector3Pr
(float x get-vector-3-x set-vector-3-x!)
(float y get-vector-3-y set-vector-3-y!)
(float z get-vector-3-z set-vector-3-z!))
(declare-struct-copier 'Vector3)
(define-c (free Vector3) (make-vector-3 MakeVector3Pr) (float float float))
; Vector4
(c-declare "
Vector4 * MakeVector4Pr(float x, float y, float z, float w){
Vector4 * out = (Vector4*)malloc(sizeof(Vector4));
out->x = x;
out->y = y;
out->z = z;
out->w = w;
return out;
}
void FreeVector4Pr(Vector4 * v){
free(v);
}
")
(define-c-struct Vector4
predicate: vector-3?
finalizer: FreeVector4Pr
(float x get-vector-3-x set-vector-3-x!)
(float y get-vector-3-y set-vector-3-y!)
(float z get-vector-3-z set-vector-3-z!)
(float w get-vector-3-w set-vector-3-w!))
(declare-struct-copier 'Vector4)
(define-c (free Vector4) (make-vector-4 MakeVector4Pr) (float float float float))
; /* Camera2D material */
(c-declare "
Vector2 * GetCamera2DOffset(Camera2D * c){
Vector2 * out = (Vector2*)malloc(sizeof(Vector2));
out->x = c->offset.x;
out->y = c->offset.y;
return out;
}
Vector2 * GetCamera2DTarget(Camera2D * c){
Vector2 * out = (Vector2*)malloc(sizeof(Vector2));
out->x = c->target.x;
out->y = c->target.y;
return out;
}
void SetCamera2DOffset(Camera2D * c, Vector2 * v){
c->offset.x = v->x;
c->offset.y = v->y;
}
void SetCamera2DTarget(Camera2D * c, Vector2 * v){
c->target.x = v->x;
c->target.y = v->y;
}
")
(define-c-struct Camera2D
predicate: camera-2d?
finalizer: FreeCamera2DPr
((struct Vector2) offset )
((struct Vector2) target )
(float rotation camera-2d-rotation set-camera-2d-rotation!)
(float zoom camera-2d-zoom set-camera-2d-zoom!))
(declare-struct-copier 'Camera2D)
(define-c (free Vector2) (get-camera-2d-offset GetCamera2DOffset) (Camera2D))
(define-c (free Vector2) (get-camera-2d-target GetCamera2DTarget) (Camera2D))
(define-c void (set-camera-2d-offset! SetCamera2DOffset) (Camera2D Vector2))
(define-c void (set-camera-2d-target! SetCamera2DTarget) (Camera2D Vector2))
;; Camera3D Material
(c-declare "
void FreeCamera3DPr(Camera3D * c){
free(c);
}
Camera3D * MakeCamera3DPr(Vector3 * position, Vector3 * target, Vector3 * up, float fovy, int type){
Camera3D * c = (Camera3D*) malloc(sizeof(Camera3D));
c->position.x = position->x;
c->position.y = position->y;
c->position.z = position->z;
c->target.x = target->x;
c->target.y = target->y;
c->target.z = target->z;
c->up.x = up->x;
c->up.y = up->y;
c->up.z = up->z;
c->fovy = fovy;
c->type = type;
return c;
}
Vector3 * GetCamera3DPosition(Camera3D * c){
Vector3 * v = (Vector3*)malloc(sizeof(Vector3));
v->x = c->position.x;
v->y = c->position.y;
v->z = c->position.z;
return v;
}
Vector3 * GetCamera3DTarget(Camera3D * c){
Vector3 * v = (Vector3*)malloc(sizeof(Vector3));
v->x = c->target.x;
v->y = c->target.y;
v->z = c->target.z;
return v;
}
Vector3 * GetCamera3DUp(Camera3D * c){
Vector3 * v = (Vector3*)malloc(sizeof(Vector3));
v->x = c->up.x;
v->y = c->up.y;
v->z = c->up.z;
return v;
}
void SetCamera3DPosition(Camera3D * c, Vector3 * v){
c->position.x = v->x;
c->position.y = v->y;
c->position.z = v->z;
}
void SetCamera3DTarget(Camera3D * c, Vector3 * v){
c->target.x = v->x;
c->target.y = v->y;
c->target.z = v->z;
}
void SetCamera3DUp(Camera3D * c, Vector3 * v){
c->up.x = v->x;
c->up.y = v->y;
c->up.z = v->z;
}
")
(define-c-struct Camera3D
predicate: camera-3d?
finalizer: FreeCamera3DPr
((struct Vector3) position)
((struct Vector3) target)
((struct Vector3) up)
(float fovy get-camera-3d-fovy set-camera-3d-fovy!)
(int type get-camera-3d-type set-camera-3d-type!))
(declare-struct-copier 'Camera3D)
(define-c Camera3D (make-camera-3d MakeCamera3DPr)
(Vector3 Vector3 Vector3 float int))
(define-c (free Vector3) (get-camera-3d-position GetCamera3DPosition) (Camera3D))
(define-c (free Vector3) (get-camera-3d-target GetCamera3DTarget) (Camera3D))
(define-c (free Vector3) (get-camera-3d-up GetCamera3DUp) (Camera3D))
(define-c void (set-camera-3d-position! SetCamera3DPosition) (Camera3D Vector3))
(define-c void (set-camera-3d-target! SetCamera3DTarget) (Camera3D Vector3))
(define-c void (set-camera-3d-up! SetCamera3DUp) (Camera3D Vector3))
(c-declare "
void FreeTexture2DPr(Texture2D * t){
UnloadTexture(*t);
free(t);
}
")
(define-c-struct Texture2D
predicate: texture-2d?
finalizer: FreeTexture2DPr
(unsigned-int id get-texture-2d-id set-texture-2d-id!)
(int width get-texture-2d-width set-texture-2d-width!)
(int height get-texture-2d-height set-texture-2d-height!)
(int mipmaps get-texture-2d-mipmaps set-texture-2d-mipmaps!)
(int format get-texture-2d-format set-texture-2d-format!))
(declare-struct-copier 'Texture2D)
(c-declare "
void FreeRenderTexture2DPr(RenderTexture2D * r){
UnloadRenderTexture(*r);
free(r);
}
Texture2D * GetRenderTexture2DTexture(RenderTexture2D * r){
return &(r->texture);
}
Texture2D * GetRenderTexture2DDepth(RenderTexture2D * r){
return &(r->depth);
}
")
(define-c-struct RenderTexture2D
predicate: render-texture-2d?
finalizer: FreeRenderTexture2DPr
(unsigned-int id get-render-texture-2d-id set-render-texture-2d-id!)
((struct Texture2D) texture)
((struct Texture2D) depth)
(boolean depthTexture get-render-texture-2d-depth-texture set-render-texture-2d-depth-texure!))
(declare-struct-copier 'RenderTexture2D)
(define-c Texture2D (get-render-texture-2d-texture GetRenderTexture2DTexture) (RenderTexture2D))
(define-c Texture2D (get-render-texture-2d-depth GetRenderTexture2DTexture) (RenderTexture2D))
;; Ray
(c-declare "
Ray * MakeRayPr(Vector3 * position, Vector3 * direction){
Ray * r = (Ray*)malloc(sizeof(Ray));
r->position.x = position->x;
r->position.y = position->y;
r->position.z = position->z;
r->direction.x = direction->x;
r->direction.y = direction->y;
r->direction.z = direction->z;
return r;
}
void FreeRayPr(Ray * r){
free(r);
}
Vector3 * GetRayPosition(Ray * r){
Vector3 * out = (Vector3*)malloc(sizeof(Vector3));
out->x = r->position.x;
out->y = r->position.y;
out->z = r->position.z;
return out;
}
Vector3 * GetRayDirection(Ray * r){
Vector3 * out = (Vector3*)malloc(sizeof(Vector3));
out->x = r->direction.x;
out->y = r->direction.y;
out->z = r->direction.z;
return out;
}
void SetRayPosition(Ray * r, Vector3 * v){
r->position.x = v->x;
r->position.y = v->y;
r->position.z = v->z;
}
void SetRayDirection(Ray * r, Vector3 * v){
r->direction.x = v->x;
r->direction.y = v->y;
r->direction.z = v->z;
}
")
(define-c-struct Ray
predicate: ray?
finalizer: FreeRayPr
((struct Vector3) position)
((struct Vector3) direction))
(declare-struct-copier 'Ray)
(define-c (free Vector3) (get-ray-position GetRayPosition) (Ray))
(define-c (free Vector3) (get-ray-direction GetRayDirection) (Ray))
(define-c void (set-ray-position! SetRayPosition) (Ray Vector3))
(define-c void (set-ray-direction! SetRayDirection) (Ray Vector3))
(define-c (free Ray) (ray MakeRayPr) (Vector3 Vector3))
;; Matrix type
(c-declare "
void FreeMatrixPr(Matrix * m){
free(m);
}
Matrix * MakeMatrixPr(
float m0,
float m1,
float m2,
float m3,
float m4,
float m5,
float m6,
float m7,
float m8,
float m9,
float m10,
float m11,
float m12,
float m13,
float m14,
float m15
){
Matrix * m = (Matrix*)malloc(sizeof(Matrix));
m->m0 = m0;
m->m1 = m1;
m->m2 = m2;
m->m3 = m3;
m->m4 = m4;
m->m5 = m5;
m->m6 = m6;
m->m7 = m7;
m->m8 = m8;
m->m9 = m9;
m->m10 = m10;
m->m11 = m11;
m->m12 = m12;
m->m13 = m13;
m->m14 = m14;
m->m15 = m15;
return m;
}
")
(define-c-struct Matrix
predicate: matrix?
finalizer: FreeMatrixPr
(float m0 get-matrix-m0 set-matrix-m0!)
(float m1 get-matrix-m1 set-matrix-m1!)
(float m2 get-matrix-m2 set-matrix-m2!)
(float m3 get-matrix-m3 set-matrix-m3!)
(float m4 get-matrix-m4 set-matrix-m4!)
(float m5 get-matrix-m5 set-matrix-m5!)
(float m6 get-matrix-m6 set-matrix-m6!)
(float m7 get-matrix-m7 set-matrix-m7!)
(float m8 get-matrix-m8 set-matrix-m8!)
(float m9 get-matrix-m9 set-matrix-m9!)
(float m10 get-matrix-m10 set-matrix-m10!)
(float m11 get-matrix-m11 set-matrix-m11!)
(float m12 get-matrix-m12 set-matrix-m12!)
(float m13 get-matrix-m13 set-matrix-m13!)
(float m14 get-matrix-m14 set-matrix-m14!)
(float m15 get-matrix-m15 set-matrix-m15!))
(declare-struct-copier 'Matrix)
(define-c (free Matrix) (make-matrix MakeMatrixPr)
(float
float
float
float
float
float
float
float
float
float
float
float
float
float
float
float))
(c-declare "
void FreeCharInfoPr(CharInfo * c){
free(c->data);
free(c);
}
")
(define-c-struct CharInfo
predicate: char-info?
finalizer: FreeCharInfoPr
(int value get-value set-value!)
((struct Rectangle) rec get-rectangle)
(int offsetX)
(int offsetY)
((pointer unsigned-char) data))
;(declare-struct-copier 'CharInfo)
(c-declare "
void CopyCharInfoNoAlloc(CharInfo * from_pointer, CharInfo * to_pointer){
to_pointer->data = from_pointer->data;
to_pointer->offsetY = from_pointer->offsetY;
to_pointer->offsetX = from_pointer->offsetX;
CopyRectangleNoAlloc(&(from_pointer->rec),&(to_pointer->rec));
to_pointer->value = from_pointer->value;
}
")
(c-declare "
void FreeFontPr(Font * f){
FreeCharInfoPr(f->chars);
free(f);
}
")
(define-c-struct Font
predicate: font?
finalizer: FreeFontPr
((struct Texture2D) texture get-texture)
(int baseSize get-base-size)
(int charsCount get-chars-count)
((struct CharInfo) chars get-chars))
(c-declare "
void CopyFontNoAlloc(Font * from_pointer, Font * to_pointer){
int i, n;
//CopyCharInfoNoAlloc(&(from_pointer->chars),&(to_pointer->chars));
to_pointer->charsCount = from_pointer->charsCount;
to_pointer->baseSize = from_pointer->baseSize;
CopyTexture2DNoAlloc(&(from_pointer->texture),&(to_pointer->texture));
n = from_pointer->charsCount;
to_pointer->chars = (CharInfo*)malloc(sizeof(CharInfo)*n);
for(i = 0; i < n; i++){
to_pointer->chars[i] = from_pointer->chars[i];
}
}
")
(c-declare "
void FreeMeshPr(Mesh * m){
UnloadMesh(m);
}
")
(define-c-struct Mesh
predicate: mesh?
finalizer: FreeMeshPr
(int vertexCount get-vertext-count)
(int triangleCount get-triangle-count)
((pointer float) vertices)
((pointer float) texcoords)
((pointer float) texcoords2)
((pointer float) normals)
((pointer float) tangents)
((pointer unsigned-char) colors)
((pointer short) indices)
((pointer float) animVertices)
((pointer float) animNormals)
((pointer int) boneIds)
((pointer float) boneWeights)
(unsigned-int vaoId)
((array unsigned-int 7) vboId))
(c-declare "void CopyMeshNoAlloc(Mesh * from_pointer, Mesh * to_pointer){
int i;
to_pointer->vertexCount = from_pointer->vertexCount;
to_pointer->triangleCount = from_pointer->triangleCount;
to_pointer->vertices = from_pointer->vertices;
to_pointer->texcoords = from_pointer->texcoords;
to_pointer->texcoords2 = from_pointer->texcoords2;
to_pointer->normals = from_pointer->normals;
to_pointer->tangents = from_pointer->tangents;
to_pointer->colors = from_pointer->colors;
to_pointer->indices = from_pointer->indices;
to_pointer->animVertices = from_pointer->animVertices;
to_pointer->animNormals = from_pointer->animNormals;
to_pointer->boneIds = from_pointer->boneIds;
to_pointer->boneWeights = from_pointer->boneWeights;
to_pointer->vaoId = from_pointer->vaoId;
for(i = 0; i < 7; i++) {
to_pointer->vboId[i] = from_pointer->vboId[i];
}
}")
(c-declare "void FreeMaterialMapPr(MaterialMap * m){
free(m);
}")
(define-c-struct MaterialMap
predicate: material-map?
finalizer: FreeMaterialMapPr
((struct Texture2D) texture)
((struct Color) color)
(float value))
(c-declare "void FreeMaterialPr(Material * m){
UnloadMaterial(*m);
free(m);
}
void CopyMaterialNoAlloc(Material * from_pointer, Material * to_pointer){
int i;
to_pointer->shader = from_pointer->shader;
for(i = 0; i < MAX_MATERIAL_MAPS; i++){
to_pointer->maps[i] = from_pointer->maps[i];
}
to_pointer->params = from_pointer->params;
}
")
(define-c-struct Material
predicate: material?
finalizer: FreeMaterialPr
((struct Shader) shader)
((pointer (struct MaterialMap)) maps)
((pointer float) params))
(c-declare "void FreeModelPr(Model * m){
UnloadModel(*m);
free(m);
}")
(define-c-struct Model
predicate: model?
finalizer: FreeModelPr
((struct Matrix) transform)
(int meshCount)
((pointer (struct Mesh)) meshes)
(int materialCount)
((pointer (struct Material)) materials)
((pointer int) meshMaterial)
(int boneCount)
((pointer (struct BoneInfo)) bones)
((pointer (struct Transform)) bindPose))
(c-declare "void CopyModelNoAlloc(Model * from_pointer, Model * to_pointer){
to_pointer->transform = from_pointer->transform;
to_pointer->meshCount = from_pointer->meshCount;
to_pointer->meshes = from_pointer->meshes;
to_pointer->materialCount = from_pointer->materialCount;
to_pointer->materials = from_pointer->materials;
to_pointer->meshMaterial = from_pointer->meshMaterial;
to_pointer->boneCount = from_pointer->boneCount;
to_pointer->bones = from_pointer->bones;
to_pointer->bindPose = from_pointer->bindPose;
}")
(define-c-struct ModelAnimation
predicate: model-animation?
(int boneCount)
((pointer (struct BoneInfo)) bones)
(int frameCount)
((pointer (pointer Transform)) framePoses))
(c-declare "void CopyModelAnimationNoAlloc(ModelAnimation * from, ModelAnimation * to){
to->boneCount = from->boneCount;
to->bones = from->bones;
to->frameCount = from->frameCount;
to->framePoses = from->framePoses;
}")
;; // Bounding box type
;; typedef struct BoundingBox {
;; Vector3 min; // Minimum vertex box-corner
;; Vector3 max; // Maximum vertex box-corner
;; } BoundingBox;
(define-c-struct BoundingBox
predicate: bounding-box?
((struct Vector3) min)
((struct Vector3) max))
(declare-struct-copier 'BoundingBox)
(c-declare "
Vector3 * GetBoundingBoxMin(BoundingBox * bb){
Vector3 * v = (Vector3*)malloc(sizeof(Vector3));
CopyVector3NoAlloc(&(bb->min),v);
return v;
}
Vector3 * GetBoundingBoxMax(BoundingBox * bb){
Vector3 * v = (Vector3*)malloc(sizeof(Vector3));
CopyVector3NoAlloc(&(bb->max),v);
return v;
}
")
(c-declare "
void FreeRayHitInfo(RayHitInfo * r){
free(r);
}
")
(define-c-struct RayHitInfo
predicate: ray-hit-info?
finalizer: FreeRayHitInfo
(boolean hit ray-hit-info-get-hit)
(float distance ray-hit-info-get-distance)
((struct Vector3) position)
((struct Vector3) normal))
(c-declare "
Vector3 * RayHitInfoGetPosition(RayHitInfo * r){
Vector3 * out = (Vector3*)malloc(sizeof(Vector3));
CopyVector3NoAlloc(&(r->position),out);
return out;
}
Vector3 * RayHitInfoGetNormal(RayHitInfo * r){
Vector3 * out = (Vector3*)malloc(sizeof(Vector3));
CopyVector3NoAlloc(&(r->normal),out);
return out;
}
")
(c-declare "
void FreeShaderPr(Shader * shader){
UnloadShader(*shader);
free(shader);
}
")
(define MAX_SHADER_LOCATIONS 32)
(define-c-struct Shader
predicate: shader?
finalizer: FreeShaderPr
(unsigned-int id get-shader-id)
((array int MAX_SHADER_LOCATIONS) locs))
(c-declare "void CopyShaderNoAlloc(Shader * from, Shader * to){
int i;
to->id = from->id;
for(i = 0; i < MAX_SHADER_LOCATIONS; i++){
to->locs[i] = from->locs[i];
}
}")
(declare-struct-copier 'RayHitInfo)
(c-declare "void FreeWavePr(Wave * w){
UnloadWave(*w);
free(w);
}")
(define-c-struct Wave
predicate: wave?
finalizer: FreeWavePr
(unsigned-int sampleCount get-wave-sample-count)
(unsigned-int sampleRate get-wave-sample-rate)
(unsigned-int sampleSize get-sample-size)
(unsigned-int channels get-channels)
((pointer void) data))