add some useful logs to LoadAndPrepare

This commit is contained in:
Josh Deprez 2021-09-02 11:59:42 +10:00
parent 5116a10303
commit 0af38d6d91

View file

@ -6,10 +6,12 @@ import (
"fmt" "fmt"
"image" "image"
"io/fs" "io/fs"
"log"
"math" "math"
"reflect" "reflect"
"sort" "sort"
"sync" "sync"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
) )
@ -243,6 +245,7 @@ func walk(component, parent interface{}, visit func(component, parent interface{
// LoadAndPrepare must be called before any calls to Component or Query. // LoadAndPrepare must be called before any calls to Component or Query.
func (g *Game) LoadAndPrepare(assets fs.FS) error { func (g *Game) LoadAndPrepare(assets fs.FS) error {
// Load all the Loaders. // Load all the Loaders.
startLoad := time.Now()
if err := Walk(g, func(c, _ interface{}) error { if err := Walk(g, func(c, _ interface{}) error {
l, ok := c.(Loader) l, ok := c.(Loader)
if !ok { if !ok {
@ -252,8 +255,10 @@ func (g *Game) LoadAndPrepare(assets fs.FS) error {
}); err != nil { }); err != nil {
return err return err
} }
log.Printf("finished loading in %v", time.Since(startLoad))
// Build the component databases // Build the component databases
startBuild := time.Now()
g.dbmu.Lock() g.dbmu.Lock()
g.byID = make(map[string]Identifier) g.byID = make(map[string]Identifier)
g.byAB = make(map[abKey]map[interface{}]struct{}) g.byAB = make(map[abKey]map[interface{}]struct{})
@ -262,13 +267,16 @@ func (g *Game) LoadAndPrepare(assets fs.FS) error {
return err return err
} }
g.dbmu.Unlock() g.dbmu.Unlock()
log.Printf("finished building db in %v", time.Since(startBuild))
// Prepare all the Preppers // Prepare all the Preppers
startPrep := time.Now()
for p := range g.Query(g.Ident(), PrepperType) { for p := range g.Query(g.Ident(), PrepperType) {
if err := p.(Prepper).Prepare(g); err != nil { if err := p.(Prepper).Prepare(g); err != nil {
return err return err
} }
} }
log.Printf("finished preparing in %v", time.Since(startPrep))
return nil return nil
} }