Resolve some TODOs

This commit is contained in:
Hajime Hoshi 2015-02-10 10:44:58 +09:00
parent cd4188b0a3
commit beecf31937
7 changed files with 18 additions and 22 deletions

View File

@ -109,7 +109,7 @@ func Queue(channel int, l []int16, r []int16) {
ch.r = append(ch.r, r...) ch.r = append(ch.r, r...)
} }
func Update() { func Tick() {
for _, ch := range channels { for _, ch := range channels {
ch.nextInsertionPosition += SampleRate / 60 ch.nextInsertionPosition += SampleRate / 60
} }

View File

@ -21,7 +21,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl" "github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"
"image" "image"
"image/color" "image/color"
"math"
) )
// Image represents an image. // Image represents an image.
@ -46,15 +45,8 @@ func (i *Image) Clear() (err error) {
// Fill fills the image with a solid color. // Fill fills the image with a solid color.
func (i *Image) Fill(clr color.Color) (err error) { func (i *Image) Fill(clr color.Color) (err error) {
i.pixels = nil i.pixels = nil
cr, cg, cb, ca := clr.RGBA()
const max = math.MaxUint16
r := float64(cr) / max
g := float64(cg) / max
b := float64(cb) / max
a := float64(ca) / max
useGLContext(func(c *opengl.Context) { useGLContext(func(c *opengl.Context) {
// TODO: Change to pass color.Color err = i.framebuffer.Fill(c, clr)
err = i.framebuffer.Fill(c, r, g, b, a)
}) })
return return
} }
@ -187,7 +179,8 @@ func (i *Image) dispose() {
// //
// This function may be slow (as for implementation, this calls glTexSubImage2D). // This function may be slow (as for implementation, this calls glTexSubImage2D).
func (i *Image) ReplacePixels(p []uint8) error { func (i *Image) ReplacePixels(p []uint8) error {
// TODO: Can we set p to pixels? // Don't set i.pixels here because i.pixels is used not every time.
i.pixels = nil i.pixels = nil
w, h := i.Size() w, h := i.Size()
l := 4 * w * h l := 4 * w * h

View File

@ -33,7 +33,7 @@ type ImageParts interface {
Src(i int) (x0, y0, x1, y1 int) Src(i int) (x0, y0, x1, y1 int)
} }
// TODO: Remove this in the future. // NOTE: Remove this in the future.
type imageParts []ImagePart type imageParts []ImagePart
func (p imageParts) Len() int { func (p imageParts) Len() int {

View File

@ -38,7 +38,7 @@ var vertices = make([]int16, 0, 4*8*quadsMaxNum)
var shadersInitialized = false var shadersInitialized = false
func drawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4][4]float64, quads TextureQuads, geo Matrix, color Matrix) error { func drawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4][4]float64, quads TextureQuads, geo Matrix, color Matrix) error {
// TODO: WebGL doesn't seem to have Check gl.MAX_ELEMENTS_VERTICES or gl.MAX_ELEMENTS_INDICES so far. // NOTE: WebGL doesn't seem to have Check gl.MAX_ELEMENTS_VERTICES or gl.MAX_ELEMENTS_INDICES so far.
// Let's use them to compare to len(quads) in the future. // Let's use them to compare to len(quads) in the future.
if !shadersInitialized { if !shadersInitialized {

View File

@ -17,6 +17,7 @@ package graphics
import ( import (
"github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl" "github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"
"image/color" "image/color"
"math"
) )
type TextureQuads interface { type TextureQuads interface {
@ -109,10 +110,16 @@ func (f *Framebuffer) projectionMatrix() *[4][4]float64 {
return m return m
} }
func (f *Framebuffer) Fill(c *opengl.Context, r, g, b, a float64) error { func (f *Framebuffer) Fill(c *opengl.Context, clr color.Color) error {
if err := f.setAsViewport(c); err != nil { if err := f.setAsViewport(c); err != nil {
return err return err
} }
cr, cg, cb, ca := clr.RGBA()
const max = math.MaxUint16
r := float64(cr) / max
g := float64(cg) / max
b := float64(cb) / max
a := float64(ca) / max
return c.FillFramebuffer(r, g, b, a) return c.FillFramebuffer(r, g, b, a)
} }

View File

@ -65,8 +65,7 @@ type userInterface struct{}
var currentUI = &userInterface{} var currentUI = &userInterface{}
// TODO: This returns true even when the browser is not active. // NOTE: This returns true even when the browser is not active.
// The current behavior causes sound noise...
func shown() bool { func shown() bool {
return !js.Global.Get("document").Get("hidden").Bool() return !js.Global.Get("document").Get("hidden").Bool()
} }
@ -179,7 +178,7 @@ func Init() {
}) })
// Touch (emulating mouse events) // Touch (emulating mouse events)
// TODO: Need to create indimendent touch functions? // TODO: Create indimendent touch functions
canvas.Call("addEventListener", "touchstart", func(e js.Object) { canvas.Call("addEventListener", "touchstart", func(e js.Object) {
e.Call("preventDefault") e.Call("preventDefault")
currentInput.MouseDown(0) currentInput.MouseDown(0)
@ -208,7 +207,7 @@ func Init() {
} }
func setMouseCursorFromEvent(e js.Object) { func setMouseCursorFromEvent(e js.Object) {
scale := canvas.Get("dataset").Get("ebitenScale").Int() // TODO: Float? scale := canvas.Get("dataset").Get("ebitenScale").Int()
rect := canvas.Call("getBoundingClientRect") rect := canvas.Call("getBoundingClientRect")
x, y := e.Get("clientX").Int(), e.Get("clientY").Int() x, y := e.Get("clientX").Int(), e.Get("clientY").Int()
x -= rect.Get("left").Int() x -= rect.Get("left").Int()

5
run.go
View File

@ -103,8 +103,7 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
if err := graphicsContext.postUpdate(); err != nil { if err := graphicsContext.postUpdate(); err != nil {
return err return err
} }
// TODO: I'm not sure this is 'Update'. Is 'Tick' better? audio.Tick()
audio.Update()
ui.SwapBuffers() ui.SwapBuffers()
if err != nil { if err != nil {
return err return err
@ -144,5 +143,3 @@ func SetScreenScale(scale int) {
} }
runContext.newScreenScale = scale runContext.newScreenScale = scale
} }
// TODO: Create SetScreenPosition (for GLFW)