rusting_engine 2.5.7

Vulkan 3D game engine with GPU-accelerated physics for massive physics-heavy scenes
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
//! Reflected descriptions of the engine's own components, resources, and
//! assets. Their hints and docs are what `rusting schema` prints.

use std::path::PathBuf;

use bevy_ecs::entity::Entity;

use super::TypeRegistry;
use crate::assets::{
    AlphaMode, MaterialAsset, MaterialModel, MaterialSway, WaterShading,
};
use crate::runtime::Camera2d;
use crate::runtime::ClothSheet;
use crate::runtime::ConvexDecomposition;
use crate::runtime::Rope;
use crate::runtime::WorldText;
use crate::runtime::{Ambient2d, Light2d, LightOccluder2d, Particles2d};
use crate::runtime::{
    AmbientLight, AmbientOcclusion, Antialiasing, Articulation, AutoExposure,
    AutoSimulation, AxisLock, AxisMotion, Bloom, BurstEmitter, CameraScreen,
    CameraShake, ColorGrading, ColorLut, CombineMode, Connection, Connections,
    Counter, CullingMode, Decal, DepthOfField, DeterminismMode, Dialogue,
    DialogueChoice, DialogueLine, Easing, EnvironmentMap, FieldKind, Flash,
    FluidBlock, FluidSolver, Fog, FogShader, FogVolume, Foliage, ForceField,
    Fracture, GravityVolume, GroundSurface, Health, Heightfield, HudAnchor,
    HudElement, InputAction, Joint, JointAxis, JointKind, JointMotor,
    JointSpring, LightCookie, LightProbeGrid, Lightmap, LootEntry, LootTable,
    MaterialOverride, MeshSurfaces, MotionBlur, ObjectState, OceanWave,
    PhysicsMaterial, PhysicsSettings, PhysicsSyncMode, Pickup,
    PlatformerController, PlayerController, Polygon2d, PostShader, PostVolume,
    ProceduralSky, QualityProfile, RandomSeed, ReflectionProbe, RenderBounds,
    RenderLayer, RenderSettings, ReverbZone, SceneBackground, SceneInstance,
    ShadowQuality, SkyLight, SkyShader, SlideSound, SoftBlock, SoundCue,
    SoundId, SpawnGrid, Sprite, SpriteAnimation, Squash, StateAction,
    StateTransition, SurfaceClip, Terrain, TerrainFracture, TerrainLayer,
    TileKind, TileMap, ToneMapper, ToneMapping, Tween, TweenProperty,
    TweenRepeat, Vehicle, ViewmodelCamera, WaterBody, Wheel, Wind,
};
use crate::runtime::{
    Animation, AnimationClip, AnimationCompare, AnimationLayer,
    AnimationMarker, AnimationProperty, AnimationTrack, AnimationTransition,
    BlendPoint, HumanoidBone, Ik, IkKind, Interpolation, Keyframe, Morph,
    Ragdoll, RagdollBone, RootMotion, Skin,
};
use crate::runtime::{
    ColorKey, CurveKey, EmitterShape, ParticleBlend, ParticleBlocker,
    ParticleBurst, ParticleEmitter, ParticleFacing, ParticleShader,
    ParticleSimulation, ParticleSpace, ParticleSprite,
};

crate::reflect! {
    struct AmbientLight {
        color: [f32; 3] { unit: "linear RGB", min: 0.0, max: 1.0, color: true },
        intensity: f32 { unit: "factor", min: 0.0 },
    }
}

crate::reflect! {
    struct SkyLight {
        sky_color: [f32; 3] {
            unit: "linear RGB", min: 0.0, max: 1.0, color: true,
            doc: "seen by up-facing surfaces",
        },
        ground_color: [f32; 3] {
            unit: "linear RGB", min: 0.0, max: 1.0, color: true,
            doc: "seen by down-facing surfaces",
        },
        intensity: f32 { unit: "factor", min: 0.0 },
    }
}

crate::reflect! {
    enum ToneMapper { Linear, Reinhard, Aces }
}

crate::reflect! {
    struct ToneMapping {
        mapper: ToneMapper,
        exposure: f32 { unit: "factor", min: 0.001 },
    }
}

crate::reflect! {
    enum RenderBounds {
        Sphere {
            center: [f32; 3] { unit: "m" },
            radius: f32 { unit: "m", min: 0.0 },
        },
        Aabb {
            min: [f32; 3] { unit: "m", doc: "<= max" },
            max: [f32; 3] { unit: "m", doc: ">= min" },
        },
    }
}

crate::reflect! {
    enum PhysicsSyncMode { None, Events, SelectedState, FullState }
}

crate::reflect! {
    struct AutoSimulation {
        #[skip] decision: Option<crate::runtime::AllocationDecision>,
    }
}

crate::reflect! {
    struct PlayerController {
        walk_speed: f32 { unit: "m/s", min: 0.0 },
        sprint_multiplier: f32 { unit: "factor", min: 1.0 },
        jump_speed: f32 { unit: "m/s", min: 0.0 },
        air_jumps: u32 { doc: "extra jumps in the air before landing; 1 is a double jump" },
        gravity: f32 { unit: "m/s²", min: 0.0 },
        look_sensitivity: f32 { unit: "rad/pixel", min: 0.0 },
        mouse_look: bool {
            doc: "false: clicks never capture the cursor; the mouse stays free",
        },
        collision_mask: u32 {
            unit: "bitmask", doc: "layers the body stops against",
        },
        yaw: f32 { unit: "rad", doc: "0 looks toward -Z" },
        pitch: f32 { unit: "rad", min: -1.55, max: 1.55 },
        pitch_limits: [f32; 2] {
            unit: "rad", doc: "lowest, highest pitch; within ±1.55",
        },
        yaw_limits: Option<[f32; 2]> {
            unit: "rad", doc: "lowest, highest yaw for a seated or turret view; null turns freely",
        },
        camera_distance: f32 {
            unit: "m", min: 0.0,
            doc: "0 is first person; above 0 the camera orbits behind",
        },
        camera_height: f32 {
            unit: "m", doc: "third-person orbit center above the body",
        },
        camera_offset: [f32; 3] {
            unit: "m",
            doc: "added to the camera position in the body's frame; [0.6, 0, 0] looks over the right shoulder",
        },
        max_slope: f32 {
            unit: "rad", min: 0.0, max: 1.57,
            doc: "steepest ground it walks up; steeper is a wall",
        },
        max_step_height: f32 {
            unit: "m", min: 0.0, doc: "highest ledge it steps onto",
        },
        push_bodies: bool { doc: "false: dynamic bodies block it but never move" },
        turn_speed: f32 {
            unit: "rad/s", min: 0.0,
            doc: "how fast non-camera children turn to the walk direction",
        },
        crouch_height: f32 {
            unit: "m", min: 0.0,
            doc: "body height while player.crouch is held; 0 turns crouching off",
        },
        crouch_multiplier: f32 {
            unit: "factor", min: 0.0, doc: "speed factor while crouched",
        },
        swim_speed: f32 {
            unit: "m/s", min: 0.0,
            doc: "speed in a water body; 0 turns swimming off",
        },
        float_depth: f32 {
            unit: "m", doc: "how far below the surface the body center floats",
        },
        #[skip] swimming: bool,
        #[skip] crouched: bool,
        #[skip] crouch_drop: f32,
        #[skip] camera_drop: f32,
        #[skip] vertical_speed: f32,
        #[skip] grounded: bool,
        #[skip] jump_requested: bool,
        #[skip] air_jumps_used: u32,
        #[skip] floor: Option<(bevy_ecs::entity::Entity, [f32; 3])>,
        #[skip] floor_rotation: [f32; 4],
        #[skip] wall: Option<bevy_ecs::entity::Entity>,
        #[skip] velocity: [f32; 3],
        #[skip] dash_velocity: [f32; 3],
        #[skip] dash_left: f32,
    }
}

crate::reflect! {
    struct JointSpring {
        target: f32 { unit: "m or rad" },
        stiffness: f32 { unit: "N/m or N·m/rad", min: 0.0 },
        damping: f32 { unit: "N·s/m or N·m·s/rad", min: 0.0 },
    }
}

crate::reflect! {
    struct JointMotor {
        speed: f32 { unit: "m/s or rad/s" },
        max_force: f32 { unit: "N or N·m", min: 0.0 },
    }
}

crate::reflect! {
    enum AxisMotion {
        Locked,
        Free,
        Limited {
            min: f32 { unit: "m or rad" },
            max: f32 { unit: "m or rad" },
        },
    }
}

crate::reflect! {
    struct JointAxis {
        motion: AxisMotion,
        spring: Option<JointSpring>,
        motor: Option<JointMotor>,
    }
}

