mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 16:50:18 +01:00
Optimize the inner loop of the renderer to save some cycles by hoisting out version checks and common indexing.
This commit is contained in:
parent
08d32826dc
commit
75aeb36c95
@ -201,6 +201,42 @@ func (r *Renderer) IsEmpty() bool {
|
||||
return r.SolidBlocks == 0 && r.TransparentBlocks == 0
|
||||
}
|
||||
|
||||
// down goes down the y direction in a block from top to bottom.
|
||||
// In its loop it copies the logic of Block.Content pulling some
|
||||
// things like the version check and common indexing out to
|
||||
// save some cycles.
|
||||
func down(db *DecodedBlock, x, y, z int) (int32, int) {
|
||||
mc := db.MapContent
|
||||
switch {
|
||||
case db.Version >= 24:
|
||||
for sliver := (z<<8 + x) << 1; y >= 0; y-- {
|
||||
pos := sliver + y<<5
|
||||
content := int32(mc[pos])<<8 | int32(mc[pos+1])
|
||||
if content != db.AirID && content != db.IgnoreID {
|
||||
if c, found := db.IndexMap[content]; found {
|
||||
return c, y
|
||||
}
|
||||
}
|
||||
}
|
||||
case db.Version >= 20:
|
||||
for sliver := z<<8 + x; y >= 0; y-- {
|
||||
pos := sliver + y<<4
|
||||
var content int32
|
||||
if c := mc[pos]; c <= 0x80 {
|
||||
content = int32(c)
|
||||
} else {
|
||||
content = int32(c)<<4 | int32(mc[pos+0x2000])>>4
|
||||
}
|
||||
if content != db.AirID && content != db.IgnoreID {
|
||||
if c, found := db.IndexMap[content]; found {
|
||||
return c, y
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1, -1
|
||||
}
|
||||
|
||||
func (r *Renderer) RenderBlock(block *Block, colors *Colors) (err error) {
|
||||
|
||||
bx := block.Coord.X - r.xOfs
|
||||
@ -238,12 +274,17 @@ func (r *Renderer) RenderBlock(block *Block, colors *Colors) (err error) {
|
||||
for x := 0; x < 16; x++ {
|
||||
currentY := yB[ofs]
|
||||
if currentY < blockY {
|
||||
for y := 15; y >= 0; y-- {
|
||||
if c, ok := db.Content(x, y, z); ok {
|
||||
var c int32
|
||||
for y := 15; ; y-- {
|
||||
if c, y = down(db, x, y, z); y < 0 {
|
||||
break
|
||||
}
|
||||
cY := blockY + int32(y)
|
||||
|
||||
if colors.IsTransparent(c) {
|
||||
r.tBuffer[ofs] = r.spans.Insert(r.tBuffer[ofs], cY, c)
|
||||
// We need to continue to go down because we
|
||||
// can see through this node.
|
||||
} else {
|
||||
r.cBuffer[ofs] = c
|
||||
currentY = cY
|
||||
@ -252,7 +293,6 @@ func (r *Renderer) RenderBlock(block *Block, colors *Colors) (err error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if currentY < yMin {
|
||||
yMin = currentY
|
||||
}
|
||||
@ -267,13 +307,10 @@ func (r *Renderer) RenderBlock(block *Block, colors *Colors) (err error) {
|
||||
for x := 0; x < 16; x++ {
|
||||
currentY := yB[ofs]
|
||||
if currentY < blockY {
|
||||
for y := 15; y >= 0; y-- {
|
||||
if c, ok := db.Content(x, y, z); ok {
|
||||
if c, y := down(db, x, 15, z); y >= 0 {
|
||||
r.cBuffer[ofs] = c
|
||||
currentY = blockY + int32(y)
|
||||
yB[ofs] = currentY
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if currentY < yMin {
|
||||
|
Loading…
Reference in New Issue
Block a user