mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
text: Refactoring: Remove some members from atlas
This commit is contained in:
parent
fd57753089
commit
842c535c01
56
text/text.go
56
text/text.go
@ -134,12 +134,6 @@ type atlas struct {
|
|||||||
size int
|
size int
|
||||||
|
|
||||||
charToGlyph map[char]*glyph
|
charToGlyph map[char]*glyph
|
||||||
|
|
||||||
// glyphs is the set of glyph information.
|
|
||||||
glyphs []*glyph
|
|
||||||
|
|
||||||
// num is the number of glyphs the atlas holds.
|
|
||||||
num int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *atlas) at(glyph *glyph) (int, int) {
|
func (a *atlas) at(glyph *glyph) (int, int) {
|
||||||
@ -152,43 +146,35 @@ func (a *atlas) at(glyph *glyph) (int, int) {
|
|||||||
return x * a.size, y * a.size
|
return x * a.size, y * a.size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *atlas) append(glyph *glyph) {
|
func (a *atlas) maxGlyphNum() int {
|
||||||
if a.num == len(a.glyphs) {
|
w, h := a.image.Size()
|
||||||
idx := -1
|
xnum := w / a.size
|
||||||
|
ynum := h / a.size
|
||||||
|
return xnum * ynum
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *atlas) append(g *glyph) {
|
||||||
|
if len(a.charToGlyph) == a.maxGlyphNum() {
|
||||||
|
var oldest *glyph
|
||||||
t := int64(math.MaxInt64)
|
t := int64(math.MaxInt64)
|
||||||
for i, g := range a.glyphs {
|
for _, g := range a.charToGlyph {
|
||||||
if g.atime < t {
|
if g.atime < t {
|
||||||
t = g.atime
|
t = g.atime
|
||||||
idx = i
|
oldest = g
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if idx < 0 {
|
if oldest == nil {
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
oldest := a.glyphs[idx]
|
idx := oldest.index
|
||||||
delete(a.charToGlyph, oldest.char)
|
delete(a.charToGlyph, oldest.char)
|
||||||
|
|
||||||
glyph.index = idx
|
g.index = idx
|
||||||
a.glyphs[idx] = glyph
|
} else {
|
||||||
a.charToGlyph[glyph.char] = glyph
|
g.index = len(a.charToGlyph)
|
||||||
a.draw(glyph)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
idx := -1
|
a.charToGlyph[g.char] = g
|
||||||
for i, g := range a.glyphs {
|
a.draw(g)
|
||||||
if g == nil {
|
|
||||||
idx = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if idx < 0 {
|
|
||||||
panic("not reached")
|
|
||||||
}
|
|
||||||
a.num++
|
|
||||||
glyph.index = idx
|
|
||||||
a.glyphs[idx] = glyph
|
|
||||||
a.charToGlyph[glyph.char] = glyph
|
|
||||||
a.draw(glyph)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *atlas) draw(glyph *glyph) {
|
func (a *atlas) draw(glyph *glyph) {
|
||||||
@ -253,10 +239,6 @@ func getGlyphFromCache(face font.Face, r rune, now int64) *glyph {
|
|||||||
size: g.char.atlasGroup(),
|
size: g.char.atlasGroup(),
|
||||||
charToGlyph: map[char]*glyph{},
|
charToGlyph: map[char]*glyph{},
|
||||||
}
|
}
|
||||||
w, h := a.image.Size()
|
|
||||||
xnum := w / a.size
|
|
||||||
ynum := h / a.size
|
|
||||||
a.glyphs = make([]*glyph, xnum*ynum)
|
|
||||||
atlases[g.char.atlasGroup()] = a
|
atlases[g.char.atlasGroup()] = a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user