1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-29 18:45:23 +00:00
OpenDiablo2/d2core/d2map/d2maprenderer/gfx_decode.go
danhale-git 6104adc700
D2map lint warnings (#566)
* Comments and newlines in engine.go

* Comments and newlines in object.go

* Comments and newlines in animated_entity.go

* Comments and newlines in missile.go

* Comments and newlines in npc.go

* Comments and newlines in player.go

* Removed object.go (incorrectly merged it in during rebase).

* Comments and newlines in renderer.go.

* Comments and newlines in map_entity.go.

* Comments and newlines in walk_mesh.go.

* Comments and newlines in viewport.go and tile_cache.go.

* Comments and newlines in stamp.go and wilderness_tile_types.go.

* Comments and newlines in everything else.
2020-07-09 16:11:01 -04:00

69 lines
1.4 KiB
Go

package d2maprenderer
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dt1"
func (mr *MapRenderer) decodeTileGfxData(blocks []d2dt1.Block, pixels *[]byte, tileYOffset int32, tileWidth int32) {
for _, block := range blocks {
if block.Format == d2dt1.BlockFormatIsometric {
// 3D isometric decoding
xjump := []int32{14, 12, 10, 8, 6, 4, 2, 0, 2, 4, 6, 8, 10, 12, 14}
nbpix := []int32{4, 8, 12, 16, 20, 24, 28, 32, 28, 24, 20, 16, 12, 8, 4}
blockX := int32(block.X)
blockY := int32(block.Y)
length := int32(256)
x := int32(0)
y := int32(0)
idx := 0
for length > 0 {
x = xjump[y]
n := nbpix[y]
length -= n
for n > 0 {
offset := (((blockY + y + tileYOffset) * tileWidth) + (blockX + x))
(*pixels)[offset] = block.EncodedData[idx]
x++
n--
idx++
}
y++
}
continue
}
// RLE Encoding
blockX := int32(block.X)
blockY := int32(block.Y)
x := int32(0)
y := int32(0)
idx := 0
length := block.Length
for length > 0 {
b1 := block.EncodedData[idx]
b2 := block.EncodedData[idx+1]
idx += 2
length -= 2
if (b1 | b2) == 0 {
x = 0
y++
continue
}
x += int32(b1)
length -= int32(b2)
for b2 > 0 {
offset := (((blockY + y + tileYOffset) * tileWidth) + (blockX + x))
(*pixels)[offset] = block.EncodedData[idx]
idx++
x++
b2--
}
}
}
}