mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
packing: Add an extending count at Extend
This commit is contained in:
parent
74902d47af
commit
61839506d8
@ -207,11 +207,14 @@ func walk(n *Node, f func(n *Node) error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Page) Extend() bool {
|
||||
func (p *Page) Extend(count int) bool {
|
||||
if p.size >= p.maxSize {
|
||||
return false
|
||||
}
|
||||
newSize := p.size * 2
|
||||
newSize := p.size
|
||||
for i := 0; i < count; i++ {
|
||||
newSize *= 2
|
||||
}
|
||||
edgeNodes := []*Node{}
|
||||
abort := errors.New("abort")
|
||||
aborted := false
|
||||
|
@ -257,7 +257,7 @@ func TestExtend(t *testing.T) {
|
||||
p := NewPage(1024, 4096)
|
||||
s := p.Size()
|
||||
p.Alloc(s/2, s/2)
|
||||
p.Extend()
|
||||
p.Extend(1)
|
||||
if p.Size() != s*2 {
|
||||
t.Errorf("p.Size(): got: %d, want: %d", p.Size(), s*2)
|
||||
}
|
||||
@ -281,7 +281,7 @@ func TestExtend2(t *testing.T) {
|
||||
p.Alloc(s/2, s/2)
|
||||
p.Free(n1)
|
||||
p.Free(n2)
|
||||
p.Extend()
|
||||
p.Extend(1)
|
||||
if p.Size() != s*2 {
|
||||
t.Errorf("p.Size(): got: %d, want: %d", p.Size(), s*2)
|
||||
}
|
||||
|
@ -91,16 +91,17 @@ type backend struct {
|
||||
}
|
||||
|
||||
func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
|
||||
// If the region is allocated without any extension, it's fine.
|
||||
// If the region is allocated without any extension, that's fine.
|
||||
if n := b.page.Alloc(width, height); n != nil {
|
||||
return n, true
|
||||
}
|
||||
|
||||
// Simulate the extending the page and calculate the appropriate page size.
|
||||
// By simulating, we can avoid unnecessary extention of underlying textures.
|
||||
page := b.page.Clone()
|
||||
nExtended := 0
|
||||
for {
|
||||
if !page.Extend() {
|
||||
if !page.Extend(1) {
|
||||
// The page can't be extended any more. Return as failure.
|
||||
return nil, false
|
||||
}
|
||||
@ -111,9 +112,7 @@ func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < nExtended; i++ {
|
||||
b.page.Extend()
|
||||
}
|
||||
b.page.Extend(nExtended)
|
||||
s := b.page.Size()
|
||||
b.restorable = b.restorable.Extend(s, s)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user