mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/restorable: refactoring
This commit is contained in:
parent
b36160d9e7
commit
9ef9ea0469
@ -482,12 +482,12 @@ func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeStaleIfDependingOn makes the image stale if the image depends on target.
|
// makeStaleIfDependingOn makes the image stale if the image depends on src.
|
||||||
func (i *Image) makeStaleIfDependingOn(target *Image) {
|
func (i *Image) makeStaleIfDependingOn(src *Image) {
|
||||||
if i.stale {
|
if i.stale {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if i.dependsOn(target) {
|
if i.dependsOn(src) {
|
||||||
// There is no new region to make stale.
|
// There is no new region to make stale.
|
||||||
i.makeStale(image.Rectangle{})
|
i.makeStale(image.Rectangle{})
|
||||||
}
|
}
|
||||||
@ -573,18 +573,16 @@ func (i *Image) resolveStale(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
return i.readPixelsFromGPU(graphicsDriver)
|
return i.readPixelsFromGPU(graphicsDriver)
|
||||||
}
|
}
|
||||||
|
|
||||||
// dependsOn reports whether the image depends on target.
|
// dependsOn reports whether the image depends on src.
|
||||||
func (i *Image) dependsOn(target *Image) bool {
|
func (i *Image) dependsOn(src *Image) bool {
|
||||||
for _, c := range i.drawTrianglesHistory {
|
for _, c := range i.drawTrianglesHistory {
|
||||||
for _, img := range c.images {
|
for _, img := range c.images {
|
||||||
if img == nil {
|
if img != src {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if img == target {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,16 +164,16 @@ func (i *images) resolveStaleImages(graphicsDriver graphicsdriver.Graphics) erro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeStaleIfDependingOn makes all the images stale that depend on target.
|
// makeStaleIfDependingOn makes all the images stale that depend on src.
|
||||||
//
|
//
|
||||||
// When target is modified, all images depending on target can't be restored with target.
|
// When src is modified, all images depending on src can't be restored with src.
|
||||||
// makeStaleIfDependingOn is called in such situation.
|
// makeStaleIfDependingOn is called in such situation.src.
|
||||||
func (i *images) makeStaleIfDependingOn(target *Image) {
|
func (i *images) makeStaleIfDependingOn(src *Image) {
|
||||||
if target == nil {
|
if src == nil {
|
||||||
panic("restorable: target must not be nil at makeStaleIfDependingOn")
|
panic("restorable: src must not be nil at makeStaleIfDependingOn")
|
||||||
}
|
}
|
||||||
for img := range i.images {
|
for img := range i.images {
|
||||||
img.makeStaleIfDependingOn(target)
|
img.makeStaleIfDependingOn(src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user