crate::reflect! {
    enum JointKind {
        Fixed,
        Hinge {
            limit: Option<[f32; 2]> { unit: "rad", doc: "min, max" },
            spring: Option<JointSpring>,
            motor: Option<JointMotor>,
        },
        Slider {
            limit: Option<[f32; 2]> { unit: "m", doc: "min, max" },
            spring: Option<JointSpring>,
            motor: Option<JointMotor>,
        },
        BallSocket,
        ConeTwist {
            swing: f32 { unit: "rad", min: 0.0 },
            twist: [f32; 2] { unit: "rad", doc: "min, max about X" },
        },
        Distance {
            min: f32 { unit: "m", min: 0.0 },
            max: f32 { unit: "m", min: 0.0 },
        },
        Spring {
            rest_length: f32 { unit: "m", min: 0.0 },
            stiffness: f32 { unit: "N/m", min: 0.0 },
            damping: f32 { unit: "N·s/m", min: 0.0 },
        },
        Generic {
            linear: [JointAxis; 3] { doc: "X, Y, Z along the target frame" },
            angular: [JointAxis; 3] { doc: "twist about X, swing about Y, Z" },
        },
    }
}

crate::reflect! {
    struct Joint {
        target: Entity { doc: "body this one hangs from; null is the world" },
        kind: JointKind,
        anchor: [f32; 3] { unit: "m", doc: "in this body's local space" },
        frame: [f32; 3] {
            unit: "rad", doc: "joint axes in this body's local space; X is the hinge, slider, and twist axis",
        },
        target_anchor: [f32; 3] {
            unit: "m", doc: "in the target's local space, or world space",
        },
        target_frame: [f32; 3] { unit: "rad", doc: "in the target's local space" },
        collide_connected: bool { doc: "false keeps the two bodies from colliding" },
        break_force: f32 { unit: "N", min: 0.0, doc: "0 never breaks" },
        break_torque: f32 { unit: "N·m", min: 0.0, doc: "0 never breaks" },
    }
}

crate::reflect! {
    struct Articulation {}
}

crate::reflect! {
    enum Easing {
        Linear, QuadIn, QuadOut, QuadInOut, CubicOut, SineInOut, BackOut,
        BounceOut,
    }
}

crate::reflect! {
    enum TweenProperty { Position, Rotation, Scale }
}

crate::reflect! {
    enum TweenRepeat { Once, Loop, PingPong }
}

crate::reflect! {
    struct Tween {
        property: TweenProperty { doc: "rotation is radians" },
        from: [f32; 3] { unit: "property unit" },
        to: [f32; 3] { unit: "property unit" },
        duration: f32 { unit: "s", min: 0.0, doc: "0 jumps to `to`" },
        delay: f32 { unit: "s", min: 0.0, doc: "holds `from` first" },
        easing: Easing,
        repeat: TweenRepeat,
        #[skip] elapsed: f32,
    }
}

crate::reflect! {
    struct SlideSound {
        clip: String { unit: "asset path", doc: "looped while the body slides or rolls" },
        volume: f32 { unit: "linear gain", min: 0.0 },
        full_volume_speed: f32 { unit: "m/s", min: 0.0, doc: "sliding this fast plays at full volume" },
        min_speed: f32 { unit: "m/s", min: 0.0, doc: "slower is silent" },
        bus: String { doc: "empty for the main output" },
        by_material: Vec<SurfaceClip> { doc: "clips for sliding on a named physics_material or surface; others play clip" },
        #[skip] playing: Option<SoundId>,
        #[skip] playing_clip: String,
        #[skip] level: f32,
    }
}

crate::reflect! {
    struct SurfaceClip {
        material: String { doc: "physics_material or surface name" },
        clip: String { unit: "asset path", doc: "empty is silent on it" },
    }
}

crate::reflect! {
    struct ReverbZone {
        bus: String { doc: "bus the reverb goes on; empty for every sound" },
        room: f32 { unit: "0 to 1", min: 0.0, max: 1.0, doc: "0 small and dry, near 1 rings for seconds" },
        damping: f32 { unit: "0 to 1", min: 0.0, max: 1.0, doc: "darkens the tail" },
        mix: f32 { unit: "0 to 1", min: 0.0, max: 1.0, doc: "wet share" },
        fade: f32 { unit: "s", min: 0.0, doc: "time the reverb takes to come in and go out" },
    }
}

crate::reflect! {
    struct CameraShake {
        trauma: f32 { unit: "0 to 1", min: 0.0, doc: "shake strength is trauma squared" },
        decay: f32 { unit: "1/s", min: 0.0, doc: "trauma lost per second" },
        max_offset: [f32; 3] { unit: "m", doc: "along the camera's right, up and back axes" },
        max_roll: f32 { unit: "rad", min: 0.0 },
        frequency: f32 { unit: "Hz", min: 0.0 },
    }
}

crate::reflect! {
    struct SpawnGrid {
        count: [u32; 3] { unit: "cells", doc: "along X, Y and Z, original included" },
        spacing: [f32; 3] { unit: "m" },
    }
}

crate::reflect! {
    enum RenderLayer { World, Viewmodel }
}

crate::reflect! {
    struct ViewmodelCamera {
        vertical_fov_radians: f32 {
            unit: "rad", min: 0.01, max: 3.1,
            doc: "field of view of the camera's Viewmodel meshes",
        },
    }
}

crate::reflect! {
    struct MaterialOverride {
        base_color: Option<[f32; 4]> { unit: "linear RGBA", doc: "null keeps the material's" },
        emissive: Option<[f32; 3]> { unit: "linear RGB", doc: "glow; null keeps the material's" },
        metallic: Option<f32> { min: 0.0, max: 1.0, doc: "null keeps the material's" },
        roughness: Option<f32> { min: 0.0, max: 1.0, doc: "null keeps the material's" },
        uv_scale: Option<[f32; 2]> { doc: "texture repeats; null keeps the material's" },
        uv_offset: Option<[f32; 2]> { doc: "texture shift; null keeps the material's" },
    }
}

crate::reflect! {
    struct Flash {
        color: [f32; 3] { unit: "linear RGB" },
        duration: f32 { unit: "s", min: 0.0, doc: "fade back to no tint" },
        #[skip] remaining: f32,
    }
}

crate::reflect! {
    struct Squash {
        stiffness: f32 { unit: "1/s²", min: 0.0, doc: "higher wobbles faster" },
        damping: f32 { unit: "1/s", min: 0.0, doc: "higher settles sooner" },
        #[skip] amount: f32,
        #[skip] velocity: f32,
        #[skip] rest: Option<[f32; 3]>,
    }
}

crate::reflect! {
    struct SoundCue {
        clip: String { unit: "asset path", doc: "relative to assets/, or sfx:coin 7 for a built-in sound" },
        volume: f32 { unit: "linear gain", min: 0.0 },
        on_collision: bool { doc: "CPU collider contacts only" },
        caption: String { doc: "shown for 2 s each time it fires, like [glass breaks]; empty for none" },
        full_volume_speed: f32 { unit: "m/s", min: 0.0, doc: "hits this fast play at full volume, slower ones quieter; 0 for always full" },
        with_material: String { doc: "only touches of a collider with this physics_material name; empty for any" },
        on_gpu_event: String { doc: "registered GPU physics event name that plays this cue for this body; empty for none" },
        #[skip] triggered: bool,
        #[skip] touching: bool,
        #[skip] hit_speed: Option<f32>,
    }
}

crate::reflect! {
    struct BurstEmitter {
        count: u32 { unit: "particles", doc: "each is one CPU entity" },
        speed: f32 { unit: "m/s", min: 0.0 },
        lifetime: f32 { unit: "s", min: 0.0 },
        particle_scale: f32 {
            unit: "factor", min: 0.0, doc: "of the emitter's scale",
        },
        gravity: f32 { unit: "m/s²" },
        on_collision: bool { doc: "CPU collider contacts only" },
        rate: f32 {
            unit: "particles/s", min: 0.0,
            doc: "above 0 emits every fixed step, no trigger needed",
        },
        area: [f32; 3] { unit: "m", doc: "half extents of the start box" },
        stretch: f32 { unit: "factor", min: 0.0, doc: "particle height" },
        #[skip] pending: f32,
        #[skip] triggered: bool,
        #[skip] touching: bool,
    }
}

crate::reflect! {
    enum EmitterShape { Point, Box, Sphere, Cone, Circle }
}

crate::reflect! {
    enum ParticleSpace { World, Local }
}

crate::reflect! {
    enum ParticleFacing { Billboard, Velocity }
}

crate::reflect! {
    enum ParticleBlend { Alpha, Additive }
}

crate::reflect! {
    enum ParticleSprite { Soft, Disc, Square }
}

crate::reflect! {
    enum ParticleSimulation { Cpu, Gpu }
}

crate::reflect! {
    struct ParticleBurst {
        time: f32 { unit: "s", min: 0.0, doc: "into each cycle" },
        count: u32 { unit: "particles" },
    }
}

crate::reflect! {
    struct CurveKey {
        t: f32 { unit: "life", min: 0.0, max: 1.0 },
        value: f32 { unit: "factor", min: 0.0 },
    }
}

crate::reflect! {
    struct ColorKey {
        t: f32 { unit: "life", min: 0.0, max: 1.0 },
        color: [f32; 4] {
            unit: "linear RGBA", min: 0.0, max: 1.0, color: true,
        },
    }
}

