Pass pointer to Colors struct around which makes it easier to eg. find transparent colors.

This commit is contained in:
Sascha L. Teichmann 2014-10-19 21:05:38 +02:00
parent 2a48fc3c35
commit c03d382ca6
4 changed files with 13 additions and 13 deletions

View File

@ -76,7 +76,7 @@ func main() {
numBlocks := 0
drawBlock := func(block *common.Block) {
if err := yOrder.RenderBlock(block, colors.NameIndex); err != nil {
if err := yOrder.RenderBlock(block, colors); err != nil {
log.Printf("WARN: rendering block failed: %s", err)
}
numBlocks++
@ -93,7 +93,7 @@ func main() {
if err = client.QueryCuboid(cuboid, drawBlock); err != nil {
log.Fatalf("query failed: %s", err)
}
if err = yOrder.Drain(colors.NameIndex); err != nil {
if err = yOrder.Drain(colors); err != nil {
log.Printf("WARN: rendering block failed: %s", err)
}
if renderer.IsFilled() {

View File

@ -76,7 +76,7 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) error {
btc.yOrder.Reset()
drawBlock := func(block *Block) {
if err := btc.yOrder.RenderBlock(block, btc.colors.NameIndex); err != nil {
if err := btc.yOrder.RenderBlock(block, btc.colors); err != nil {
log.Printf("WARN: rendering block failed: %s", err)
}
}
@ -109,7 +109,7 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) error {
if err := btc.client.QueryCuboid(query, drawBlock); err != nil {
return err
}
if err := btc.yOrder.Drain(btc.colors.NameIndex); err != nil {
if err := btc.yOrder.Drain(btc.colors); err != nil {
log.Printf("WARN: rendering block failed: %s", err)
}
}

View File

@ -63,7 +63,7 @@ type posBuf struct {
Pos int
}
func NewDecodedBlock(data []byte, nameIndex map[string]int32) (db *DecodedBlock, err error) {
func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error) {
version := data[0]
contentWidth := int(data[2])
@ -155,7 +155,7 @@ func NewDecodedBlock(data []byte, nameIndex map[string]int32) (db *DecodedBlock,
case "ignore":
ignoreId = nodeId
default:
if index, found := nameIndex[name]; found {
if index, found := colors.NameIndex[name]; found {
indexMap[nodeId] = index
} else {
log.Printf("Missing color entry for %s.", name)

View File

@ -58,18 +58,18 @@ func copyData(data []byte) []byte {
return ndata
}
func (yo *YOrder) RenderBlock(block *Block, nameIndex map[string]int32) (err error) {
func (yo *YOrder) RenderBlock(block *Block, colors *Colors) (err error) {
var nblock *Block
if len(yo.blocks) == yo.capacity {
oblock := yo.blocks[0]
if oblock.Coord.Y < block.Coord.Y {
// New one is above highest old. Directly render new.
err = yo.Renderer.RenderBlock(block, nameIndex)
err = yo.Renderer.RenderBlock(block, colors)
return
}
// Render old one. Store copy of new in heap.
heap.Pop(yo)
err = yo.Renderer.RenderBlock(oblock, nameIndex)
err = yo.Renderer.RenderBlock(oblock, colors)
l := len(block.Data)
if cap(oblock.Data) < l {
oblock.Data = make([]byte, l, max(l, 8*1024))
@ -87,9 +87,9 @@ func (yo *YOrder) RenderBlock(block *Block, nameIndex map[string]int32) (err err
return
}
func (yo *YOrder) Drain(nameIndex map[string]int32) (err error) {
func (yo *YOrder) Drain(colors *Colors) (err error) {
for len(yo.blocks) > 0 {
if err = yo.Renderer.RenderBlock(heap.Pop(yo).(*Block), nameIndex); err != nil {
if err = yo.Renderer.RenderBlock(heap.Pop(yo).(*Block), colors); err != nil {
return
}
}
@ -162,7 +162,7 @@ func (r *Renderer) IsFilled() bool {
return true
}
func (r *Renderer) RenderBlock(block *Block, nameIndex map[string]int32) (err error) {
func (r *Renderer) RenderBlock(block *Block, colors *Colors) (err error) {
bx := block.Coord.X - r.xOfs
bz := block.Coord.Z - r.zOfs
@ -178,7 +178,7 @@ func (r *Renderer) RenderBlock(block *Block, nameIndex map[string]int32) (err er
// Decoding is pretty expensive so do it that late.
var db *DecodedBlock
if db, err = NewDecodedBlock(block.Data, nameIndex); err != nil {
if db, err = NewDecodedBlock(block.Data, colors); err != nil {
return
}