Class: Gosu::BlockAllocator::Impl

Inherits:
Struct
  • Object
show all
Defined in:
lib/gosu_android/graphics/blockAllocator.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Impl

Returns a new instance of Impl.



7
8
9
10
11
12
# File 'lib/gosu_android/graphics/blockAllocator.rb', line 7

def initialize(*args)      
  old_initialize *args
  if self[:blocks] == nil
    self[:blocks] = Array.new
  end  
end

Instance Method Details

#is_block_free(block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gosu_android/graphics/blockAllocator.rb', line 23

def is_block_free(block)
  #(The right-th column and the bottom-th row are outside of the block.)
  right = block.left + block.width
  bottom = block.top + block.height

  #Block isn't valid.
  if (right > self[:width] || bottom > self[:height])
      return false
  end
  
  #Test if the block collides with any existing rects.
  self[:blocks].each do |i|
      if (i.left < right and block.left < i.left + i.width and
          i.top < bottom and block.top < i.top + i.height)
          return false
      end
  end
  true  
end

#mark_block_used(block, a_width, a_height) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/gosu_android/graphics/blockAllocator.rb', line 14

def mark_block_used(block, a_width, a_height)
  self[:first_x] += a_width
  if (self[:first_x] + a_width) >= self[:width]
    self[:first_x] = 0
    self[:first_y] += a_height
  end
  self[:blocks].push block     
end

#old_initializeObject



5
# File 'lib/gosu_android/graphics/blockAllocator.rb', line 5

alias :old_initialize :initialize