crate::reflect! {
    struct ParticleEmitter {
        autoplay: bool { doc: "off waits for play()" },
        rate: f32 { unit: "particles/s", min: 0.0 },
        bursts: Vec<ParticleBurst> { doc: "fired once per cycle" },
        max_particles: u32 { unit: "particles", doc: "alive at once" },
        prewarm: bool { doc: "start as if one cycle already played" },
        duration: f32 { unit: "s", min: 0.0, doc: "one cycle" },
        looping: bool { doc: "off stops emitting after one cycle" },
        on_collision: bool { doc: "restart on contact; CPU colliders only" },
        impact_speed: f32 {
            unit: "m/s", min: 0.0,
            doc: "contacts closing this fast spawn impact_count particles there; 0 is off",
        },
        impact_count: u32 { doc: "particles per impact or settle" },
        on_settle: bool { doc: "spawn impact_count particles when the body falls asleep" },
        on_fracture: bool { doc: "spawn impact_count particles at the break when the parent object breaks" },
        shape: EmitterShape,
        shape_size: [f32; 3] {
            unit: "m", min: 0.0,
            doc: "box half extents; x is the radius of round shapes",
        },
        lifetime: [f32; 2] { unit: "s", min: 0.0, doc: "min, max" },
        speed: [f32; 2] { unit: "m/s", doc: "min, max" },
        size: [f32; 2] { unit: "m", min: 0.0, doc: "min, max" },
        rotation: [f32; 2] { unit: "rad", doc: "min, max" },
        spin: [f32; 2] { unit: "rad/s", doc: "min, max" },
        direction: [f32; 3] { doc: "launch axis in the emitter's space" },
        spread: f32 {
            unit: "rad", min: 0.0, max: std::f64::consts::PI,
            doc: "half angle around direction; 3.14 is every way",
        },
        gravity: f32 { unit: "m/s²", doc: "downward" },
        drag: f32 { unit: "1/s", min: 0.0 },
        wind: [f32; 3] { unit: "m/s²", doc: "constant world push" },
        turbulence: f32 { unit: "m/s²", min: 0.0 },
        turbulence_frequency: f32 { unit: "1/m", min: 0.0 },
        wind_factor: f32 { unit: "factor", min: 0.0, doc: "share of the scene's rusting.wind; 0 ignores it" },
        size_over_life: Vec<CurveKey> { doc: "size factor keys by life" },
        color_over_life: Vec<ColorKey> { doc: "color keys by life" },
        start_colors: Vec<[f32; 4]> {
            doc: "each particle picks one; tints its color",
        },
        emissive: f32 { unit: "factor", min: 0.0, doc: "above 1 blooms" },
        fade_in: f32 { unit: "life", min: 0.0, max: 1.0 },
        fade_out: f32 { unit: "life", min: 0.0, max: 1.0 },
        space: ParticleSpace,
        facing: ParticleFacing,
        stretch: f32 {
            unit: "s", min: 0.0, doc: "Velocity facing: length per m/s",
        },
        blend: ParticleBlend,
        sprite: ParticleSprite,
        simulation: ParticleSimulation {
            doc: "Gpu: up to 1M particles, fewer settings",
        },
        collide: bool { doc: "Gpu: bounce off physics colliders" },
        trail: f32 { unit: "s", min: 0.0, doc: "Gpu: seconds of path trailing each particle, 0 for none" },
        on_parent_death: u32 { doc: "Gpu under a Gpu parent emitter: particles spawned where each parent particle dies; 0 for a normal emitter" },
        blockers: bool { doc: "Cpu: particles die inside rusting.particle_blocker boxes and below heightfield ground" },
        #[skip] command: crate::runtime::ParticleCommand,
    }
}

crate::reflect! {
    enum AnimationProperty {
        Position,
        Rotation,
        Scale,
        Color,
        Emissive,
        Visible,
        Orientation,
        Field {
            component: String { doc: "registered scene component name" },
            path: String { doc: "JSON pointer to a number, e.g. /intensity" },
        },
    }
}

crate::reflect! {
    enum Interpolation { Step, Linear, Smooth }
}

crate::reflect! {
    struct Keyframe {
        time: f32 { unit: "s", min: 0.0 },
        value: Vec<f32> {
            doc: "3 for transforms (rotation in rad), 4 for Color, 3 for Emissive, 1 otherwise",
        },
    }
}

crate::reflect! {
    struct AnimationTrack {
        target: String { doc: "empty for this entity, else child names: Arm/Hand" },
        property: AnimationProperty,
        interpolation: Interpolation,
        keys: Vec<Keyframe> { doc: "sorted by time" },
    }
}

crate::reflect! {
    struct AnimationMarker {
        time: f32 { unit: "s", min: 0.0 },
        name: String { doc: "event name game code receives" },
    }
}

crate::reflect! {
    struct AnimationClip {
        name: String,
        duration: f32 { unit: "s", min: 0.0, doc: "0 uses the last key" },
        repeat: TweenRepeat,
        tracks: Vec<AnimationTrack>,
        events: Vec<AnimationMarker>,
        blend: Vec<BlendPoint> {
            doc: "blend space: clips mixed by blend_parameter (and blend_parameter_y for 2D); empty for a plain clip",
        },
        blend_parameter: String { doc: "parameter that picks the blend position (x axis in 2D)" },
        blend_parameter_y: String { doc: "y axis parameter; set for a 2D blend space" },
    }
}

crate::reflect! {
    struct BlendPoint {
        clip: String,
        at: f32 { doc: "position on the blend parameter axis" },
        at_y: f32 { doc: "position on the y axis of a 2D blend space" },
    }
}

crate::reflect! {
    enum AnimationCompare { Above, Below, Equal }
}

crate::reflect! {
    struct AnimationTransition {
        from: String { doc: "clip name; empty matches any clip" },
        to: String,
        parameter: String { doc: "parameter to test; empty skips the test" },
        compare: AnimationCompare,
        value: f32,
        at_end: bool { doc: "also wait until `from` has played once" },
        fade: f32 { unit: "s", min: 0.0, doc: "crossfade length; 0 cuts" },
    }
}

crate::reflect! {
    struct HumanoidBone {
        bone: String { doc: "standard name such as Hips, Spine, Head, LeftUpperArm, RightFoot" },
        path: String { doc: "this rig's path to the bone" },
    }
}

crate::reflect! {
    enum RootMotion {
        Off,
        InPlace,
        Transform,
        Velocity,
    }
}

crate::reflect! {
    struct AnimationLayer {
        clip: String,
        weight: f32 { min: 0.0, max: 1.0, doc: "how much of the layer shows" },
        weight_parameter: String { doc: "parameter read as the weight; empty uses weight" },
        additive: bool { doc: "add the clip's motion from its first frame instead of replacing" },
        mask: Vec<String> { doc: "target paths (with children) the layer writes; empty writes all" },
    }
}

crate::reflect! {
    struct Animation {
        clips: Vec<AnimationClip>,
        autoplay: String { doc: "clip played on start; empty plays nothing" },
        speed: f32 { unit: "factor", min: 0.0 },
        parameters: std::collections::BTreeMap<String, f32> {
            doc: "named numbers game code sets for transitions",
        },
        transitions: Vec<AnimationTransition> {
            doc: "state machine edges; the first match each tick wins",
        },
        layers: Vec<AnimationLayer> {
            doc: "clips played on top of the state machine, in order",
        },
        root_motion: RootMotion {
            doc: "Off moves the root bone as keyed; InPlace collects for game code; Transform moves this object; Velocity drives its GPU body",
        },
        root_bone: String { doc: "path of the bone whose Position track carries root motion; empty is this object" },
        humanoid: Vec<HumanoidBone> {
            doc: "humanoid bone names (Hips, Spine, LeftUpperArm...) of this rig's bone paths, for retargeting; empty matches by bone name",
        },
        #[skip] command: Option<crate::runtime::AnimationCommand>,
    }
}

crate::reflect! {
    enum IkKind {
        LookAt,
        TwoBone,
        Foot,
        Chain,
    }
}

crate::reflect! {
    struct RagdollBone {
        path: String { doc: "bone path from the character" },
        length: f32 { unit: "m", min: 0.0, doc: "capsule along the bone's local +Y, ends included" },
        radius: f32 { unit: "m", min: 0.0 },
        mass: f32 { unit: "kg", min: 0.0 },
        joint: JointKind { doc: "joint to the nearest ancestor bone's body" },
        frame: [f32; 3] { unit: "rad", doc: "joint axes in the bone's frame; the default turns X along the bone" },
    }
}

crate::reflect! {
    struct Rope {
        target: Entity { doc: "body at the far end; null ties it to the world" },
        anchor: [f32; 3] { unit: "m", doc: "rope end in this body's local space" },
        target_anchor: [f32; 3] { unit: "m", doc: "rope end in the target's local space, or world space" },
        length: f32 { unit: "m", min: 0.0, doc: "longest the rope stretches" },
        segments: u32 { doc: "bead count, 1 to 256; more bend smoother and cost more" },
        radius: f32 { unit: "m", min: 0.0, doc: "bead radius; keep it under half of length / (segments + 1)" },
        mass: f32 { unit: "kg", min: 0.0, doc: "per bead" },
    }
}

