mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +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.
|
// This is for testing usage.
|
||||||
func (i *Image) Dump(path string) error {
|
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))
|
path = strings.ReplaceAll(path, "*", fmt.Sprintf("%d", i.id))
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -476,7 +476,11 @@ func (i *Image) hasDependency() bool {
|
|||||||
|
|
||||||
// Restore restores *graphicscommand.Image from the pixels using its state.
|
// Restore restores *graphicscommand.Image from the pixels using its state.
|
||||||
func (i *Image) restore() error {
|
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 {
|
if i.screen {
|
||||||
// The screen image should also be recreated because framebuffer might
|
// The screen image should also be recreated because framebuffer might
|
||||||
// be changed.
|
// be changed.
|
||||||
|
@ -95,10 +95,7 @@ func RestoreIfNeeded() error {
|
|||||||
// This is for testing usage.
|
// This is for testing usage.
|
||||||
func DumpImages(dir string) error {
|
func DumpImages(dir string) error {
|
||||||
for img := range theImages.images {
|
for img := range theImages.images {
|
||||||
if img.screen {
|
if err := img.Dump(filepath.Join(dir, "*.png")); err != nil {
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := img.image.Dump(filepath.Join(dir, "*.png")); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,12 +151,6 @@ func (i *images) restore() error {
|
|||||||
panic("restorable: restore cannot be called when restoring is disabled")
|
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.
|
// 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.
|
// It is assured that there are not loops since cyclic drawing makes images stale.
|
||||||
type edge struct {
|
type edge struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user