1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-10-31 00:07:17 -04:00

Map stitching and render upates (#95)

* Added region stitching and modified the rendering loops.
This commit is contained in:
Tim Sarbin 2019-11-06 21:25:09 -05:00 committed by GitHub
parent 01a48d8720
commit da4ffba9c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 94 deletions

View File

@ -3,6 +3,7 @@ package Map
import ( import (
"math" "math"
"math/rand" "math/rand"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/Common" "github.com/OpenDiablo2/OpenDiablo2/Common"
"github.com/OpenDiablo2/OpenDiablo2/Sound" "github.com/OpenDiablo2/OpenDiablo2/Sound"
@ -40,10 +41,32 @@ func (v *Engine) GenerateMap(regionType RegionIdType, levelPreset int) {
Rect: Common.Rectangle{0, 0, int(region.TileWidth), int(region.TileHeight)}, Rect: Common.Rectangle{0, 0, int(region.TileWidth), int(region.TileHeight)},
Region: region, Region: region,
}) })
v.soundManager.PlayBGM("/data/global/music/Act1/town1.wav") // TODO: Temp stuff here
} }
func (v *Engine) GetRegionAt(x, y int) *Region { func (v *Engine) GenerateAct1Overworld() {
v.soundManager.PlayBGM("/data/global/music/Act1/town1.wav") // TODO: Temp stuff here
randomSource := rand.NewSource(v.gameState.Seed)
region := LoadRegion(randomSource, RegionAct1Town, 1, v.fileProvider)
v.regions = append(v.regions, EngineRegion{
Rect: Common.Rectangle{0, 0, int(region.TileWidth), int(region.TileHeight)},
Region: region,
})
if strings.Contains(region.RegionPath, "E1") {
region2 := LoadRegion(randomSource, RegionAct1Town, 2, v.fileProvider)
v.regions = append(v.regions, EngineRegion{
Rect: Common.Rectangle{int(region.TileWidth - 1), 0, int(region2.TileWidth), int(region2.TileHeight)},
Region: region2,
})
} else if strings.Contains(region.RegionPath, "S1") {
region2 := LoadRegion(randomSource, RegionAct1Town, 3, v.fileProvider)
v.regions = append(v.regions, EngineRegion{
Rect: Common.Rectangle{0, int(region.TileHeight - 1), int(region2.TileWidth), int(region2.TileHeight)},
Region: region2,
})
}
}
func (v *Engine) GetRegionAt(x, y int) *EngineRegion {
if v.regions == nil { if v.regions == nil {
return nil return nil
} }
@ -51,102 +74,61 @@ func (v *Engine) GetRegionAt(x, y int) *Region {
if !region.Rect.IsInRect(x, y) { if !region.Rect.IsInRect(x, y) {
continue continue
} }
return region.Region return &region
} }
return nil return nil
} }
func (v *Engine) Render(target *ebiten.Image) { func (v *Engine) Render(target *ebiten.Image) {
for _, region := range v.regions { for _, region := range v.regions {
for y := 0; y < int(region.Region.TileHeight); y++ { v.RenderRegion(region, target)
offX := -(y * 80)
offY := y * 40
for x := 0; x < int(region.Region.TileWidth); x++ {
sx, sy := Common.IsoToScreen(x, y, int(v.OffsetX), int(v.OffsetY))
if sx > -160 && sy > -160 && sx <= 880 && sy <= 1000 {
tile := region.Region.DS1.Tiles[y][x]
for i := range tile.Floors {
if tile.Floors[i].Hidden || tile.Floors[i].Prop1 == 0 {
continue
}
region.Region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeFloors, i, target)
}
}
offX += 80
offY += 40
}
}
} }
for _, region := range v.regions { }
for y := 0; y < int(region.Region.TileHeight); y++ {
offX := -(y * 80) func (v *Engine) RenderRegion(region EngineRegion, target *ebiten.Image) {
offY := y * 40 for y := 0; y < int(region.Region.TileHeight); y++ {
for x := 0; x < int(region.Region.TileWidth); x++ { offX := -((y + region.Rect.Top) * 80) + (region.Rect.Left * 80)
sx, sy := Common.IsoToScreen(x, y, int(v.OffsetX), int(v.OffsetY)) offY := ((y + region.Rect.Top) * 40) + (region.Rect.Left * 40)
if sx > -160 && sy > -160 && sx <= 880 && sy <= 1000 { for x := 0; x < int(region.Region.TileWidth); x++ {
tile := region.Region.DS1.Tiles[y][x] sx, sy := Common.IsoToScreen(x+region.Rect.Left, y+region.Rect.Top, int(v.OffsetX), int(v.OffsetY))
for i := range tile.Shadows { if sx > -160 && sy > -160 && sx <= 880 && sy <= 1000 {
if tile.Shadows[i].Hidden || tile.Shadows[i].Prop1 == 0 { v.RenderTile(region.Region, offX, offY, x, y, target)
continue
}
region.Region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeShadows, i, target)
}
}
offX += 80
offY += 40
}
}
}
for _, region := range v.regions {
for y := 0; y < int(region.Region.TileHeight); y++ {
offX := -(y * 80)
offY := y * 40
for x := 0; x < int(region.Region.TileWidth); x++ {
tile := region.Region.DS1.Tiles[y][x]
for i := range tile.Walls {
if tile.Walls[i].Hidden || tile.Walls[i].Orientation == 15 || tile.Walls[i].Orientation == 10 || tile.Walls[i].Orientation == 11 || tile.Walls[i].Orientation == 0 {
continue
}
region.Region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeWalls, i, target)
}
offX += 80
offY += 40
}
}
}
for _, region := range v.regions {
for y := 0; y < int(region.Region.TileHeight); y++ {
offX := -(y * 80)
offY := y * 40
for x := 0; x < int(region.Region.TileWidth); x++ {
tile := region.Region.DS1.Tiles[y][x]
for i := range tile.Walls {
if tile.Walls[i].Hidden || tile.Walls[i].Orientation != 15 {
continue
}
region.Region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeWalls, i, target)
}
offX += 80
offY += 40
}
}
}
for _, region := range v.regions {
for y := 0; y < int(region.Region.TileHeight); y++ {
offX := -(y * 80)
offY := y * 40
for x := 0; x < int(region.Region.TileWidth); x++ {
sx, sy := Common.IsoToScreen(x, y, int(v.OffsetX), int(v.OffsetY))
if sx > -160 && sy > -160 && sx <= 880 && sy <= 1000 {
for _, obj := range region.Region.AnimationEntities {
if int(math.Floor(obj.LocationX)) == x && int(math.Floor(obj.LocationY)) == y {
obj.Render(target, offX+int(v.OffsetX), offY+int(v.OffsetY))
}
}
}
offX += 80
offY += 40
} }
offX += 80
offY += 40
} }
} }
} }
func (v *Engine) RenderTile(region *Region, offX, offY, x, y int, target *ebiten.Image) {
tile := region.DS1.Tiles[y][x]
for i := range tile.Floors {
if tile.Floors[i].Hidden || tile.Floors[i].Prop1 == 0 {
continue
}
region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeFloors, i, target)
}
for i := range tile.Shadows {
if tile.Shadows[i].Hidden || tile.Shadows[i].Prop1 == 0 {
continue
}
region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeShadows, i, target)
}
for i := range tile.Walls {
if tile.Walls[i].Hidden || tile.Walls[i].Orientation == 15 || tile.Walls[i].Orientation == 10 || tile.Walls[i].Orientation == 11 || tile.Walls[i].Orientation == 0 {
continue
}
region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeWalls, i, target)
}
for _, obj := range region.AnimationEntities {
if int(math.Floor(obj.LocationX)) == x && int(math.Floor(obj.LocationY)) == y {
obj.Render(target, offX+int(v.OffsetX), offY+int(v.OffsetY))
}
}
for i := range tile.Walls {
if tile.Walls[i].Hidden || tile.Walls[i].Orientation != 15 {
continue
}
region.RenderTile(offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeWalls, i, target)
}
}

