Module: Box2D::WorldRegistry

Included in:
World
Defined in:
lib/box2d/world_registry.rb

Instance Method Summary collapse

Instance Method Details

#body_for_id(id) ⇒ Object



5
6
7
8
# File 'lib/box2d/world_registry.rb', line 5

def body_for_id(id)
  key = ValueConversion.id_key(id)
  @bodies[key] ||= Body.new(self, id)
end

#body_user_data(body) ⇒ Object



59
60
61
# File 'lib/box2d/world_registry.rb', line 59

def body_user_data(body)
  @body_user_data[ValueConversion.id_key(body.id)]
end

#register_body(body) ⇒ Object



18
19
20
21
# File 'lib/box2d/world_registry.rb', line 18

def register_body(body)
  @bodies[ValueConversion.id_key(body.id)] = body
  body
end

#register_chain(chain) ⇒ Object



28
29
30
31
# File 'lib/box2d/world_registry.rb', line 28

def register_chain(chain)
  @chains[ValueConversion.id_key(chain.id)] = chain
  chain
end

#register_joint(joint) ⇒ Object



33
34
35
36
# File 'lib/box2d/world_registry.rb', line 33

def register_joint(joint)
  @joints[ValueConversion.id_key(joint.id)] = joint
  joint
end

#register_shape(shape) ⇒ Object



23
24
25
26
# File 'lib/box2d/world_registry.rb', line 23

def register_shape(shape)
  @shapes[ValueConversion.id_key(shape.id)] = shape
  shape
end

#set_body_user_data(body, value) ⇒ Object



63
64
65
# File 'lib/box2d/world_registry.rb', line 63

def set_body_user_data(body, value)
  @body_user_data[ValueConversion.id_key(body.id)] = value
end

#set_shape_user_data(shape, value) ⇒ Object



71
72
73
# File 'lib/box2d/world_registry.rb', line 71

def set_shape_user_data(shape, value)
  @shape_user_data[ValueConversion.id_key(shape.id)] = value
end

#shape_for_id(id) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/box2d/world_registry.rb', line 10

def shape_for_id(id)
  key = ValueConversion.id_key(id)
  return @shapes[key] if @shapes.key?(key)

  body = body_for_id(Native.b2Shape_GetBody(id)) if Native.b2Shape_IsValid(id)
  @shapes[key] = Shape.new(self, id, body:)
end

#shape_user_data(shape) ⇒ Object



67
68
69
# File 'lib/box2d/world_registry.rb', line 67

def shape_user_data(shape)
  @shape_user_data[ValueConversion.id_key(shape.id)]
end

#unregister_body(body) ⇒ Object



38
39
40
41
42
43
# File 'lib/box2d/world_registry.rb', line 38

def unregister_body(body)
  @bodies.delete(ValueConversion.id_key(body.id))
  @body_user_data.delete(ValueConversion.id_key(body.id))
  body.shapes.each { |shape| unregister_shape(shape) }
  body.chains.each { |chain| unregister_chain(chain) }
end

#unregister_chain(chain) ⇒ Object



51
52
53
# File 'lib/box2d/world_registry.rb', line 51

def unregister_chain(chain)
  @chains.delete(ValueConversion.id_key(chain.id))
end

#unregister_joint(joint) ⇒ Object



55
56
57
# File 'lib/box2d/world_registry.rb', line 55

def unregister_joint(joint)
  @joints.delete(ValueConversion.id_key(joint.id))
end

#unregister_shape(shape) ⇒ Object



45
46
47
48
49
# File 'lib/box2d/world_registry.rb', line 45

def unregister_shape(shape)
  key = ValueConversion.id_key(shape.id)
  @shapes.delete(key)
  @shape_user_data.delete(key)
end