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,148 @@
1
+ // SPDX-FileCopyrightText: 2023 Erin Catto
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ #pragma once
5
+
6
+ #include "array.h"
7
+ #include "core.h"
8
+
9
+ #include "box2d/collision.h"
10
+ #include "box2d/types.h"
11
+
12
+ typedef struct b2Shape b2Shape;
13
+ typedef struct b2World b2World;
14
+
15
+ enum b2ContactFlags
16
+ {
17
+ // Set when the solid shapes are touching.
18
+ b2_contactTouchingFlag = 0x00000001,
19
+
20
+ // Contact has a hit event
21
+ b2_contactHitEventFlag = 0x00000002,
22
+
23
+ // This contact wants contact events
24
+ b2_contactEnableContactEvents = 0x00000004,
25
+ };
26
+
27
+ // A contact edge is used to connect bodies and contacts together
28
+ // in a contact graph where each body is a node and each contact
29
+ // is an edge. A contact edge belongs to a doubly linked list
30
+ // maintained in each attached body. Each contact has two contact
31
+ // edges, one for each attached body.
32
+ typedef struct b2ContactEdge
33
+ {
34
+ int bodyId;
35
+ int prevKey;
36
+ int nextKey;
37
+ } b2ContactEdge;
38
+
39
+ // Cold contact data. Used as a persistent handle and for persistent island
40
+ // connectivity.
41
+ typedef struct b2Contact
42
+ {
43
+ // index of simulation set stored in b2World
44
+ // B2_NULL_INDEX when slot is free
45
+ int setIndex;
46
+
47
+ // index into the constraint graph color array
48
+ // B2_NULL_INDEX for non-touching or sleeping contacts
49
+ // B2_NULL_INDEX when slot is free
50
+ int colorIndex;
51
+
52
+ // contact index within set or graph color
53
+ // B2_NULL_INDEX when slot is free
54
+ int localIndex;
55
+
56
+ b2ContactEdge edges[2];
57
+ int shapeIdA;
58
+ int shapeIdB;
59
+
60
+ // A contact only belongs to an island if touching, otherwise B2_NULL_INDEX.
61
+ int islandPrev;
62
+ int islandNext;
63
+ int islandId;
64
+
65
+ int contactId;
66
+
67
+ // b2ContactFlags
68
+ uint32_t flags;
69
+
70
+ bool isMarked;
71
+ } b2Contact;
72
+
73
+ // Shifted to be distinct from b2ContactFlags
74
+ enum b2ContactSimFlags
75
+ {
76
+ // Set when the shapes are touching
77
+ b2_simTouchingFlag = 0x00010000,
78
+
79
+ // This contact no longer has overlapping AABBs
80
+ b2_simDisjoint = 0x00020000,
81
+
82
+ // This contact started touching
83
+ b2_simStartedTouching = 0x00040000,
84
+
85
+ // This contact stopped touching
86
+ b2_simStoppedTouching = 0x00080000,
87
+
88
+ // This contact has a hit event
89
+ b2_simEnableHitEvent = 0x00100000,
90
+
91
+ // This contact wants pre-solve events
92
+ b2_simEnablePreSolveEvents = 0x00200000,
93
+ };
94
+
95
+ /// The class manages contact between two shapes. A contact exists for each overlapping
96
+ /// AABB in the broad-phase (except if filtered). Therefore a contact object may exist
97
+ /// that has no contact points.
98
+ typedef struct b2ContactSim
99
+ {
100
+ int contactId;
101
+
102
+ #if B2_VALIDATE
103
+ int bodyIdA;
104
+ int bodyIdB;
105
+ #endif
106
+
107
+ int bodySimIndexA;
108
+ int bodySimIndexB;
109
+
110
+ int shapeIdA;
111
+ int shapeIdB;
112
+
113
+ float invMassA;
114
+ float invIA;
115
+
116
+ float invMassB;
117
+ float invIB;
118
+
119
+ b2Manifold manifold;
120
+
121
+ // Mixed friction and restitution
122
+ float friction;
123
+ float restitution;
124
+ float rollingResistance;
125
+ float tangentSpeed;
126
+
127
+ // b2ContactSimFlags
128
+ uint32_t simFlags;
129
+
130
+ b2SimplexCache cache;
131
+ } b2ContactSim;
132
+
133
+ void b2InitializeContactRegisters( void );
134
+
135
+ void b2CreateContact( b2World* world, b2Shape* shapeA, b2Shape* shapeB );
136
+ void b2DestroyContact( b2World* world, b2Contact* contact, bool wakeBodies );
137
+
138
+ b2ContactSim* b2GetContactSim( b2World* world, b2Contact* contact );
139
+
140
+ bool b2ShouldShapesCollide( b2Filter filterA, b2Filter filterB );
141
+
142
+ bool b2UpdateContact( b2World* world, b2ContactSim* contactSim, b2Shape* shapeA, b2Transform transformA, b2Vec2 centerOffsetA,
143
+ b2Shape* shapeB, b2Transform transformB, b2Vec2 centerOffsetB );
144
+
145
+ b2Manifold b2ComputeManifold( b2Shape* shapeA, b2Transform transformA, b2Shape* shapeB, b2Transform transformB );
146
+
147
+ B2_ARRAY_INLINE( b2Contact, b2Contact )
148
+ B2_ARRAY_INLINE( b2ContactSim, b2ContactSim )