From d6cd2e2e7e2317c3a2bf22bc050e588fef741b46 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 26 Aug 2014 00:05:08 -0300 Subject: [PATCH 1/2] Prettied up some code. --- src/modules/audio/openal/Pool.cpp | 26 +++++++++++--------------- src/modules/graphics/Volatile.cpp | 17 ++++------------- src/modules/graphics/opengl/OpenGL.cpp | 7 +++---- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/modules/audio/openal/Pool.cpp b/src/modules/audio/openal/Pool.cpp index 8d239f4d7..3472c249c 100644 --- a/src/modules/audio/openal/Pool.cpp +++ b/src/modules/audio/openal/Pool.cpp @@ -98,11 +98,7 @@ bool Pool::isPlaying(Source *s) bool p = false; { thread::Lock lock(mutex); - for (auto i = playing.begin(); i != playing.end(); i++) - { - if (i->first == s) - p = true; - } + p = (playing.find(s) != playing.end()); } return p; } @@ -181,11 +177,11 @@ bool Pool::play(Source *source, ALuint &out) void Pool::stop() { thread::Lock lock(mutex); - for (auto i = playing.begin(); i != playing.end(); i++) + for (const auto &i : playing) { - i->first->stopAtomic(); - i->first->release(); - available.push(i->second); + i.first->stopAtomic(); + i.first->release(); + available.push(i.second); } playing.clear(); @@ -200,8 +196,8 @@ void Pool::stop(Source *source) void Pool::pause() { thread::Lock lock(mutex); - for (auto i = playing.begin(); i != playing.end(); i++) - i->first->pauseAtomic(); + for (const auto &i : playing) + i.first->pauseAtomic(); } void Pool::pause(Source *source) @@ -215,8 +211,8 @@ void Pool::pause(Source *source) void Pool::resume() { thread::Lock lock(mutex); - for (auto i = playing.begin(); i != playing.end(); i++) - i->first->resumeAtomic(); + for (const auto &i : playing) + i.first->resumeAtomic(); } void Pool::resume(Source *source) @@ -230,8 +226,8 @@ void Pool::resume(Source *source) void Pool::rewind() { thread::Lock lock(mutex); - for (auto i = playing.begin(); i != playing.end(); i++) - i->first->rewindAtomic(); + for (const auto &i : playing) + i.first->rewindAtomic(); } // For those times we don't need it backed. diff --git a/src/modules/graphics/Volatile.cpp b/src/modules/graphics/Volatile.cpp index 920d8668d..d97b1623a 100644 --- a/src/modules/graphics/Volatile.cpp +++ b/src/modules/graphics/Volatile.cpp @@ -43,26 +43,17 @@ Volatile::~Volatile() bool Volatile::loadAll() { bool success = true; - std::list::iterator i = all.begin(); - while (i != all.end()) - { - success = success && (*i)->loadVolatile(); - i++; - } + for (Volatile *v : all) + success = success && v->loadVolatile(); return success; } void Volatile::unloadAll() { - std::list::iterator i = all.begin(); - - while (i != all.end()) - { - (*i)->unloadVolatile(); - i++; - } + for (Volatile *v : all) + v->unloadVolatile(); } } // graphics diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index f45bed50d..9be31ae92 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -521,11 +521,10 @@ void OpenGL::deleteTexture(GLuint texture) { // glDeleteTextures binds texture 0 to all texture units the deleted texture // was bound to before deletion. - std::vector::iterator it; - for (it = state.textureUnits.begin(); it != state.textureUnits.end(); ++it) + for (GLuint &texid : state.textureUnits) { - if (*it == texture) - *it = 0; + if (texid == texture) + texid = 0; } glDeleteTextures(1, &texture); From 1449a81bdf8ac3c73e9d9746130c22cfbcea04c2 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 26 Aug 2014 22:16:01 -0300 Subject: [PATCH 2/2] Removed some dead code. --- src/modules/graphics/opengl/OpenGL.cpp | 34 -------------------------- src/modules/graphics/opengl/OpenGL.h | 5 ---- src/scripts/graphics.lua | 11 +++++---- src/scripts/graphics.lua.h | 20 +++++++-------- 4 files changed, 16 insertions(+), 54 deletions(-) diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index 9be31ae92..ec13d9b4f 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -661,40 +661,6 @@ void OpenGL::setTextureWrap(const graphics::Texture::Wrap &w) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gt); } -graphics::Texture::Wrap OpenGL::getTextureWrap() -{ - GLint gs, gt; - - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &gs); - glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, >); - - Texture::Wrap w; - - switch (gs) - { - case GL_CLAMP_TO_EDGE: - w.s = Texture::WRAP_CLAMP; - break; - case GL_REPEAT: - default: - w.s = Texture::WRAP_REPEAT; - break; - } - - switch (gt) - { - case GL_CLAMP_TO_EDGE: - w.t = Texture::WRAP_CLAMP; - break; - case GL_REPEAT: - default: - w.t = Texture::WRAP_REPEAT; - break; - } - - return w; -} - int OpenGL::getMaxTextureSize() const { return maxTextureSize; diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index 34f2146dc..9d9ad6497 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -274,11 +274,6 @@ public: **/ void setTextureWrap(const graphics::Texture::Wrap &w); - /** - * Returns the texture wrap mode for the currently bound texture. - **/ - graphics::Texture::Wrap getTextureWrap(); - /** * Returns the maximum supported width or height of a texture. **/ diff --git a/src/scripts/graphics.lua b/src/scripts/graphics.lua index 95bb8f236..e9e3659eb 100644 --- a/src/scripts/graphics.lua +++ b/src/scripts/graphics.lua @@ -1295,8 +1295,7 @@ do #define number float #define Image sampler2D #define extern uniform -#define Texel texture2D -#define love_Canvases gl_FragData]] +#define Texel texture2D]] local GLSL_UNIFORMS = [[ #define TransformMatrix gl_ModelViewMatrix @@ -1339,12 +1338,14 @@ void main() { #define PIXEL #define VaryingTexCoord gl_TexCoord[0] -#define VaryingColor gl_Color]], +#define VaryingColor gl_Color + +#define love_Canvases gl_FragData]], FOOTER = [[ void main() { // fix crashing issue in OSX when _tex0_ is unused within effect() - float dummy = texture2D(_tex0_, vec2(.5)).r; + float dummy = Texel(_tex0_, vec2(.5)).r; // See Shader::checkSetScreenParams in Shader.cpp. vec2 pixelcoord = vec2(gl_FragCoord.x, (gl_FragCoord.y * love_ScreenSize.z) + love_ScreenSize.w); @@ -1355,7 +1356,7 @@ void main() { FOOTER_MULTI_CANVAS = [[ void main() { // fix crashing issue in OSX when _tex0_ is unused within effect() - float dummy = texture2D(_tex0_, vec2(.5)).r; + float dummy = Texel(_tex0_, vec2(.5)).r; // See Shader::checkSetScreenParams in Shader.cpp. vec2 pixelcoord = vec2(gl_FragCoord.x, (gl_FragCoord.y * love_ScreenSize.z) + love_ScreenSize.w); diff --git a/src/scripts/graphics.lua.h b/src/scripts/graphics.lua.h index 6a3463cc6..8842ecaf4 100644 --- a/src/scripts/graphics.lua.h +++ b/src/scripts/graphics.lua.h @@ -6276,9 +6276,7 @@ const unsigned char graphics_lua[] = 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x20, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x0a, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x54, 0x65, 0x78, 0x65, 0x6c, 0x20, 0x74, 0x65, 0x78, 0x74, - 0x75, 0x72, 0x65, 0x32, 0x44, 0x0a, - 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x43, 0x61, 0x6e, 0x76, 0x61, - 0x73, 0x65, 0x73, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5d, 0x5d, 0x0a, + 0x75, 0x72, 0x65, 0x32, 0x44, 0x5d, 0x5d, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x20, 0x3d, 0x20, 0x5b, 0x5b, 0x0a, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72, 0x6d, 0x4d, @@ -6351,16 +6349,18 @@ const unsigned char graphics_lua[] = 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x20, 0x67, 0x6c, 0x5f, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x5b, 0x30, 0x5d, 0x0a, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x6c, - 0x6f, 0x72, 0x20, 0x67, 0x6c, 0x5f, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x5d, 0x5d, 0x2c, 0x0a, + 0x6f, 0x72, 0x20, 0x67, 0x6c, 0x5f, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x0a, + 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x43, 0x61, 0x6e, 0x76, 0x61, + 0x73, 0x65, 0x73, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5d, 0x5d, 0x2c, 0x0a, 0x09, 0x09, 0x46, 0x4f, 0x4f, 0x54, 0x45, 0x52, 0x20, 0x3d, 0x20, 0x5b, 0x5b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x20, 0x7b, 0x0a, 0x09, 0x2f, 0x2f, 0x20, 0x66, 0x69, 0x78, 0x20, 0x63, 0x72, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x69, 0x73, 0x73, 0x75, 0x65, 0x20, 0x69, 0x6e, 0x20, 0x4f, 0x53, 0x58, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x20, 0x69, 0x73, 0x20, 0x75, 0x6e, 0x75, 0x73, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x65, 0x66, 0x66, 0x65, 0x63, 0x74, 0x28, 0x29, 0x0a, - 0x09, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x28, 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x2c, 0x20, 0x76, 0x65, 0x63, - 0x32, 0x28, 0x2e, 0x35, 0x29, 0x29, 0x2e, 0x72, 0x3b, 0x0a, + 0x09, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x3d, 0x20, 0x54, 0x65, 0x78, + 0x65, 0x6c, 0x28, 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x2c, 0x20, 0x76, 0x65, 0x63, 0x32, 0x28, 0x2e, 0x35, + 0x29, 0x29, 0x2e, 0x72, 0x3b, 0x0a, 0x09, 0x2f, 0x2f, 0x20, 0x53, 0x65, 0x65, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x3a, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x53, 0x65, 0x74, 0x53, 0x63, 0x72, 0x65, 0x65, 0x6e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x2e, 0x63, 0x70, 0x70, 0x2e, 0x0a, @@ -6383,9 +6383,9 @@ const unsigned char graphics_lua[] = 0x73, 0x73, 0x75, 0x65, 0x20, 0x69, 0x6e, 0x20, 0x4f, 0x53, 0x58, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x20, 0x69, 0x73, 0x20, 0x75, 0x6e, 0x75, 0x73, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x65, 0x66, 0x66, 0x65, 0x63, 0x74, 0x28, 0x29, 0x0a, - 0x09, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x28, 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x2c, 0x20, 0x76, 0x65, 0x63, - 0x32, 0x28, 0x2e, 0x35, 0x29, 0x29, 0x2e, 0x72, 0x3b, 0x0a, + 0x09, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x64, 0x75, 0x6d, 0x6d, 0x79, 0x20, 0x3d, 0x20, 0x54, 0x65, 0x78, + 0x65, 0x6c, 0x28, 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x2c, 0x20, 0x76, 0x65, 0x63, 0x32, 0x28, 0x2e, 0x35, + 0x29, 0x29, 0x2e, 0x72, 0x3b, 0x0a, 0x09, 0x2f, 0x2f, 0x20, 0x53, 0x65, 0x65, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x3a, 0x3a, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x53, 0x65, 0x74, 0x53, 0x63, 0x72, 0x65, 0x65, 0x6e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x2e, 0x63, 0x70, 0x70, 0x2e, 0x0a,