crate::reflect! {
    struct Ragdoll {
        bones: Vec<RagdollBone>,
        hit_speed: f32 { unit: "m/s", min: 0.0, doc: "a body closing on the character this fast makes it go limp; 0 only on command" },
        recover_after: f32 { unit: "s", min: 0.0, doc: "seconds limp before getting up; 0 waits for game code" },
        blend_time: f32 { unit: "s", min: 0.0, doc: "seconds to blend back to the animation, or for active muscles to regain strength" },
        muscle: f32 { unit: "Hz", min: 0.0, doc: "above 0 keeps the bodies on and turns them toward the animation; 5 loose, 15 stiff" },
        #[skip] command: Option<bool>,
    }
}

crate::reflect! {
    struct Ik {
        kind: IkKind { doc: "LookAt turns this object; TwoBone bends its parent and grandparent" },
        target: Entity { doc: "object to reach or look at; null turns the solve off" },
        pole: Entity { doc: "TwoBone: the middle joint bends toward it; null keeps the bend plane" },
        weight: f32 { min: 0.0, max: 1.0, doc: "0 keeps the animated pose, 1 solves fully" },
        forward: [f32; 3] { doc: "LookAt: local axis that points at the target" },
        reach: f32 { unit: "m", min: 0.0, doc: "Foot: ground search above and below the character's floor" },
        joints: u32 { doc: "Chain: how many joints above this object bend" },
    }
}

crate::reflect! {
    struct Morph {
        weights: Vec<f32> { doc: "one weight per blend shape of the mesh, usually 0 to 1" },
    }
}

crate::reflect! {
    struct Skin {
        joints: Vec<String> { doc: "joint paths from this object; `..` is the parent" },
        inverse_bind: Vec<[[f32; 4]; 4]> { doc: "column-major, one per joint" },
    }
}

crate::reflect! {
    enum FluidSolver { Particles, Grid, Granular }
}

crate::reflect! {
    struct FluidBlock {
        spacing: f32 { unit: "m", min: 0.02, doc: "rest spacing of particles" },
        count_x: u32 { unit: "particles" },
        count_y: u32 { unit: "particles" },
        count_z: u32 { unit: "particles" },
        container_half_extents: [f32; 3] {
            unit: "m", min: 0.1, doc: "the box is centered on the entity",
        },
        iterations: u32 { unit: "passes", min: 1.0, max: 16.0 },
        viscosity: f32 { unit: "factor", min: 0.0, max: 1.0 },
        solver: FluidSolver { doc: "Particles for small splashy volumes, Grid (FLIP) for large water, Granular for sand and gravel" },
        friction: f32 { unit: "factor", min: 0.0, max: 2.0, doc: "Granular: grain friction; higher piles steeper" },
        visible: bool { doc: "draw the fluid as a water surface" },
        show_particles: bool { doc: "also draw one sphere per particle" },
    }
}

crate::reflect! {
    struct SoftBlock {
        spacing: f32 { unit: "m", min: 0.01, doc: "side of one cube of six tetrahedra" },
        count_x: u32 { unit: "cubes" },
        count_y: u32 { unit: "cubes" },
        count_z: u32 { unit: "cubes" },
        density: f32 { unit: "kg/m³", min: 1.0 },
        softness: f32 { unit: "compliance", min: 0.0, doc: "edge compliance; 0 is rigid, 1e-3 a wobbly jelly" },
        squash: f32 { unit: "compliance", min: 0.0, doc: "volume compliance; 0 keeps the volume" },
        damping: f32 { unit: "1/s", min: 0.0, doc: "fraction of velocity lost per second" },
        tear_strain: f32 { unit: "factor", min: 0.0, doc: "edges stretched past rest times 1 + this tear; 0 never" },
        substeps: u32 { unit: "substeps", min: 1.0, max: 64.0 },
        visible: bool { doc: "draw the outer faces" },
        color: [f32; 4] { unit: "linear RGBA", doc: "block color, multiplied into texture" },
        texture: PathBuf { unit: "asset path", doc: "image laid once on each side of the block, upright on the walls; empty for plain color" },
    }
}

crate::reflect! {
    struct ClothSheet {
        spacing: f32 { unit: "m", min: 0.01, doc: "side of one square of two triangles" },
        count_x: u32 { unit: "squares" },
        count_y: u32 { unit: "squares" },
        density: f32 { unit: "kg/m²", min: 0.001 },
        stretch: f32 { unit: "compliance", min: 0.0, doc: "edge compliance; 0 does not stretch" },
        bend: f32 { unit: "compliance", min: 0.0, doc: "bend compliance; larger folds more easily" },
        damping: f32 { unit: "1/s", min: 0.0, doc: "fraction of velocity lost per second" },
        wind: [f32; 3] { unit: "m/s", doc: "air velocity blowing on the sheet" },
        drag: f32 { unit: "factor", min: 0.0, doc: "how hard moving air pushes the sheet" },
        thickness: f32 { unit: "m", min: 0.0, doc: "half the closest two layers get" },
        self_collision: bool { doc: "keep folds from passing through each other" },
        tear_strain: f32 { unit: "factor", min: 0.0, doc: "edges stretched past rest times 1 + this tear; 0 never" },
        substeps: u32 { unit: "substeps", min: 1.0, max: 64.0 },
        pin_top: bool { doc: "hold the top edge on the holder, or in place without one" },
        holder: Entity { doc: "body the top edge hangs on; null pins it in place" },
        visible: bool { doc: "draw both sides of the sheet" },
        color: [f32; 4] { unit: "linear RGBA", doc: "sheet color, multiplied into texture" },
        texture: PathBuf { unit: "asset path", doc: "image stretched once over the sheet, top row at the top edge; empty for plain color" },
    }
}

crate::reflect! {
    struct WorldText {
        text: String { doc: "lines split at \\n; characters outside printable ASCII draw as ?" },
        size: f32 { unit: "m", min: 0.01, doc: "height of a capital letter" },
        color: [f32; 4] { unit: "linear RGBA", doc: "unlit text color" },
    }
}

crate::reflect! {
    struct WaterBody {
        size: [f32; 2] { unit: "m", min: 0.5, doc: "x and z size, centered on the entity" },
        resolution: u32 { unit: "cells", min: 2.0, max: 256.0, doc: "grid cells along the longer side" },
        wave_height: f32 { unit: "m", min: 0.0, doc: "crest height above the rest level" },
        wave_length: f32 { unit: "m", min: 0.1, doc: "distance between crests" },
        wave_speed: f32 { unit: "m/s", min: 0.0 },
        flow_direction: f32 { unit: "deg", doc: "direction of waves and current around +Y; 0 is +X" },
        flow_speed: f32 { unit: "m/s", min: 0.0, doc: "current that carries floating bodies; 0 is a lake" },
        color: [f32; 4] { doc: "RGBA of the surface" },
        flat_shading: bool {
            doc: "Light each wave triangle with its own face normal for a faceted sea.",
        },
        deep_color: Option<[f32; 4]> { doc: "RGBA where the view crosses depth_fade metres of water; null keeps one color" },
        depth_fade: f32 { unit: "m", min: 0.01, doc: "metres of water before the color is deep_color" },
        shore_foam: f32 { unit: "m", min: 0.0, doc: "foam band width along the shore in metres of depth; 0 is none" },
        crest_foam: f32 { min: 0.0, doc: "foam where steep Gerstner waves pinch into crests; 0 is none" },
        ripples: f32 { min: 0.0, max: 1.0, doc: "strength of small scrolling waves on top of the mesh; 0 is none" },
        ripple_length: f32 { unit: "m", min: 0.01, doc: "distance between small waves" },
        waves: Vec<OceanWave> { doc: "Gerstner waves in place of the three sines; empty keeps the sines" },
        time: Option<f64> { unit: "s", doc: "the game's own clock for the waves; null follows the fixed tick" },
        ocean: bool { doc: "endless sea: bodies float everywhere and the size grid follows the active camera, finer near it" },
    }
}

crate::reflect! {
    struct OceanWave {
        direction: f32 { unit: "deg", doc: "direction the crests travel around +Y; 0 is +X" },
        length: f32 { unit: "m", min: 0.05, doc: "distance between crests; longer waves travel faster" },
        height: f32 { unit: "m", min: 0.0, doc: "crest height above the rest level" },
        steepness: f32 { min: 0.0, max: 1.0, doc: "0 is a sine, 1 a pointed crest; keep the sum over all waves at 1 or below" },
    }
}

crate::reflect! {
    struct GravityVolume {
        gravity: [f32; 3] { unit: "m/s²", doc: "acceleration inside the volume; [0, 0, 0] is zero-g" },
        toward_center: f32 {
            unit: "m/s²", min: 0.0,
            doc: "above 0, pulls toward the volume's centre instead, for a planet",
        },
        priority: i32 { doc: "the highest wins where volumes overlap" },
    }
}

crate::reflect! {
    struct Heightfield {
        heights: Vec<Vec<f32>> { unit: "m", doc: "heights[row][column]; rows run along +Z, columns along +X, centred on the object" },
        spacing: f32 { unit: "m", min: 0.001, doc: "distance between neighbouring samples" },
        cells: Vec<Vec<u8>> { doc: "cells[row][column]: index into surfaces; missing cells use the collider's own" },
        surfaces: Vec<GroundSurface> { doc: "ground patches with their own friction, restitution and sound material" },
        image: String { doc: "16-bit grey PNG or .r16/.raw square under assets/ the heights load from; empty keeps the saved heights" },
        height_scale: f32 { unit: "m", doc: "height of a white image sample" },
    }
}

