mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-22 06:10:26 +01:00
Pass pointer to Colors struct around which makes it easier to eg. find transparent colors.
This commit is contained in:
parent
2a48fc3c35
commit
c03d382ca6
@ -76,7 +76,7 @@ func main() {
|
|||||||
|
|
||||||
numBlocks := 0
|
numBlocks := 0
|
||||||
drawBlock := func(block *common.Block) {
|
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)
|
log.Printf("WARN: rendering block failed: %s", err)
|
||||||
}
|
}
|
||||||
numBlocks++
|
numBlocks++
|
||||||
@ -93,7 +93,7 @@ func main() {
|
|||||||
if err = client.QueryCuboid(cuboid, drawBlock); err != nil {
|
if err = client.QueryCuboid(cuboid, drawBlock); err != nil {
|
||||||
log.Fatalf("query failed: %s", err)
|
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)
|
log.Printf("WARN: rendering block failed: %s", err)
|
||||||
}
|
}
|
||||||
if renderer.IsFilled() {
|
if renderer.IsFilled() {
|
||||||
|
@ -76,7 +76,7 @@ func (btc *BaseTileCreator) CreateTile(x, z int16, i, j int) error {
|
|||||||
btc.yOrder.Reset()
|
btc.yOrder.Reset()
|
||||||
|
|
||||||
drawBlock := func(block *Block) {
|
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)
|
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 {
|
if err := btc.client.QueryCuboid(query, drawBlock); err != nil {
|
||||||
return err
|
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)
|
log.Printf("WARN: rendering block failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ type posBuf struct {
|
|||||||
Pos int
|
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]
|
version := data[0]
|
||||||
|
|
||||||
contentWidth := int(data[2])
|
contentWidth := int(data[2])
|
||||||
@ -155,7 +155,7 @@ func NewDecodedBlock(data []byte, nameIndex map[string]int32) (db *DecodedBlock,
|
|||||||
case "ignore":
|
case "ignore":
|
||||||
ignoreId = nodeId
|
ignoreId = nodeId
|
||||||
default:
|
default:
|
||||||
if index, found := nameIndex[name]; found {
|
if index, found := colors.NameIndex[name]; found {
|
||||||
indexMap[nodeId] = index
|
indexMap[nodeId] = index
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Missing color entry for %s.", name)
|
log.Printf("Missing color entry for %s.", name)
|
||||||
|
@ -58,18 +58,18 @@ func copyData(data []byte) []byte {
|
|||||||
return ndata
|
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
|
var nblock *Block
|
||||||
if len(yo.blocks) == yo.capacity {
|
if len(yo.blocks) == yo.capacity {
|
||||||
oblock := yo.blocks[0]
|
oblock := yo.blocks[0]
|
||||||
if oblock.Coord.Y < block.Coord.Y {
|
if oblock.Coord.Y < block.Coord.Y {
|
||||||
// New one is above highest old. Directly render new.
|
// New one is above highest old. Directly render new.
|
||||||
err = yo.Renderer.RenderBlock(block, nameIndex)
|
err = yo.Renderer.RenderBlock(block, colors)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Render old one. Store copy of new in heap.
|
// Render old one. Store copy of new in heap.
|
||||||
heap.Pop(yo)
|
heap.Pop(yo)
|
||||||
err = yo.Renderer.RenderBlock(oblock, nameIndex)
|
err = yo.Renderer.RenderBlock(oblock, colors)
|
||||||
l := len(block.Data)
|
l := len(block.Data)
|
||||||
if cap(oblock.Data) < l {
|
if cap(oblock.Data) < l {
|
||||||
oblock.Data = make([]byte, l, max(l, 8*1024))
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (yo *YOrder) Drain(nameIndex map[string]int32) (err error) {
|
func (yo *YOrder) Drain(colors *Colors) (err error) {
|
||||||
for len(yo.blocks) > 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ func (r *Renderer) IsFilled() bool {
|
|||||||
return true
|
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
|
bx := block.Coord.X - r.xOfs
|
||||||
bz := block.Coord.Z - r.zOfs
|
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.
|
// Decoding is pretty expensive so do it that late.
|
||||||
var db *DecodedBlock
|
var db *DecodedBlock
|
||||||
if db, err = NewDecodedBlock(block.Data, nameIndex); err != nil {
|
if db, err = NewDecodedBlock(block.Data, colors); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user