Module: Jolt::Native::QueryFunctions
- Defined in:
- lib/jolt/native/query_functions.rb
Class Method Summary collapse
- .attach(native) ⇒ Object
- .body_collector ⇒ Object
- .install_object_layer_filter(native) ⇒ Object
- .object_layer_filter(native, layer_ids, layer_count) ⇒ Object
Class Method Details
.attach(native) ⇒ Object
8 9 10 |
# File 'lib/jolt/native/query_functions.rb', line 8 def attach(native) install_object_layer_filter(native) end |
.body_collector ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/jolt/native/query_functions.rb', line 33 def body_collector hits = [] callback = FFI::Function.new(:float, %i[pointer uint32]) do |_context, body_id| hits << body_id 1.0 end [callback, hits] end |
.install_object_layer_filter(native) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jolt/native/query_functions.rb', line 22 def install_object_layer_filter(native) @object_layer_callback ||= FFI::Function.new(:bool, %i[pointer uint32]) do |context, layer| count = context.read_uint32 layer < count && context.get_uint8(layer + 4) == 1 end @object_layer_procs ||= ObjectLayerFilterProcs.new.tap do |procs| procs[:should_collide] = @object_layer_callback end native.JPH_ObjectLayerFilter_SetProcs(@object_layer_procs.pointer) end |
.object_layer_filter(native, layer_ids, layer_count) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/jolt/native/query_functions.rb', line 12 def object_layer_filter(native, layer_ids, layer_count) context = FFI::MemoryPointer.new(:uint8, layer_count + 4, true) context.write_uint32(layer_count) layer_ids.each { |id| context.put_uint8(id + 4, 1) } filter = native.JPH_ObjectLayerFilter_Create(context) raise InitializationError, "failed to create object layer filter" if filter.null? [filter, context] end |