crate::reflect! {
    struct MeshSurfaces {
        triangles: Vec<u8> { doc: "triangles[i]: index into surfaces for the mesh's triangle i; missing entries use the collider's own" },
        surfaces: Vec<GroundSurface> { doc: "patches with their own friction, restitution and sound material" },
    }
}

crate::reflect! {
    struct Polygon2d {
        points: Vec<[f32; 2]> { unit: "m", doc: "outline in the object's XY plane; counterclockwise, convex for a Polygon collider" },
        depth: f32 { unit: "m", min: 0.001, doc: "thickness along Z, centred on the object" },
        closed: bool { doc: "the chain joins its last point back to the first" },
    }
}

crate::reflect! {
    struct Fracture {
        pieces: u32 { min: 0.0, max: 256.0, doc: "Voronoi cells to cut the mesh into; 0 or 1 makes no Voronoi cuts" },
        seed: u64 { doc: "picks where the Voronoi cells lie" },
        slices: Vec<[f32; 4]> { doc: "planes [x, y, z, d] in the object's frame that cut every piece where [x, y, z] · p = d" },
        break_energy: f32 { unit: "J", min: 0.0, doc: "impact energy within one fixed tick that breaks the object during play; 0 never breaks it" },
        debris_lifetime: f32 { unit: "s", min: 0.0, doc: "seconds a piece stays once it sleeps; 0 keeps pieces" },
        merge_debris: bool { doc: "once every piece of a break sleeps, they merge into one static body" },
    }
}

crate::reflect! {
    struct TerrainFracture {
        chunk_cells: u32 { min: 1.0, doc: "height cells along each side of a breakable chunk" },
        pieces: u32 { min: 0.0, max: 256.0, doc: "Voronoi pieces a dug-out slab breaks into, around points drawn from the scene's RandomSeed at the tick; 0 or 1 keeps one box" },
        break_energy: f32 { unit: "J", min: 0.0, doc: "impact energy on one chunk within one fixed tick that digs it out; 0 never breaks" },
        depth: f32 { unit: "m", min: 0.0, doc: "how far the chunk's ground drops; the slab's thickness" },
        density: f32 { unit: "kg/m³", min: 0.0, doc: "density of the dug-out slab" },
        debris_lifetime: f32 { unit: "s", min: 0.0, doc: "seconds a slab stays once it sleeps; 0 keeps it" },
        refreeze: f32 { unit: "s", min: 0.0, doc: "seconds any debris resting on this terrain sleeps before it freezes back into the heights; 0 never refreezes" },
        broken: Vec<u32> { doc: "chunks already dug out, row * chunk columns + column, sorted" },
    }
}

crate::reflect! {
    struct ConvexDecomposition {
        resolution: u32 { min: 1.0, max: 128.0, doc: "voxels along the mesh's longest side" },
        max_hulls: u32 { min: 1.0, max: 256.0, doc: "most hulls the mesh splits into" },
        concavity: f32 { min: 0.0, doc: "a part stops splitting once its hull exceeds the solid inside it by less than this share of the mesh's volume" },
        candidates: u32 { min: 1.0, doc: "split planes tried per axis; resolution or more tries every voxel plane" },
    }
}

crate::reflect! {
    struct GroundSurface {
        name: String { doc: "material name a sound_cue with_material matches" },
        friction: f32 { min: 0.0 },
        restitution: f32 { min: 0.0, max: 1.0 },
    }
}

crate::reflect! {
    enum FieldKind { Directional, Radial, Vortex, Wind, Custom }
}

crate::reflect! {
    struct ForceField {
        kind: FieldKind { doc: "Directional and Wind push along direction, Radial out from the centre, Vortex around direction" },
        strength: f32 { unit: "m/s²", doc: "the same for light and heavy bodies; negative Radial pulls in" },
        direction: [f32; 3] { doc: "world direction, or the vortex axis" },
        falloff_distance: f32 { unit: "m", min: 0.0, doc: "above 0, the push fades to nothing this far from the centre" },
        turbulence: f32 { min: 0.0, doc: "Wind gusts as a share of strength; 0 is steady" },
        function: String { doc: "Custom: the name a game registered with App::add_force_field_function" },
    }
}

crate::reflect! {
    struct AxisLock {
        linear: [bool; 3] { doc: "no movement along world x, y, z; [false, false, true] keeps a 2D body in the XY plane" },
        angular: [bool; 3] { doc: "no turning around world x, y, z; [true, true, false] lets a 2D body turn only in its plane" },
    }
}

crate::reflect! {
    enum CombineMode { Default, Average, Min, Multiply, Max }
}

crate::reflect! {
    struct PhysicsMaterial {
        name: String { doc: "surface name sound cues match with with_material, like metal or ice" },
        friction_combine: CombineMode { doc: "Default is the geometric mean; where sides differ, the later mode in the list wins" },
        restitution_combine: CombineMode { doc: "Default is the larger; where sides differ, the later mode in the list wins" },
    }
}

crate::reflect! {
    struct Vehicle {
        wheels: Vec<Wheel> { doc: "suspension rays and tires" },
        engine_torque: f32 { unit: "N·m", min: 0.0, doc: "flat up to max_rpm" },
        max_rpm: f32 { unit: "rpm", min: 1.0, doc: "no torque above it; the gearbox shifts up near it" },
        gear_ratios: Vec<f32> { doc: "forward gears from first; reverse uses the first" },
        final_drive: f32 { min: 0.0, doc: "multiplies every gear" },
        brake_torque: f32 { unit: "N·m", min: 0.0, doc: "per wheel at full brake" },
        max_steer: f32 { unit: "rad", min: 0.0, doc: "steered wheels' angle at full lock" },
        player_input: bool { doc: "forward/back drive, left/right steer, jump brakes" },
        throttle: f32 { min: -1.0, max: 1.0, doc: "below 0 drives backward" },
        brake: f32 { min: 0.0, max: 1.0, doc: "0 to 1" },
        steer: f32 { min: -1.0, max: 1.0, doc: "above 0 turns right" },
        gear: usize { doc: "state: index into gear_ratios" },
        rpm: f32 { unit: "rpm", doc: "state: engine speed" },
    }
}

crate::reflect! {
    struct Wheel {
        position: [f32; 3] { unit: "m", doc: "suspension mount in body space; forward is -Z" },
        radius: f32 { unit: "m", min: 0.01, doc: "tire radius" },
        suspension: f32 { unit: "m", min: 0.0, doc: "spring travel below the mount" },
        stiffness: f32 { unit: "N/m", min: 0.0, doc: "spring" },
        damping: f32 { unit: "N·s/m", min: 0.0, doc: "spring damper" },
        steer: bool { doc: "turns with steer" },
        drive: bool { doc: "gets engine torque" },
        grip: f32 { min: 0.0, doc: "friction at the peak of the tire curve" },
        spin: f32 { unit: "rad/s", doc: "state: positive rolls forward" },
        compression: f32 { unit: "m", doc: "state: spring pressed in" },
        grounded: bool { doc: "state: touched ground this step" },
    }
}

crate::reflect! {
    enum HudAnchor {
        TopLeft, Top, TopRight, Center, BottomLeft, Bottom, BottomRight,
    }
}

crate::reflect! {
    struct HudElement {
        text: String { doc: "{name} shows the counter with that name" },
        anchor: HudAnchor,
        offset: [f32; 2] {
            unit: "logical pixels",
            doc: "[x, y] inward from the anchor: [24, 24] on BottomRight is 24 px left of the right edge and 24 px above the bottom; on Top, Bottom and Center, +x is right",
        },
        font_size: f32 { unit: "logical pixels", min: 1.0 },
        color: [f32; 4] { unit: "sRGBA", min: 0.0, max: 1.0, color: true },
        button: bool { doc: "a click sends HudButtonPressed" },
        requires: Option<String> {
            unit: "counter name",
            doc: "null, or shown only once that counter is complete",
        },
        camera: Option<String> {
            unit: "camera name",
            doc: "null anchors to the window; a name anchors to that camera's viewport and shows only while it is active",
        },
        follow: Option<String> {
            unit: "object name",
            doc: "null, or the element sits on that object's place on screen, aligned by anchor, with offset in pixels (+y down); hidden while the object is behind the camera",
        },
        follow_offset: [f32; 3] { unit: "m", doc: "world-space offset from the followed object, such as [0, 2, 0] above a head" },
        font: Option<String> {
            unit: "path under assets/",
            doc: "null uses the built-in font; a TTF or OTF file such as fonts/pixel.ttf draws the text in it",
        },
    }
}

crate::reflect! {
    struct InputAction {
        action: String { doc: "name game code and scenarios use" },
        inputs: Vec<String> {
            doc: "winit key names (KeyF, Space, ArrowUp), MouseLeft, MouseRight, MouseMiddle, or gamepad inputs (PadSouth, PadStart, PadDpadUp, PadLeftStickUp)",
        },
    }
}

crate::reflect! {
    struct Counter {
        name: String { doc: "the lowest-ID counter wins when names repeat" },
        value: i32,
        target: Option<i32> {
            doc: "null, or the value that completes the counter",
        },
    }
}

