memleak fixed, colordance on deque

This commit is contained in:
anton.gurov 2019-10-31 15:45:52 +03:00
parent 96d6818754
commit 1c44dd0885
4 changed files with 48 additions and 64 deletions

View File

@ -1,7 +1,7 @@
package gamemap package gamemap
import ( import (
"container/ring" "github.com/gammazero/deque"
"lab.zaar.be/thefish/alchemyst-go/util" "lab.zaar.be/thefish/alchemyst-go/util"
) )
import blt "lab.zaar.be/thefish/bearlibterminal" import blt "lab.zaar.be/thefish/bearlibterminal"
@ -10,19 +10,28 @@ type ColorHolder interface {
GetColor() uint32 GetColor() uint32
} }
type cdeque struct {
deque.Deque
}
func (c *cdeque) Next() uint8 {
c.Rotate(1)
return c.Front().(uint8)
}
type DanceColorHolder struct { type DanceColorHolder struct {
A uint8 A uint8
R *ring.Ring R *cdeque
G *ring.Ring G *cdeque
B *ring.Ring B *cdeque
} }
func (chd *DanceColorHolder) GetColor() uint32 { func (chd *DanceColorHolder) GetColor() uint32 {
return blt.ColorFromARGB( return blt.ColorFromARGB(
chd.A, chd.A,
chd.R.Next().Value.(uint8), chd.R.Next(),
chd.G.Next().Value.(uint8), chd.G.Next(),
chd.B.Next().Value.(uint8), chd.B.Next(),
) )
} }
@ -68,13 +77,33 @@ type Tile struct {
Visible bool Visible bool
} }
func singleColorRing(colorValue uint8) *ring.Ring { func (t *Tile) GetChar() string {
r := ring.New(1) return t.Char
r.Next().Value = colorValue
return r
} }
func fillColorRing(colorValue uint8, minGlow, maxGlow, step int) *ring.Ring { func (t *Tile) GetRawColor() uint32 {
if t.Visible {
return t.Appearance.ColorSet.Fg.GetColor()
} else {
return t.Appearance.ColorSet.DarkFg.GetColor()
}
}
func (t *Tile) GetRawBgColor() uint32 {
if t.Visible {
return t.Appearance.ColorSet.Bg.GetColor()
} else {
return t.Appearance.ColorSet.DarkBg.GetColor()
}
}
func singleColorRing(colorValue uint8) *cdeque {
c := &cdeque{}
c.PushBack(colorValue)
return c
}
func fillColorRing(colorValue uint8, minGlow, maxGlow, step int) *cdeque {
q := make([]uint8, 0) q := make([]uint8, 0)
color := int(colorValue) color := int(colorValue)
for color < maxGlow { for color < maxGlow {
@ -88,19 +117,11 @@ func fillColorRing(colorValue uint8, minGlow, maxGlow, step int) *ring.Ring {
// color = crng.Range(1, step+minGlow) // color = crng.Range(1, step+minGlow)
//} //}
r := ring.New(len(q)) c := &cdeque{}
for _, v := range q { for _, v := range q {
r.Next().Value = v c.PushBack(uint8(v))
} }
return r return c
}
func colordance(colorValue uint8, minGlow, maxGlow, step int) uint8 {
color := crng.Range(0, step) + int(colorValue)
if color > maxGlow {
color = crng.Range(0, step) + minGlow
}
return uint8(color)
} }
func NewWall() *Tile { func NewWall() *Tile {
@ -164,14 +185,6 @@ func NewWaterTile() *Tile {
fillColorRing(19, 0, 15, 2), fillColorRing(19, 0, 15, 2),
fillColorRing(70, 120, 220, 12), fillColorRing(70, 120, 220, 12),
}, },
//Bg: func() uint32 {
// return blt.ColorFromARGB(
// 255,
// ch.R,
// colordance(ch.G, 0, 15, 2),
// colordance(ch.B, 120, 220, 12),
// )
//},
DarkFg: &PlainColorHolder{255, 30, 20, 50 }, DarkFg: &PlainColorHolder{255, 30, 20, 50 },
DarkBg: &PlainColorHolder{255, 7, 7, 30}, DarkBg: &PlainColorHolder{255, 7, 7, 30},
}, },
@ -199,37 +212,9 @@ func NewDeepWaterTile() *Tile {
fillColorRing(2,2,42,4), fillColorRing(2,2,42,4),
fillColorRing(154, 150, 229, 12), fillColorRing(154, 150, 229, 12),
}, },
//Bg: func() uint32 {
// return blt.ColorFromARGB(
// 255,
// ch.R,
// colordance(ch.G, 2, 42, 4),
// colordance(ch.B, 180, 229, 12),
// )
//},
DarkFg: &PlainColorHolder{255, 30, 20, 50}, DarkFg: &PlainColorHolder{255, 30, 20, 50},
DarkBg: &PlainColorHolder{255, 7, 7, 30}, DarkBg: &PlainColorHolder{255, 7, 7, 30},
}, },
}, },
} }
} }
func (t *Tile) GetChar() string {
return t.Char
}
func (t *Tile) GetRawColor() uint32 {
if !t.Visible {
return t.Appearance.ColorSet.Fg.GetColor()
} else {
return t.Appearance.ColorSet.DarkFg.GetColor()
}
}
func (t *Tile) GetRawBgColor() uint32 {
if !t.Visible {
return t.Appearance.ColorSet.Bg.GetColor()
} else {
return t.Appearance.ColorSet.DarkBg.GetColor()
}
}

2
go.mod
View File

@ -3,7 +3,7 @@ module lab.zaar.be/thefish/alchemyst-go
go 1.12 go 1.12
require ( require (
github.com/jcerise/gogue v0.0.0-20190708063629-bff568e35ab7 github.com/gammazero/deque v0.0.0-20190521012701-46e4ffb7a622
github.com/rs/zerolog v1.15.0 github.com/rs/zerolog v1.15.0
lab.zaar.be/thefish/bearlibterminal v0.0.0-20191018101635-dd37bbc90d77 lab.zaar.be/thefish/bearlibterminal v0.0.0-20191018101635-dd37bbc90d77
) )

4
go.sum
View File

@ -1,6 +1,6 @@
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/jcerise/gogue v0.0.0-20190708063629-bff568e35ab7 h1:TG/3V/P65tB8OZG74FueHTyWJuB3YPedeaBWh26xy1g= github.com/gammazero/deque v0.0.0-20190521012701-46e4ffb7a622 h1:lxbhOGZ9pU3Kf8P6lFluUcE82yVZn2EqEf4+mWRNPV0=
github.com/jcerise/gogue v0.0.0-20190708063629-bff568e35ab7/go.mod h1:k5qi7+cPUTmOtJwFGd7zRgjsbgDCO9btHgbW+I953N0= github.com/gammazero/deque v0.0.0-20190521012701-46e4ffb7a622/go.mod h1:D90+MBHVc9Sk1lJAbEVgws0eYEurY4mv2TDso3Nxh3w=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY= github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY=

1
vendor/github.com/jcerise/gogue generated vendored

@ -1 +0,0 @@
Subproject commit bff568e35ab7d105d7ccfe1d1301438513261a1b