class Gosu::BlockAllocator
Public Class Methods
new(width, height)
click to toggle source
# File lib/gosu_android/graphics/blockAllocator.rb, line 48 def initialize(width, height) @pimpl = Impl.new(width, height, nil, 0, 0, width, height) end
Public Instance Methods
alloc(a_width, a_height)
click to toggle source
# File lib/gosu_android/graphics/blockAllocator.rb, line 60 def alloc(a_width, a_height) #The rect wouldn't even fit onto the texture! if a_width > width || a_height > height return [false] end #We know there's no space left. if a_width > @pimpl.max_w && a_height > @pimpl.max_h return [false] end #Start to look for a place next to the last returned rect. Chances are #good we'll find a place there. b = Block.new(@pimpl.first_x, @pimpl.first_y, a_width, a_height) if @pimpl.is_block_free(b) @pimpl.mark_block_used(b, a_width, a_height) return [true, b] end b.top = 0 b.left = 0 #Brute force: Look for a free place on this texture. while(b.top <= (height - a_height)) do while(b.left <= (width - a_width)) do if @pimpl.is_block_free(b) #Found a nice place! #Try to make up for the large for()-stepping. while (b.top > 0 and @pimpl.is_block_free(Block.new(b.left, b.top - 1, a_width, a_height))) do b.top -= 1 end while (b.left > 0 and @pimpl.is_block_free(Block.new(b.left - 1, b.top, a_width, a_height))) do b.left -= 1 end @pimpl.mark_block_used(b, a_width, a_height) return [true, b] end b.top += 16 b.left += 8 end end #So there was no space for the bitmap. Remember this for later. @pimpl.max_w = a_width - 1 @pimpl.max_h = a_height - 1 return [false] end
free(left, top)
click to toggle source
# File lib/gosu_android/graphics/blockAllocator.rb, line 106 def free (left, top) @pimpl.blocks.delete_if do |block| if block.left == left and block.top == top @pimpl.max_w = @pimpl.max_w - 1 @pimpl.max_h = @pimpl.max_h - 1 true else false end end end
height()
click to toggle source
# File lib/gosu_android/graphics/blockAllocator.rb, line 56 def height @pimpl.height end
width()
click to toggle source
# File lib/gosu_android/graphics/blockAllocator.rb, line 52 def width @pimpl.width end