box2d-ruby 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +336 -0
  4. data/examples/contact_events.rb +22 -0
  5. data/examples/debug_draw.rb +15 -0
  6. data/examples/falling_ball.rb +19 -0
  7. data/examples/rugl_debug_draw.rb +68 -0
  8. data/examples/stagecraft_debug_draw.rb +64 -0
  9. data/examples/support/box2d_debug_lines.rb +125 -0
  10. data/ext/box2d/CMakeLists.txt +35 -0
  11. data/ext/box2d/extconf.rb +42 -0
  12. data/ext/box2d/native.c +9 -0
  13. data/ext/box2d/vendor/box2d/LICENSE +21 -0
  14. data/ext/box2d/vendor/box2d/VERSION +1 -0
  15. data/ext/box2d/vendor/box2d/include/box2d/base.h +131 -0
  16. data/ext/box2d/vendor/box2d/include/box2d/box2d.h +1222 -0
  17. data/ext/box2d/vendor/box2d/include/box2d/collision.h +830 -0
  18. data/ext/box2d/vendor/box2d/include/box2d/id.h +144 -0
  19. data/ext/box2d/vendor/box2d/include/box2d/math_functions.h +761 -0
  20. data/ext/box2d/vendor/box2d/include/box2d/types.h +1457 -0
  21. data/ext/box2d/vendor/box2d/src/CMakeLists.txt +223 -0
  22. data/ext/box2d/vendor/box2d/src/aabb.c +132 -0
  23. data/ext/box2d/vendor/box2d/src/aabb.h +56 -0
  24. data/ext/box2d/vendor/box2d/src/arena_allocator.c +112 -0
  25. data/ext/box2d/vendor/box2d/src/arena_allocator.h +48 -0
  26. data/ext/box2d/vendor/box2d/src/array.c +8 -0
  27. data/ext/box2d/vendor/box2d/src/array.h +179 -0
  28. data/ext/box2d/vendor/box2d/src/atomic.h +79 -0
  29. data/ext/box2d/vendor/box2d/src/bitset.c +67 -0
  30. data/ext/box2d/vendor/box2d/src/bitset.h +65 -0
  31. data/ext/box2d/vendor/box2d/src/body.c +1884 -0
  32. data/ext/box2d/vendor/box2d/src/body.h +194 -0
  33. data/ext/box2d/vendor/box2d/src/box2d.natvis +41 -0
  34. data/ext/box2d/vendor/box2d/src/broad_phase.c +524 -0
  35. data/ext/box2d/vendor/box2d/src/broad_phase.h +83 -0
  36. data/ext/box2d/vendor/box2d/src/constants.h +54 -0
  37. data/ext/box2d/vendor/box2d/src/constraint_graph.c +322 -0
  38. data/ext/box2d/vendor/box2d/src/constraint_graph.h +58 -0
  39. data/ext/box2d/vendor/box2d/src/contact.c +650 -0
  40. data/ext/box2d/vendor/box2d/src/contact.h +148 -0
  41. data/ext/box2d/vendor/box2d/src/contact_solver.c +2120 -0
  42. data/ext/box2d/vendor/box2d/src/contact_solver.h +54 -0
  43. data/ext/box2d/vendor/box2d/src/core.c +178 -0
  44. data/ext/box2d/vendor/box2d/src/core.h +149 -0
  45. data/ext/box2d/vendor/box2d/src/ctz.h +112 -0
  46. data/ext/box2d/vendor/box2d/src/distance.c +1415 -0
  47. data/ext/box2d/vendor/box2d/src/distance_joint.c +556 -0
  48. data/ext/box2d/vendor/box2d/src/dynamic_tree.c +1989 -0
  49. data/ext/box2d/vendor/box2d/src/geometry.c +1028 -0
  50. data/ext/box2d/vendor/box2d/src/hull.c +328 -0
  51. data/ext/box2d/vendor/box2d/src/id_pool.c +79 -0
  52. data/ext/box2d/vendor/box2d/src/id_pool.h +35 -0
  53. data/ext/box2d/vendor/box2d/src/island.c +977 -0
  54. data/ext/box2d/vendor/box2d/src/island.h +89 -0
  55. data/ext/box2d/vendor/box2d/src/joint.c +1272 -0
  56. data/ext/box2d/vendor/box2d/src/joint.h +335 -0
  57. data/ext/box2d/vendor/box2d/src/manifold.c +1726 -0
  58. data/ext/box2d/vendor/box2d/src/math_functions.c +159 -0
  59. data/ext/box2d/vendor/box2d/src/motor_joint.c +283 -0
  60. data/ext/box2d/vendor/box2d/src/mouse_joint.c +214 -0
  61. data/ext/box2d/vendor/box2d/src/mover.c +73 -0
  62. data/ext/box2d/vendor/box2d/src/prismatic_joint.c +656 -0
  63. data/ext/box2d/vendor/box2d/src/revolute_joint.c +534 -0
  64. data/ext/box2d/vendor/box2d/src/sensor.c +389 -0
  65. data/ext/box2d/vendor/box2d/src/sensor.h +36 -0
  66. data/ext/box2d/vendor/box2d/src/shape.c +1714 -0
  67. data/ext/box2d/vendor/box2d/src/shape.h +123 -0
  68. data/ext/box2d/vendor/box2d/src/solver.c +2038 -0
  69. data/ext/box2d/vendor/box2d/src/solver.h +155 -0
  70. data/ext/box2d/vendor/box2d/src/solver_set.c +613 -0
  71. data/ext/box2d/vendor/box2d/src/solver_set.h +57 -0
  72. data/ext/box2d/vendor/box2d/src/table.c +238 -0
  73. data/ext/box2d/vendor/box2d/src/table.h +37 -0
  74. data/ext/box2d/vendor/box2d/src/timer.c +185 -0
  75. data/ext/box2d/vendor/box2d/src/types.c +151 -0
  76. data/ext/box2d/vendor/box2d/src/weld_joint.c +310 -0
  77. data/ext/box2d/vendor/box2d/src/wheel_joint.c +551 -0
  78. data/ext/box2d/vendor/box2d/src/world.c +3301 -0
  79. data/ext/box2d/vendor/box2d/src/world.h +192 -0
  80. data/generator/generate.rb +316 -0
  81. data/generator/layout_probe.c +507 -0
  82. data/generator/verify_layouts.rb +32 -0
  83. data/lib/box2d/body.rb +172 -0
  84. data/lib/box2d/body_definition.rb +38 -0
  85. data/lib/box2d/body_shapes.rb +135 -0
  86. data/lib/box2d/chain.rb +61 -0
  87. data/lib/box2d/debug_draw.rb +118 -0
  88. data/lib/box2d/events.rb +103 -0
  89. data/lib/box2d/fixed_stepper.rb +39 -0
  90. data/lib/box2d/handle.rb +46 -0
  91. data/lib/box2d/hit.rb +5 -0
  92. data/lib/box2d/joint.rb +197 -0
  93. data/lib/box2d/native.rb +1462 -0
  94. data/lib/box2d/native_loader.rb +45 -0
  95. data/lib/box2d/pixel_scale.rb +29 -0
  96. data/lib/box2d/shape.rb +109 -0
  97. data/lib/box2d/shape_definition.rb +44 -0
  98. data/lib/box2d/value_conversion.rb +80 -0
  99. data/lib/box2d/version.rb +7 -0
  100. data/lib/box2d/world.rb +135 -0
  101. data/lib/box2d/world_joints.rb +156 -0
  102. data/lib/box2d/world_queries.rb +122 -0
  103. data/lib/box2d/world_registry.rb +95 -0
  104. data/lib/box2d.rb +31 -0
  105. data/script/build_platform_gem.rb +24 -0
  106. data/script/deterministic_scene.rb +56 -0
  107. data/script/update_deterministic_snapshot.rb +11 -0
  108. data/script/verify_platform_gem.rb +24 -0
  109. metadata +164 -0
