mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-10 06:16:27 -05:00
Added more debugging to map test (#284)
This commit is contained in:
parent
6606774ece
commit
935789dccf
@ -11,6 +11,35 @@ type SubTileFlags struct {
|
||||
Unknown3 bool
|
||||
}
|
||||
|
||||
func (s* SubTileFlags) DebugString() string {
|
||||
result := ""
|
||||
if s.BlockWalk {
|
||||
result += "BlockWalk "
|
||||
}
|
||||
if s.BlockLOS {
|
||||
result += "BlockLOS "
|
||||
}
|
||||
if s.BlockJump {
|
||||
result += "BlockJump "
|
||||
}
|
||||
if s.BlockPlayerWalk {
|
||||
result += "BlockPlayerWalk "
|
||||
}
|
||||
if s.Unknown1 {
|
||||
result += "Unknown1 "
|
||||
}
|
||||
if s.BlockLight {
|
||||
result += "BlockLight "
|
||||
}
|
||||
if s.Unknown2 {
|
||||
result += "Unknown2 "
|
||||
}
|
||||
if s.Unknown3 {
|
||||
result += "Unknown3 "
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func NewSubTileFlags(data byte) SubTileFlags {
|
||||
return SubTileFlags{
|
||||
BlockWalk: data & 1 == 1,
|
||||
|
@ -15,3 +15,10 @@ type Tile struct {
|
||||
blockHeaderSize int32
|
||||
Blocks []Block
|
||||
}
|
||||
|
||||
func (t *Tile) GetSubTileFlags(x, y int) *SubTileFlags {
|
||||
if x < 0 || x > 4 || y < 0 || y > 4 {
|
||||
return &SubTileFlags{}
|
||||
}
|
||||
return &t.SubTileFlags[x + (y * 5)]
|
||||
}
|
||||
|
@ -126,6 +126,23 @@ func (mr *MapRegion) loadSpecials() {
|
||||
}
|
||||
}
|
||||
|
||||
func (mr *MapRegion) GetTile(x, y int) *d2ds1.TileRecord {
|
||||
return &mr.ds1.Tiles[y][x]
|
||||
}
|
||||
|
||||
func (mr *MapRegion) GetTileData(style int32, sequence int32, tileType d2enum.TileType) *d2dt1.Tile {
|
||||
for _, tile := range mr.tiles {
|
||||
if tile.Style == style && tile.Sequence == sequence && tile.Type == int32(tileType) {
|
||||
return &tile
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mr *MapRegion) GetTileSize() (int, int) {
|
||||
return mr.tileRect.Width, mr.tileRect.Height
|
||||
}
|
||||
|
||||
func (mr *MapRegion) loadEntities() []MapEntity {
|
||||
var entities []MapEntity
|
||||
|
||||
@ -193,7 +210,7 @@ func (mr *MapRegion) getRandomTile(tiles []d2dt1.Tile, x, y int, seed int64) byt
|
||||
return 0
|
||||
}
|
||||
|
||||
func (mr *MapRegion) getTiles(style, sequence, tileType int32, x, y int, seed int64) []d2dt1.Tile {
|
||||
func (mr *MapRegion) getTiles(style, sequence, tileType int32) []d2dt1.Tile {
|
||||
var tiles []d2dt1.Tile
|
||||
for _, tile := range mr.tiles {
|
||||
if tile.Style != style || tile.Sequence != sequence || tile.Type != tileType {
|
||||
@ -342,7 +359,7 @@ func (mr *MapRegion) renderWall(tile d2ds1.WallRecord, viewport *Viewport, targe
|
||||
return
|
||||
}
|
||||
|
||||
viewport.PushTranslationOrtho(-80, float64(tile.YAdjust))
|
||||
viewport.PushTranslationOrtho(-80, float64(tile.YAdjust) - 16)
|
||||
defer viewport.PopTranslation()
|
||||
|
||||
target.PushTranslation(viewport.GetTranslationScreen())
|
||||
@ -380,9 +397,15 @@ func (mr *MapRegion) renderDebug(debugVisLevel int, viewport *Viewport, target d
|
||||
}
|
||||
|
||||
func (mr *MapRegion) renderTileDebug(x, y int, debugVisLevel int, viewport *Viewport, target d2render.Surface) {
|
||||
ax := x - mr.tileRect.Left
|
||||
ay := y - mr.tileRect.Top
|
||||
|
||||
if debugVisLevel > 0 {
|
||||
subtileColor := color.RGBA{R: 80, G: 80, B: 255, A: 100}
|
||||
tileColor := color.RGBA{R: 255, G: 255, B: 255, A: 255}
|
||||
if ay < 0 || ax < 0 || ay >= len(mr.ds1.Tiles) || x >= len(mr.ds1.Tiles[ay]) {
|
||||
return
|
||||
}
|
||||
subTileColor := color.RGBA{R: 80, G: 80, B: 255, A: 50}
|
||||
tileColor := color.RGBA{R: 255, G: 255, B: 255, A: 100}
|
||||
|
||||
screenX1, screenY1 := viewport.WorldToScreen(float64(x), float64(y))
|
||||
screenX2, screenY2 := viewport.WorldToScreen(float64(x+1), float64(y))
|
||||
@ -399,19 +422,19 @@ func (mr *MapRegion) renderTileDebug(x, y int, debugVisLevel int, viewport *View
|
||||
|
||||
if debugVisLevel > 1 {
|
||||
for i := 1; i <= 4; i++ {
|
||||
x := i * 16
|
||||
y := i * 8
|
||||
x2 := i * 16
|
||||
y2 := i * 8
|
||||
|
||||
target.PushTranslation(-x, y)
|
||||
target.DrawLine(80, 40, subtileColor)
|
||||
target.PushTranslation(-x2, y2)
|
||||
target.DrawLine(80, 40, subTileColor)
|
||||
target.Pop()
|
||||
|
||||
target.PushTranslation(x, y)
|
||||
target.DrawLine(-80, 40, subtileColor)
|
||||
target.PushTranslation(x2, y2)
|
||||
target.DrawLine(-80, 40, subTileColor)
|
||||
target.Pop()
|
||||
}
|
||||
|
||||
tile := mr.ds1.Tiles[y][x]
|
||||
tile := mr.ds1.Tiles[ay][ax]
|
||||
for i, floor := range tile.Floors {
|
||||
target.PushTranslation(-20, 10+(i+1)*14)
|
||||
target.DrawText("f: %v-%v", floor.Style, floor.Sequence)
|
||||
@ -458,7 +481,7 @@ func (mr *MapRegion) setImageCacheRecord(style, sequence byte, tileType d2enum.T
|
||||
}
|
||||
|
||||
func (mr *MapRegion) generateFloorCache(tile *d2ds1.FloorShadowRecord, tileX, tileY int) {
|
||||
tileOptions := mr.getTiles(int32(tile.Style), int32(tile.Sequence), 0, tileX, tileY, mr.seed)
|
||||
tileOptions := mr.getTiles(int32(tile.Style), int32(tile.Sequence), 0)
|
||||
var tileData []*d2dt1.Tile
|
||||
var tileIndex byte
|
||||
|
||||
@ -504,7 +527,7 @@ func (mr *MapRegion) generateFloorCache(tile *d2ds1.FloorShadowRecord, tileX, ti
|
||||
}
|
||||
|
||||
func (mr *MapRegion) generateShadowCache(tile *d2ds1.FloorShadowRecord, tileX, tileY int) {
|
||||
tileOptions := mr.getTiles(int32(tile.Style), int32(tile.Sequence), 13, tileX, tileY, mr.seed)
|
||||
tileOptions := mr.getTiles(int32(tile.Style), int32(tile.Sequence), 13)
|
||||
var tileIndex byte
|
||||
var tileData *d2dt1.Tile
|
||||
if tileOptions == nil {
|
||||
@ -538,7 +561,7 @@ func (mr *MapRegion) generateShadowCache(tile *d2ds1.FloorShadowRecord, tileX, t
|
||||
}
|
||||
|
||||
func (mr *MapRegion) generateWallCache(tile *d2ds1.WallRecord, tileX, tileY int) {
|
||||
tileOptions := mr.getTiles(int32(tile.Style), int32(tile.Sequence), int32(tile.Type), tileX, tileY, mr.seed)
|
||||
tileOptions := mr.getTiles(int32(tile.Style), int32(tile.Sequence), int32(tile.Type))
|
||||
var tileIndex byte
|
||||
var tileData *d2dt1.Tile
|
||||
if tileOptions == nil {
|
||||
@ -552,7 +575,7 @@ func (mr *MapRegion) generateWallCache(tile *d2ds1.WallRecord, tileX, tileY int)
|
||||
var newTileData *d2dt1.Tile = nil
|
||||
|
||||
if tile.Type == 3 {
|
||||
newTileOptions := mr.getTiles(int32(tile.Style), int32(tile.Sequence), int32(4), tileX, tileY, mr.seed)
|
||||
newTileOptions := mr.getTiles(int32(tile.Style), int32(tile.Sequence), int32(4))
|
||||
newTileIndex := mr.getRandomTile(newTileOptions, tileX, tileY, mr.seed)
|
||||
newTileData = &newTileOptions[newTileIndex]
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package d2gamescene
|
||||
|
||||
import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dt1"
|
||||
"math"
|
||||
"os"
|
||||
|
||||
@ -136,6 +137,7 @@ func (met *MapEngineTest) LoadRegionByIndex(n int, levelPreset, fileIndex int) {
|
||||
}
|
||||
|
||||
met.mapEngine.MoveCameraTo(met.mapEngine.WorldToOrtho(met.mapEngine.GetCenterPosition()))
|
||||
met.mapEngine.SetDebugVisLevel(met.debugVisLevel)
|
||||
}
|
||||
|
||||
func (met *MapEngineTest) Load() []func() {
|
||||
@ -159,8 +161,9 @@ func (met *MapEngineTest) Render(screen d2render.Surface) {
|
||||
|
||||
screenX, screenY, _ := d2render.GetCursorPos()
|
||||
worldX, worldY := met.mapEngine.ScreenToWorld(screenX, screenY)
|
||||
subtileX := int(math.Ceil(math.Mod(worldX*10, 10))) / 2
|
||||
subtileY := int(math.Ceil(math.Mod(worldY*10, 10))) / 2
|
||||
//subtileX := int(math.Ceil(math.Mod(worldX*10, 10))) / 2
|
||||
//subtileY := int(math.Ceil(math.Mod(worldY*10, 10))) / 2
|
||||
|
||||
curRegion := met.mapEngine.GetRegionAtTile(int(worldX), int(worldY))
|
||||
if curRegion == nil {
|
||||
return
|
||||
@ -186,19 +189,84 @@ func (met *MapEngineTest) Render(screen d2render.Surface) {
|
||||
}
|
||||
met.filesCount = len(levelFilesToPick)
|
||||
|
||||
screen.PushTranslation(5, 5)
|
||||
screen.DrawText("%d, %d (Tile %d.%d, %d.%d)", screenX, screenY, int(math.Floor(worldX))-tileRect.Left, subtileX, int(math.Floor(worldY))-tileRect.Top, subtileY)
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("Map: " + curRegion.GetLevelType().Name)
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("%met: %met/%met [%met, %met]", regionPath, fileIndex+1, met.filesCount, met.currentRegion, met.levelPreset)
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("N - next region, P - previous region")
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("Shift+N - next preset, Shift+P - previous preset")
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("Ctrl+N - next file, Ctrl+P - previous file")
|
||||
screen.PopN(6)
|
||||
tileX := int(math.Floor(worldX))-tileRect.Left
|
||||
tileY := int(math.Floor(worldY))-tileRect.Top
|
||||
subtileX := int((worldX - float64(int(worldX))) * 5)
|
||||
subtileY := 4 - int((worldY - float64(int(worldY))) * 5)
|
||||
|
||||
regionWidth, regionHeight := curRegion.GetTileSize()
|
||||
if tileX >= 0 && tileY >= 0 && tileX < regionWidth && tileY < regionHeight {
|
||||
tile := curRegion.GetTile(tileX, tileY)
|
||||
screen.PushTranslation(5, 5)
|
||||
screen.DrawText("%d, %d (Tile %d.%d, %d.%d)", screenX, screenY, tileX, subtileX, tileY, subtileY)
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("Map: " + curRegion.GetLevelType().Name)
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("%v: %v/%v [%v, %v]", regionPath, fileIndex+1, met.filesCount, met.currentRegion, met.levelPreset)
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("N - next region, P - previous region")
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("Shift+N - next preset, Shift+P - previous preset")
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("Ctrl+N - next file, Ctrl+P - previous file")
|
||||
screen.PushTranslation(0, 16)
|
||||
popN := 7
|
||||
if len(tile.Floors) > 0 {
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("Floors:")
|
||||
screen.PushTranslation(16, 0)
|
||||
for idx, floor := range tile.Floors {
|
||||
popN++
|
||||
screen.PushTranslation(0, 16)
|
||||
tileData := curRegion.GetTileData(int32(floor.Style), int32(floor.Sequence), d2enum.Floor)
|
||||
tileSubAttrs := d2dt1.SubTileFlags{}
|
||||
if tileData != nil {
|
||||
tileSubAttrs = *tileData.GetSubTileFlags(subtileX, subtileY)
|
||||
}
|
||||
screen.DrawText("Floor %v: [ANI:%t] %s", idx, floor.Animated, tileSubAttrs.DebugString())
|
||||
|
||||
}
|
||||
screen.PushTranslation(-16, 0)
|
||||
popN += 3
|
||||
}
|
||||
if len(tile.Walls) > 0 {
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("Walls:")
|
||||
screen.PushTranslation(16, 0)
|
||||
for idx, wall := range tile.Walls {
|
||||
popN++
|
||||
screen.PushTranslation(0, 16)
|
||||
tileData := curRegion.GetTileData(int32(wall.Style), int32(wall.Sequence), d2enum.Floor)
|
||||
tileSubAttrs := d2dt1.SubTileFlags{}
|
||||
if tileData != nil {
|
||||
tileSubAttrs = *tileData.GetSubTileFlags(subtileX, subtileY)
|
||||
}
|
||||
screen.DrawText("Wall %v: [HID:%t] %s", idx, wall.Hidden, tileSubAttrs.DebugString())
|
||||
|
||||
}
|
||||
screen.PushTranslation(-16, 0)
|
||||
popN += 3
|
||||
}
|
||||
if len(tile.Walls) > 0 {
|
||||
screen.PushTranslation(0, 16)
|
||||
screen.DrawText("Shadows:")
|
||||
screen.PushTranslation(16, 0)
|
||||
for idx, shadow := range tile.Shadows {
|
||||
popN++
|
||||
screen.PushTranslation(0, 16)
|
||||
tileData := curRegion.GetTileData(int32(shadow.Style), int32(shadow.Sequence), d2enum.Floor)
|
||||
tileSubAttrs := d2dt1.SubTileFlags{}
|
||||
if tileData != nil {
|
||||
tileSubAttrs = *tileData.GetSubTileFlags(subtileX, subtileY)
|
||||
}
|
||||
screen.DrawText("Wall %v: [HID:%t] %s", idx, shadow.Hidden, tileSubAttrs.DebugString())
|
||||
|
||||
}
|
||||
screen.PushTranslation(-16, 0)
|
||||
popN += 3
|
||||
}
|
||||
screen.PopN(popN)
|
||||
}
|
||||
}
|
||||
|
||||
func (met *MapEngineTest) Advance(tickTime float64) {
|
||||
|
Loading…
Reference in New Issue
Block a user