mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) Extend() bool {
|
func (p *Page) Extend(count int) bool {
|
||||||
if p.size >= p.maxSize {
|
if p.size >= p.maxSize {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
newSize := p.size * 2
|
newSize := p.size
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
|
newSize *= 2
|
||||||
|
}
|
||||||
edgeNodes := []*Node{}
|
edgeNodes := []*Node{}
|
||||||
abort := errors.New("abort")
|
abort := errors.New("abort")
|
||||||
aborted := false
|
aborted := false
|
||||||
|
@ -257,7 +257,7 @@ func TestExtend(t *testing.T) {
|
|||||||
p := NewPage(1024, 4096)
|
p := NewPage(1024, 4096)
|
||||||
s := p.Size()
|
s := p.Size()
|
||||||
p.Alloc(s/2, s/2)
|
p.Alloc(s/2, s/2)
|
||||||
p.Extend()
|
p.Extend(1)
|
||||||
if p.Size() != s*2 {
|
if p.Size() != s*2 {
|
||||||
t.Errorf("p.Size(): got: %d, want: %d", 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.Alloc(s/2, s/2)
|
||||||
p.Free(n1)
|
p.Free(n1)
|
||||||
p.Free(n2)
|
p.Free(n2)
|
||||||
p.Extend()
|
p.Extend(1)
|
||||||
if p.Size() != s*2 {
|
if p.Size() != s*2 {
|
||||||
t.Errorf("p.Size(): got: %d, want: %d", 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) {
|
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 {
|
if n := b.page.Alloc(width, height); n != nil {
|
||||||
return n, true
|
return n, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulate the extending the page and calculate the appropriate page size.
|
// 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()
|
page := b.page.Clone()
|
||||||
nExtended := 0
|
nExtended := 0
|
||||||
for {
|
for {
|
||||||
if !page.Extend() {
|
if !page.Extend(1) {
|
||||||
// The page can't be extended any more. Return as failure.
|
// The page can't be extended any more. Return as failure.
|
||||||
return nil, false
|
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(nExtended)
|
||||||
b.page.Extend()
|
|
||||||
}
|
|
||||||
s := b.page.Size()
|
s := b.page.Size()
|
||||||
b.restorable = b.restorable.Extend(s, s)
|
b.restorable = b.restorable.Extend(s, s)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user