@@ -0,0 +1,155 @@
1
+ // SPDX-FileCopyrightText: 2023 Erin Catto
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ #pragma once
5
+
6
+ #include "box2d/math_functions.h"
7
+
8
+ #include "core.h"
9
+
10
+ #include <stdbool.h>
11
+ #include <stdint.h>
12
+
13
+ typedef struct b2BodySim b2BodySim;
14
+ typedef struct b2BodyState b2BodyState;
15
+ typedef struct b2ContactSim b2ContactSim;
16
+ typedef struct b2JointSim b2JointSim;
17
+ typedef struct b2World b2World;
18
+
19
+ typedef struct b2Softness
20
+ {
21
+ float biasRate;
22
+ float massScale;
23
+ float impulseScale;
24
+ } b2Softness;
25
+
26
+ typedef enum b2SolverStageType
27
+ {
28
+ b2_stagePrepareJoints,
29
+ b2_stagePrepareContacts,
30
+ b2_stageIntegrateVelocities,
31
+ b2_stageWarmStart,
32
+ b2_stageSolve,
33
+ b2_stageIntegratePositions,
34
+ b2_stageRelax,
35
+ b2_stageRestitution,
36
+ b2_stageStoreImpulses
37
+ } b2SolverStageType;
38
+
39
+ typedef enum b2SolverBlockType
40
+ {
41
+ b2_bodyBlock,
42
+ b2_jointBlock,
43
+ b2_contactBlock,
44
+ b2_graphJointBlock,
45
+ b2_graphContactBlock
46
+ } b2SolverBlockType;
47
+
48
+ // Each block of work has a sync index that gets incremented when a worker claims the block. This ensures only a single worker
49
+ // claims a block, yet lets work be distributed dynamically across multiple workers (work stealing). This also reduces contention
50
+ // on a single block index atomic. For non-iterative stages the sync index is simply set to one. For iterative stages (solver
51
+ // iteration) the same block of work is executed once per iteration and the atomic sync index is shared across iterations, so it
52
+ // increases monotonically.
53
+ typedef struct b2SolverBlock
54
+ {
55
+ int startIndex;
56
+ int16_t count;
57
+ int16_t blockType; // b2SolverBlockType
58
+ // todo consider false sharing of this atomic
59
+ b2AtomicInt syncIndex;
60
+ } b2SolverBlock;
61
+
62
+ // Each stage must be completed before going to the next stage.
63
+ // Non-iterative stages use a stage instance once while iterative stages re-use the same instance each iteration.
64
+ typedef struct b2SolverStage
65
+ {
66
+ b2SolverStageType type;
67
+ b2SolverBlock* blocks;
68
+ int blockCount;
69
+ int colorIndex;
70
+ // todo consider false sharing of this atomic
71
+ b2AtomicInt completionCount;
72
+ } b2SolverStage;
73
+
74
+ // Context for a time step. Recreated each time step.
75
+ typedef struct b2StepContext
76
+ {
77
+ // time step
78
+ float dt;
79
+
80
+ // inverse time step (0 if dt == 0).
81
+ float inv_dt;
82
+
83
+ // sub-step
84
+ float h;
85
+ float inv_h;
86
+
87
+ int subStepCount;
88
+
89
+ b2Softness jointSoftness;
90
+ b2Softness contactSoftness;
91
+ b2Softness staticSoftness;
92
+
93
+ float restitutionThreshold;
94
+ float maxLinearVelocity;
95
+
96
+ struct b2World* world;
97
+ struct b2ConstraintGraph* graph;
98
+
99
+ // shortcut to body states from awake set
100
+ b2BodyState* states;
101
+
102
+ // shortcut to body sims from awake set
103
+ b2BodySim* sims;
104
+
105
+ // array of all shape ids for shapes that have enlarged AABBs
106
+ int* enlargedShapes;
107
+ int enlargedShapeCount;
108
+
109
+ // Array of bullet bodies that need continuous collision handling
110
+ int* bulletBodies;
111
+ b2AtomicInt bulletBodyCount;
112
+
113
+ // joint pointers for simplified parallel-for access.
114
+ b2JointSim** joints;
115
+
116
+ // contact pointers for simplified parallel-for access.
117
+ // - parallel-for collide with no gaps
118
+ // - parallel-for prepare and store contacts with NULL gaps for SIMD remainders
119
+ // despite being an array of pointers, these are contiguous sub-arrays corresponding
120
+ // to constraint graph colors
121
+ b2ContactSim** contacts;
122
+
123
+ struct b2ContactConstraintSIMD* simdContactConstraints;
124
+ int activeColorCount;
125
+ int workerCount;
126
+
127
+ b2SolverStage* stages;
128
+ int stageCount;
129
+ bool enableWarmStarting;
130
+
131
+ // todo padding to prevent false sharing
132
+ char dummy1[64];
133
+
134
+ // sync index (16-bits) | stage type (16-bits)
135
+ b2AtomicU32 atomicSyncBits;
136
+
137
+ char dummy2[64];
138
+
139
+ } b2StepContext;
140
+
141
+ static inline b2Softness b2MakeSoft( float hertz, float zeta, float h )
142
+ {
143
+ if ( hertz == 0.0f )
144
+ {
145
+ return ( b2Softness ){ 0.0f, 1.0f, 0.0f };
146
+ }
147
+
148
+ float omega = 2.0f * B2_PI * hertz;
149
+ float a1 = 2.0f * zeta + h * omega;
150
+ float a2 = h * omega * a1;
151
+ float a3 = 1.0f / ( 1.0f + a2 );
152
+ return ( b2Softness ){ omega / a1, a2 * a3, a3 };
153
+ }
154
+
155
+ void b2Solve( b2World* world, b2StepContext* stepContext );