From e1745f1c2bc5395f13edd182bd30d95d415cc1c1 Mon Sep 17 00:00:00 2001 From: falsycat Date: Mon, 14 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Tidied a part of codes. --- sjplayer/src/sjplayer/Actor.d | 6 ++---- sjplayer/src/sjplayer/Background.d | 6 ++---- sjplayer/src/sjplayer/CircleElement.d | 3 +-- sjplayer/src/sjplayer/ElementDrawer.d | 6 ++---- sjplayer/src/sjplayer/PostEffect.d | 15 +++++---------- src/sj/CubeProgram.d | 12 ++++-------- src/sj/SelectScene.d | 10 ++++++---- src/sj/Text.d | 7 ++----- src/sj/TextProgram.d | 6 ++---- src/sj/TitleTextProgram.d | 9 +++------ src/sj/util/image.d | 3 +-- 11 files changed, 30 insertions(+), 53 deletions(-) diff --git a/sjplayer/src/sjplayer/Actor.d b/sjplayer/src/sjplayer/Actor.d index 74ab72f..3b64c93 100644 --- a/sjplayer/src/sjplayer/Actor.d +++ b/sjplayer/src/sjplayer/Actor.d @@ -93,8 +93,7 @@ class ActorProgram { verts_ = ArrayBuffer.Create(); vao_.Bind(); - VertexArrayAttacher attacher; - with (attacher) { + with (VertexArrayAttacher()) { index = 0; type = GL_FLOAT; dimension = 2; @@ -102,8 +101,7 @@ class ActorProgram { } verts_.Bind(); - ArrayBufferAllocator verts_allocator; - with (verts_allocator) { + with (ArrayBufferAllocator()) { const v = [vec2(-1, 1), vec2(1, 1), vec2(1, -1), vec2(-1, -1),]; data = v.ptr; size = typeof(v[0]).sizeof * v.length; diff --git a/sjplayer/src/sjplayer/Background.d b/sjplayer/src/sjplayer/Background.d index 0d77129..4082311 100644 --- a/sjplayer/src/sjplayer/Background.d +++ b/sjplayer/src/sjplayer/Background.d @@ -72,8 +72,7 @@ class BackgroundProgram { verts_ = ArrayBuffer.Create(); vao_.Bind(); - VertexArrayAttacher attacher; - with (attacher) { + with (VertexArrayAttacher()) { index = 0; type = GL_FLOAT; dimension = 2; @@ -81,8 +80,7 @@ class BackgroundProgram { } verts_.Bind(); - ArrayBufferAllocator verts_allocator; - with (verts_allocator) { + with (ArrayBufferAllocator()) { const v = [vec2(-1, 1), vec2(1, 1), vec2(1, -1), vec2(-1, -1),]; data = v.ptr; size = typeof(v[0]).sizeof * v.length; diff --git a/sjplayer/src/sjplayer/CircleElement.d b/sjplayer/src/sjplayer/CircleElement.d index cfacf65..b801555 100644 --- a/sjplayer/src/sjplayer/CircleElement.d +++ b/sjplayer/src/sjplayer/CircleElement.d @@ -152,8 +152,7 @@ class CircleElementProgram { /// void SetupVertexArray(ref VertexArrayRef vao, ref ArrayBufferRef verts, ref ArrayBufferRef instances) { - VertexArrayAttacher attacher; - with (attacher) { + with (VertexArrayAttacher()) { // verts type = GL_FLOAT; dimension = 2; diff --git a/sjplayer/src/sjplayer/ElementDrawer.d b/sjplayer/src/sjplayer/ElementDrawer.d index a34eaea..d053e4c 100644 --- a/sjplayer/src/sjplayer/ElementDrawer.d +++ b/sjplayer/src/sjplayer/ElementDrawer.d @@ -30,8 +30,7 @@ class ElementDrawer(Program, Element, vec2[] vertices) : program_.SetupVertexArray(vao_, verts_, instances_); verts_.Bind(); - ArrayBufferAllocator verts_allocator; - with (verts_allocator) { + with (ArrayBufferAllocator()) { const v = vertices; // place to memory data = v.ptr; @@ -41,8 +40,7 @@ class ElementDrawer(Program, Element, vec2[] vertices) : } instances_.Bind(); - ArrayBufferAllocator instance_allocator; - with (instance_allocator) { + with (ArrayBufferAllocator()) { size = Instance.sizeof * elements.length; usage = GL_DYNAMIC_DRAW; Allocate(instances_); diff --git a/sjplayer/src/sjplayer/PostEffect.d b/sjplayer/src/sjplayer/PostEffect.d index 70d1f08..15274f0 100644 --- a/sjplayer/src/sjplayer/PostEffect.d +++ b/sjplayer/src/sjplayer/PostEffect.d @@ -30,8 +30,7 @@ class PostEffect { tex_ = TextureRect.Create(); sampler_ = Sampler.Create(); - TextureRectAllocator allocator; - with (allocator) { + with (TextureRectAllocator()) { internalFormat = GL_RGB; size = sz; format = GL_RED; @@ -40,8 +39,7 @@ class PostEffect { Allocate(tex_); } - SamplerConfigurer configurer; - with (configurer) { + with (SamplerConfigurer()) { filterMin = GL_NEAREST; filterMag = GL_NEAREST; Configure(sampler_); @@ -152,8 +150,7 @@ class PostEffectProgram { ubo_index_ = gl.GetUniformBlockIndex(program_.id, "Instance".toStringz); vao_.Bind(); - VertexArrayAttacher attacher; - with (attacher) { + with (VertexArrayAttacher()) { index = 0; type = GL_FLOAT; dimension = 2; @@ -161,8 +158,7 @@ class PostEffectProgram { } verts_.Bind(); - ArrayBufferAllocator verts_allocator; - with (verts_allocator) { + with (ArrayBufferAllocator()) { const v = [vec2(-1, 1), vec2(1, 1), vec2(1, -1), vec2(-1, -1),]; data = v.ptr; size = typeof(v[0]).sizeof * v.length; @@ -171,8 +167,7 @@ class PostEffectProgram { } ubo_.Bind(); - UniformBufferAllocator ub_allocator; - with (ub_allocator) { + with (UniformBufferAllocator()) { size = PostEffect.Instance.sizeof; usage = GL_DYNAMIC_DRAW; Allocate(ubo_); diff --git a/src/sj/CubeProgram.d b/src/sj/CubeProgram.d index 06faad4..fbb26e9 100644 --- a/src/sj/CubeProgram.d +++ b/src/sj/CubeProgram.d @@ -127,8 +127,7 @@ class CubeProgram { material_index_ = gl.GetUniformBlockIndex(program_.id, "Material".toStringz); material_.Bind(); - UniformBufferAllocator material_allocator; - with (material_allocator) { + with (UniformBufferAllocator()) { data = null; size = Material.sizeof; usage = GL_DYNAMIC_DRAW; @@ -140,8 +139,7 @@ class CubeProgram { instances_ = ArrayBuffer.Create(); vao_.Bind(); - VertexArrayAttacher attacher; - with (attacher) { + with (VertexArrayAttacher()) { index = 0; type = GL_FLOAT; offset = vec3.sizeof * 0; @@ -175,8 +173,7 @@ class CubeProgram { } verts_.Bind(); - ArrayBufferAllocator verts_allocator; - with (verts_allocator) { + with (ArrayBufferAllocator()) { enum v = [ // left vec3(-1, 1, -1), vec3(-1, 1, 1), vec3(-1, -1, 1), @@ -224,8 +221,7 @@ class CubeProgram { } instances_.Bind(); - ArrayBufferAllocator instances_allocator; - with (instances_allocator) { + with (ArrayBufferAllocator()) { data = null; size = MaxInstanceCount * mat4.sizeof; usage = GL_DYNAMIC_DRAW; diff --git a/src/sj/SelectScene.d b/src/sj/SelectScene.d index 6864b4c..a128df5 100644 --- a/src/sj/SelectScene.d +++ b/src/sj/SelectScene.d @@ -166,11 +166,13 @@ private class FirstSetupState : AbstractSceneState { override UpdateResult Update(KeyInput input) { const ratio = anime_.Update(); - owner.lobby_.cube_matrix.rotation += LoadingCubeRotationSpeed * (ratio+0.2); - owner.lobby_.cube_interval = cube_interval_ease_.Calculate(ratio); + with (owner.lobby_) { + cube_matrix.rotation += LoadingCubeRotationSpeed * (ratio+0.2); + cube_interval = cube_interval_ease_.Calculate(ratio); - owner.lobby_.background.inner_color = bg_inner_ease_.Calculate(ratio); - owner.lobby_.background.outer_color = bg_outer_ease_.Calculate(ratio); + background.inner_color = bg_inner_ease_.Calculate(ratio); + background.outer_color = bg_outer_ease_.Calculate(ratio); + } if (anime_.isFinished) { stage_appear_state_.Initialize(0); diff --git a/src/sj/Text.d b/src/sj/Text.d index 2dc6a80..9d699e5 100644 --- a/src/sj/Text.d +++ b/src/sj/Text.d @@ -29,7 +29,6 @@ class Text { static assert(TextProgram.Vertex.sizeof == float.sizeof * 5); vertices_.Bind(); - ArrayBufferAllocator vertices_allocator; with (ArrayBufferAllocator()) { size = text.length * TextProgram.Vertex.sizeof * 4; usage = GL_STATIC_DRAW; @@ -103,8 +102,7 @@ class Text { } texture_.Bind(); - Texture2DAllocator texture_allocator; - with (texture_allocator) { + with (Texture2DAllocator()) { level = 0; internalFormat = GL_RGBA8; data = pixels.ptr; @@ -115,8 +113,7 @@ class Text { } indices_.Bind(); - ElementArrayBufferAllocator indices_allcator; - with (indices_allcator) { + with (ElementArrayBufferAllocator()) { size = glyph_count * 6 * ushort.sizeof; usage = GL_STATIC_DRAW; Allocate(indices_); diff --git a/src/sj/TextProgram.d b/src/sj/TextProgram.d index 486ac55..74f5d9e 100644 --- a/src/sj/TextProgram.d +++ b/src/sj/TextProgram.d @@ -59,8 +59,7 @@ class TextProgram { program_.Validate(); sampler_ = Sampler.Create(); - SamplerConfigurer configurer; - with (configurer) { + with (SamplerConfigurer()) { filterMin = GL_LINEAR; filterMag = GL_LINEAR; Configure(sampler_); @@ -70,8 +69,7 @@ class TextProgram { /// void SetupVertexArray(ref VertexArrayRef vao, ref ArrayBufferRef vertices) { vao.Bind(); - VertexArrayAttacher attacher; - with (attacher) { + with (VertexArrayAttacher()) { index = 0; type = GL_FLOAT; offset = 0; diff --git a/src/sj/TitleTextProgram.d b/src/sj/TitleTextProgram.d index 55e9fa5..07a7e82 100644 --- a/src/sj/TitleTextProgram.d +++ b/src/sj/TitleTextProgram.d @@ -99,8 +99,7 @@ class TitleTextProgram { tex_ = CreateTextureFromBuffer(ImgBuf); sampler_ = Sampler.Create(); - SamplerConfigurer configurer; - with (configurer) { + with (SamplerConfigurer()) { filterMin = GL_LINEAR; filterMag = GL_LINEAR; Configure(sampler_); @@ -110,8 +109,7 @@ class TitleTextProgram { vertices_ = ArrayBuffer.Create(); vao_.Bind(); - VertexArrayAttacher attacher; - with (attacher) { + with (VertexArrayAttacher()) { index = 0; type = GL_FLOAT; offset = 0; @@ -128,8 +126,7 @@ class TitleTextProgram { } vertices_.Bind(); - ArrayBufferAllocator allocator; - with (allocator) { + with (ArrayBufferAllocator()) { const v = [ -1f, 1f, 0f, 1f, 0f, -1f, -1f, 0f, 1f, 1f, diff --git a/src/sj/util/image.d b/src/sj/util/image.d index 70ba1b5..6afa030 100644 --- a/src/sj/util/image.d +++ b/src/sj/util/image.d @@ -23,8 +23,7 @@ Texture2DRef CreateTextureFromImage(sfImage* img) { sz.y.isPowerOf2.enforce(); auto tex = Texture2D.Create(); - Texture2DAllocator allocator; - with (allocator) { + with (Texture2DAllocator()) { level = 0; internalFormat = GL_RGBA8; data = sfImage_getPixelsPtr(img);