crate::reflect! {
    struct Health {
        value: i32 { doc: "hit points left" },
        max: i32 { doc: "healing stops here" },
        team: String { doc: "objects on the same non-empty team are allies" },
    }
}

crate::reflect! {
    struct LootTable {
        entries: Vec<LootEntry> { doc: "one is picked per roll" },
    }
}

crate::reflect! {
    struct Dialogue {
        lines: Vec<DialogueLine> { doc: "the first line starts it" },
        current: String { doc: "id of the line shown; empty when not running" },
    }
}

crate::reflect! {
    struct DialogueLine {
        id: String { doc: "what next and choices point at" },
        speaker: String { doc: "translation key or name" },
        text: String { doc: "translation key or text" },
        next: String { doc: "line after this one when it has no choices; empty ends" },
        choices: Vec<DialogueChoice> { doc: "player answers" },
    }
}

crate::reflect! {
    struct DialogueChoice {
        text: String { doc: "translation key or text" },
        next: String { doc: "line it leads to; empty ends" },
        counter: String { doc: "counter it adds to; empty for none" },
        add: i32 { doc: "amount added to counter" },
    }
}

crate::reflect! {
    struct LootEntry {
        item: String { doc: "what the roll gives" },
        weight: u32 { doc: "chance over the table's total; 0 never drops" },
    }
}

crate::reflect! {
    struct ObjectState {
        state: String { doc: "game code changes it with scene.set_state" },
        since_tick: u64 { doc: "the fixed tick the state was entered on" },
        transitions: Vec<StateTransition> {
            doc: "checked each fixed tick; the first that applies changes the state",
        },
        actions: Vec<StateAction> {
            doc: "counter changes when a state is entered or left",
        },
    }
}

crate::reflect! {
    struct StateAction {
        state: String,
        exit: bool { doc: "run on leaving the state instead of entering it" },
        counter: String { unit: "counter name" },
        add: i32 { doc: "added to counter" },
    }
}

crate::reflect! {
    struct StateTransition {
        from: String { doc: "empty matches any state" },
        to: String,
        after_seconds: f32 { unit: "s", min: 0.0, doc: "time in the current state" },
        counter: String { unit: "counter name", doc: "empty means no counter guard" },
        at_least: i32 { doc: "the counter's value must reach this" },
        held: String { unit: "input action", doc: "must be held; empty for none" },
        touching: String { unit: "object name", doc: "must be touched; empty for none" },
        then_counter: String { unit: "counter name", doc: "taking the transition adds to it; empty for none" },
        then_add: i32 { doc: "added to then_counter" },
    }
}

crate::reflect! {
    struct Pickup {
        counter: String { unit: "counter name" },
        value: i32 { doc: "added on collect" },
        requires: Option<String> {
            unit: "counter name",
            doc: "null, or collectable only once that counter is complete",
        },
        collected: bool { doc: "set by the engine; scenarios can check it" },
    }
}

crate::reflect! {
    struct Connection {
        handler: String {
            doc: "name the game registered with App::add_signal_handler",
        },
        target: Entity { doc: "object passed to the handler as the receiver" },
    }
}

crate::reflect! {
    struct Connections {
        list: Vec<Connection> {
            doc: "signal handlers run, in order, when this object emits",
        },
    }
}

crate::reflect! {
    struct SceneInstance {
        source: PathBuf {
            unit: "scene file",
            doc: "placed under this object on load, relative to this scene; \
                  empty places nothing",
        },
    }
}

crate::reflect! {
    struct SceneBackground {
        color: [f32; 4] {
            unit: "linear RGBA", min: 0.0, max: 1.0, color: true,
        },
    }
}

crate::reflect! {
    struct EnvironmentMap {
        texture: PathBuf {
            unit: "asset path",
            doc: "equirectangular (2:1) image that surfaces reflect; .hdr keeps bright light",
        },
        intensity: f32 { unit: "factor", min: 0.0 },
        background: bool { doc: "also draw the image behind the scene" },
        #[skip] handle: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
    }
}

crate::reflect! {
    struct ParticleShader {
        source: String {
            doc: "GLSL starting with `#rusting particle 1`; see docs/surface-shaders.md",
        },
    }
}

crate::reflect! {
    struct FogShader {
        source: String {
            doc: "GLSL starting with `#rusting fog 1`; see docs/surface-shaders.md",
        },
    }
}

crate::reflect! {
    struct SkyShader {
        source: String {
            doc: "GLSL starting with `#rusting sky 1`; see docs/surface-shaders.md",
        },
    }
}

crate::reflect! {
    struct PostShader {
        source: String {
            doc: "GLSL starting with `#rusting post 1`; see docs/surface-shaders.md",
        },
    }
}

crate::reflect! {
    struct ColorLut {
        texture: PathBuf {
            unit: "asset path",
            doc: "strip of N squares of N x N pixels; blue picks the square",
        },
        intensity: f32 { unit: "factor", min: 0.0, max: 1.0 },
        #[skip] handle: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
    }
}

crate::reflect! {
    struct LightCookie {
        texture: PathBuf {
            unit: "asset path",
            doc: "image the spot light on this object projects",
        },
        #[skip] handle: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
    }
}

crate::reflect! {
    struct ReflectionProbe {
        extents: [f32; 3] {
            unit: "m", min: 0.0,
            doc: "half size of the box along each world axis",
        },
        intensity: f32 { unit: "factor", min: 0.0 },
    }
}

crate::reflect! {
    struct LightProbeGrid {
        extents: [f32; 3] {
            unit: "m", min: 0.0,
            doc: "half size of the box along each world axis",
        },
        resolution: [u32; 3] {
            unit: "probes", min: 1.0, max: 8.0,
            doc: "probes along each axis, at most 64 in all",
        },
        intensity: f32 { unit: "factor", min: 0.0 },
    }
}

crate::reflect! {
    struct Lightmap {
        resolution: u32 {
            unit: "texels", min: 2.0, max: 64.0,
            doc: "texels along each side of each of the six faces",
        },
    }
}

crate::reflect! {
    struct Terrain {
        layers: Vec<TerrainLayer> { doc: "up to four paint layers; list them low to high for height bands" },
        splat: Vec<Vec<[f32; 4]>> {
            doc: "splat[row][column]: weight of each layer at that height sample; missing samples use height bands",
        },
        tiling: f32 { unit: "m", min: 0.001, doc: "distance the layer textures span before they repeat" },
        chunk_cells: u32 { unit: "cells", min: 0.0, doc: "height cells along each side of a chunk; 0 picks it from the heightfield size (at most about 150 chunks)" },
        lod_distance: f32 {
            unit: "m", min: 0.0,
            doc: "chunks past it draw at half detail, past twice it at quarter detail; 0 keeps full detail",
        },
        cast_shadows: bool,
        tint: [f32; 3] {
            unit: "linear RGB", min: 0.0, color: true,
            doc: "multiplied into every layer; changing only tint and roughness skips the chunk rebuild",
        },
        roughness: f32 { unit: "factor", min: 0.0, doc: "multiplies every layer's roughness; below 1 is glossier" },
    }
}

crate::reflect! {
    struct TerrainLayer {
        texture: PathBuf { unit: "asset path", doc: "image painted by this layer; empty paints the plain color" },
        color: [f32; 3] { unit: "linear RGB", min: 0.0, color: true, doc: "tint multiplied into the texture" },
        min_height: f32 { unit: "m", doc: "height band start used where there are no splat weights" },
        normal: PathBuf { unit: "asset path", doc: "tangent-space normal map (OpenGL style, green up); empty keeps the ground's normal" },
        roughness: PathBuf { unit: "asset path", doc: "roughness map, read from its red channel; empty is 0.9" },
        tiling: f32 { unit: "m", min: 0.0, doc: "metres this layer repeats over; 0 uses the terrain's tiling" },
    }
}

crate::reflect! {
    struct Wind {
        direction: [f32; 3] { doc: "world direction the wind blows toward" },
        strength: f32 { unit: "m/s²", min: 0.0, doc: "push, like a wind force field's strength" },
        gusts: f32 { unit: "factor", min: 0.0, doc: "gust size as a share of strength; 0 is steady" },
    }
}

crate::reflect! {
    struct Foliage {
        count: u32 {
            unit: "copies", min: 0.0, max: 65536.0,
            doc: "copies of the mesh scattered over the disc",
        },
        radius: f32 {
            unit: "m", min: 0.0,
            doc: "disc radius on the object's local XZ plane",
        },
        seed: u32 { doc: "picks the scatter; the same seed gives the same layout" },
        scale_min: f32 { unit: "factor", min: 0.0, doc: "smallest copy scale" },
        scale_max: f32 { unit: "factor", min: 0.0, doc: "largest copy scale" },
        sway: f32 {
            unit: "m per m/s²", min: 0.0,
            doc: "lean per m/s² of force field push, per metre of height",
        },
        conform: bool { doc: "sets each copy on the heightfield below it" },
        layers: Vec<u32> {
            doc: "terrain layer indices copies may stand on; empty allows all",
        },
    }
}

