This commit is contained in:
Hajime Hoshi 2014-12-06 22:56:57 +09:00
parent ca56d05dfa
commit 7d4540d863
7 changed files with 26 additions and 42 deletions

View File

@ -53,12 +53,12 @@ func NewGame(textures Textures) *Game {
}
func (game *Game) isInitialized() bool {
for name, _ := range texturePaths {
for name := range texturePaths {
if !game.textures.Has(name) {
return false
}
}
for name, _ := range renderTargetSizes {
for name := range renderTargetSizes {
if !game.textures.Has(name) {
return false
}

View File

@ -23,7 +23,7 @@ func (i *Input) StateForKey(key ui.Key) int {
}
func (i *Input) Update(keys ui.Keys) {
for key, _ := range i.states {
for key := range i.states {
if !keys.Includes(key) {
i.states[key] = 0
continue

View File

@ -60,7 +60,7 @@ func toBlocks(ints [][]int) [][]bool {
}
var Pieces = map[BlockType]*Piece{
BlockType1: &Piece{
BlockType1: {
blockType: BlockType1,
blocks: toBlocks([][]int{
{0, 0, 0, 0},
@ -69,7 +69,7 @@ var Pieces = map[BlockType]*Piece{
{0, 0, 0, 0},
}),
},
BlockType2: &Piece{
BlockType2: {
blockType: BlockType2,
blocks: toBlocks([][]int{
{1, 0, 0},
@ -77,7 +77,7 @@ var Pieces = map[BlockType]*Piece{
{0, 0, 0},
}),
},
BlockType3: &Piece{
BlockType3: {
blockType: BlockType3,
blocks: toBlocks([][]int{
{0, 1, 0},
@ -85,7 +85,7 @@ var Pieces = map[BlockType]*Piece{
{0, 0, 0},
}),
},
BlockType4: &Piece{
BlockType4: {
blockType: BlockType4,
blocks: toBlocks([][]int{
{0, 0, 1},
@ -93,7 +93,7 @@ var Pieces = map[BlockType]*Piece{
{0, 0, 0},
}),
},
BlockType5: &Piece{
BlockType5: {
blockType: BlockType5,
blocks: toBlocks([][]int{
{1, 1, 0},
@ -101,7 +101,7 @@ var Pieces = map[BlockType]*Piece{
{0, 0, 0},
}),
},
BlockType6: &Piece{
BlockType6: {
blockType: BlockType6,
blocks: toBlocks([][]int{
{0, 1, 1},
@ -109,7 +109,7 @@ var Pieces = map[BlockType]*Piece{
{0, 0, 0},
}),
},
BlockType7: &Piece{
BlockType7: {
blockType: BlockType7,
blocks: toBlocks([][]int{
{1, 1},
@ -217,9 +217,9 @@ func (p *Piece) Draw(
angle Angle) {
size := len(p.blocks)
blocks := make([][]BlockType, size)
for i, _ := range p.blocks {
for i := range p.blocks {
blocks[i] = make([]BlockType, size)
for j, _ := range blocks[i] {
for j := range blocks[i] {
if p.isBlocked(i, j, angle) {
blocks[i][j] = p.blockType
}

View File

@ -10,21 +10,8 @@ type program struct {
shaderIds []shaderId
}
type programId int
const (
programRegular programId = iota
programColorMatrix
)
var programs = map[programId]*program{
// TODO: programRegular is not used for now. Remove this.
programRegular: &program{
shaderIds: []shaderId{shaderVertex, shaderFragment},
},
programColorMatrix: &program{
var programColorMatrix = program{
shaderIds: []shaderId{shaderVertex, shaderColorMatrix},
},
}
func (p *program) create() {
@ -52,9 +39,8 @@ func initialize() {
}
}()
for _, program := range programs {
program.create()
}
programColorMatrix.create()
programColorMatrix.native.Use()
}
type qualifierVariableType int
@ -66,8 +52,8 @@ const (
var (
shaderLocationCache = map[qualifierVariableType]map[string]gl.AttribLocation{
qualifierVariableTypeAttribute: map[string]gl.AttribLocation{},
qualifierVariableTypeUniform: map[string]gl.AttribLocation{},
qualifierVariableTypeAttribute: {},
qualifierVariableTypeUniform: {},
}
)
@ -102,10 +88,8 @@ func getUniformLocation(program gl.Program, name string) gl.UniformLocation {
}
func use(projectionMatrix [16]float32, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) gl.Program {
programId := programColorMatrix
program := programs[programId]
// TODO: Check the performance.
program.native.Use()
program := programColorMatrix
getUniformLocation(program.native, "projection_matrix").UniformMatrix4fv(false, projectionMatrix)

View File

@ -21,7 +21,7 @@ const (
)
var shaders = map[shaderId]*shader{
shaderVertex: &shader{
shaderVertex: {
shaderType: gl.VERTEX_SHADER,
source: `
uniform mat4 projection_matrix;
@ -36,7 +36,7 @@ void main(void) {
}
`,
},
shaderFragment: &shader{
shaderFragment: {
shaderType: gl.FRAGMENT_SHADER,
source: `
uniform sampler2D texture;
@ -47,7 +47,7 @@ void main(void) {
}
`,
},
shaderColorMatrix: &shader{
shaderColorMatrix: {
shaderType: gl.FRAGMENT_SHADER,
source: `
uniform sampler2D texture;
@ -61,7 +61,7 @@ void main(void) {
}
`,
},
shaderSolidColor: &shader{
shaderSolidColor: {
shaderType: gl.FRAGMENT_SHADER,
source: `
uniform vec4 color;