Rename ID -> Id

This commit is contained in:
Hajime Hoshi 2013-10-21 22:18:10 +09:00
parent 3a383b3078
commit a0f17a4971
8 changed files with 51 additions and 51 deletions

View File

@ -10,7 +10,7 @@ import (
) )
type Input struct { type Input struct {
textTextureID graphics.TextureID textTextureId graphics.TextureId
inputState ebiten.InputState inputState ebiten.InputState
} }
@ -29,7 +29,7 @@ func (game *Input) InitTextures(tf graphics.TextureFactory) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if game.textTextureID, err = tf.NewTextureFromImage(img); err != nil { if game.textTextureId, err = tf.NewTextureFromImage(img); err != nil {
panic(err) panic(err)
} }
} }
@ -74,6 +74,6 @@ func (game *Input) drawText(g graphics.Context, text string, x, y int) {
geometryMatrix := matrix.IdentityGeometry() geometryMatrix := matrix.IdentityGeometry()
geometryMatrix.Translate(float64(x), float64(y)) geometryMatrix.Translate(float64(x), float64(y))
colorMatrix := matrix.IdentityColor() colorMatrix := matrix.IdentityColor()
g.DrawTextureParts(game.textTextureID, parts, g.DrawTextureParts(game.textTextureId, parts,
geometryMatrix, colorMatrix) geometryMatrix, colorMatrix)
} }

View File

@ -15,7 +15,7 @@ const (
) )
type Monochrome struct { type Monochrome struct {
ebitenTextureID graphics.TextureID ebitenTextureId graphics.TextureId
ch chan bool ch chan bool
colorMatrix matrix.Color colorMatrix matrix.Color
geometryMatrix matrix.Geometry geometryMatrix matrix.Geometry
@ -40,7 +40,7 @@ func (game *Monochrome) InitTextures(tf graphics.TextureFactory) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if game.ebitenTextureID, err = tf.NewTextureFromImage(img); err != nil { if game.ebitenTextureId, err = tf.NewTextureFromImage(img); err != nil {
panic(err) panic(err)
} }
@ -102,6 +102,6 @@ func (game *Monochrome) Update(context ebiten.GameContext) {
func (game *Monochrome) Draw(g graphics.Context) { func (game *Monochrome) Draw(g graphics.Context) {
g.Fill(128, 128, 255) g.Fill(128, 128, 255)
g.DrawTexture(game.ebitenTextureID, g.DrawTexture(game.ebitenTextureId,
game.geometryMatrix, game.colorMatrix) game.geometryMatrix, game.colorMatrix)
} }

View File

@ -11,9 +11,9 @@ import (
) )
type Rects struct { type Rects struct {
rectTextureID graphics.RenderTargetID rectTextureId graphics.RenderTargetId
rectTextureInited bool rectTextureInited bool
offscreenID graphics.RenderTargetID offscreenId graphics.RenderTargetId
offscreenInited bool offscreenInited bool
rectBounds *graphics.Rect rectBounds *graphics.Rect
rectColor *color.RGBA rectColor *color.RGBA
@ -37,11 +37,11 @@ func New() *Rects {
func (game *Rects) InitTextures(tf graphics.TextureFactory) { func (game *Rects) InitTextures(tf graphics.TextureFactory) {
var err error var err error
game.rectTextureID, err = tf.NewRenderTarget(rectTextureWidth, rectTextureHeight) game.rectTextureId, err = tf.NewRenderTarget(rectTextureWidth, rectTextureHeight)
if err != nil { if err != nil {
panic(err) panic(err)
} }
game.offscreenID, err = tf.NewRenderTarget(offscreenWidth, offscreenHeight) game.offscreenId, err = tf.NewRenderTarget(offscreenWidth, offscreenHeight)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -88,22 +88,22 @@ func (game *Rects) rectColorMatrix() matrix.Color {
func (game *Rects) Draw(g graphics.Context) { func (game *Rects) Draw(g graphics.Context) {
if !game.rectTextureInited { if !game.rectTextureInited {
g.SetOffscreen(game.rectTextureID) g.SetOffscreen(game.rectTextureId)
g.Fill(255, 255, 255) g.Fill(255, 255, 255)
game.rectTextureInited = true game.rectTextureInited = true
} }
g.SetOffscreen(game.offscreenID) g.SetOffscreen(game.offscreenId)
if !game.offscreenInited { if !game.offscreenInited {
g.Fill(0, 0, 0) g.Fill(0, 0, 0)
game.offscreenInited = true game.offscreenInited = true
} }
g.DrawTexture(g.ToTexture(game.rectTextureID), g.DrawTexture(g.ToTexture(game.rectTextureId),
game.rectGeometryMatrix(), game.rectGeometryMatrix(),
game.rectColorMatrix()) game.rectColorMatrix())
g.ResetOffscreen() g.ResetOffscreen()
g.DrawTexture(g.ToTexture(game.offscreenID), g.DrawTexture(g.ToTexture(game.offscreenId),
matrix.IdentityGeometry(), matrix.IdentityGeometry(),
matrix.IdentityColor()) matrix.IdentityColor())
} }

View File

@ -16,7 +16,7 @@ const (
) )
type Rotating struct { type Rotating struct {
ebitenTextureID graphics.TextureID ebitenTextureId graphics.TextureId
x int x int
geometryMatrix matrix.Geometry geometryMatrix matrix.Geometry
} }
@ -36,7 +36,7 @@ func (game *Rotating) InitTextures(tf graphics.TextureFactory) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if game.ebitenTextureID, err = tf.NewTextureFromImage(img); err != nil { if game.ebitenTextureId, err = tf.NewTextureFromImage(img); err != nil {
panic(err) panic(err)
} }
} }
@ -56,7 +56,7 @@ func (game *Rotating) Update(context ebiten.GameContext) {
func (game *Rotating) Draw(g graphics.Context) { func (game *Rotating) Draw(g graphics.Context) {
g.Fill(128, 128, 255) g.Fill(128, 128, 255)
g.DrawTexture(game.ebitenTextureID, g.DrawTexture(game.ebitenTextureId,
game.geometryMatrix, game.geometryMatrix,
matrix.IdentityColor()) matrix.IdentityColor())
} }

View File

@ -64,7 +64,7 @@ func (sprite *Sprite) Update() {
} }
type Sprites struct { type Sprites struct {
ebitenTextureID graphics.TextureID ebitenTextureId graphics.TextureId
sprites []*Sprite sprites []*Sprite
} }
@ -86,7 +86,7 @@ func (game *Sprites) InitTextures(tf graphics.TextureFactory) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if game.ebitenTextureID, err = tf.NewTextureFromImage(img); err != nil { if game.ebitenTextureId, err = tf.NewTextureFromImage(img); err != nil {
panic(err) panic(err)
} }
} }
@ -125,7 +125,7 @@ func (game *Sprites) Draw(g graphics.Context) {
locations = append(locations, location) locations = append(locations, location)
} }
geometryMatrix := matrix.IdentityGeometry() geometryMatrix := matrix.IdentityGeometry()
g.DrawTextureParts(game.ebitenTextureID, locations, g.DrawTextureParts(game.ebitenTextureId, locations,
geometryMatrix, matrix.IdentityColor()) geometryMatrix, matrix.IdentityColor())
} }