crate::reflect! {
    struct Fog {
        color: [f32; 3] {
            unit: "linear RGB", min: 0.0, max: 1.0, color: true,
            doc: "color that distant objects fade into",
        },
        density: f32 {
            unit: "1/m", min: 0.0, max: 1.0,
            doc: "extinction per metre at `height`; 0.01 hides things \
                  about 300 m away",
        },
        height: f32 {
            unit: "m",
            doc: "world height where the fog has its full density",
        },
        height_falloff: f32 {
            unit: "1/m", min: 0.0, max: 2.0,
            doc: "how fast the fog thins above `height`; 0 is uniform",
        },
        sun_scatter: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "brightens fog toward the sun",
        },
        sky_affect: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "how much the background fades into the fog",
        },
        light_shafts: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "how much shadows block the glow toward the sun: light shafts",
        },
    }
}

crate::reflect! {
    struct CameraScreen {
        camera: String { doc: "name of the camera whose image this mesh shows" },
        size: [u32; 2] { unit: "px", doc: "feed width and height" },
        update_every: u32 {
            unit: "frames", min: 1.0, max: 60.0,
            doc: "draws the feed every this many frames",
        },
        enabled: bool { doc: "off keeps the last image without drawing" },
        grading: Option<ColorGrading> {
            doc: "the feed's own color grading; none uses the scene's",
        },
        exposure: f32 {
            unit: "factor", min: 0.0, max: 64.0,
            doc: "multiplies the scene's exposure for this feed; 1 matches the player's view",
        },
    }
}

crate::reflect! {
    struct ColorGrading {
        contrast: f32 {
            unit: "factor", min: 0.0, max: 3.0,
            doc: "contrast around mid grey; 1 leaves the image as is",
        },
        saturation: f32 {
            unit: "factor", min: 0.0, max: 3.0,
            doc: "0 is grey, 1 unchanged, above 1 stronger colors",
        },
        shadows: [f32; 3] {
            unit: "linear rgb",
            doc: "tint multiplied into dark tones; [1, 1, 1] is none",
        },
        highlights: [f32; 3] {
            unit: "linear rgb",
            doc: "tint multiplied into bright tones; [1, 1, 1] is none",
        },
        vignette: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "how much the corners darken; 0 is none",
        },
        grain: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "film grain, changing every fixed tick",
        },
        chromatic_aberration: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "red and blue split toward the edges",
        },
        scanlines: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "darkens every other pixel row",
        },
        color_bleed: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "smears color sideways like VHS tape",
        },
        noise_band: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "a band of static rolling down the image",
        },
        distortion: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "tube bulge and row wobble over time",
        },
        lens_droplets: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "rain drops on the camera lens that bend the image behind them",
        },
    }
}

crate::reflect! {
    struct ProceduralSky {
        intensity: f32 {
            unit: "factor", min: 0.0,
            doc: "multiplies the sky's brightness, which follows the sun's",
        },
        haze: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "0 clear air, 1 hazy with a wide glow around the sun",
        },
        ground_color: [f32; 3] {
            unit: "linear rgb", min: 0.0, max: 1.0,
            doc: "albedo of the ground seen below the horizon",
        },
        sun_size: f32 {
            unit: "degrees", min: 0.0, max: 20.0,
            doc: "diameter of the drawn sun disc; 0 hides it",
        },
        cloud_cover: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "share of the sky under clouds: 0 clear, 1 overcast",
        },
        cloud_darkness: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "0 white clouds, 1 dark storm clouds",
        },
        cloud_speed: f32 {
            unit: "m/s", min: 0.0,
            doc: "how fast the clouds drift at their height of 2 km",
        },
        wind_direction: [f32; 2] {
            doc: "world x and z the clouds drift toward",
        },
    }
}

crate::reflect! {
    struct Decal {
        texture: PathBuf {
            unit: "asset path",
            doc: "image painted onto surfaces in the box; empty paints color",
        },
        color: [f32; 4] {
            unit: "linear rgba", min: 0.0,
            doc: "multiplies the image; alpha scales its coverage",
        },
        extents: [f32; 3] {
            unit: "m", min: 0.0,
            doc: "half size of the box; it projects along local -Z",
        },
        roughness: Option<f32> {
            min: 0.0, max: 1.0,
            doc: "roughness painted by coverage, low for wet stains; null keeps the surface's",
        },
        survive_fracture: bool {
            doc: "false: removed when its parent breaks; true: moves onto the nearest piece",
        },
        #[skip] handle: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
    }
}

crate::reflect! {
    struct Sprite {
        texture: PathBuf {
            unit: "asset path",
            doc: "image drawn on the sprite; empty draws color",
        },
        color: [f32; 4] {
            unit: "linear rgba", min: 0.0,
            doc: "multiplies the image",
        },
        size: [f32; 2] {
            unit: "m", min: 0.0,
            doc: "width and height before the object's scale",
        },
        region: [f32; 4] {
            min: 0.0, max: 1.0,
            doc: "part of the image to draw, [u0, v0, u1, v1] with v down",
        },
        flip_x: bool,
        flip_y: bool,
        layer: i32 {
            doc: "canvas layer; higher layers draw over lower ones whatever their z",
        },
        #[skip] handle: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
        normal_map: PathBuf {
            unit: "asset path",
            doc: "tangent-space normal map (green up) that 2D lights shade; empty is flat",
        },
        #[skip] normal_handle: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
        in_scene: bool {
            doc: "draw inside the 3D scene, hidden by nearer meshes, instead of over it",
        },
    }
}

crate::reflect! {
    struct SpriteAnimation {
        columns: u32 { min: 1.0, doc: "frames across the sheet" },
        rows: u32 { min: 1.0, doc: "frames down the sheet" },
        first: u32 { doc: "first frame shown, counted row by row from the top left" },
        count: u32 { min: 1.0, doc: "frames in the animation" },
        fps: f32 { unit: "frames/s", min: 0.0 },
        looping: bool { doc: "start over after the last frame; otherwise hold it" },
        #[skip] elapsed: f64,
    }
}

crate::reflect! {
    struct Light2d {
        color: [f32; 3] { unit: "linear rgb", min: 0.0 },
        intensity: f32 { min: 0.0 },
        radius: f32 { unit: "m", min: 0.0, doc: "sprites farther than this in XY get none of the light" },
        height: f32 { unit: "m", min: 0.0, doc: "above the sprites; only normal-mapped sprites see it" },
    }
}

crate::reflect! {
    struct LightOccluder2d {
        points: Vec<[f32; 2]> { unit: "m", doc: "closed outline in the object's XY plane that blocks 2D lights" },
    }
}

crate::reflect! {
    struct Camera2d {
        target: String { doc: "name of the object to follow; empty stays put" },
        offset: [f32; 2] { unit: "m", doc: "from the target to the view center" },
        smoothing: f32 { unit: "s", min: 0.0, doc: "time to close about two thirds of the gap; 0 snaps" },
        limits: Option<[f32; 4]> { unit: "m", doc: "min x, min y, max x, max y the orthographic view stays inside" },
        pixels_per_unit: f32 { min: 0.0, doc: "art pixels per metre; above 0 zooms to whole screen pixels per art pixel and snaps to screen pixels" },
        #[skip] center: Option<[f32; 2]>,
    }
}

crate::reflect! {
    struct Particles2d {
        layer: i32 { doc: "canvas layer; higher layers draw over lower ones whatever their z" },
    }
}

crate::reflect! {
    struct Ambient2d {
        color: [f32; 3] {
            unit: "linear rgb", min: 0.0,
            doc: "light every sprite gets before 2D lights; without one sprites keep full color",
        },
    }
}

crate::reflect! {
    struct ParticleBlocker {
        extents: [f32; 3] {
            unit: "m", min: 0.0,
            doc: "half size of the box in the object's local axes",
        },
    }
}

crate::reflect! {
    struct FogVolume {
        color: [f32; 3] {
            unit: "linear rgb", min: 0.0,
            doc: "color the box fades into",
        },
        density: f32 {
            unit: "1/m", min: 0.0,
            doc: "extinction per metre inside the box",
        },
        extents: [f32; 3] {
            unit: "m", min: 0.0,
            doc: "half size of the box in the object's local axes",
        },
    }
}

crate::reflect! {
    struct PostVolume {
        extents: [f32; 3] {
            unit: "m", min: 0.0,
            doc: "half size of the box around the object, world axes",
        },
        blend: f32 {
            unit: "m", min: 0.0,
            doc: "fade-out distance outside the box; 0 switches at the wall",
        },
        priority: i32 {
            doc: "higher volumes blend over lower ones",
        },
    }
}

crate::reflect! {
    struct AutoExposure {
        key: f32 {
            unit: "linear", min: 0.001, max: 1.0,
            doc: "average brightness the image is brought to; 0.18 is mid grey",
        },
        min_exposure: f32 {
            unit: "factor", min: 0.001,
            doc: "lowest exposure, for very bright scenes",
        },
        max_exposure: f32 {
            unit: "factor", min: 0.001,
            doc: "highest exposure, for very dark scenes",
        },
        speed: f32 {
            unit: "1/s", min: 0.0,
            doc: "how fast exposure follows a change in brightness",
        },
    }
}

