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.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +336 -0
- data/examples/contact_events.rb +22 -0
- data/examples/debug_draw.rb +15 -0
- data/examples/falling_ball.rb +19 -0
- data/examples/rugl_debug_draw.rb +68 -0
- data/examples/stagecraft_debug_draw.rb +64 -0
- data/examples/support/box2d_debug_lines.rb +125 -0
- data/ext/box2d/CMakeLists.txt +35 -0
- data/ext/box2d/extconf.rb +42 -0
- data/ext/box2d/native.c +9 -0
- data/ext/box2d/vendor/box2d/LICENSE +21 -0
- data/ext/box2d/vendor/box2d/VERSION +1 -0
- data/ext/box2d/vendor/box2d/include/box2d/base.h +131 -0
- data/ext/box2d/vendor/box2d/include/box2d/box2d.h +1222 -0
- data/ext/box2d/vendor/box2d/include/box2d/collision.h +830 -0
- data/ext/box2d/vendor/box2d/include/box2d/id.h +144 -0
- data/ext/box2d/vendor/box2d/include/box2d/math_functions.h +761 -0
- data/ext/box2d/vendor/box2d/include/box2d/types.h +1457 -0
- data/ext/box2d/vendor/box2d/src/CMakeLists.txt +223 -0
- data/ext/box2d/vendor/box2d/src/aabb.c +132 -0
- data/ext/box2d/vendor/box2d/src/aabb.h +56 -0
- data/ext/box2d/vendor/box2d/src/arena_allocator.c +112 -0
- data/ext/box2d/vendor/box2d/src/arena_allocator.h +48 -0
- data/ext/box2d/vendor/box2d/src/array.c +8 -0
- data/ext/box2d/vendor/box2d/src/array.h +179 -0
- data/ext/box2d/vendor/box2d/src/atomic.h +79 -0
- data/ext/box2d/vendor/box2d/src/bitset.c +67 -0
- data/ext/box2d/vendor/box2d/src/bitset.h +65 -0
- data/ext/box2d/vendor/box2d/src/body.c +1884 -0
- data/ext/box2d/vendor/box2d/src/body.h +194 -0
- data/ext/box2d/vendor/box2d/src/box2d.natvis +41 -0
- data/ext/box2d/vendor/box2d/src/broad_phase.c +524 -0
- data/ext/box2d/vendor/box2d/src/broad_phase.h +83 -0
- data/ext/box2d/vendor/box2d/src/constants.h +54 -0
- data/ext/box2d/vendor/box2d/src/constraint_graph.c +322 -0
- data/ext/box2d/vendor/box2d/src/constraint_graph.h +58 -0
- data/ext/box2d/vendor/box2d/src/contact.c +650 -0
- data/ext/box2d/vendor/box2d/src/contact.h +148 -0
- data/ext/box2d/vendor/box2d/src/contact_solver.c +2120 -0
- data/ext/box2d/vendor/box2d/src/contact_solver.h +54 -0
- data/ext/box2d/vendor/box2d/src/core.c +178 -0
- data/ext/box2d/vendor/box2d/src/core.h +149 -0
- data/ext/box2d/vendor/box2d/src/ctz.h +112 -0
- data/ext/box2d/vendor/box2d/src/distance.c +1415 -0
- data/ext/box2d/vendor/box2d/src/distance_joint.c +556 -0
- data/ext/box2d/vendor/box2d/src/dynamic_tree.c +1989 -0
- data/ext/box2d/vendor/box2d/src/geometry.c +1028 -0
- data/ext/box2d/vendor/box2d/src/hull.c +328 -0
- data/ext/box2d/vendor/box2d/src/id_pool.c +79 -0
- data/ext/box2d/vendor/box2d/src/id_pool.h +35 -0
- data/ext/box2d/vendor/box2d/src/island.c +977 -0
- data/ext/box2d/vendor/box2d/src/island.h +89 -0
- data/ext/box2d/vendor/box2d/src/joint.c +1272 -0
- data/ext/box2d/vendor/box2d/src/joint.h +335 -0
- data/ext/box2d/vendor/box2d/src/manifold.c +1726 -0
- data/ext/box2d/vendor/box2d/src/math_functions.c +159 -0
- data/ext/box2d/vendor/box2d/src/motor_joint.c +283 -0
- data/ext/box2d/vendor/box2d/src/mouse_joint.c +214 -0
- data/ext/box2d/vendor/box2d/src/mover.c +73 -0
- data/ext/box2d/vendor/box2d/src/prismatic_joint.c +656 -0
- data/ext/box2d/vendor/box2d/src/revolute_joint.c +534 -0
- data/ext/box2d/vendor/box2d/src/sensor.c +389 -0
- data/ext/box2d/vendor/box2d/src/sensor.h +36 -0
- data/ext/box2d/vendor/box2d/src/shape.c +1714 -0
- data/ext/box2d/vendor/box2d/src/shape.h +123 -0
- data/ext/box2d/vendor/box2d/src/solver.c +2038 -0
- data/ext/box2d/vendor/box2d/src/solver.h +155 -0
- data/ext/box2d/vendor/box2d/src/solver_set.c +613 -0
- data/ext/box2d/vendor/box2d/src/solver_set.h +57 -0
- data/ext/box2d/vendor/box2d/src/table.c +238 -0
- data/ext/box2d/vendor/box2d/src/table.h +37 -0
- data/ext/box2d/vendor/box2d/src/timer.c +185 -0
- data/ext/box2d/vendor/box2d/src/types.c +151 -0
- data/ext/box2d/vendor/box2d/src/weld_joint.c +310 -0
- data/ext/box2d/vendor/box2d/src/wheel_joint.c +551 -0
- data/ext/box2d/vendor/box2d/src/world.c +3301 -0
- data/ext/box2d/vendor/box2d/src/world.h +192 -0
- data/generator/generate.rb +316 -0
- data/generator/layout_probe.c +507 -0
- data/generator/verify_layouts.rb +32 -0
- data/lib/box2d/body.rb +172 -0
- data/lib/box2d/body_definition.rb +38 -0
- data/lib/box2d/body_shapes.rb +135 -0
- data/lib/box2d/chain.rb +61 -0
- data/lib/box2d/debug_draw.rb +118 -0
- data/lib/box2d/events.rb +103 -0
- data/lib/box2d/fixed_stepper.rb +39 -0
- data/lib/box2d/handle.rb +46 -0
- data/lib/box2d/hit.rb +5 -0
- data/lib/box2d/joint.rb +197 -0
- data/lib/box2d/native.rb +1462 -0
- data/lib/box2d/native_loader.rb +45 -0
- data/lib/box2d/pixel_scale.rb +29 -0
- data/lib/box2d/shape.rb +109 -0
- data/lib/box2d/shape_definition.rb +44 -0
- data/lib/box2d/value_conversion.rb +80 -0
- data/lib/box2d/version.rb +7 -0
- data/lib/box2d/world.rb +135 -0
- data/lib/box2d/world_joints.rb +156 -0
- data/lib/box2d/world_queries.rb +122 -0
- data/lib/box2d/world_registry.rb +95 -0
- data/lib/box2d.rb +31 -0
- data/script/build_platform_gem.rb +24 -0
- data/script/deterministic_scene.rb +56 -0
- data/script/update_deterministic_snapshot.rb +11 -0
- data/script/verify_platform_gem.rb +24 -0
- metadata +164 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Box2D
|
|
4
|
+
module WorldQueries
|
|
5
|
+
def raycast(from, to, filter: {})
|
|
6
|
+
ensure_access!
|
|
7
|
+
origin = ValueConversion.native_vec2(from, label: "from")
|
|
8
|
+
destination = ValueConversion.native_vec2(to, label: "to")
|
|
9
|
+
translation = Native::Vec2.new
|
|
10
|
+
translation[:x] = destination[:x] - origin[:x]
|
|
11
|
+
translation[:y] = destination[:y] - origin[:y]
|
|
12
|
+
result = Native.b2World_CastRayClosest(@id, origin, translation, ShapeDefinition.query_filter(filter))
|
|
13
|
+
return unless result[:hit]
|
|
14
|
+
|
|
15
|
+
Hit.new(
|
|
16
|
+
shape: shape_for_id(result[:shapeId]),
|
|
17
|
+
point: ValueConversion.vec2(result[:point]),
|
|
18
|
+
normal: ValueConversion.vec2(result[:normal]),
|
|
19
|
+
fraction: result[:fraction]
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def overlap_aabb(lower, upper, filter: {}, &block)
|
|
24
|
+
return enum_for(__method__, lower, upper, filter:) unless block
|
|
25
|
+
|
|
26
|
+
ensure_access!
|
|
27
|
+
bounds = Native::AABB.new
|
|
28
|
+
bounds[:lowerBound] = ValueConversion.native_vec2(lower, label: "lower")
|
|
29
|
+
bounds[:upperBound] = ValueConversion.native_vec2(upper, label: "upper")
|
|
30
|
+
if bounds[:lowerBound][:x] > bounds[:upperBound][:x] || bounds[:lowerBound][:y] > bounds[:upperBound][:y]
|
|
31
|
+
raise ArgumentError, "lower AABB bound must not exceed upper bound"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
perform_overlap(block) do |callback|
|
|
35
|
+
Native.b2World_OverlapAABB(@id, bounds, ShapeDefinition.query_filter(filter), callback, nil)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def overlap_circle(center, radius:, filter: {}, &block)
|
|
40
|
+
return enum_for(__method__, center, radius:, filter:) unless block
|
|
41
|
+
|
|
42
|
+
ensure_access!
|
|
43
|
+
point = ValueConversion.native_vec2(center, label: "center")
|
|
44
|
+
proxy = Native.b2MakeProxy(
|
|
45
|
+
point.pointer,
|
|
46
|
+
1,
|
|
47
|
+
ValueConversion.positive_float(radius, label: "radius")
|
|
48
|
+
)
|
|
49
|
+
overlap_proxy(proxy, filter, block)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def overlap_capsule(point1, point2, radius:, filter: {}, &block)
|
|
53
|
+
return enum_for(__method__, point1, point2, radius:, filter:) unless block
|
|
54
|
+
|
|
55
|
+
ensure_access!
|
|
56
|
+
points, count = native_query_points([point1, point2], minimum: 2, maximum: 2)
|
|
57
|
+
proxy = Native.b2MakeProxy(
|
|
58
|
+
points,
|
|
59
|
+
count,
|
|
60
|
+
ValueConversion.positive_float(radius, label: "radius")
|
|
61
|
+
)
|
|
62
|
+
overlap_proxy(proxy, filter, block)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def overlap_polygon(points, position: [0, 0], angle: 0, radius: 0.0, filter: {}, &block)
|
|
66
|
+
return enum_for(__method__, points, position:, angle:, radius:, filter:) unless block
|
|
67
|
+
|
|
68
|
+
ensure_access!
|
|
69
|
+
point_buffer, count = native_query_points(points, minimum: 3, maximum: 8)
|
|
70
|
+
hull = Native.b2ComputeHull(point_buffer, count)
|
|
71
|
+
raise ArgumentError, "points do not form a valid convex hull" if hull[:count] < 3
|
|
72
|
+
|
|
73
|
+
proxy = Native.b2MakeOffsetProxy(
|
|
74
|
+
hull.pointer + Native::Hull.offset_of(:points),
|
|
75
|
+
hull[:count],
|
|
76
|
+
ValueConversion.non_negative_float(radius, label: "radius"),
|
|
77
|
+
ValueConversion.native_vec2(position, label: "position"),
|
|
78
|
+
ValueConversion.native_rot(angle)
|
|
79
|
+
)
|
|
80
|
+
overlap_proxy(proxy, filter, block)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def overlap_proxy(proxy, filter, block)
|
|
86
|
+
ensure_access!
|
|
87
|
+
perform_overlap(block) do |callback|
|
|
88
|
+
Native.b2World_OverlapShape(@id, proxy.pointer, ShapeDefinition.query_filter(filter), callback, nil)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def perform_overlap(block)
|
|
93
|
+
callback_error = nil
|
|
94
|
+
callback = FFI::Function.new(:bool, [Native::ShapeId.by_value, :pointer]) do |shape_id, _context|
|
|
95
|
+
begin
|
|
96
|
+
block.call(shape_for_id(shape_id)) != false
|
|
97
|
+
rescue Exception => error
|
|
98
|
+
callback_error ||= error
|
|
99
|
+
false
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
yield callback
|
|
103
|
+
raise callback_error if callback_error
|
|
104
|
+
|
|
105
|
+
self
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def native_query_points(points, minimum:, maximum:)
|
|
109
|
+
values = points.to_a
|
|
110
|
+
unless values.length.between?(minimum, maximum)
|
|
111
|
+
raise ArgumentError, "points must contain #{minimum}..#{maximum} vertices"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
pointer = FFI::MemoryPointer.new(Native::Vec2, values.length)
|
|
115
|
+
values.each_with_index do |point, index|
|
|
116
|
+
vector = ValueConversion.native_vec2(point, label: "points[#{index}]")
|
|
117
|
+
pointer.put_bytes(index * Native::Vec2.size, vector.pointer.read_bytes(Native::Vec2.size))
|
|
118
|
+
end
|
|
119
|
+
[pointer, values.length]
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Box2D
|
|
4
|
+
module WorldRegistry
|
|
5
|
+
def body_for_id(id)
|
|
6
|
+
key = ValueConversion.id_key(id)
|
|
7
|
+
@bodies[key] ||= Body.new(self, id)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def shape_for_id(id)
|
|
11
|
+
key = ValueConversion.id_key(id)
|
|
12
|
+
return @shapes[key] if @shapes.key?(key)
|
|
13
|
+
|
|
14
|
+
body = body_for_id(Native.b2Shape_GetBody(id)) if Native.b2Shape_IsValid(id)
|
|
15
|
+
@shapes[key] = Shape.new(self, id, body:)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def register_body(body)
|
|
19
|
+
@bodies[ValueConversion.id_key(body.id)] = body
|
|
20
|
+
body
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def register_shape(shape)
|
|
24
|
+
@shapes[ValueConversion.id_key(shape.id)] = shape
|
|
25
|
+
shape
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def register_chain(chain)
|
|
29
|
+
@chains[ValueConversion.id_key(chain.id)] = chain
|
|
30
|
+
chain
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def register_joint(joint)
|
|
34
|
+
@joints[ValueConversion.id_key(joint.id)] = joint
|
|
35
|
+
joint
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def unregister_body(body)
|
|
39
|
+
@bodies.delete(ValueConversion.id_key(body.id))
|
|
40
|
+
@body_user_data.delete(ValueConversion.id_key(body.id))
|
|
41
|
+
body.shapes.each { |shape| unregister_shape(shape) }
|
|
42
|
+
body.chains.each { |chain| unregister_chain(chain) }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def unregister_shape(shape)
|
|
46
|
+
key = ValueConversion.id_key(shape.id)
|
|
47
|
+
@shapes.delete(key)
|
|
48
|
+
@shape_user_data.delete(key)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def unregister_chain(chain)
|
|
52
|
+
@chains.delete(ValueConversion.id_key(chain.id))
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def unregister_joint(joint)
|
|
56
|
+
@joints.delete(ValueConversion.id_key(joint.id))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def body_user_data(body)
|
|
60
|
+
@body_user_data[ValueConversion.id_key(body.id)]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def set_body_user_data(body, value)
|
|
64
|
+
@body_user_data[ValueConversion.id_key(body.id)] = value
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def shape_user_data(shape)
|
|
68
|
+
@shape_user_data[ValueConversion.id_key(shape.id)]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def set_shape_user_data(shape, value)
|
|
72
|
+
@shape_user_data[ValueConversion.id_key(shape.id)] = value
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def initialize_registries
|
|
78
|
+
@bodies = {}
|
|
79
|
+
@shapes = {}
|
|
80
|
+
@chains = {}
|
|
81
|
+
@joints = {}
|
|
82
|
+
@body_user_data = {}
|
|
83
|
+
@shape_user_data = {}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def clear_registries
|
|
87
|
+
[@bodies, @shapes, @chains, @joints].each do |registry|
|
|
88
|
+
registry.each_value { |handle| handle.send(:invalidate!) }
|
|
89
|
+
registry.clear
|
|
90
|
+
end
|
|
91
|
+
@body_user_data.clear
|
|
92
|
+
@shape_user_data.clear
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
data/lib/box2d.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "box2d/version"
|
|
4
|
+
|
|
5
|
+
module Box2D
|
|
6
|
+
class Error < StandardError; end
|
|
7
|
+
class LoadError < Error; end
|
|
8
|
+
class UseAfterDestroyError < Error; end
|
|
9
|
+
class ReentrantStepError < Error; end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require_relative "box2d/native_loader"
|
|
13
|
+
require_relative "box2d/native"
|
|
14
|
+
require_relative "box2d/value_conversion"
|
|
15
|
+
require_relative "box2d/fixed_stepper"
|
|
16
|
+
require_relative "box2d/pixel_scale"
|
|
17
|
+
require_relative "box2d/handle"
|
|
18
|
+
require_relative "box2d/shape_definition"
|
|
19
|
+
require_relative "box2d/shape"
|
|
20
|
+
require_relative "box2d/chain"
|
|
21
|
+
require_relative "box2d/body_shapes"
|
|
22
|
+
require_relative "box2d/body"
|
|
23
|
+
require_relative "box2d/joint"
|
|
24
|
+
require_relative "box2d/events"
|
|
25
|
+
require_relative "box2d/hit"
|
|
26
|
+
require_relative "box2d/debug_draw"
|
|
27
|
+
require_relative "box2d/world_registry"
|
|
28
|
+
require_relative "box2d/body_definition"
|
|
29
|
+
require_relative "box2d/world_joints"
|
|
30
|
+
require_relative "box2d/world_queries"
|
|
31
|
+
require_relative "box2d/world"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "rbconfig"
|
|
5
|
+
require "rubygems/package"
|
|
6
|
+
|
|
7
|
+
root = File.expand_path("..", __dir__)
|
|
8
|
+
extension = "native.#{RbConfig::CONFIG.fetch("DLEXT")}"
|
|
9
|
+
compiled_library = File.join(root, "ext/box2d", extension)
|
|
10
|
+
packaged_library = File.join(root, "lib/box2d", extension)
|
|
11
|
+
abort "compile the native library before packaging" unless File.file?(compiled_library)
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
FileUtils.cp(compiled_library, packaged_library)
|
|
15
|
+
ENV["BOX2D_PRECOMPILED"] = "true"
|
|
16
|
+
specification = Gem::Specification.load(File.join(root, "box2d.gemspec"))
|
|
17
|
+
gem_file = Gem::Package.build(specification)
|
|
18
|
+
FileUtils.mkdir_p(File.join(root, "pkg"))
|
|
19
|
+
destination = File.join(root, "pkg", File.basename(gem_file))
|
|
20
|
+
FileUtils.mv(gem_file, destination)
|
|
21
|
+
puts destination
|
|
22
|
+
ensure
|
|
23
|
+
FileUtils.rm_f(packaged_library)
|
|
24
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rbconfig"
|
|
4
|
+
|
|
5
|
+
module DeterministicScene
|
|
6
|
+
SEED = 12_345
|
|
7
|
+
BODY_COUNT = 100
|
|
8
|
+
STEPS = 240
|
|
9
|
+
TIME_STEP = 1.0 / 60
|
|
10
|
+
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
def capture
|
|
14
|
+
random = Random.new(SEED)
|
|
15
|
+
world = Box2D::World.new
|
|
16
|
+
world.create_body(position: [0, -1]) { |body| body.box(20, 1) }
|
|
17
|
+
bodies = BODY_COUNT.times.map do |index|
|
|
18
|
+
column = index % 10
|
|
19
|
+
row = index / 10
|
|
20
|
+
x = column - 4.5 + random.rand(-0.04..0.04)
|
|
21
|
+
y = row + 0.6 + random.rand(0.0..0.04)
|
|
22
|
+
angle = random.rand(-0.03..0.03)
|
|
23
|
+
world.create_body(type: :dynamic, position: [x, y], angle:) do |body|
|
|
24
|
+
body.box(0.4, 0.4, density: 1.0, friction: 0.6)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
STEPS.times { world.step(TIME_STEP) }
|
|
28
|
+
bodies.map { |body| body.position.to_a }
|
|
29
|
+
ensure
|
|
30
|
+
world&.destroy if world&.valid?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def platform
|
|
34
|
+
cpu = RbConfig::CONFIG.fetch("host_cpu")
|
|
35
|
+
os = RbConfig::CONFIG.fetch("host_os")
|
|
36
|
+
return "#{darwin_cpu(cpu)}-darwin" if os.include?("darwin")
|
|
37
|
+
return "#{linux_cpu(cpu)}-linux" if os.include?("linux")
|
|
38
|
+
return "x64-mingw-ucrt" if os.match?(/mingw|mswin/)
|
|
39
|
+
|
|
40
|
+
"#{cpu}-#{os}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def snapshot_path
|
|
44
|
+
File.expand_path("../spec/snapshots/100_boxes/#{platform}.json", __dir__)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def darwin_cpu(cpu)
|
|
48
|
+
cpu.match?(/arm|aarch64/) ? "arm64" : "x86_64"
|
|
49
|
+
end
|
|
50
|
+
private_class_method :darwin_cpu
|
|
51
|
+
|
|
52
|
+
def linux_cpu(cpu)
|
|
53
|
+
cpu.match?(/arm|aarch64/) ? "aarch64" : "x86_64"
|
|
54
|
+
end
|
|
55
|
+
private_class_method :linux_cpu
|
|
56
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require_relative "../lib/box2d"
|
|
6
|
+
require_relative "deterministic_scene"
|
|
7
|
+
|
|
8
|
+
path = DeterministicScene.snapshot_path
|
|
9
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
10
|
+
File.write(path, JSON.pretty_generate(DeterministicScene.capture) << "\n")
|
|
11
|
+
puts path
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "tmpdir"
|
|
4
|
+
require "rbconfig"
|
|
5
|
+
require "rubygems/package"
|
|
6
|
+
|
|
7
|
+
gem_path = File.expand_path(ARGV.fetch(0))
|
|
8
|
+
abort "platform gem does not exist: #{gem_path}" unless File.file?(gem_path)
|
|
9
|
+
|
|
10
|
+
specification = Gem::Package.new(gem_path).spec
|
|
11
|
+
if specification.platform == Gem::Platform::RUBY
|
|
12
|
+
abort "expected a platform gem, got the source gem: #{gem_path}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Dir.mktmpdir("box2d-platform-gem") do |directory|
|
|
16
|
+
Gem::Package.new(gem_path).extract_files(directory)
|
|
17
|
+
native_library = Dir[File.join(directory, "lib/box2d/native.{bundle,so,dll}")].first
|
|
18
|
+
abort "platform gem does not contain a native library" unless native_library
|
|
19
|
+
|
|
20
|
+
rspec = Gem.bin_path("rspec-core", "rspec")
|
|
21
|
+
environment = {"BOX2D_LIBRARY_PATH" => native_library}
|
|
22
|
+
success = system(environment, RbConfig.ruby, rspec, "--format", "progress")
|
|
23
|
+
abort "specs failed against #{File.basename(gem_path)}" unless success
|
|
24
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: box2d-ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yudai Takada
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: ffi
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.17'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.17'
|
|
26
|
+
description: A generated FFI binding and memory-safe Ruby API for Box2D v3.
|
|
27
|
+
email:
|
|
28
|
+
- t.yudai92@gmail.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions:
|
|
31
|
+
- ext/box2d/extconf.rb
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- LICENSE.txt
|
|
35
|
+
- README.md
|
|
36
|
+
- examples/contact_events.rb
|
|
37
|
+
- examples/debug_draw.rb
|
|
38
|
+
- examples/falling_ball.rb
|
|
39
|
+
- examples/rugl_debug_draw.rb
|
|
40
|
+
- examples/stagecraft_debug_draw.rb
|
|
41
|
+
- examples/support/box2d_debug_lines.rb
|
|
42
|
+
- ext/box2d/CMakeLists.txt
|
|
43
|
+
- ext/box2d/extconf.rb
|
|
44
|
+
- ext/box2d/native.c
|
|
45
|
+
- ext/box2d/vendor/box2d/LICENSE
|
|
46
|
+
- ext/box2d/vendor/box2d/VERSION
|
|
47
|
+
- ext/box2d/vendor/box2d/include/box2d/base.h
|
|
48
|
+
- ext/box2d/vendor/box2d/include/box2d/box2d.h
|
|
49
|
+
- ext/box2d/vendor/box2d/include/box2d/collision.h
|
|
50
|
+
- ext/box2d/vendor/box2d/include/box2d/id.h
|
|
51
|
+
- ext/box2d/vendor/box2d/include/box2d/math_functions.h
|
|
52
|
+
- ext/box2d/vendor/box2d/include/box2d/types.h
|
|
53
|
+
- ext/box2d/vendor/box2d/src/CMakeLists.txt
|
|
54
|
+
- ext/box2d/vendor/box2d/src/aabb.c
|
|
55
|
+
- ext/box2d/vendor/box2d/src/aabb.h
|
|
56
|
+
- ext/box2d/vendor/box2d/src/arena_allocator.c
|
|
57
|
+
- ext/box2d/vendor/box2d/src/arena_allocator.h
|
|
58
|
+
- ext/box2d/vendor/box2d/src/array.c
|
|
59
|
+
- ext/box2d/vendor/box2d/src/array.h
|
|
60
|
+
- ext/box2d/vendor/box2d/src/atomic.h
|
|
61
|
+
- ext/box2d/vendor/box2d/src/bitset.c
|
|
62
|
+
- ext/box2d/vendor/box2d/src/bitset.h
|
|
63
|
+
- ext/box2d/vendor/box2d/src/body.c
|
|
64
|
+
- ext/box2d/vendor/box2d/src/body.h
|
|
65
|
+
- ext/box2d/vendor/box2d/src/box2d.natvis
|
|
66
|
+
- ext/box2d/vendor/box2d/src/broad_phase.c
|
|
67
|
+
- ext/box2d/vendor/box2d/src/broad_phase.h
|
|
68
|
+
- ext/box2d/vendor/box2d/src/constants.h
|
|
69
|
+
- ext/box2d/vendor/box2d/src/constraint_graph.c
|
|
70
|
+
- ext/box2d/vendor/box2d/src/constraint_graph.h
|
|
71
|
+
- ext/box2d/vendor/box2d/src/contact.c
|
|
72
|
+
- ext/box2d/vendor/box2d/src/contact.h
|
|
73
|
+
- ext/box2d/vendor/box2d/src/contact_solver.c
|
|
74
|
+
- ext/box2d/vendor/box2d/src/contact_solver.h
|
|
75
|
+
- ext/box2d/vendor/box2d/src/core.c
|
|
76
|
+
- ext/box2d/vendor/box2d/src/core.h
|
|
77
|
+
- ext/box2d/vendor/box2d/src/ctz.h
|
|
78
|
+
- ext/box2d/vendor/box2d/src/distance.c
|
|
79
|
+
- ext/box2d/vendor/box2d/src/distance_joint.c
|
|
80
|
+
- ext/box2d/vendor/box2d/src/dynamic_tree.c
|
|
81
|
+
- ext/box2d/vendor/box2d/src/geometry.c
|
|
82
|
+
- ext/box2d/vendor/box2d/src/hull.c
|
|
83
|
+
- ext/box2d/vendor/box2d/src/id_pool.c
|
|
84
|
+
- ext/box2d/vendor/box2d/src/id_pool.h
|
|
85
|
+
- ext/box2d/vendor/box2d/src/island.c
|
|
86
|
+
- ext/box2d/vendor/box2d/src/island.h
|
|
87
|
+
- ext/box2d/vendor/box2d/src/joint.c
|
|
88
|
+
- ext/box2d/vendor/box2d/src/joint.h
|
|
89
|
+
- ext/box2d/vendor/box2d/src/manifold.c
|
|
90
|
+
- ext/box2d/vendor/box2d/src/math_functions.c
|
|
91
|
+
- ext/box2d/vendor/box2d/src/motor_joint.c
|
|
92
|
+
- ext/box2d/vendor/box2d/src/mouse_joint.c
|
|
93
|
+
- ext/box2d/vendor/box2d/src/mover.c
|
|
94
|
+
- ext/box2d/vendor/box2d/src/prismatic_joint.c
|
|
95
|
+
- ext/box2d/vendor/box2d/src/revolute_joint.c
|
|
96
|
+
- ext/box2d/vendor/box2d/src/sensor.c
|
|
97
|
+
- ext/box2d/vendor/box2d/src/sensor.h
|
|
98
|
+
- ext/box2d/vendor/box2d/src/shape.c
|
|
99
|
+
- ext/box2d/vendor/box2d/src/shape.h
|
|
100
|
+
- ext/box2d/vendor/box2d/src/solver.c
|
|
101
|
+
- ext/box2d/vendor/box2d/src/solver.h
|
|
102
|
+
- ext/box2d/vendor/box2d/src/solver_set.c
|
|
103
|
+
- ext/box2d/vendor/box2d/src/solver_set.h
|
|
104
|
+
- ext/box2d/vendor/box2d/src/table.c
|
|
105
|
+
- ext/box2d/vendor/box2d/src/table.h
|
|
106
|
+
- ext/box2d/vendor/box2d/src/timer.c
|
|
107
|
+
- ext/box2d/vendor/box2d/src/types.c
|
|
108
|
+
- ext/box2d/vendor/box2d/src/weld_joint.c
|
|
109
|
+
- ext/box2d/vendor/box2d/src/wheel_joint.c
|
|
110
|
+
- ext/box2d/vendor/box2d/src/world.c
|
|
111
|
+
- ext/box2d/vendor/box2d/src/world.h
|
|
112
|
+
- generator/generate.rb
|
|
113
|
+
- generator/layout_probe.c
|
|
114
|
+
- generator/verify_layouts.rb
|
|
115
|
+
- lib/box2d.rb
|
|
116
|
+
- lib/box2d/body.rb
|
|
117
|
+
- lib/box2d/body_definition.rb
|
|
118
|
+
- lib/box2d/body_shapes.rb
|
|
119
|
+
- lib/box2d/chain.rb
|
|
120
|
+
- lib/box2d/debug_draw.rb
|
|
121
|
+
- lib/box2d/events.rb
|
|
122
|
+
- lib/box2d/fixed_stepper.rb
|
|
123
|
+
- lib/box2d/handle.rb
|
|
124
|
+
- lib/box2d/hit.rb
|
|
125
|
+
- lib/box2d/joint.rb
|
|
126
|
+
- lib/box2d/native.rb
|
|
127
|
+
- lib/box2d/native_loader.rb
|
|
128
|
+
- lib/box2d/pixel_scale.rb
|
|
129
|
+
- lib/box2d/shape.rb
|
|
130
|
+
- lib/box2d/shape_definition.rb
|
|
131
|
+
- lib/box2d/value_conversion.rb
|
|
132
|
+
- lib/box2d/version.rb
|
|
133
|
+
- lib/box2d/world.rb
|
|
134
|
+
- lib/box2d/world_joints.rb
|
|
135
|
+
- lib/box2d/world_queries.rb
|
|
136
|
+
- lib/box2d/world_registry.rb
|
|
137
|
+
- script/build_platform_gem.rb
|
|
138
|
+
- script/deterministic_scene.rb
|
|
139
|
+
- script/update_deterministic_snapshot.rb
|
|
140
|
+
- script/verify_platform_gem.rb
|
|
141
|
+
homepage: https://rubygems.org/gems/box2d-ruby
|
|
142
|
+
licenses:
|
|
143
|
+
- MIT
|
|
144
|
+
metadata:
|
|
145
|
+
rubygems_mfa_required: 'true'
|
|
146
|
+
homepage_uri: https://rubygems.org/gems/box2d-ruby
|
|
147
|
+
rdoc_options: []
|
|
148
|
+
require_paths:
|
|
149
|
+
- lib
|
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
|
+
requirements:
|
|
152
|
+
- - ">="
|
|
153
|
+
- !ruby/object:Gem::Version
|
|
154
|
+
version: 3.2.0
|
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
requirements: []
|
|
161
|
+
rubygems_version: 4.0.6
|
|
162
|
+
specification_version: 4
|
|
163
|
+
summary: Idiomatic Ruby bindings for the Box2D v3 physics engine
|
|
164
|
+
test_files: []
|