View File

@ -22,6 +22,7 @@ type TileCacheRecord struct {
} }
type Region struct { type Region struct {
RegionPath string
LevelType Common.LevelTypeRecord LevelType Common.LevelTypeRecord
levelPreset *Common.LevelPresetRecord levelPreset *Common.LevelPresetRecord
TileWidth int32 TileWidth int32
@ -118,6 +119,7 @@ func LoadRegion(seed rand.Source, levelType RegionIdType, levelPreset int, fileP
random := rand.New(seed) random := rand.New(seed)
levelIndex := int(math.Round(float64(len(levelFilesToPick)-1) * random.Float64())) levelIndex := int(math.Round(float64(len(levelFilesToPick)-1) * random.Float64()))
levelFile := levelFilesToPick[levelIndex] levelFile := levelFilesToPick[levelIndex]
result.RegionPath = levelFile
result.DS1 = LoadDS1("/data/global/tiles/"+levelFile, fileProvider) result.DS1 = LoadDS1("/data/global/tiles/"+levelFile, fileProvider)
result.TileWidth = result.DS1.Width result.TileWidth = result.DS1.Width
result.TileHeight = result.DS1.Height result.TileHeight = result.DS1.Height

View File

@ -44,7 +44,7 @@ func (v *MapEngineTest) Load() []func() {
func() { func() {
v.mapEngine = Map.CreateMapEngine(v.gameState, v.soundManager, v.fileProvider) v.mapEngine = Map.CreateMapEngine(v.gameState, v.soundManager, v.fileProvider)
v.mapEngine.GenerateMap(Map.RegionAct1Town, 1) v.mapEngine.GenerateAct1Overworld()
//v.mapEngine.GenerateMap(Map.RegionAct1Tristram, 300) //v.mapEngine.GenerateMap(Map.RegionAct1Tristram, 300)
//v.mapEngine.GenerateMap(Map.RegionAct1Cathedral, 257) //v.mapEngine.GenerateMap(Map.RegionAct1Cathedral, 257)
//v.mapEngine.GenerateMap(Map.RegionAct2Town, 301) //v.mapEngine.GenerateMap(Map.RegionAct2Town, 301)
@ -73,13 +73,21 @@ func (v *MapEngineTest) Render(screen *ebiten.Image) {
tileX, tileY := Common.ScreenToIso(actualX, actualY) tileX, tileY := Common.ScreenToIso(actualX, actualY)
subtileX := int(math.Ceil(math.Mod((tileX*10), 10))) / 2 subtileX := int(math.Ceil(math.Mod((tileX*10), 10))) / 2
subtileY := int(math.Ceil(math.Mod((tileY*10), 10))) / 2 subtileY := int(math.Ceil(math.Mod((tileY*10), 10))) / 2
line := fmt.Sprintf("%d, %d (Tile %d.%d, %d.%d)", int(math.Ceil(actualX)), int(math.Ceil(actualY)), int(math.Ceil(tileX)), subtileX, int(math.Ceil(tileY)), subtileY)
ebitenutil.DebugPrintAt(screen, line, 5, 5)
curRegion := v.mapEngine.GetRegionAt(int(tileX), int(tileY)) curRegion := v.mapEngine.GetRegionAt(int(tileX), int(tileY))
if curRegion == nil { if curRegion == nil {
return return
} }
ebitenutil.DebugPrintAt(screen, "Map: "+curRegion.LevelType.Name, 5, 17) line := fmt.Sprintf("%d, %d (Tile %d.%d, %d.%d)",
int(math.Ceil(actualX)),
int(math.Ceil(actualY)),
int(math.Ceil(tileX))-curRegion.Rect.Left,
subtileX,
int(math.Ceil(tileY))-curRegion.Rect.Top,
subtileY,
)
ebitenutil.DebugPrintAt(screen, line, 5, 5)
ebitenutil.DebugPrintAt(screen, "Map: "+curRegion.Region.LevelType.Name, 5, 17)
ebitenutil.DebugPrintAt(screen, curRegion.Region.RegionPath, 5, 29)
} }
func (v *MapEngineTest) Update(tickTime float64) { func (v *MapEngineTest) Update(tickTime float64) {

4
go.sum
View File

@ -2,6 +2,7 @@ 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/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 h1:tDnuU0igiBiQFjsvq1Bi7DpoUjqI76VVvW045vpeFeM=
github.com/JoshVarga/blast v0.0.0-20180421040937-681c804fb9f0/go.mod h1:h/5OEGj4G+fpYxluLjSMZbFY011ZxAntO98nCl8mrCs= github.com/JoshVarga/blast v0.0.0-20180421040937-681c804fb9f0/go.mod h1:h/5OEGj4G+fpYxluLjSMZbFY011ZxAntO98nCl8mrCs=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/giorgisio/goav v0.1.0 h1:ZyfG3NfX7PMSimv4ulhmnQJf/XeHpMdGCn+afRmY5Oc= github.com/giorgisio/goav v0.1.0 h1:ZyfG3NfX7PMSimv4ulhmnQJf/XeHpMdGCn+afRmY5Oc=
github.com/giorgisio/goav v0.1.0/go.mod h1:RtH8HyxLRLU1iY0pjfhWBKRhnbsnmfoI+FxMwb5bfEo= github.com/giorgisio/goav v0.1.0/go.mod h1:RtH8HyxLRLU1iY0pjfhWBKRhnbsnmfoI+FxMwb5bfEo=
github.com/go-gl/glfw v0.0.0-20181213070059-819e8ce5125f h1:7MsFMbSn8Lcw0blK4+NEOf8DuHoOBDhJsHz04yh13pM= github.com/go-gl/glfw v0.0.0-20181213070059-819e8ce5125f h1:7MsFMbSn8Lcw0blK4+NEOf8DuHoOBDhJsHz04yh13pM=
@ -11,6 +12,7 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9
github.com/gofrs/flock v0.7.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gofrs/flock v0.7.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gofrs/flock v0.7.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gofrs/flock v0.7.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/google/pprof v0.0.0-20191105193234-27840fff0d09/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/gopherjs/gopherjs v0.0.0-20180628210949-0892b62f0d9f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20180628210949-0892b62f0d9f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c h1:16eHWuMGvCjSfgRJKqIzapE78onvvTbdi1rMkU00lZw= github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c h1:16eHWuMGvCjSfgRJKqIzapE78onvvTbdi1rMkU00lZw=
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
@ -35,6 +37,7 @@ github.com/hajimehoshi/oto v0.3.3/go.mod h1:e9eTLBB9iZto045HLbzfHJIc+jP3xaKrjZTg
github.com/hajimehoshi/oto v0.3.4/go.mod h1:PgjqsBJff0efqL2nlMJidJgVJywLn6M4y8PI4TfeWfA= github.com/hajimehoshi/oto v0.3.4/go.mod h1:PgjqsBJff0efqL2nlMJidJgVJywLn6M4y8PI4TfeWfA=
github.com/hajimehoshi/oto v0.5.2 h1:5FEPlejAsR2PVRqiW7h2PIwp9UWR+8zxj2And102YU4= github.com/hajimehoshi/oto v0.5.2 h1:5FEPlejAsR2PVRqiW7h2PIwp9UWR+8zxj2And102YU4=
github.com/hajimehoshi/oto v0.5.2/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI= github.com/hajimehoshi/oto v0.5.2/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jakecoffman/cp v0.1.0/go.mod h1:a3xPx9N8RyFAACD644t2dj/nK4SuLg1v+jL61m2yVo4= github.com/jakecoffman/cp v0.1.0/go.mod h1:a3xPx9N8RyFAACD644t2dj/nK4SuLg1v+jL61m2yVo4=
github.com/jfreymuth/oggvorbis v1.0.0/go.mod h1:abe6F9QRjuU9l+2jek3gj46lu40N4qlYxh2grqkLEDM= github.com/jfreymuth/oggvorbis v1.0.0/go.mod h1:abe6F9QRjuU9l+2jek3gj46lu40N4qlYxh2grqkLEDM=
github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2QD06bfOE0= github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2QD06bfOE0=
@ -44,6 +47,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pkg/profile v1.3.0/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20180710024300-14dda7b62fcd h1:nLIcFw7GiqKXUS7HiChg6OAYWgASB2H97dZKd1GhDSs= golang.org/x/exp v0.0.0-20180710024300-14dda7b62fcd h1:nLIcFw7GiqKXUS7HiChg6OAYWgASB2H97dZKd1GhDSs=