From 833e467fdefe7ff8fa45f87e7ce73d310eaea3b1 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 22 May 2019 00:24:38 +0900 Subject: [PATCH] Make Ebiten buildable on the playground environment Bug: #871 --- .travis.yml | 1 + graphics_notmac.go => graphics_opengl.go | 4 ++- graphics_playground.go | 35 ++++++++++++++++++++++++ run.go | 5 ++++ ui_glfw.go | 4 +-- ui_playground.go | 35 ++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 3 deletions(-) rename graphics_notmac.go => graphics_opengl.go (83%) create mode 100644 graphics_playground.go create mode 100644 ui_playground.go diff --git a/.travis.yml b/.travis.yml index b33805bb1..ae74c1d0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,6 +49,7 @@ script: - gjbt github.com/hajimehoshi/ebiten # TODO: Test the subdirectories - GOOS=windows GOARCH=amd64 go build -tags example -v github.com/hajimehoshi/ebiten/examples/... - GOOS=windows GOARCH=386 go build -tags example -v github.com/hajimehoshi/ebiten/examples/... + - CGO_ENABLED=0 go vet github.com/hajimehoshi/ebiten # This is necessary for the Go playground # - test -z $(gofmt -s -l $GOPATH/src/github.com/hajimehoshi/ebiten) diff --git a/graphics_notmac.go b/graphics_opengl.go similarity index 83% rename from graphics_notmac.go rename to graphics_opengl.go index 4baa78efe..d2cca2cf0 100644 --- a/graphics_notmac.go +++ b/graphics_opengl.go @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build !darwin ios js +// +build android freebsd ios js linux,cgo windows + +// As the Go playground tries to compile this with CGO_ENABLED=0 and GOOS=linux, check Cgo on build tags. package ebiten diff --git a/graphics_playground.go b/graphics_playground.go new file mode 100644 index 000000000..fad4841e4 --- /dev/null +++ b/graphics_playground.go @@ -0,0 +1,35 @@ +// Copyright 2019 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 !android +// +build !darwin +// +build !freebsd +// +build !ios +// +build !js +// +build !linux,cgo !cgo +// +build !windows + +package ebiten + +import ( + "github.com/hajimehoshi/ebiten/internal/driver" +) + +func graphicsDriver() driver.Graphics { + if !isPlayground { + panic("ebiten: a graphics driver is not implemented on this environment") + } + // TODO: Implement this + return nil +} diff --git a/run.go b/run.go index 54fc43206..373d3d822 100644 --- a/run.go +++ b/run.go @@ -17,6 +17,7 @@ package ebiten import ( "image" "sync/atomic" + "time" "github.com/hajimehoshi/ebiten/internal/clock" "github.com/hajimehoshi/ebiten/internal/driver" @@ -25,6 +26,10 @@ import ( var _ = __EBITEN_REQUIRES_GO_VERSION_1_12_OR_LATER__ +// isPlayground indicates whether the current environment is the Go Playground (play.golang.org) or not. +// The fixed time is explicitly defined. See "About the Playground" at play.golang.org. +var isPlayground = time.Now().UnixNano() == 1257894000000000000 + // TPS represents a default ticks per second, that represents how many times game updating happens in a second. const DefaultTPS = 60 diff --git a/ui_glfw.go b/ui_glfw.go index 5d50972b3..66a873de4 100644 --- a/ui_glfw.go +++ b/ui_glfw.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build darwin freebsd linux windows -// +build !js +// +build darwin freebsd linux,cgo windows // +build !android // +build !ios +// +build !js package ebiten diff --git a/ui_playground.go b/ui_playground.go new file mode 100644 index 000000000..cd9ee02bf --- /dev/null +++ b/ui_playground.go @@ -0,0 +1,35 @@ +// Copyright 2019 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 !android +// +build !darwin +// +build !freebsd +// +build !ios +// +build !js +// +build !linux,cgo !cgo +// +build !windows + +package ebiten + +import ( + "github.com/hajimehoshi/ebiten/internal/driver" +) + +func uiDriver() driver.UI { + if !isPlayground { + panic("ebiten: a UI driver is not implemented on this environment") + } + // TODO: Implement this + return nil +}