Eager load used sprites

This commit is contained in:
2020-03-21 10:59:07 +00:00
parent 7a8e9dbd97
commit 8b02f534f1
3 changed files with 35 additions and 7 deletions

View File

@@ -62,6 +62,21 @@ func (a *AssetStore) Map(name string) (*Map, error) {
return m, nil
}
func (m *Map) LoadSprites() error {
// Eager load the sprites we use
for x := m.Rect.Min.X; x <= m.Rect.Max.X; x++ {
for y := m.Rect.Min.Y; y <= m.Rect.Max.Y; y++ {
for z := 0; z < maps.MaxHeight; z++ {
if _, err := m.SpritesForCell(x, y, z); err != nil {
return err
}
}
}
}
return nil
}
// SpritesForCell returns the sprites needed to correctly render this cell.
// They should be rendered from first to last to get the correct ordering
func (m *Map) SpritesForCell(x, y, z int) ([]*Sprite, error) {