View File

@ -11,7 +11,7 @@ import (
) )
type TestPattern struct { type TestPattern struct {
textureId graphics.TextureID textureId graphics.TextureId
textureWidth int textureWidth int
textureHeight int textureHeight int
geos []matrix.Geometry geos []matrix.Geometry

View File

@ -19,28 +19,28 @@ type TexturePart struct {
} }
type Context interface { type Context interface {
ToTexture(id RenderTargetID) TextureID ToTexture(id RenderTargetId) TextureId
Clear() Clear()
Fill(r, g, b uint8) Fill(r, g, b uint8)
DrawTexture(id TextureID, DrawTexture(id TextureId,
geometryMatrix matrix.Geometry, geometryMatrix matrix.Geometry,
colorMatrix matrix.Color) colorMatrix matrix.Color)
DrawTextureParts(id TextureID, DrawTextureParts(id TextureId,
parts []TexturePart, parts []TexturePart,
geometryMatrix matrix.Geometry, geometryMatrix matrix.Geometry,
colorMatrix matrix.Color) colorMatrix matrix.Color)
ResetOffscreen() ResetOffscreen()
SetOffscreen(id RenderTargetID) SetOffscreen(id RenderTargetId)
} }
type TextureFactory interface { type TextureFactory interface {
NewRenderTarget(width, height int) (RenderTargetID, error) NewRenderTarget(width, height int) (RenderTargetId, error)
NewTextureFromImage(img image.Image) (TextureID, error) NewTextureFromImage(img image.Image) (TextureId, error)
} }
type TextureID int type TextureId int
// A render target is essentially same as a texture, but it is assumed that the // A render target is essentially same as a texture, but it is assumed that the
// all alpha of a render target is maximum. // all alpha of a render target is maximum.
type RenderTargetID int type RenderTargetId int

View File

@ -15,13 +15,13 @@ import (
) )
type Context struct { type Context struct {
screenId graphics.RenderTargetID screenId graphics.RenderTargetId
screenWidth int screenWidth int
screenHeight int screenHeight int
screenScale int screenScale int
textures map[graphics.TextureID]*Texture textures map[graphics.TextureId]*Texture
renderTargets map[graphics.RenderTargetID]*RenderTarget renderTargets map[graphics.RenderTargetId]*RenderTarget
renderTargetToTexture map[graphics.RenderTargetID]graphics.TextureID renderTargetToTexture map[graphics.RenderTargetId]graphics.TextureId
currentOffscreen *RenderTarget currentOffscreen *RenderTarget
mainFramebufferTexture *RenderTarget mainFramebufferTexture *RenderTarget
} }
@ -31,9 +31,9 @@ func newContext(screenWidth, screenHeight, screenScale int) *Context {
screenWidth: screenWidth, screenWidth: screenWidth,
screenHeight: screenHeight, screenHeight: screenHeight,
screenScale: screenScale, screenScale: screenScale,
textures: map[graphics.TextureID]*Texture{}, textures: map[graphics.TextureId]*Texture{},
renderTargets: map[graphics.RenderTargetID]*RenderTarget{}, renderTargets: map[graphics.RenderTargetId]*RenderTarget{},
renderTargetToTexture: map[graphics.RenderTargetID]graphics.TextureID{}, renderTargetToTexture: map[graphics.RenderTargetId]graphics.TextureId{},
} }
return context return context
} }
@ -59,8 +59,8 @@ func (context *Context) Init() {
} }
} }
func (context *Context) ToTexture(renderTargetID graphics.RenderTargetID) graphics.TextureID { func (context *Context) ToTexture(renderTargetId graphics.RenderTargetId) graphics.TextureId {
return context.renderTargetToTexture[renderTargetID] return context.renderTargetToTexture[renderTargetId]
} }
func (context *Context) Clear() { func (context *Context) Clear() {
@ -78,25 +78,25 @@ func (context *Context) Fill(r, g, b uint8) {
} }
func (context *Context) DrawTexture( func (context *Context) DrawTexture(
textureID graphics.TextureID, textureId graphics.TextureId,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
texture, ok := context.textures[textureID] texture, ok := context.textures[textureId]
if !ok { if !ok {
panic("invalid texture ID") panic("invalid texture ID")
} }
source := graphics.Rect{0, 0, texture.width, texture.height} source := graphics.Rect{0, 0, texture.width, texture.height}
locations := []graphics.TexturePart{{0, 0, source}} locations := []graphics.TexturePart{{0, 0, source}}
context.DrawTextureParts(textureID, locations, context.DrawTextureParts(textureId, locations,
geometryMatrix, colorMatrix) geometryMatrix, colorMatrix)
} }
func (context *Context) DrawTextureParts( func (context *Context) DrawTextureParts(
textureID graphics.TextureID, parts []graphics.TexturePart, textureId graphics.TextureId, parts []graphics.TexturePart,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
texture, ok := context.textures[textureID] texture, ok := context.textures[textureId]
if !ok { if !ok {
panic("invalid texture ID") panic("invalid texture Id")
} }
shaderProgram := context.setShaderProgram(geometryMatrix, colorMatrix) shaderProgram := context.setShaderProgram(geometryMatrix, colorMatrix)
@ -151,8 +151,8 @@ func (context *Context) ResetOffscreen() {
context.SetOffscreen(context.screenId) context.SetOffscreen(context.screenId)
} }
func (context *Context) SetOffscreen(renderTargetID graphics.RenderTargetID) { func (context *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) {
renderTarget := context.renderTargets[renderTargetID] renderTarget := context.renderTargets[renderTargetId]
context.setOffscreen(renderTarget) context.setOffscreen(renderTarget)
} }
@ -267,13 +267,13 @@ func (context *Context) setShaderProgram(
} }
func (context *Context) NewRenderTarget(width, height int) ( func (context *Context) NewRenderTarget(width, height int) (
graphics.RenderTargetID, error) { graphics.RenderTargetId, error) {
renderTarget, err := newRenderTarget(width, height) renderTarget, err := newRenderTarget(width, height)
if err != nil { if err != nil {
return 0, nil return 0, nil
} }
renderTargetId := graphics.RenderTargetID(<-newId) renderTargetId := graphics.RenderTargetId(<-newId)
textureId := graphics.TextureID(<-newId) textureId := graphics.TextureId(<-newId)
context.renderTargets[renderTargetId] = renderTarget context.renderTargets[renderTargetId] = renderTarget
context.textures[textureId] = renderTarget.texture context.textures[textureId] = renderTarget.texture
context.renderTargetToTexture[renderTargetId] = textureId context.renderTargetToTexture[renderTargetId] = textureId
@ -286,12 +286,12 @@ func (context *Context) NewRenderTarget(width, height int) (
} }
func (context *Context) NewTextureFromImage(img image.Image) ( func (context *Context) NewTextureFromImage(img image.Image) (
graphics.TextureID, error) { graphics.TextureId, error) {
texture, err := newTextureFromImage(img) texture, err := newTextureFromImage(img)
if err != nil { if err != nil {
return 0, err return 0, err
} }
textureId := graphics.TextureID(<-newId) textureId := graphics.TextureId(<-newId)
context.textures[textureId] = texture context.textures[textureId] = texture
return textureId, nil return textureId, nil
} }