diff --git a/debug_ebitendebug.go b/debug_ebitendebug.go new file mode 100644 index 000000000..c10b9882e --- /dev/null +++ b/debug_ebitendebug.go @@ -0,0 +1,21 @@ +// Copyright 2018 The Ebiten Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build ebitendebug + +package ebiten + +func isDebug() bool { + return true +} diff --git a/debug_notebitendebug.go b/debug_notebitendebug.go new file mode 100644 index 000000000..65ce26660 --- /dev/null +++ b/debug_notebitendebug.go @@ -0,0 +1,21 @@ +// Copyright 2018 The Ebiten Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !ebitendebug + +package ebiten + +func isDebug() bool { + return false +} diff --git a/doc.go b/doc.go index 8df43efd5..7b874a073 100644 --- a/doc.go +++ b/doc.go @@ -43,5 +43,6 @@ // by pressing Q key. // // The EBITEN_INTERNAL_IMAGES_KEY environment variable specifies the key -// to dump all the internal images. +// to dump all the internal images. This is valid only when the build tag +// 'ebitendebug' is specified. package ebiten diff --git a/run.go b/run.go index fff07362e..3bdbf98db 100644 --- a/run.go +++ b/run.go @@ -109,6 +109,11 @@ type imageDumper struct { } func (i *imageDumper) update(screen *Image) error { + const ( + envScreenshotKey = "EBITEN_SCREENSHOT_KEY" + envInternalImagesKey = "EBITEN_INTERNAL_IMAGES_KEY" + ) + if err := i.f(screen); err != nil { return err } @@ -117,16 +122,21 @@ func (i *imageDumper) update(screen *Image) error { if i.keyState == nil { i.keyState = map[Key]int{} - if keyname := os.Getenv("EBITEN_SCREENSHOT_KEY"); keyname != "" { + if keyname := os.Getenv(envScreenshotKey); keyname != "" { if key, ok := keyNameToKey(keyname); ok { i.hasScreenshotKey = true i.screenshotKey = key } } - if keyname := os.Getenv("EBITEN_INTERNAL_IMAGES_KEY"); keyname != "" { - if key, ok := keyNameToKey(keyname); ok { - i.hasDumpInternalImagesKey = true - i.dumpInternalImagesKey = key + + if keyname := os.Getenv(envInternalImagesKey); keyname != "" { + if isDebug() { + if key, ok := keyNameToKey(keyname); ok { + i.hasDumpInternalImagesKey = true + i.dumpInternalImagesKey = key + } + } else { + fmt.Fprintf(os.Stderr, "%s is disabled. Specify a build tag 'ebitendebug' to enable it.\n", envInternalImagesKey) } } }