60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/gosu_android/graphics/blockAllocator.rb', line 60
def alloc(a_width, a_height)
if a_width > width || a_height > height
return [false]
end
if a_width > @pimpl.max_w && a_height > @pimpl.max_h
return [false]
end
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
while(b.top <= (height - a_height)) do
while(b.left <= (width - a_width)) do
if @pimpl.is_block_free(b)
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
@pimpl.max_w = a_width - 1
@pimpl.max_h = a_height - 1
return [false]
end
|