mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-06-29 10:35:23 +00:00
Sped up sprint loading time exponentially
This commit is contained in:
parent
01524fdb1d
commit
036d35956e
23
Sprite.go
23
Sprite.go
|
@ -80,6 +80,7 @@ func CreateSprite(data []byte, palette Palette) Sprite {
|
||||||
|
|
||||||
x := uint32(0)
|
x := uint32(0)
|
||||||
y := uint32(result.Frames[i].Height - 1)
|
y := uint32(result.Frames[i].Height - 1)
|
||||||
|
go func(ix, dataPointer uint32) {
|
||||||
for true {
|
for true {
|
||||||
b := data[dataPointer]
|
b := data[dataPointer]
|
||||||
dataPointer++
|
dataPointer++
|
||||||
|
@ -92,30 +93,30 @@ func CreateSprite(data []byte, palette Palette) Sprite {
|
||||||
} else if (b & 0x80) > 0 {
|
} else if (b & 0x80) > 0 {
|
||||||
transparentPixels := b & 0x7F
|
transparentPixels := b & 0x7F
|
||||||
for ti := byte(0); ti < transparentPixels; ti++ {
|
for ti := byte(0); ti < transparentPixels; ti++ {
|
||||||
result.Frames[i].ImageData[x+(y*result.Frames[i].Width)+uint32(ti)] = -1
|
result.Frames[ix].ImageData[x+(y*result.Frames[ix].Width)+uint32(ti)] = -1
|
||||||
}
|
}
|
||||||
x += uint32(transparentPixels)
|
x += uint32(transparentPixels)
|
||||||
} else {
|
} else {
|
||||||
for bi := 0; bi < int(b); bi++ {
|
for bi := 0; bi < int(b); bi++ {
|
||||||
result.Frames[i].ImageData[x+(y*result.Frames[i].Width)+uint32(bi)] = int16(data[dataPointer])
|
result.Frames[ix].ImageData[x+(y*result.Frames[ix].Width)+uint32(bi)] = int16(data[dataPointer])
|
||||||
dataPointer++
|
dataPointer++
|
||||||
}
|
}
|
||||||
x += uint32(b)
|
x += uint32(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.Frames[i].Image, _ = ebiten.NewImage(int(result.Frames[i].Width), int(result.Frames[i].Height), ebiten.FilterNearest)
|
result.Frames[ix].Image, _ = ebiten.NewImage(int(result.Frames[ix].Width), int(result.Frames[ix].Height), ebiten.FilterNearest)
|
||||||
newData := make([]byte, result.Frames[i].Width*result.Frames[i].Height*4)
|
newData := make([]byte, result.Frames[ix].Width*result.Frames[ix].Height*4)
|
||||||
for ii := uint32(0); ii < result.Frames[i].Width*result.Frames[i].Height; ii++ {
|
for ii := uint32(0); ii < result.Frames[ix].Width*result.Frames[ix].Height; ii++ {
|
||||||
if result.Frames[i].ImageData[ii] == -1 {
|
if result.Frames[ix].ImageData[ii] == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newData[ii*4] = palette.Colors[result.Frames[i].ImageData[ii]].R
|
newData[ii*4] = palette.Colors[result.Frames[ix].ImageData[ii]].R
|
||||||
newData[(ii*4)+1] = palette.Colors[result.Frames[i].ImageData[ii]].G
|
newData[(ii*4)+1] = palette.Colors[result.Frames[ix].ImageData[ii]].G
|
||||||
newData[(ii*4)+2] = palette.Colors[result.Frames[i].ImageData[ii]].B
|
newData[(ii*4)+2] = palette.Colors[result.Frames[ix].ImageData[ii]].B
|
||||||
newData[(ii*4)+3] = 0xFF
|
newData[(ii*4)+3] = 0xFF
|
||||||
}
|
}
|
||||||
|
result.Frames[ix].Image.ReplacePixels(newData)
|
||||||
result.Frames[i].Image.ReplacePixels(newData)
|
}(i, dataPointer)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user