mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-20 23:47:16 -05:00
Performance Enhancements (#118)
* More optimizations. Fixed button rendering issue.
This commit is contained in:
parent
a105bb390a
commit
7859b69da6
@ -37,6 +37,7 @@ type SpriteFrame struct {
|
||||
NextBlock uint32
|
||||
Length uint32
|
||||
ImageData []int16
|
||||
FrameData []byte
|
||||
Image *ebiten.Image
|
||||
}
|
||||
|
||||
@ -117,22 +118,62 @@ func CreateSprite(data []byte, palette PaletteRec) *Sprite {
|
||||
x += uint32(b)
|
||||
}
|
||||
}
|
||||
var img = image.NewRGBA(image.Rect(0, 0, int(result.Frames[i].Width), int(result.Frames[i].Height)))
|
||||
result.Frames[i].FrameData = make([]byte, result.Frames[i].Width*result.Frames[i].Height*4)
|
||||
for ii := uint32(0); ii < result.Frames[i].Width*result.Frames[i].Height; ii++ {
|
||||
if result.Frames[i].ImageData[ii] < 1 { // TODO: Is this == -1 or < 1?
|
||||
continue
|
||||
}
|
||||
img.Pix[ii*4] = palette.Colors[result.Frames[i].ImageData[ii]].R
|
||||
img.Pix[(ii*4)+1] = palette.Colors[result.Frames[i].ImageData[ii]].G
|
||||
img.Pix[(ii*4)+2] = palette.Colors[result.Frames[i].ImageData[ii]].B
|
||||
img.Pix[(ii*4)+3] = 0xFF
|
||||
result.Frames[i].FrameData[ii*4] = palette.Colors[result.Frames[i].ImageData[ii]].R
|
||||
result.Frames[i].FrameData[(ii*4)+1] = palette.Colors[result.Frames[i].ImageData[ii]].G
|
||||
result.Frames[i].FrameData[(ii*4)+2] = palette.Colors[result.Frames[i].ImageData[ii]].B
|
||||
result.Frames[i].FrameData[(ii*4)+3] = 0xFF
|
||||
}
|
||||
newImage, _ := ebiten.NewImageFromImage(img, ebiten.FilterNearest)
|
||||
result.Frames[i].Image = newImage
|
||||
img = nil
|
||||
//newImage, _ := ebiten.NewImageFromImage(img, ebiten.FilterNearest)
|
||||
//result.Frames[i].Image = newImage
|
||||
//img = nil
|
||||
}(i)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
totalWidth := 0
|
||||
totalHeight := 0
|
||||
frame := 0
|
||||
for d := 0; d < int(result.Directions); d++ {
|
||||
curMaxHeight := 0
|
||||
for f := 0; f < int(result.FramesPerDirection); f++ {
|
||||
totalWidth += int(result.Frames[frame].Width)
|
||||
curMaxHeight = int(Max(uint32(curMaxHeight), result.Frames[frame].Height))
|
||||
frame++
|
||||
}
|
||||
totalHeight += curMaxHeight
|
||||
}
|
||||
atlas, _ := ebiten.NewImage(totalWidth, totalHeight, ebiten.FilterNearest)
|
||||
frame = 0
|
||||
curX := 0
|
||||
curY := 0
|
||||
for d := 0; d < int(result.Directions); d++ {
|
||||
curMaxHeight := 0
|
||||
for f := 0; f < int(result.FramesPerDirection); f++ {
|
||||
curMaxHeight = int(Max(uint32(curMaxHeight), result.Frames[frame].Height))
|
||||
result.Frames[frame].Image = atlas.SubImage(image.Rect(curX, curY, curX+int(result.Frames[frame].Width), curY+int(result.Frames[frame].Height))).(*ebiten.Image)
|
||||
for y := 0; y < int(result.Frames[frame].Height); y++ {
|
||||
for x := 0; x < int(result.Frames[frame].Width); x++ {
|
||||
pix := (x + (y * int(result.Frames[frame].Width))) * 4
|
||||
atlas.Set(curX+x, curY+y, color.RGBA{
|
||||
R: result.Frames[frame].FrameData[pix],
|
||||
G: result.Frames[frame].FrameData[pix+1],
|
||||
B: result.Frames[frame].FrameData[pix+2],
|
||||
A: result.Frames[frame].FrameData[pix+3],
|
||||
})
|
||||
}
|
||||
}
|
||||
//result.Frames[frame].Image.ReplacePixels(result.Frames[frame].FrameData)
|
||||
curX += int(result.Frames[frame].Width)
|
||||
frame++
|
||||
}
|
||||
curY += curMaxHeight
|
||||
curX = 0
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
10
go.mod
10
go.mod
@ -1,15 +1,21 @@
|
||||
module github.com/OpenDiablo2/OpenDiablo2
|
||||
|
||||
go 1.13
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/JoshVarga/blast v0.0.0-20180421040937-681c804fb9f0
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
|
||||
github.com/giorgisio/goav v0.1.0
|
||||
github.com/google/pprof v0.0.0-20191105193234-27840fff0d09 // indirect
|
||||
github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de // indirect
|
||||
github.com/gopherjs/gopherwasm v1.1.0 // indirect
|
||||
github.com/hajimehoshi/ebiten v1.10.0
|
||||
github.com/hajimehoshi/ebiten v1.10.1-0.20191108205544-35436ea50457
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/pkg/profile v1.3.0
|
||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 // indirect
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de // indirect
|
||||
golang.org/x/mobile v0.0.0-20191031020345-0945064e013a // indirect
|
||||
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd // indirect
|
||||
golang.org/x/tools v0.0.0-20191107010934-f79515f33823 // indirect
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -29,6 +29,8 @@ github.com/hajimehoshi/ebiten v1.9.3 h1:YijWGMBwH2XA1ZytUQFy33UDHeCSS6d4JZKH1wq3
|
||||
github.com/hajimehoshi/ebiten v1.9.3/go.mod h1:XxiJ4Eltvb1KmcD0i6F81eIB1asJhK47y5DC+FPkyso=
|
||||
github.com/hajimehoshi/ebiten v1.10.0 h1:ADLOUI/7aaTOP7GRlQBHVI1Qtvfdt9M6XQqeULSK7Uo=
|
||||
github.com/hajimehoshi/ebiten v1.10.0/go.mod h1:8BJhIws+Jkol+z7hSGP/WFsaDAPTtRQ+ELBPPQetq2w=
|
||||
github.com/hajimehoshi/ebiten v1.10.1-0.20191108205544-35436ea50457 h1:n9Axj1heARCUjNydhLXjmb6jWsTz5CGechSJRyxFXl0=
|
||||
github.com/hajimehoshi/ebiten v1.10.1-0.20191108205544-35436ea50457/go.mod h1:8BJhIws+Jkol+z7hSGP/WFsaDAPTtRQ+ELBPPQetq2w=
|
||||
github.com/hajimehoshi/go-mp3 v0.2.0/go.mod h1:4i+c5pDNKDrxl1iu9iG90/+fhP37lio6gNhjCx9WBJw=
|
||||
github.com/hajimehoshi/go-mp3 v0.2.1/go.mod h1:Rr+2P46iH6PwTPVgSsEwBkon0CK5DxCAeX/Rp65DCTE=
|
||||
github.com/hajimehoshi/oto v0.1.1/go.mod h1:hUiLWeBQnbDu4pZsAhOnGqMI1ZGibS6e2qhQdfpwz04=
|
||||
|
Loading…
x
Reference in New Issue
Block a user