crate::reflect! {
    struct DepthOfField {
        focus_distance: f32 {
            unit: "m", min: 0.01,
            doc: "distance from the camera that stays sharp",
        },
        blur: f32 {
            unit: "fraction", min: 0.0, max: 0.05,
            doc: "largest blur radius as a fraction of the screen height",
        },
    }
}

crate::reflect! {
    struct MotionBlur {
        intensity: f32 {
            unit: "fraction", min: 0.0, max: 1.0,
            doc: "fraction of the last frame's camera motion the smear covers",
        },
    }
}

crate::reflect! {
    struct Bloom {
        intensity: f32 {
            unit: "factor", min: 0.0, max: 4.0,
            doc: "share of the light above `threshold` added back as glow",
        },
        threshold: f32 {
            unit: "linear", min: 0.0, max: 16.0,
            doc: "brightness where the glow starts, with a soft knee",
        },
        spread: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "0 keeps the glow tight; 1 spreads it widely",
        },
    }
}

crate::reflect! {
    struct AmbientOcclusion {
        radius: f32 {
            unit: "m", min: 0.05, max: 10.0,
            doc: "world distance searched for occluders",
        },
        intensity: f32 {
            unit: "exponent", min: 0.0, max: 8.0,
            doc: "above 1 darkens creases more",
        },
        indirect: f32 {
            unit: "factor", min: 0.0, max: 4.0,
            doc: "light bounced off nearby surfaces; 0 off, High profile only",
        },
    }
}

crate::reflect! {
    struct TileKind {
        color: [f32; 4] {
            unit: "linear RGBA", min: 0.0, max: 1.0, color: true,
            doc: "multiplies the texture",
        },
        texture: Option<PathBuf> {
            unit: "asset path",
            doc: "null or an image; alpha below 0.5 is cut out",
        },
        solid: bool { doc: "blocks CPU colliders" },
    }
}

crate::reflect! {
    struct TileMap {
        tile_size: f32 { unit: "m", min: 0.001 },
        rows: Vec<String> {
            doc: "one string per row, top first; characters without a kind are empty",
        },
        tiles: std::collections::BTreeMap<String, TileKind> {
            doc: "maps a one-character string to its kind",
        },
    }
}

crate::reflect! {
    struct PlatformerController {
        run_speed: f32 { unit: "m/s", min: 0.0 },
        jump_speed: f32 { unit: "m/s", min: 0.0 },
        gravity: f32 { unit: "m/s²", min: 0.0 },
        collision_mask: u32 {
            unit: "bitmask", doc: "layers the body stops against",
        },
        air_jumps: u32 { doc: "extra jumps in the air before landing; 1 is a double jump" },
        #[skip] air_jumps_used: u32,
        #[skip] vertical_speed: f32,
        #[skip] grounded: bool,
        #[skip] jump_buffer: f32,
        #[skip] air_time: f32,
        #[skip] floor: Option<(bevy_ecs::entity::Entity, [f32; 3])>,
        #[skip] dash_velocity: [f32; 3],
        #[skip] dash_left: f32,
    }
}

crate::reflect! {
    enum QualityProfile { Auto, Eco, Balanced, High }
}

crate::reflect! {
    enum CullingMode { Auto, Disabled, Frustum, FrustumAndOcclusion }
}

crate::reflect! {
    enum Antialiasing { Auto, Off, Msaa2, Msaa4, Fxaa, Taa }
}

crate::reflect! {
    enum ShadowQuality { Auto, Low, Medium, High }
}

crate::reflect! {
    struct RenderSettings {
        quality: QualityProfile,
        vsync: bool,
        limit_fps: bool,
        max_fps: u32 { unit: "frames/s", min: 1.0 },
        render_scale: f32 {
            unit: "factor", min: 0.25, max: 2.0,
            doc: "Fraction of the window size the 3D scene renders at, stretched over the window. Below 1 is faster and blurrier; UI stays sharp.",
        },
        pixelated: bool {
            doc: "Stretch a scaled frame with nearest-neighbour filtering: square pixels instead of blur.",
        },
        upscale_sharpness: f32 {
            unit: "factor", min: 0.0, max: 1.0,
            doc: "Above 0, a render scale below 1 is stretched with an edge-preserving filter and contrast-adaptive sharpening of this strength (FSR 1 style) instead of blur.",
        },
        background_color: [f32; 4] {
            unit: "linear RGBA", min: 0.0, max: 1.0, color: true,
        },
        culling: CullingMode,
        antialiasing: Antialiasing,
        shadows: ShadowQuality,
        hard_shadows: bool {
            doc: "One shadow-map tap per pixel: crisp shadow edges instead of 3x3 filtered ones.",
        },
        reflections: bool,
        max_texture_size: u32 {
            unit: "px",
            doc: "Largest texture side uploaded to the GPU; larger textures are halved until they fit. 0 is no cap.",
        },
    }
}

crate::reflect! {
    struct PhysicsSettings {
        gravity: [f32; 3] { unit: "m/s²" },
        enabled: bool,
        kill_y: Option<f32> { unit: "m", doc: "Loose dynamic CPU bodies below this height are despawned and send FellOut." },
        substeps: u32 { doc: "CPU solver substeps per fixed step; more hold joint chains and mass ratios tighter at that many times the cost." },
        gpu_locks: AxisLock { doc: "axis locks every GPU body shares; PLANE_XY keeps a 2D game's GPU bodies in its plane" },
    }
}

crate::reflect! {
    struct RandomSeed(u64)
}

crate::reflect! {
    enum DeterminismMode { Off, Local, CrossPlatform }
}

crate::reflect! {
    enum MaterialModel { Pbr, Unlit }
}

crate::reflect! {
    enum AlphaMode {
        Opaque,
        Mask { cutoff: f32 { min: 0.0, max: 1.0 } },
        Blend,
    }
}

crate::reflect! {
    struct MaterialSway {
        amplitude: f32 { unit: "m per m/s²", min: 0.0, doc: "lean per m/s² of force field push, per metre of height; 0 is still" },
        frequency: f32 { unit: "Hz", min: 0.0, doc: "gusts per second, phased by position; 0 is a steady lean" },
        height: f32 { unit: "m", min: 0.0, doc: "height over which the bend grows from a rooted base; 0 is a straight lean" },
    }
}

crate::reflect! {
    struct WaterShading {
        deep_color: [f32; 4] { unit: "linear RGBA", min: 0.0, max: 1.0, color: true, doc: "color where the view crosses depth_fade metres of water" },
        depth_fade: f32 { unit: "m", min: 0.0, doc: "metres of water before the color is deep_color; 0 is one color" },
        shore_foam: f32 { unit: "m", min: 0.0, doc: "foam band width in metres of water depth; 0 is none" },
        crest_foam: f32 { min: 0.0, doc: "foam where steep vertex-shader waves pinch into crests; 0 is none" },
        ripples: f32 { min: 0.0, max: 1.0, doc: "strength of the small scrolling waves; 0 is none" },
        ripple_length: f32 { unit: "m", min: 0.01, doc: "distance between small waves" },
    }
}

crate::reflect! {
    struct MaterialAsset {
        name: String,
        model: MaterialModel,
        alpha_mode: AlphaMode,
        base_color: [f32; 4] {
            unit: "linear RGBA", min: 0.0, max: 1.0, color: true,
        },
        emissive: [f32; 3] { unit: "linear RGB", min: 0.0, color: true },
        metallic: f32 { min: 0.0, max: 1.0 },
        roughness: f32 { min: 0.0, max: 1.0 },
        transmission: f32 { min: 0.0, max: 1.0 },
        ior: f32 { min: 1.0, max: 3.0 },
        thickness: f32 { unit: "m", min: 0.0 },
        uv_scale: [f32; 2],
        uv_offset: [f32; 2],
        flat_shading: bool {
            doc: "Light each triangle with its own face normal for a faceted, low-poly look.",
        },
        wettable: bool {
            doc: "Darker and shinier as the global wetness (GameScene::set_wetness) rises.",
        },
        splat: bool {
            doc: "Terrain paint: blend the base-color array's four layers by the vertex color.",
        },
        splat_scale: [f32; 4] {
            doc: "Terrain paint: repeats of each layer per unit of the mesh's texture coordinates.",
        },
        shader: String {
            doc: "Surface shader GLSL starting with `#rusting surface 1`; empty for the built-in surface.",
        },
        sway: MaterialSway {
            doc: "Bend in the force-field wind around the origin, on the GPU; amplitude 0 keeps the mesh still.",
        },
        water: WaterShading {
            doc: "Water look set by rusting.water: depth color, shore foam and ripples; all zero is a plain surface.",
        },
        base_color_texture: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
        normal_texture: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
        metallic_roughness_texture: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
        occlusion_texture: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
        emissive_texture: Option<crate::assets::Handle<crate::assets::TextureAsset>>,
    }
}

pub(super) fn register(registry: &mut TypeRegistry) {
    registry.register_resource::<RenderSettings>("rusting.render_settings");
    registry.register_resource::<PhysicsSettings>("rusting.physics_settings");
    registry.register_resource::<RandomSeed>("rusting.random_seed");
    registry.register_resource::<DeterminismMode>("rusting.determinism");
    registry.register_asset::<MaterialAsset>("rusting.material");
}