diff --git a/culling.go b/culling.go index 849b86e..86e6aa8 100644 --- a/culling.go +++ b/culling.go @@ -80,14 +80,14 @@ func (c *Culling2D) GetName() string { // Updates visibility of all contained sprites. func (c *Culling2D) Update(delta float64) { - for i := range c.cullables { - if c.cullables[i].Pos.X > c.viewport.Z || - c.cullables[i].Pos.X+c.cullables[i].Size.X < c.viewport.X || - c.cullables[i].Pos.Y > c.viewport.W || - c.cullables[i].Pos.Y+c.cullables[i].Size.Y < c.viewport.Y { - c.cullables[i].Visible = false + for _, cullable := range c.cullables { + if cullable.Pos.X > c.viewport.Z || + cullable.Pos.X+cullable.Size.X < c.viewport.X || + cullable.Pos.Y > c.viewport.W || + cullable.Pos.Y+cullable.Size.Y < c.viewport.Y { + cullable.Visible = false } else { - c.cullables[i].Visible = true + cullable.Visible = true } } } diff --git a/keyframe.go b/keyframe.go index bdcb65b..a998a84 100644 --- a/keyframe.go +++ b/keyframe.go @@ -206,22 +206,22 @@ func (s *KeyframeRenderer) GetName() string { // Updates animation state and renders sprites. func (s *KeyframeRenderer) Update(delta float64) { // update animation state - for i := range s.sprites { - if s.sprites[i].KeyframeAnimation == nil { + for _, sprite := range s.sprites { + if sprite.KeyframeAnimation == nil { continue } - s.sprites[i].Interpolation += delta * s.sprites[i].KeyframeAnimation.Speed + sprite.Interpolation += delta * sprite.KeyframeAnimation.Speed - if s.sprites[i].Interpolation > 1 { - s.sprites[i].Interpolation = 0 - s.sprites[i].Current++ + if sprite.Interpolation > 1 { + sprite.Interpolation = 0 + sprite.Current++ - if s.sprites[i].Current > s.sprites[i].KeyframeAnimation.End { - if s.sprites[i].KeyframeAnimation.Loop { - s.sprites[i].Current = s.sprites[i].KeyframeAnimation.Start + if sprite.Current > sprite.KeyframeAnimation.End { + if sprite.KeyframeAnimation.Loop { + sprite.Current = sprite.KeyframeAnimation.Start } else { - s.sprites[i].Current = s.sprites[i].KeyframeAnimation.End + sprite.Current = sprite.KeyframeAnimation.End } } } @@ -233,17 +233,17 @@ func (s *KeyframeRenderer) Update(delta float64) { s.Shader.SendUniform1i(Default_shader_2D_tex, 0) s.vao.Bind() - for i := range s.sprites { - if !s.sprites[i].Visible { + for _, sprite := range s.sprites { + if !sprite.Visible { continue } - texCoord := s.sprites[i].KeyframeSet.Keyframes[s.sprites[i].Current].texCoord + texCoord := sprite.KeyframeSet.Keyframes[sprite.Current].texCoord texCoord.Bind() texCoord.AttribPointer(s.Shader.GetAttribLocation(Default_shader_2D_texcoord_attrib), 2, gl.FLOAT, false, 0) - s.Shader.SendMat3(Default_shader_2D_model, *s.sprites[i].CalcModel()) - s.sprites[i].Tex.Bind() + s.Shader.SendMat3(Default_shader_2D_model, *sprite.CalcModel()) + sprite.Tex.Bind() gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, nil) } diff --git a/model.go b/model.go index 0ca2c77..51fe768 100644 --- a/model.go +++ b/model.go @@ -174,20 +174,20 @@ func (s *ModelRenderer) Update(delta float64) { var tid uint32 - for i := range s.models { - if !s.models[i].Visible { + for _, model := range s.models { + if !model.Visible { continue } - s.Shader.SendMat4(Default_shader_3D_model, *s.models[i].CalcModel()) - s.models[i].Vao.Bind() + s.Shader.SendMat4(Default_shader_3D_model, *model.CalcModel()) + model.Vao.Bind() // prevent texture switching when not neccessary - if tid != s.models[i].Tex.GetId() { - tid = s.models[i].Tex.GetId() - s.models[i].Tex.Bind() + if tid != model.Tex.GetId() { + tid = model.Tex.GetId() + model.Tex.Bind() } - gl.DrawElements(gl.TRIANGLES, s.models[i].Index.Size(), gl.UNSIGNED_INT, nil) + gl.DrawElements(gl.TRIANGLES, model.Index.Size(), gl.UNSIGNED_INT, nil) } } diff --git a/sprite.go b/sprite.go index be4c0bd..bb6898b 100644 --- a/sprite.go +++ b/sprite.go @@ -140,17 +140,17 @@ func (s *SpriteRenderer) Update(delta float64) { s.vao.Bind() var tid uint32 - for i := range s.sprites { - if !s.sprites[i].Visible { + for _, sprite := range s.sprites { + if !sprite.Visible { continue } - s.Shader.SendMat3(Default_shader_2D_model, *s.sprites[i].CalcModel()) + s.Shader.SendMat3(Default_shader_2D_model, *sprite.CalcModel()) // prevent texture switching when not neccessary - if tid != s.sprites[i].Tex.GetId() { - tid = s.sprites[i].Tex.GetId() - s.sprites[i].Tex.Bind() + if tid != sprite.Tex.GetId() { + tid = sprite.Tex.GetId() + sprite.Tex.Bind() } gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, nil) diff --git a/text.go b/text.go index 3f46074..99dea7b 100644 --- a/text.go +++ b/text.go @@ -423,15 +423,15 @@ func (r *TextRenderer) Update(delta float64) { r.Shader.SendUniform1i(Default_shader_text_tex, 0) r.Font.Tex.Bind() - for i := range r.texts { - if !r.texts[i].Visible { + for _, text := range r.texts { + if !text.Visible { continue } - r.texts[i].vao.Bind() - r.Shader.SendUniform4f(Default_shader_text_color, float32(r.texts[i].Color.X), float32(r.texts[i].Color.Y), float32(r.texts[i].Color.Z), float32(r.texts[i].Color.W)) - r.Shader.SendMat3(Default_shader_text_model, *r.texts[i].CalcModel()) + text.vao.Bind() + r.Shader.SendUniform4f(Default_shader_text_color, float32(text.Color.X), float32(text.Color.Y), float32(text.Color.Z), float32(text.Color.W)) + r.Shader.SendMat3(Default_shader_text_model, *text.CalcModel()) - gl.DrawElements(gl.TRIANGLES, r.texts[i].index.Size(), gl.UNSIGNED_INT, nil) + gl.DrawElements(gl.TRIANGLES, text.index.Size(), gl.UNSIGNED_INT, nil) } }