Class: TCOD::Path
- Inherits:
-
Object
- Object
- TCOD::Path
- Defined in:
- lib/libtcod/map.rb
Instance Attribute Summary collapse
-
#ptr ⇒ Object
readonly
Returns the value of attribute ptr.
Class Method Summary collapse
- .by_callback(width, height, user_data = nil, diagonalCost = 1.41, &b) ⇒ Object
- .by_map(tcod_map, diagonalCost = 1.41) ⇒ Object
- .finalize(ptr) ⇒ Object
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#compute(ox, oy, dx, dy) ⇒ Object
Compute a path between two points ox, oy - Coordinates of the origin of the path dx, dy - Coordinates of the destination of the path Returns false if there is no possible path.
- #destination ⇒ Object
-
#each(&b) ⇒ Object
Custom additions.
- #empty? ⇒ Boolean
-
#initialize(ptr) ⇒ Path
constructor
Generally shouldn’t be called directly.
- #origin ⇒ Object
- #reverse! ⇒ Object
- #size ⇒ Object
- #walk(recalculate_when_needed = true) ⇒ Object
Constructor Details
#initialize(ptr) ⇒ Path
Generally shouldn’t be called directly
48 49 50 51 52 |
# File 'lib/libtcod/map.rb', line 48 def initialize(ptr) @ptr = ptr ObjectSpace.define_finalizer(self, self.class.finalize(ptr)) end |
Instance Attribute Details
#ptr ⇒ Object (readonly)
Returns the value of attribute ptr.
37 38 39 |
# File 'lib/libtcod/map.rb', line 37 def ptr @ptr end |
Class Method Details
.by_callback(width, height, user_data = nil, diagonalCost = 1.41, &b) ⇒ Object
43 44 45 |
# File 'lib/libtcod/map.rb', line 43 def self.by_callback(width, height, user_data=nil, diagonalCost=1.41, &b) Path.new TCOD.path_new_using_function(width, height, b, user_data, diagonalCost) end |
.by_map(tcod_map, diagonalCost = 1.41) ⇒ Object
39 40 41 |
# File 'lib/libtcod/map.rb', line 39 def self.by_map(tcod_map, diagonalCost=1.41) Path.new TCOD.path_new_using_map(tcod_map.ptr, diagonalCost) end |
.finalize(ptr) ⇒ Object
97 98 99 |
# File 'lib/libtcod/map.rb', line 97 def self.finalize(ptr) proc { TCOD.path_delete(ptr) } end |
Instance Method Details
#[](index) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/libtcod/map.rb', line 76 def [](index) px = FFI::MemoryPointer.new(:int) py = FFI::MemoryPointer.new(:int) TCOD.path_get(@ptr, index, px, py) [px.read_int, py.read_int] end |
#compute(ox, oy, dx, dy) ⇒ Object
Compute a path between two points ox, oy - Coordinates of the origin of the path dx, dy - Coordinates of the destination of the path Returns false if there is no possible path.
58 59 60 |
# File 'lib/libtcod/map.rb', line 58 def compute(ox, oy, dx, dy) TCOD.path_compute(@ptr, ox, oy, dx, dy) end |
#destination ⇒ Object
90 91 92 93 94 95 |
# File 'lib/libtcod/map.rb', line 90 def destination px = FFI::MemoryPointer.new(:int) py = FFI::MemoryPointer.new(:int) TCOD.path_get_destination(@ptr, px, py) [px.read_int, py.read_int] end |
#each(&b) ⇒ Object
Custom additions
102 103 104 105 106 |
# File 'lib/libtcod/map.rb', line 102 def each(&b) 0.upto(self.size-1) do |i| yield self[i] end end |
#origin ⇒ Object
83 84 85 86 87 88 |
# File 'lib/libtcod/map.rb', line 83 def origin px = FFI::MemoryPointer.new(:int) py = FFI::MemoryPointer.new(:int) TCOD.path_get_origin(@ptr, px, py) [px.read_int, py.read_int] end |
#reverse! ⇒ Object
74 |
# File 'lib/libtcod/map.rb', line 74 def reverse!; TCOD.path_reverse(@ptr); end |
#size ⇒ Object
73 |
# File 'lib/libtcod/map.rb', line 73 def size; TCOD.path_size(@ptr); end |
#walk(recalculate_when_needed = true) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/libtcod/map.rb', line 62 def walk(recalculate_when_needed=true) px = FFI::MemoryPointer.new(:int) py = FFI::MemoryPointer.new(:int) if TCOD.path_walk(@ptr, px, py, recalculate_when_needed) [px.read_int, py.read_int] else false end end |