Class: TCOD::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/libtcod/map.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#ptrObject (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

#destinationObject



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

#empty?Boolean

Returns:

  • (Boolean)


72
# File 'lib/libtcod/map.rb', line 72

def empty?; TCOD.path_is_empty(@ptr); end

#originObject



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

#sizeObject



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