Compare commits

...

1 commit

2 changed files with 53 additions and 8 deletions

View file

@ -77,7 +77,7 @@ func (t *Tri) Update(c *Context) {
}
tt := *t
tt.Spawned = true
tt.Visible = false
tt.Visible = true
tt.Disconnect()
if c.Spawn(&tt) == nil {
counter++

View file

@ -11,7 +11,7 @@ import (
)
const (
LayerBufSize = 0
LayerBufSize = 100
)
type GraphicsLibrary = ebiten.GraphicsLibrary
@ -115,6 +115,12 @@ func NewEngine(
ret.handleEvents = make(EventChan)
ret.Objects = &Objects{}
ret.buttons = MouseButtonMap{}
siz := ret.RealWinSize()
w, h := int(siz.X), int(siz.Y)
for i:=0 ; i<len(ret.bufs) ; i++ {
ret.bufs[i] = NewImage(w, h)
}
return ret
}
@ -295,7 +301,8 @@ func (e *engine) Update() error {
return nil
}
func (e *engine) Draw(i *ebiten.Image) {
func (e *engine) Draw(image *ebiten.Image) {
var wg sync.WaitGroup
e.dt = time.Since(e.lastTime).Seconds()
eng := (*Engine)(e)
m := map[Layer][]Drawer{}
@ -317,15 +324,53 @@ func (e *engine) Draw(i *ebiten.Image) {
// Drawing layers.
layers := maps.NewSparse[Layer, []Drawer](nil, m)
c := &Context{Engine: eng, typ: drawContext, Image: i}
for layer := range layers.Chan() {
ln := layers.Size()
pageN := ln / LayerBufSize
mod := ln % LayerBufSize
chn := layers.Chan()
opts := &ebiten.DrawImageOptions{GeoM: Matrix{}}
for n := 0 ; n<pageN ; n++ {
for i:=0 ; i<LayerBufSize ; i++ {
layer := <-chn
buf := e.bufs[i]
c := &Context{Engine: eng, typ: drawContext, Image: buf}
wg.Add(1)
go func() {
for _, drawer := range layer {
drawer.Draw(c)
}
wg.Done()
}()
}
wg.Wait()
for _, buf := range e.bufs {
image.DrawImage(buf, opts)
buf.Clear()
}
}
// Empty the buff to generate it again.
for i:=0 ; i<mod ; i++ {
layer := <-chn
buf := e.bufs[i]
c := &Context{Engine: eng, typ: drawContext, Image: buf}
wg.Add(1)
go func() {
for _, drawer := range layer {
drawer.Draw(c)
}
wg.Done()
}()
}
wg.Wait()
for i:=0 ; i<mod ; i++ {
buf := e.bufs[i]
image.DrawImage(buf, opts)
buf.Clear()
}
// Empty the camera buffer to generate it again.
eng.Camera.buffered = false
e.lastTime = time.Now()
}