Add 'Tag' to the methods of TextureFactory

This commit is contained in:
Hajime Hoshi 2013-12-03 23:24:34 +09:00
parent 79c74273f5
commit dd979ac4d6
9 changed files with 32 additions and 16 deletions

View File

@ -42,7 +42,7 @@ func (game *Input) InitTextures(tf graphics.TextureFactory) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if game.textTextureId, err = tf.CreateTextureFromImage(img); err != nil { if game.textTextureId, err = tf.CreateTextureFromImage("text", img); err != nil {
panic(err) panic(err)
} }
} }

View File

@ -51,7 +51,7 @@ func (game *Monochrome) InitTextures(tf graphics.TextureFactory) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if game.ebitenTextureId, err = tf.CreateTextureFromImage(img); err != nil { if game.ebitenTextureId, err = tf.CreateTextureFromImage("ebiten", img); err != nil {
panic(err) panic(err)
} }

View File

@ -48,11 +48,11 @@ func (game *Rects) OnScreenSizeUpdated(e ui.ScreenSizeUpdatedEvent) {
func (game *Rects) InitTextures(tf graphics.TextureFactory) { func (game *Rects) InitTextures(tf graphics.TextureFactory) {
var err error var err error
game.rectTextureId, err = tf.CreateRenderTarget(rectTextureWidth, rectTextureHeight) game.rectTextureId, err = tf.CreateRenderTarget("rect", rectTextureWidth, rectTextureHeight)
if err != nil { if err != nil {
panic(err) panic(err)
} }
game.offscreenId, err = tf.CreateRenderTarget(offscreenWidth, offscreenHeight) game.offscreenId, err = tf.CreateRenderTarget("offscreen", offscreenWidth, offscreenHeight)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -48,7 +48,7 @@ func (game *Rotating) InitTextures(tf graphics.TextureFactory) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if game.ebitenTextureId, err = tf.CreateTextureFromImage(img); err != nil { if game.ebitenTextureId, err = tf.CreateTextureFromImage("ebiten", img); err != nil {
panic(err) panic(err)
} }
} }

View File

@ -95,7 +95,7 @@ func (game *Sprites) InitTextures(tf graphics.TextureFactory) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if game.ebitenTextureId, err = tf.CreateTextureFromImage(img); err != nil { if game.ebitenTextureId, err = tf.CreateTextureFromImage("ebiten", img); err != nil {
panic(err) panic(err)
} }
} }

View File

@ -31,7 +31,7 @@ func (game *TestPattern) InitTextures(tf graphics.TextureFactory) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if game.textureId, err = tf.CreateTextureFromImage(img); err != nil { if game.textureId, err = tf.CreateTextureFromImage("test", img); err != nil {
panic(err) panic(err)
} }
size := img.Bounds().Size() size := img.Bounds().Size()

View File

@ -59,12 +59,11 @@ func main() {
var u ui.UI = cocoa.New(screenWidth, screenHeight, screenScale, title) var u ui.UI = cocoa.New(screenWidth, screenHeight, screenScale, title)
// TODO: Get a map or something // TODO: Get a map or something
u.LoadResources(game.InitTextures) u.LoadResources(game.InitTextures)
inputStateUpdated := u.InputStateUpdated()
screenSizeUpdated := u.ScreenSizeUpdated()
drawing := make(chan *graphics.LazyCanvas) drawing := make(chan *graphics.LazyCanvas)
go func() { go func() {
inputStateUpdated := u.InputStateUpdated()
screenSizeUpdated := u.ScreenSizeUpdated()
frameTime := time.Duration(int64(time.Second) / int64(fps)) frameTime := time.Duration(int64(time.Second) / int64(fps))
tick := time.Tick(frameTime) tick := time.Tick(frameTime)
for { for {

View File

@ -110,12 +110,12 @@ func (context *Context) createRenderTarget(width, height int, filter texture.Fil
return renderTargetId, nil return renderTargetId, nil
} }
func (context *Context) CreateRenderTarget(width, height int) ( func (context *Context) CreateRenderTarget(tag string, width, height int) (
graphics.RenderTargetId, error) { graphics.RenderTargetId, error) {
return context.createRenderTarget(width, height, texture.FilterLinear) return context.createRenderTarget(width, height, texture.FilterLinear)
} }
func (context *Context) CreateTextureFromImage(img image.Image) ( func (context *Context) CreateTextureFromImage(tag string, img image.Image) (
graphics.TextureId, error) { graphics.TextureId, error) {
return context.ids.CreateTextureFromImage(img) return context.ids.CreateTextureFromImage(img)
} }

View File

@ -4,8 +4,25 @@ import (
"image" "image"
) )
// TODO: Remove this? type TextureCreatedEvent struct {
type TextureFactory interface { Tag string
CreateRenderTarget(width, height int) (RenderTargetId, error) Id TextureId
CreateTextureFromImage(img image.Image) (TextureId, error) Error error
}
type RenderTargetCreatedEvent struct {
Tag string
RenderTargetId RenderTargetId
Error error
}
type TextureFactoryEvents interface {
TextureCreated() <-chan TextureCreatedEvent
RenderTargetCreated() <-chan RenderTargetCreatedEvent
}
type TextureFactory interface {
CreateRenderTarget(tag string, width, height int) (RenderTargetId, error)
CreateTextureFromImage(tag string, img image.Image) (TextureId, error)
//TextureFactoryEvents
} }