mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
restorable: Refactoring
Reduces accesses to Image member from outside.
This commit is contained in:
parent
434802af6e
commit
b348223297
@ -182,6 +182,11 @@ func (i *Image) IsInvalidated() bool {
|
||||
//
|
||||
// This is for testing usage.
|
||||
func (i *Image) Dump(path string) error {
|
||||
// Screen image cannot be dumped.
|
||||
if i.screen {
|
||||
return nil
|
||||
}
|
||||
|
||||
path = strings.ReplaceAll(path, "*", fmt.Sprintf("%d", i.id))
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
|
@ -476,7 +476,11 @@ func (i *Image) hasDependency() bool {
|
||||
|
||||
// Restore restores *graphicscommand.Image from the pixels using its state.
|
||||
func (i *Image) restore() error {
|
||||
w, h := i.image.Size()
|
||||
w, h := i.Size()
|
||||
|
||||
// Dispose the internal image after getting its size for safety.
|
||||
i.image.Dispose()
|
||||
|
||||
if i.screen {
|
||||
// The screen image should also be recreated because framebuffer might
|
||||
// be changed.
|
||||
|
@ -95,10 +95,7 @@ func RestoreIfNeeded() error {
|
||||
// This is for testing usage.
|
||||
func DumpImages(dir string) error {
|
||||
for img := range theImages.images {
|
||||
if img.screen {
|
||||
continue
|
||||
}
|
||||
if err := img.image.Dump(filepath.Join(dir, "*.png")); err != nil {
|
||||
if err := img.Dump(filepath.Join(dir, "*.png")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -154,12 +151,6 @@ func (i *images) restore() error {
|
||||
panic("restorable: restore cannot be called when restoring is disabled")
|
||||
}
|
||||
|
||||
// Dispose image explicitly
|
||||
for img := range i.images {
|
||||
img.image.Dispose()
|
||||
// img.image can't be set nil here, or Size() panics when restoring.
|
||||
}
|
||||
|
||||
// Let's do topological sort based on dependencies of drawing history.
|
||||
// It is assured that there are not loops since cyclic drawing makes images stale.
|
||||
type edge struct {
|
||||
|
Loading…
Reference in New Issue
Block a user