Changing the terminology of tile components. (#220)
Orientation > Type MainIndex > Style SubIndex > Sequence
This commit is contained in:
parent
90b5e8a334
commit
b0d753aef9
|
@ -199,10 +199,10 @@ func (v *Engine) RenderPass1(region *Region, offX, offY, x, y int, target *ebite
|
|||
tile := region.DS1.Tiles[y][x]
|
||||
// Draw lower walls
|
||||
for i := range tile.Walls {
|
||||
if tile.Walls[i].Orientation <= 15 || tile.Walls[i].Prop1 == 0 {
|
||||
if tile.Walls[i].Type <= 15 || tile.Walls[i].Prop1 == 0 {
|
||||
continue
|
||||
}
|
||||
if tile.Walls[i].Hidden || tile.Walls[i].Orientation == 10 || tile.Walls[i].Orientation == 11 || tile.Walls[i].Orientation == 0 {
|
||||
if tile.Walls[i].Hidden || tile.Walls[i].Type == 10 || tile.Walls[i].Type == 11 || tile.Walls[i].Type == 0 {
|
||||
continue
|
||||
}
|
||||
region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, d2enum.RegionLayerTypeWalls, i, target)
|
||||
|
@ -228,10 +228,10 @@ func (v *Engine) RenderPass2(region *Region, offX, offY, x, y int, target *ebite
|
|||
|
||||
// Draw upper walls
|
||||
for i := range tile.Walls {
|
||||
if tile.Walls[i].Orientation >= 15 {
|
||||
if tile.Walls[i].Type >= 15 {
|
||||
continue
|
||||
}
|
||||
if tile.Walls[i].Hidden || tile.Walls[i].Orientation == 10 || tile.Walls[i].Orientation == 11 || tile.Walls[i].Orientation == 0 {
|
||||
if tile.Walls[i].Hidden || tile.Walls[i].Type == 10 || tile.Walls[i].Type == 11 || tile.Walls[i].Type == 0 {
|
||||
continue
|
||||
}
|
||||
region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, d2enum.RegionLayerTypeWalls, i, target)
|
||||
|
@ -256,7 +256,7 @@ func (v *Engine) RenderPass3(region *Region, offX, offY, x, y int, target *ebite
|
|||
tile := region.DS1.Tiles[y][x]
|
||||
// Draw ceilings
|
||||
for i := range tile.Walls {
|
||||
if tile.Walls[i].Orientation != 15 {
|
||||
if tile.Walls[i].Type != 15 {
|
||||
continue
|
||||
}
|
||||
region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, d2enum.RegionLayerTypeWalls, i, target)
|
||||
|
@ -286,10 +286,10 @@ func (v *Engine) DrawTileLines(region *Region, offX, offY, x, y int, target *ebi
|
|||
|
||||
tile := region.DS1.Tiles[y][x]
|
||||
for i := range tile.Floors {
|
||||
floorSpec := fmt.Sprintf("f: %v-%v", tile.Floors[i].MainIndex, tile.Floors[i].SubIndex)
|
||||
floorSpec := fmt.Sprintf("f: %v-%v", tile.Floors[i].Style, tile.Floors[i].Sequence)
|
||||
ebitenutil.DebugPrintAt(target, floorSpec, offX+int(v.OffsetX)-20, offY+int(v.OffsetY)+10+((i+1)*14))
|
||||
}
|
||||
// wallSpec := fmt.Sprintf("w: %v-%v", tile.Walls[0].MainIndex, tile.Walls[0].SubIndex)
|
||||
// wallSpec := fmt.Sprintf("w: %v-%v", tile.Walls[0].Style, tile.Walls[0].Sequence)
|
||||
// ebitenutil.DebugPrintAt(target, wallSpec, offX+int(v.OffsetX)-20, offY+int(v.OffsetY)+34)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,10 +94,10 @@ func (v *Region) loadSpecials() {
|
|||
for y := range v.DS1.Tiles {
|
||||
for x := range v.DS1.Tiles[y] {
|
||||
for _, wall := range v.DS1.Tiles[y][x].Walls {
|
||||
if wall.Orientation != 10 {
|
||||
if wall.Type != 10 {
|
||||
continue
|
||||
}
|
||||
if wall.MainIndex == 30 && wall.SubIndex == 0 {
|
||||
if wall.Style == 30 && wall.Sequence == 0 {
|
||||
v.StartX = float64(x) + 0.5
|
||||
v.StartY = float64(y) + 0.5
|
||||
log.Printf("Starting location: %d, %d", x, y)
|
||||
|
@ -178,25 +178,25 @@ func (v *Region) getRandomTile(tiles []d2dt1.Tile, x, y int, seed int64) (*d2dt1
|
|||
return &tiles[0], 0
|
||||
}
|
||||
|
||||
func (v *Region) getTile(mainIndex, subIndex, orientation int32, x, y int, seed int64) (*d2dt1.Tile, byte) {
|
||||
func (v *Region) getTile(style, sequence, tileType int32, x, y int, seed int64) (*d2dt1.Tile, byte) {
|
||||
var tiles []d2dt1.Tile
|
||||
for _, tile := range v.Tiles {
|
||||
if tile.MainIndex != mainIndex || tile.SubIndex != subIndex || tile.Orientation != orientation {
|
||||
if tile.Style != style || tile.Sequence != sequence || tile.Type != tileType {
|
||||
continue
|
||||
}
|
||||
tiles = append(tiles, tile)
|
||||
}
|
||||
if len(tiles) == 0 {
|
||||
log.Printf("Unknown tile ID [%d %d %d]\n", mainIndex, subIndex, orientation)
|
||||
log.Printf("Unknown tile ID [%d %d %d]\n", style, sequence, tileType)
|
||||
return nil, 0
|
||||
}
|
||||
return v.getRandomTile(tiles, x, y, seed)
|
||||
}
|
||||
|
||||
func (v *Region) renderFloor(tile d2ds1.FloorShadowRecord, offsetX, offsetY int, target *ebiten.Image, tileX, tileY int) {
|
||||
img := v.GetImageCacheRecord(tile.MainIndex, tile.SubIndex, 0, tile.RandomIndex)
|
||||
img := v.GetImageCacheRecord(tile.Style, tile.Sequence, 0, tile.RandomIndex)
|
||||
if img == nil {
|
||||
log.Printf("Render called on uncached floor {%v,%v}", tile.MainIndex, tile.SubIndex)
|
||||
log.Printf("Render called on uncached floor {%v,%v}", tile.Style, tile.Sequence)
|
||||
return
|
||||
}
|
||||
opts := &ebiten.DrawImageOptions{}
|
||||
|
@ -206,9 +206,9 @@ func (v *Region) renderFloor(tile d2ds1.FloorShadowRecord, offsetX, offsetY int,
|
|||
}
|
||||
|
||||
func (v *Region) renderWall(tile d2ds1.WallRecord, offsetX, offsetY int, target *ebiten.Image, tileX, tileY int) {
|
||||
img := v.GetImageCacheRecord(tile.MainIndex, tile.SubIndex, tile.Orientation, tile.RandomIndex)
|
||||
img := v.GetImageCacheRecord(tile.Style, tile.Sequence, tile.Type, tile.RandomIndex)
|
||||
if img == nil {
|
||||
log.Printf("Render called on uncached wall {%v,%v,%v}", tile.MainIndex, tile.SubIndex, tile.Orientation)
|
||||
log.Printf("Render called on uncached wall {%v,%v,%v}", tile.Style, tile.Sequence, tile.Type)
|
||||
return
|
||||
}
|
||||
opts := &ebiten.DrawImageOptions{}
|
||||
|
@ -217,9 +217,9 @@ func (v *Region) renderWall(tile d2ds1.WallRecord, offsetX, offsetY int, target
|
|||
}
|
||||
|
||||
func (v *Region) renderShadow(tile d2ds1.FloorShadowRecord, offsetX, offsetY int, target *ebiten.Image, tileX, tileY int) {
|
||||
img := v.GetImageCacheRecord(tile.MainIndex, tile.SubIndex, 13, tile.RandomIndex)
|
||||
img := v.GetImageCacheRecord(tile.Style, tile.Sequence, 13, tile.RandomIndex)
|
||||
if img == nil {
|
||||
log.Printf("Render called on uncached shadow {%v,%v}", tile.MainIndex, tile.SubIndex)
|
||||
log.Printf("Render called on uncached shadow {%v,%v}", tile.Style, tile.Sequence)
|
||||
return
|
||||
}
|
||||
opts := &ebiten.DrawImageOptions{}
|
||||
|
@ -301,15 +301,15 @@ func (v *Region) decodeTileGfxData(blocks []d2dt1.Block, pixels *[]byte, tileYOf
|
|||
}
|
||||
|
||||
func (v *Region) generateFloorCache(tile *d2ds1.FloorShadowRecord, tileX, tileY int) *ebiten.Image {
|
||||
tileData, tileIndex := v.getTile(int32(tile.MainIndex), int32(tile.SubIndex), 0, tileX, tileY, v.seed)
|
||||
tileData, tileIndex := v.getTile(int32(tile.Style), int32(tile.Sequence), 0, tileX, tileY, v.seed)
|
||||
if tileData == nil {
|
||||
log.Printf("Could not locate tile Idx:%d, Sub: %d, Ori: %d\n", tile.MainIndex, tile.SubIndex, 0)
|
||||
log.Printf("Could not locate tile Style:%d, Seq: %d, Type: %d\n", tile.Style, tile.Sequence, 0)
|
||||
tileData = &d2dt1.Tile{}
|
||||
tileData.Width = 10
|
||||
tileData.Height = 10
|
||||
}
|
||||
tile.RandomIndex = tileIndex
|
||||
cachedImage := v.GetImageCacheRecord(tile.MainIndex, tile.SubIndex, 0, tileIndex)
|
||||
cachedImage := v.GetImageCacheRecord(tile.Style, tile.Sequence, 0, tileIndex)
|
||||
if cachedImage != nil {
|
||||
return cachedImage
|
||||
}
|
||||
|
@ -323,12 +323,12 @@ func (v *Region) generateFloorCache(tile *d2ds1.FloorShadowRecord, tileX, tileY
|
|||
pixels := make([]byte, 4*tileData.Width*tileHeight)
|
||||
v.decodeTileGfxData(tileData.Blocks, &pixels, tileYOffset, tileData.Width)
|
||||
image.ReplacePixels(pixels)
|
||||
v.SetImageCacheRecord(tile.MainIndex, tile.SubIndex, 0, tileIndex, image)
|
||||
v.SetImageCacheRecord(tile.Style, tile.Sequence, 0, tileIndex, image)
|
||||
return image
|
||||
}
|
||||
|
||||
func (v *Region) generateShadowCache(tile *d2ds1.FloorShadowRecord, tileX, tileY int) *ebiten.Image {
|
||||
tileData, tileIndex := v.getTile(int32(tile.MainIndex), int32(tile.SubIndex), 13, tileX, tileY, v.seed)
|
||||
tileData, tileIndex := v.getTile(int32(tile.Style), int32(tile.Sequence), 13, tileX, tileY, v.seed)
|
||||
if tileData == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ func (v *Region) generateShadowCache(tile *d2ds1.FloorShadowRecord, tileX, tileY
|
|||
tileHeight := int(tileMaxY - tileMinY)
|
||||
tile.YAdjust = int(tileMinY + 80)
|
||||
|
||||
cachedImage := v.GetImageCacheRecord(tile.MainIndex, tile.SubIndex, 13, tileIndex)
|
||||
cachedImage := v.GetImageCacheRecord(tile.Style, tile.Sequence, 13, tileIndex)
|
||||
if cachedImage != nil {
|
||||
return cachedImage
|
||||
}
|
||||
|
@ -352,12 +352,12 @@ func (v *Region) generateShadowCache(tile *d2ds1.FloorShadowRecord, tileX, tileY
|
|||
pixels := make([]byte, 4*tileData.Width*int32(tileHeight))
|
||||
v.decodeTileGfxData(tileData.Blocks, &pixels, tileYOffset, tileData.Width)
|
||||
image.ReplacePixels(pixels)
|
||||
v.SetImageCacheRecord(tile.MainIndex, tile.SubIndex, 13, tileIndex, image)
|
||||
v.SetImageCacheRecord(tile.Style, tile.Sequence, 13, tileIndex, image)
|
||||
return image
|
||||
}
|
||||
|
||||
func (v *Region) generateWallCache(tile *d2ds1.WallRecord, tileX, tileY int) *ebiten.Image {
|
||||
tileData, tileIndex := v.getTile(int32(tile.MainIndex), int32(tile.SubIndex), int32(tile.Orientation), tileX, tileY, v.seed)
|
||||
tileData, tileIndex := v.getTile(int32(tile.Style), int32(tile.Sequence), int32(tile.Type), tileX, tileY, v.seed)
|
||||
if tileData == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -365,8 +365,8 @@ func (v *Region) generateWallCache(tile *d2ds1.WallRecord, tileX, tileY int) *eb
|
|||
tile.RandomIndex = tileIndex
|
||||
var newTileData *d2dt1.Tile = nil
|
||||
|
||||
if tile.Orientation == 3 {
|
||||
newTileData, _ = v.getTile(int32(tile.MainIndex), int32(tile.SubIndex), int32(4), tileX, tileY, v.seed)
|
||||
if tile.Type == 3 {
|
||||
newTileData, _ = v.getTile(int32(tile.Style), int32(tile.Sequence), int32(4), tileX, tileY, v.seed)
|
||||
}
|
||||
|
||||
tileMinY := int32(0)
|
||||
|
@ -387,13 +387,13 @@ func (v *Region) generateWallCache(tile *d2ds1.WallRecord, tileX, tileY int) *eb
|
|||
tileYOffset := -tileMinY
|
||||
//tileHeight := int(tileMaxY - tileMinY)
|
||||
|
||||
if tile.Orientation == 15 {
|
||||
if tile.Type == 15 {
|
||||
tile.YAdjust = -int(tileData.RoofHeight)
|
||||
} else {
|
||||
tile.YAdjust = int(tileMinY) + 80
|
||||
}
|
||||
|
||||
cachedImage := v.GetImageCacheRecord(tile.MainIndex, tile.SubIndex, tile.Orientation, tileIndex)
|
||||
cachedImage := v.GetImageCacheRecord(tile.Style, tile.Sequence, tile.Type, tileIndex)
|
||||
if cachedImage != nil {
|
||||
return cachedImage
|
||||
}
|
||||
|
@ -415,16 +415,16 @@ func (v *Region) generateWallCache(tile *d2ds1.WallRecord, tileX, tileY int) *eb
|
|||
log.Panicf(err.Error())
|
||||
}
|
||||
|
||||
v.SetImageCacheRecord(tile.MainIndex, tile.SubIndex, tile.Orientation, tileIndex, image)
|
||||
v.SetImageCacheRecord(tile.Style, tile.Sequence, tile.Type, tileIndex, image)
|
||||
return image
|
||||
}
|
||||
|
||||
func (v *Region) GetImageCacheRecord(mainIndex, subIndex, orientation, randomIndex byte) *ebiten.Image {
|
||||
lookupIndex := uint32(mainIndex)<<24 | uint32(subIndex)<<16 | uint32(orientation)<<8 | uint32(randomIndex)
|
||||
func (v *Region) GetImageCacheRecord(style, sequence, tileType, randomIndex byte) *ebiten.Image {
|
||||
lookupIndex := uint32(style)<<24 | uint32(sequence)<<16 | uint32(tileType)<<8 | uint32(randomIndex)
|
||||
return v.imageCacheRecords[lookupIndex]
|
||||
}
|
||||
|
||||
func (v *Region) SetImageCacheRecord(mainIndex, subIndex, orientation, randomIndex byte, image *ebiten.Image) {
|
||||
lookupIndex := uint32(mainIndex)<<24 | uint32(subIndex)<<16 | uint32(orientation)<<8 | uint32(randomIndex)
|
||||
func (v *Region) SetImageCacheRecord(style, sequence, tileType, randomIndex byte, image *ebiten.Image) {
|
||||
lookupIndex := uint32(style)<<24 | uint32(sequence)<<16 | uint32(tileType)<<8 | uint32(randomIndex)
|
||||
v.imageCacheRecords[lookupIndex] = image
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module github.com/OpenDiablo2/OpenDiablo2
|
|||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/OpenDiablo2/D2Shared v0.0.0-20191121150938-91629c87a1be
|
||||
github.com/OpenDiablo2/D2Shared v0.0.0-20191121164327-8f10634564d8
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
|
||||
github.com/hajimehoshi/ebiten v1.11.0-alpha.0.20191119174134-52f6be26392b
|
||||
|
|
4
go.sum
4
go.sum
|
@ -2,8 +2,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
|
|||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/JoshVarga/blast v0.0.0-20180421040937-681c804fb9f0 h1:tDnuU0igiBiQFjsvq1Bi7DpoUjqI76VVvW045vpeFeM=
|
||||
github.com/JoshVarga/blast v0.0.0-20180421040937-681c804fb9f0/go.mod h1:h/5OEGj4G+fpYxluLjSMZbFY011ZxAntO98nCl8mrCs=
|
||||
github.com/OpenDiablo2/D2Shared v0.0.0-20191121150938-91629c87a1be h1:KbpiV80D35hozRinTXGXUWeaNWgPhLyYXd6zc8V1p+Y=
|
||||
github.com/OpenDiablo2/D2Shared v0.0.0-20191121150938-91629c87a1be/go.mod h1:zRNOUiglwakbufN8EsNWqLLDHsZoQDA6/dI2GIu2nnU=
|
||||
github.com/OpenDiablo2/D2Shared v0.0.0-20191121164327-8f10634564d8 h1:9aq7+ledMj7J87eWQcFqCzIQablBSNLwSEhsJmefAX4=
|
||||
github.com/OpenDiablo2/D2Shared v0.0.0-20191121164327-8f10634564d8/go.mod h1:zRNOUiglwakbufN8EsNWqLLDHsZoQDA6/dI2GIu2nnU=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
|
||||
|
|
Loading…
Reference in New Issue